From 94025aad6c31c86c4ee12b6e06c5ac2dd3b5dd55 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Jan 2020 12:20:31 +0100 Subject: [PATCH 001/675] base-sim: refactor common PIN/PUK unlock operations Keep the saved GError directly as GTask context, instead of allocating the SendPinPukContext unconditionally. --- src/mm-base-sim.c | 136 ++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 84 deletions(-) diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 8a5b4ee5..731fee3f 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -492,17 +492,6 @@ send_pin (MMBaseSim *self, /*****************************************************************************/ /* SEND PIN/PUK (common logic) */ -typedef struct { - GError *save_error; -} SendPinPukContext; - -static void -send_pin_puk_context_free (SendPinPukContext *ctx) -{ - g_clear_error (&ctx->save_error); - g_free (ctx); -} - static GError * error_for_unlock_check (MMModemLock lock) { @@ -536,17 +525,17 @@ error_for_unlock_check (MMModemLock lock) } gboolean -mm_base_sim_send_pin_finish (MMBaseSim *self, - GAsyncResult *res, - GError **error) +mm_base_sim_send_pin_finish (MMBaseSim *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } gboolean -mm_base_sim_send_puk_finish (MMBaseSim *self, - GAsyncResult *res, - GError **error) +mm_base_sim_send_puk_finish (MMBaseSim *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } @@ -554,13 +543,10 @@ mm_base_sim_send_puk_finish (MMBaseSim *self, static void update_lock_info_ready (MMIfaceModem *modem, GAsyncResult *res, - GTask *task) + GTask *task) { - SendPinPukContext *ctx; - GError *error = NULL; - MMModemLock lock; - - ctx = g_task_get_task_data (task); + GError *error = NULL; + MMModemLock lock; lock = mm_iface_modem_update_lock_info_finish (modem, res, &error); /* Even if we may be SIM-PIN2/PUK2 locked, we don't consider this an error @@ -568,15 +554,17 @@ update_lock_info_ready (MMIfaceModem *modem, if (lock != MM_MODEM_LOCK_NONE && lock != MM_MODEM_LOCK_SIM_PIN2 && lock != MM_MODEM_LOCK_SIM_PUK2) { + const GError *saved_error; + /* Device is locked. Now: * - If we got an error in the original send-pin action, report it. * - If we got an error in the pin-check action, report it. * - Otherwise, build our own error from the lock code. */ - if (ctx->save_error) { + saved_error = g_task_get_task_data (task); + if (saved_error) { g_clear_error (&error); - error = ctx->save_error; - ctx->save_error = NULL; + error = g_error_copy (saved_error); } else if (!error) error = error_for_unlock_check (lock); @@ -588,17 +576,16 @@ update_lock_info_ready (MMIfaceModem *modem, } static void -send_pin_ready (MMBaseSim *self, +send_pin_ready (MMBaseSim *self, GAsyncResult *res, - GTask *task) + GTask *task) { - SendPinPukContext *ctx; - MMModemLock known_lock = MM_MODEM_LOCK_UNKNOWN; + GError *error = NULL; + MMModemLock known_lock = MM_MODEM_LOCK_UNKNOWN; - ctx = g_task_get_task_data (task); - - if (!MM_BASE_SIM_GET_CLASS (self)->send_pin_finish (self, res, &ctx->save_error)) { - if (g_error_matches (ctx->save_error, + if (!MM_BASE_SIM_GET_CLASS (self)->send_pin_finish (self, res, &error)) { + g_task_set_task_data (task, error, (GDestroyNotify)g_error_free); + if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_SIM_PUK)) known_lock = MM_MODEM_LOCK_SIM_PUK; @@ -613,15 +600,14 @@ send_pin_ready (MMBaseSim *self, } static void -send_puk_ready (MMBaseSim *self, +send_puk_ready (MMBaseSim *self, GAsyncResult *res, - GTask *task) + GTask *task) { - SendPinPukContext *ctx; - - ctx = g_task_get_task_data (task); + GError *error = NULL; - MM_BASE_SIM_GET_CLASS (self)->send_puk_finish (self, res, &ctx->save_error); + if (!MM_BASE_SIM_GET_CLASS (self)->send_puk_finish (self, res, &error)) + g_task_set_task_data (task, error, (GDestroyNotify)g_error_free); /* Once pin/puk has been sent, recheck lock */ mm_iface_modem_update_lock_info (MM_IFACE_MODEM (self->priv->modem), @@ -631,73 +617,55 @@ send_puk_ready (MMBaseSim *self, } void -mm_base_sim_send_pin (MMBaseSim *self, - const gchar *pin, - GAsyncReadyCallback callback, - gpointer user_data) +mm_base_sim_send_pin (MMBaseSim *self, + const gchar *pin, + GAsyncReadyCallback callback, + gpointer user_data) { - SendPinPukContext *ctx; GTask *task; + task = g_task_new (self, NULL, callback, user_data); + /* If sending PIN is not implemented, report an error */ if (!MM_BASE_SIM_GET_CLASS (self)->send_pin || !MM_BASE_SIM_GET_CLASS (self)->send_pin_finish) { - g_task_report_new_error (self, - callback, - user_data, - mm_base_sim_send_pin, - MM_CORE_ERROR, - MM_CORE_ERROR_UNSUPPORTED, - "Cannot send PIN: " - "operation not supported"); + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "Cannot send PIN: operation not supported"); + g_object_unref (task); return; } - ctx = g_new0 (SendPinPukContext, 1); - - task = g_task_new (self, NULL, callback, user_data); - g_task_set_task_data (task, ctx, (GDestroyNotify)send_pin_puk_context_free); - MM_BASE_SIM_GET_CLASS (self)->send_pin (self, - pin, - (GAsyncReadyCallback)send_pin_ready, - task); + pin, + (GAsyncReadyCallback)send_pin_ready, + task); } void -mm_base_sim_send_puk (MMBaseSim *self, - const gchar *puk, - const gchar *new_pin, - GAsyncReadyCallback callback, - gpointer user_data) +mm_base_sim_send_puk (MMBaseSim *self, + const gchar *puk, + const gchar *new_pin, + GAsyncReadyCallback callback, + gpointer user_data) { - SendPinPukContext *ctx; GTask *task; + task = g_task_new (self, NULL, callback, user_data); + /* If sending PIN is not implemented, report an error */ if (!MM_BASE_SIM_GET_CLASS (self)->send_puk || !MM_BASE_SIM_GET_CLASS (self)->send_puk_finish) { - g_task_report_new_error (self, - callback, - user_data, - mm_base_sim_send_puk, - MM_CORE_ERROR, - MM_CORE_ERROR_UNSUPPORTED, - "Cannot send PUK: " - "operation not supported"); + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "Cannot send PUK: operation not supported"); + g_object_unref (task); return; } - ctx = g_new0 (SendPinPukContext, 1); - - task = g_task_new (self, NULL, callback, user_data); - g_task_set_task_data (task, ctx, (GDestroyNotify)send_pin_puk_context_free); - MM_BASE_SIM_GET_CLASS (self)->send_puk (self, - puk, - new_pin, - (GAsyncReadyCallback)send_puk_ready, - task); + puk, + new_pin, + (GAsyncReadyCallback)send_puk_ready, + task); } /*****************************************************************************/ From b6add181572d93d35cc53631f8c311ce33474f20 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Jan 2020 12:25:17 +0100 Subject: [PATCH 002/675] iface-modem-simple: don't abort connection attempt if SIM-PUK2 locked --- src/mm-iface-modem-simple.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mm-iface-modem-simple.c b/src/mm-iface-modem-simple.c index ac845d76..ccf4ecc6 100644 --- a/src/mm-iface-modem-simple.c +++ b/src/mm-iface-modem-simple.c @@ -432,10 +432,11 @@ update_lock_info_ready (MMIfaceModem *self, } /* If we are already unlocked, go on to next step. Note that we do also - * allow SIM-PIN2, as we don't need to unlock that in order to get + * allow SIM-PIN2/SIM-PUK2, as we don't need to unlock that in order to get * connected. */ if (lock == MM_MODEM_LOCK_NONE || - lock == MM_MODEM_LOCK_SIM_PIN2) { + lock == MM_MODEM_LOCK_SIM_PIN2 || + lock == MM_MODEM_LOCK_SIM_PUK2) { ctx->step++; connection_step (ctx); return; From 634bb1caac878c7e26a6b5179f779ffd34478622 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Jan 2020 12:34:28 +0100 Subject: [PATCH 003/675] base-sim: avoid using 'self' to refer to the modem --- src/mm-base-sim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 731fee3f..560db93d 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -155,13 +155,13 @@ handle_change_pin_context_free (HandleChangePinContext *ctx) } static void -after_change_update_lock_info_ready (MMIfaceModem *self, +after_change_update_lock_info_ready (MMIfaceModem *modem, GAsyncResult *res, HandleChangePinContext *ctx) { /* We just want to ensure that we tried to update the unlock * retries, no big issue if it failed */ - mm_iface_modem_update_lock_info_finish (self, res, NULL); + mm_iface_modem_update_lock_info_finish (modem, res, NULL); if (ctx->save_error) { g_dbus_method_invocation_take_error (ctx->invocation, ctx->save_error); From 9f192be632b388522088c5efa2e26fe293090707 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Jan 2020 12:45:41 +0100 Subject: [PATCH 004/675] iface-modem: allow loading current required lock info --- src/mm-iface-modem.c | 18 ++++++++++++++++++ src/mm-iface-modem.h | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 624a4ee4..b2272cb9 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -3171,6 +3171,24 @@ set_lock_status (MMIfaceModem *self, } } +MMModemLock +mm_iface_modem_get_unlock_required (MMIfaceModem *self) +{ + MmGdbusModem *skeleton = NULL; + MMModemLock lock; + + g_object_get (self, + MM_IFACE_MODEM_DBUS_SKELETON, &skeleton, + NULL); + if (skeleton) { + lock = mm_gdbus_modem_get_unlock_required (skeleton); + g_object_unref (skeleton); + } else + lock = MM_MODEM_LOCK_UNKNOWN; + + return lock; +} + MMUnlockRetries * mm_iface_modem_get_unlock_retries (MMIfaceModem *self) { diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index c4aba7aa..4cb68608 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -460,7 +460,8 @@ MMModemLock mm_iface_modem_update_lock_info_finish (MMIfaceModem *self, GAsyncResult *res, GError **error); -MMUnlockRetries *mm_iface_modem_get_unlock_retries (MMIfaceModem *self); +MMModemLock mm_iface_modem_get_unlock_required (MMIfaceModem *self); +MMUnlockRetries *mm_iface_modem_get_unlock_retries (MMIfaceModem *self); void mm_iface_modem_update_unlock_retries (MMIfaceModem *self, MMUnlockRetries *unlock_retries); From fd052c8e584a41efc211690e993f6ef0ee3092ac Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Jan 2020 12:46:11 +0100 Subject: [PATCH 005/675] base-sim: don't allow sending PIN/PUK if not required This avoids issues when e.g. sending SIM-PIN while the modem is already unlocked or when SIM-PIN is not enabled. Under those conditions, the needlessly sent SIM-PIN unlock attempt may fail while libmm-glib/mmcli reports a successful operation. E.g.: # mmcli --sim=/org/freedesktop/ModemManager1/SIM/0 --pin=3497 successfully sent PIN code to the SIM But in reality... Wed Nov 20 14:38:52 2019 daemon.debug [4254]: [1574260732.489513] Verifying PIN... Wed Nov 20 14:38:52 2019 daemon.debug [4254]: [/dev/cdc-wdm0] sent message... <<<<<< RAW: <<<<<< length = 27 <<<<<< data = 01:1A:00:00:0B:02:00:09:00:26:00:0E:00:02:06:00:01:04:33:34:39:37:01:02:00:06:00 Wed Nov 20 14:38:52 2019 daemon.debug [4254]: [/dev/cdc-wdm0] sent generic request (translated)... <<<<<< QMUX: <<<<<< length = 26 <<<<<< flags = 0x00 <<<<<< service = "uim" <<<<<< client = 2 <<<<<< QMI: <<<<<< flags = "none" <<<<<< transaction = 9 <<<<<< tlv_length = 14 <<<<<< message = "Verify PIN" (0x0026) <<<<<< TLV: <<<<<< type = "Info" (0x02) <<<<<< length = 6 <<<<<< value = 01:04:33:34:39:37 <<<<<< translated = [ pin_id = 'pin1' pin_value = '3497' ] Wed Nov 20 14:38:52 2019 daemon.debug [4254]: [/dev/cdc-wdm0] received message... <<<<<< RAW: <<<<<< length = 30 <<<<<< data = 01:1D:00:80:0B:02:02:09:00:26:00:11:00:02:04:00:01:00:52:00:13:02:00:69:84:10:02:00:03:0A Wed Nov 20 14:38:52 2019 daemon.debug [4254]: [/dev/cdc-wdm0] received generic response (translated)... <<<<<< QMUX: <<<<<< length = 29 <<<<<< flags = 0x80 <<<<<< service = "uim" <<<<<< client = 2 <<<<<< QMI: <<<<<< flags = "response" <<<<<< transaction = 9 <<<<<< tlv_length = 17 <<<<<< message = "Verify PIN" (0x0026) <<<<<< TLV: <<<<<< type = "Result" (0x02) <<<<<< length = 4 <<<<<< value = 01:00:52:00 <<<<<< translated = FAILURE: AccessDenied As we already know what the current lock status is, just abort the user operation if the unlock operation isn't required. --- src/mm-base-sim.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 560db93d..7eca8e4a 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -635,6 +635,14 @@ mm_base_sim_send_pin (MMBaseSim *self, return; } + /* Only allow sending SIM-PIN if really SIM-PIN locked */ + if (mm_iface_modem_get_unlock_required (MM_IFACE_MODEM (self->priv->modem)) != MM_MODEM_LOCK_SIM_PIN) { + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, + "Cannot send PIN: device is not SIM-PIN locked"); + g_object_unref (task); + return; + } + MM_BASE_SIM_GET_CLASS (self)->send_pin (self, pin, (GAsyncReadyCallback)send_pin_ready, @@ -661,6 +669,14 @@ mm_base_sim_send_puk (MMBaseSim *self, return; } + /* Only allow sending SIM-PUK if really SIM-PUK locked */ + if (mm_iface_modem_get_unlock_required (MM_IFACE_MODEM (self->priv->modem)) != MM_MODEM_LOCK_SIM_PUK) { + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, + "Cannot send PUK: device is not SIM-PUK locked"); + g_object_unref (task); + return; + } + MM_BASE_SIM_GET_CLASS (self)->send_puk (self, puk, new_pin, From 5da33df35b3266f8905578c56a43a56d79726602 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 26 Feb 2020 13:12:20 +0100 Subject: [PATCH 006/675] huawei: avoid attempting to complete GTask twice --- plugins/huawei/mm-plugin-huawei.c | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/huawei/mm-plugin-huawei.c b/plugins/huawei/mm-plugin-huawei.c index 58de1eea..26bf3f2a 100644 --- a/plugins/huawei/mm-plugin-huawei.c +++ b/plugins/huawei/mm-plugin-huawei.c @@ -261,7 +261,6 @@ huawei_custom_init_step (GTask *task) if (g_task_return_error_if_cancelled (task)) { mm_dbg ("(Huawei) no need to keep on running custom init in (%s)", mm_port_get_device (MM_PORT (ctx->port))); - g_task_return_boolean (task, TRUE); g_object_unref (task); return; } From 9ef84d2cff27e99c2e805d636528d1740bc4985a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 27 Dec 2019 22:24:24 +0100 Subject: [PATCH 007/675] kerneldevice: support reading interface 'description' --- src/kerneldevice/mm-kernel-device-generic.c | 93 +++++++++++++-------- src/kerneldevice/mm-kernel-device-udev.c | 13 +++ src/kerneldevice/mm-kernel-device.c | 10 +++ src/kerneldevice/mm-kernel-device.h | 18 ++-- 4 files changed, 90 insertions(+), 44 deletions(-) diff --git a/src/kerneldevice/mm-kernel-device-generic.c b/src/kerneldevice/mm-kernel-device-generic.c index c32831d7..b6e4e2df 100644 --- a/src/kerneldevice/mm-kernel-device-generic.c +++ b/src/kerneldevice/mm-kernel-device-generic.c @@ -59,6 +59,7 @@ struct _MMKernelDeviceGenericPrivate { guint8 interface_subclass; guint8 interface_protocol; guint8 interface_number; + gchar *interface_description; gchar *physdev_sysfs_path; guint16 physdev_vid; guint16 physdev_pid; @@ -424,23 +425,34 @@ preload_interface_number (MMKernelDeviceGeneric *self) g_object_set_data_full (G_OBJECT (self), "ID_USB_INTERFACE_NUM", g_strdup_printf ("%02x", self->priv->interface_number), g_free); } +static void +preload_interface_description (MMKernelDeviceGeneric *self) +{ + self->priv->interface_description = (self->priv->interface_sysfs_path ? read_sysfs_property_as_string (self->priv->interface_sysfs_path, "interface") : NULL); + mm_dbg ("(%s/%s) interface description: %s", + mm_kernel_event_properties_get_subsystem (self->priv->properties), + mm_kernel_event_properties_get_name (self->priv->properties), + self->priv->interface_description ? self->priv->interface_description : "unknown"); +} + static void preload_contents (MMKernelDeviceGeneric *self) { - preload_sysfs_path (self); - preload_interface_sysfs_path (self); - preload_interface_class (self); - preload_interface_subclass (self); - preload_interface_protocol (self); - preload_interface_number (self); - preload_physdev_sysfs_path (self); - preload_manufacturer (self); - preload_product (self); - preload_driver (self); - preload_physdev_vid (self); - preload_physdev_pid (self); - preload_physdev_revision (self); - preload_physdev_subsystem (self); + preload_sysfs_path (self); + preload_interface_sysfs_path (self); + preload_interface_class (self); + preload_interface_subclass (self); + preload_interface_protocol (self); + preload_interface_number (self); + preload_interface_description (self); + preload_physdev_sysfs_path (self); + preload_manufacturer (self); + preload_product (self); + preload_driver (self); + preload_physdev_vid (self); + preload_physdev_pid (self); + preload_physdev_revision (self); + preload_physdev_subsystem (self); } /*****************************************************************************/ @@ -501,6 +513,14 @@ kernel_device_get_interface_sysfs_path (MMKernelDevice *self) return MM_KERNEL_DEVICE_GENERIC (self)->priv->interface_sysfs_path; } +static const gchar * +kernel_device_get_interface_description (MMKernelDevice *self) +{ + g_return_val_if_fail (MM_IS_KERNEL_DEVICE_GENERIC (self), NULL); + + return MM_KERNEL_DEVICE_GENERIC (self)->priv->interface_description; +} + static const gchar * kernel_device_get_physdev_uid (MMKernelDevice *self) { @@ -1115,28 +1135,29 @@ mm_kernel_device_generic_class_init (MMKernelDeviceGenericClass *klass) object_class->get_property = get_property; object_class->set_property = set_property; - kernel_device_class->get_subsystem = kernel_device_get_subsystem; - kernel_device_class->get_name = kernel_device_get_name; - kernel_device_class->get_driver = kernel_device_get_driver; - kernel_device_class->get_sysfs_path = kernel_device_get_sysfs_path; - kernel_device_class->get_physdev_uid = kernel_device_get_physdev_uid; - kernel_device_class->get_physdev_vid = kernel_device_get_physdev_vid; - kernel_device_class->get_physdev_pid = kernel_device_get_physdev_pid; - kernel_device_class->get_physdev_revision = kernel_device_get_physdev_revision; - kernel_device_class->get_physdev_sysfs_path = kernel_device_get_physdev_sysfs_path; - kernel_device_class->get_physdev_subsystem = kernel_device_get_physdev_subsystem; - kernel_device_class->get_physdev_manufacturer = kernel_device_get_physdev_manufacturer; - kernel_device_class->get_physdev_product = kernel_device_get_physdev_product; - kernel_device_class->get_interface_class = kernel_device_get_interface_class; - kernel_device_class->get_interface_subclass = kernel_device_get_interface_subclass; - kernel_device_class->get_interface_protocol = kernel_device_get_interface_protocol; - kernel_device_class->get_interface_sysfs_path = kernel_device_get_interface_sysfs_path; - kernel_device_class->cmp = kernel_device_cmp; - kernel_device_class->has_property = kernel_device_has_property; - kernel_device_class->get_property = kernel_device_get_property; - kernel_device_class->get_property_as_boolean = kernel_device_get_property_as_boolean; - kernel_device_class->get_property_as_int = kernel_device_get_property_as_int; - kernel_device_class->get_property_as_int_hex = kernel_device_get_property_as_int_hex; + kernel_device_class->get_subsystem = kernel_device_get_subsystem; + kernel_device_class->get_name = kernel_device_get_name; + kernel_device_class->get_driver = kernel_device_get_driver; + kernel_device_class->get_sysfs_path = kernel_device_get_sysfs_path; + kernel_device_class->get_physdev_uid = kernel_device_get_physdev_uid; + kernel_device_class->get_physdev_vid = kernel_device_get_physdev_vid; + kernel_device_class->get_physdev_pid = kernel_device_get_physdev_pid; + kernel_device_class->get_physdev_revision = kernel_device_get_physdev_revision; + kernel_device_class->get_physdev_sysfs_path = kernel_device_get_physdev_sysfs_path; + kernel_device_class->get_physdev_subsystem = kernel_device_get_physdev_subsystem; + kernel_device_class->get_physdev_manufacturer = kernel_device_get_physdev_manufacturer; + kernel_device_class->get_physdev_product = kernel_device_get_physdev_product; + kernel_device_class->get_interface_class = kernel_device_get_interface_class; + kernel_device_class->get_interface_subclass = kernel_device_get_interface_subclass; + kernel_device_class->get_interface_protocol = kernel_device_get_interface_protocol; + kernel_device_class->get_interface_sysfs_path = kernel_device_get_interface_sysfs_path; + kernel_device_class->get_interface_description = kernel_device_get_interface_description; + kernel_device_class->cmp = kernel_device_cmp; + kernel_device_class->has_property = kernel_device_has_property; + kernel_device_class->get_property = kernel_device_get_property; + kernel_device_class->get_property_as_boolean = kernel_device_get_property_as_boolean; + kernel_device_class->get_property_as_int = kernel_device_get_property_as_int; + kernel_device_class->get_property_as_int_hex = kernel_device_get_property_as_int_hex; /* Device-wide properties are stored per-port in the generic backend */ kernel_device_class->has_global_property = kernel_device_has_property; diff --git a/src/kerneldevice/mm-kernel-device-udev.c b/src/kerneldevice/mm-kernel-device-udev.c index 6ca50dc3..3dc3eeb7 100644 --- a/src/kerneldevice/mm-kernel-device-udev.c +++ b/src/kerneldevice/mm-kernel-device-udev.c @@ -534,6 +534,18 @@ kernel_device_get_interface_sysfs_path (MMKernelDevice *_self) return (self->priv->parent ? g_udev_device_get_sysfs_path (self->priv->parent) : NULL); } +static const gchar * +kernel_device_get_interface_description (MMKernelDevice *_self) +{ + MMKernelDeviceUdev *self; + + g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), NULL); + + self = MM_KERNEL_DEVICE_UDEV (_self); + ensure_parent (self); + return (self->priv->parent ? g_udev_device_get_sysfs_attr (self->priv->parent, "interface") : NULL); +} + static gboolean kernel_device_cmp (MMKernelDevice *_a, MMKernelDevice *_b) @@ -935,6 +947,7 @@ mm_kernel_device_udev_class_init (MMKernelDeviceUdevClass *klass) kernel_device_class->get_interface_subclass = kernel_device_get_interface_subclass; kernel_device_class->get_interface_protocol = kernel_device_get_interface_protocol; kernel_device_class->get_interface_sysfs_path = kernel_device_get_interface_sysfs_path; + kernel_device_class->get_interface_description = kernel_device_get_interface_description; kernel_device_class->cmp = kernel_device_cmp; kernel_device_class->has_property = kernel_device_has_property; kernel_device_class->get_property = kernel_device_get_property; diff --git a/src/kerneldevice/mm-kernel-device.c b/src/kerneldevice/mm-kernel-device.c index 35c840a8..e52ae67e 100644 --- a/src/kerneldevice/mm-kernel-device.c +++ b/src/kerneldevice/mm-kernel-device.c @@ -183,6 +183,16 @@ mm_kernel_device_get_interface_sysfs_path (MMKernelDevice *self) NULL); } +const gchar * +mm_kernel_device_get_interface_description (MMKernelDevice *self) +{ + g_return_val_if_fail (MM_IS_KERNEL_DEVICE (self), NULL); + + return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_interface_description ? + MM_KERNEL_DEVICE_GET_CLASS (self)->get_interface_description (self) : + NULL); +} + gboolean mm_kernel_device_cmp (MMKernelDevice *a, MMKernelDevice *b) diff --git a/src/kerneldevice/mm-kernel-device.h b/src/kerneldevice/mm-kernel-device.h index 6e66d4d2..c66b23dd 100644 --- a/src/kerneldevice/mm-kernel-device.h +++ b/src/kerneldevice/mm-kernel-device.h @@ -41,10 +41,11 @@ struct _MMKernelDeviceClass { const gchar * (* get_driver) (MMKernelDevice *self); const gchar * (* get_sysfs_path) (MMKernelDevice *self); - gint (* get_interface_class) (MMKernelDevice *self); - gint (* get_interface_subclass) (MMKernelDevice *self); - gint (* get_interface_protocol) (MMKernelDevice *self); - const gchar * (* get_interface_sysfs_path) (MMKernelDevice *self); + gint (* get_interface_class) (MMKernelDevice *self); + gint (* get_interface_subclass) (MMKernelDevice *self); + gint (* get_interface_protocol) (MMKernelDevice *self); + const gchar * (* get_interface_sysfs_path) (MMKernelDevice *self); + const gchar * (* get_interface_description) (MMKernelDevice *self); const gchar * (* get_physdev_uid) (MMKernelDevice *self); guint16 (* get_physdev_vid) (MMKernelDevice *self); @@ -77,10 +78,11 @@ const gchar *mm_kernel_device_get_name (MMKernelDevice *self); const gchar *mm_kernel_device_get_driver (MMKernelDevice *self); const gchar *mm_kernel_device_get_sysfs_path (MMKernelDevice *self); -gint mm_kernel_device_get_interface_class (MMKernelDevice *self); -gint mm_kernel_device_get_interface_subclass (MMKernelDevice *self); -gint mm_kernel_device_get_interface_protocol (MMKernelDevice *self); -const gchar *mm_kernel_device_get_interface_sysfs_path (MMKernelDevice *self); +gint mm_kernel_device_get_interface_class (MMKernelDevice *self); +gint mm_kernel_device_get_interface_subclass (MMKernelDevice *self); +gint mm_kernel_device_get_interface_protocol (MMKernelDevice *self); +const gchar *mm_kernel_device_get_interface_sysfs_path (MMKernelDevice *self); +const gchar *mm_kernel_device_get_interface_description (MMKernelDevice *self); const gchar *mm_kernel_device_get_physdev_uid (MMKernelDevice *self); guint16 mm_kernel_device_get_physdev_vid (MMKernelDevice *self); From 353e27065dc9d8cf95e0ad81e14aae61648e2c85 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 27 Dec 2019 22:47:36 +0100 Subject: [PATCH 008/675] huawei: try to read port type hints from interface descriptions So far, we're really only interested in the "modem" and "pcui" ports. root@9d52738:/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4# find . -name interface|sort ./1-1.4:2.0/interface ./1-1.4:2.1/interface ./1-1.4:2.2/interface ./1-1.4:2.3/interface ./1-1.4:2.4/interface ./1-1.4:2.5/interface ./1-1.4:2.6/interface root@9d52738:/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4# find . -name interface|sort|xargs cat CDC Ethernet Control Model (ECM) CDC Ethernet Data Huawei Mobile Connect - Modem Huawei Mobile Connect - Application Huawei Mobile Connect - Pcui Huawei Mobile Connect - Ctrl Huawei Mobile Connect - Serial B Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/issues/170 --- plugins/huawei/mm-plugin-huawei.c | 63 +++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/plugins/huawei/mm-plugin-huawei.c b/plugins/huawei/mm-plugin-huawei.c index 26bf3f2a..2fd73995 100644 --- a/plugins/huawei/mm-plugin-huawei.c +++ b/plugins/huawei/mm-plugin-huawei.c @@ -421,42 +421,67 @@ static void propagate_port_mode_results (GList *probes) { MMDevice *device; - GList *l; - gboolean primary_flagged = FALSE; + GList *l; + gboolean primary_flagged = FALSE; g_assert (probes != NULL); - device = mm_port_probe_peek_device (MM_PORT_PROBE (probes->data)); /* Now we propagate the tags to the specific port probes */ + device = mm_port_probe_peek_device (MM_PORT_PROBE (probes->data)); for (l = probes; l; l = g_list_next (l)) { - MMPortSerialAtFlag at_port_flags = MM_PORT_SERIAL_AT_FLAG_NONE; - guint usbif; + MMPortSerialAtFlag at_port_flags = MM_PORT_SERIAL_AT_FLAG_NONE; + MMPortProbe *probe; + guint usbif; + const gchar *description; + + probe = MM_PORT_PROBE (l->data); - usbif = mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (MM_PORT_PROBE (l->data)), "ID_USB_INTERFACE_NUM"); + /* Tags only applicable to AT ports */ + if (!mm_port_probe_is_at (probe)) + goto next; + /* Port type hints from AT^GETPORTMODE */ + usbif = mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (probe), "ID_USB_INTERFACE_NUM"); if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED))) { if (usbif + 1 == GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_PCUI_PORT))) { at_port_flags = MM_PORT_SERIAL_AT_FLAG_PRIMARY; primary_flagged = TRUE; - } else if (usbif + 1 == GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_MODEM_PORT))) + } else if (usbif + 1 == GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_MODEM_PORT))) { at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP; - else if (!g_object_get_data (G_OBJECT (device), TAG_HUAWEI_MODEM_PORT) && - usbif + 1 == GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_NDIS_PORT))) + } else if (!g_object_get_data (G_OBJECT (device), TAG_HUAWEI_MODEM_PORT) && + usbif + 1 == GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_NDIS_PORT))) { /* If NDIS reported only instead of MDM, use it */ at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP; - } else if (usbif == 0 && - mm_port_probe_is_at (MM_PORT_PROBE (l->data))) { - /* If GETPORTMODE is not supported, we assume usbif 0 is the modem port */ - at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP; + } + goto next; + } + + /* Port type hints from interface description */ + description = mm_kernel_device_get_interface_description (mm_port_probe_peek_port (probe)); + if (description) { + gchar *lower_description; - /* /\* TODO. */ - /* * For CDMA modems we assume usbif0 is both primary and PPP, since */ - /* * they don't have problems with talking on secondary ports. */ - /* *\/ */ - /* if (caps & CAP_CDMA) */ - /* pflags |= MM_PORT_SERIAL_AT_FLAG_PRIMARY; */ + mm_dbg ("(Huawei) %s interface description: %s", mm_port_probe_get_port_name (probe), description); + + lower_description = g_ascii_strdown (description, -1); + if (strstr (lower_description, "modem")) + at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP; + else if (strstr (lower_description, "pcui")) { + at_port_flags = MM_PORT_SERIAL_AT_FLAG_PRIMARY; + primary_flagged = TRUE; + } + g_free (lower_description); + goto next; + } + + /* If GETPORTMODE unsupported and no other port type hints, we assume + * usbif 0 is the modem port */ + if (usbif == 0) { + at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP; + goto next; } + next: g_object_set_data (G_OBJECT (l->data), TAG_AT_PORT_FLAGS, GUINT_TO_POINTER (at_port_flags)); } From 6eabfd27bf3c4c53d7779722b46e7261d22c1d92 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 21 Jan 2020 12:21:28 +0100 Subject: [PATCH 009/675] huawei: only tag GETPORTMODE supported if it was really used E.g. do nothing if the response is empty: (ttyUSB1): -->'AT^GETPORTMODE' (ttyUSB1): <--'^GETPORTMODE: TYPE: WCDMA: Huawei Technologies Co.,Ltd.,OK' --- plugins/huawei/mm-plugin-huawei.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/plugins/huawei/mm-plugin-huawei.c b/plugins/huawei/mm-plugin-huawei.c index 2fd73995..09189058 100644 --- a/plugins/huawei/mm-plugin-huawei.c +++ b/plugins/huawei/mm-plugin-huawei.c @@ -99,7 +99,7 @@ huawei_custom_init_finish (MMPortProbe *probe, static void huawei_custom_init_step (GTask *task); -static void +static gboolean cache_port_mode (MMDevice *device, const gchar *reply, const gchar *type, @@ -114,9 +114,12 @@ cache_port_mode (MMDevice *device, errno = 0; /* shift by 1 so NULL return from g_object_get_data() means no tag */ i = 1 + strtol (p + strlen (type), NULL, 10); - if (i > 0 && i < 256 && errno == 0) - g_object_set_data (G_OBJECT (device), tag, GUINT_TO_POINTER ((guint) i)); + if (i > 0 && i < 256 && errno == 0) { + g_object_set_data (G_OBJECT (device), tag, GINT_TO_POINTER ((gint) i)); + return TRUE; + } } + return FALSE; } static void @@ -146,20 +149,22 @@ getportmode_ready (MMPortSerialAt *port, /* Port mode not supported */ } else { MMDevice *device; + guint n_cached_port_modes = 0; mm_dbg ("(Huawei) port mode layout retrieved"); /* Results are cached in the parent device object */ device = mm_port_probe_peek_device (ctx->probe); - cache_port_mode (device, response, "PCUI:", TAG_HUAWEI_PCUI_PORT); - cache_port_mode (device, response, "MDM:", TAG_HUAWEI_MODEM_PORT); - cache_port_mode (device, response, "NDIS:", TAG_HUAWEI_NDIS_PORT); - cache_port_mode (device, response, "DIAG:", TAG_HUAWEI_DIAG_PORT); + n_cached_port_modes += cache_port_mode (device, response, "PCUI:", TAG_HUAWEI_PCUI_PORT); + n_cached_port_modes += cache_port_mode (device, response, "MDM:", TAG_HUAWEI_MODEM_PORT); + n_cached_port_modes += cache_port_mode (device, response, "NDIS:", TAG_HUAWEI_NDIS_PORT); + n_cached_port_modes += cache_port_mode (device, response, "DIAG:", TAG_HUAWEI_DIAG_PORT); /* GETPORTMODE response format in newer devices... (e.g. E3372) */ - cache_port_mode (device, response, "pcui:", TAG_HUAWEI_PCUI_PORT); - cache_port_mode (device, response, "modem:", TAG_HUAWEI_MODEM_PORT); + n_cached_port_modes += cache_port_mode (device, response, "pcui:", TAG_HUAWEI_PCUI_PORT); + n_cached_port_modes += cache_port_mode (device, response, "modem:", TAG_HUAWEI_MODEM_PORT); - g_object_set_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED, GUINT_TO_POINTER (TRUE)); + if (n_cached_port_modes > 0) + g_object_set_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED, GUINT_TO_POINTER (TRUE)); /* Mark port as being AT already */ mm_port_probe_set_result_at (ctx->probe, TRUE); From b9e6f30ba835f5019db55d98631f6571fdc575ef Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 20 Feb 2020 16:11:42 +0100 Subject: [PATCH 010/675] kerneldevice,udev: don't assume interface is the direct parent object E.g. it may be one more layer up: looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8.4/1-8.4:1.1/ttyUSB1/tty/ttyUSB1': KERNEL=="ttyUSB1" SUBSYSTEM=="tty" DRIVER=="" looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8.4/1-8.4:1.1/ttyUSB1': KERNELS=="ttyUSB1" SUBSYSTEMS=="usb-serial" DRIVERS=="option1" ATTRS{port_number}=="0" looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8.4/1-8.4:1.1': KERNELS=="1-8.4:1.1" SUBSYSTEMS=="usb" DRIVERS=="option" ATTRS{bNumEndpoints}=="02" ATTRS{supports_autosuspend}=="1" ATTRS{bInterfaceNumber}=="01" ATTRS{bAlternateSetting}==" 0" ATTRS{bInterfaceSubClass}=="06" ATTRS{bInterfaceProtocol}=="13" ATTRS{interface}=="Huawei Mobile Connect - Application" ATTRS{bInterfaceClass}=="ff" ATTRS{authorized}=="1" --- src/kerneldevice/mm-kernel-device-udev.c | 62 ++++++++++++++++++------ 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/src/kerneldevice/mm-kernel-device-udev.c b/src/kerneldevice/mm-kernel-device-udev.c index 3dc3eeb7..620d1441 100644 --- a/src/kerneldevice/mm-kernel-device-udev.c +++ b/src/kerneldevice/mm-kernel-device-udev.c @@ -39,7 +39,7 @@ static GParamSpec *properties[PROP_LAST]; struct _MMKernelDeviceUdevPrivate { GUdevDevice *device; - GUdevDevice *parent; + GUdevDevice *interface; GUdevDevice *physdev; guint16 vendor; guint16 product; @@ -263,12 +263,42 @@ ensure_physdev (MMKernelDeviceUdev *self) /*****************************************************************************/ static void -ensure_parent (MMKernelDeviceUdev *self) +ensure_interface (MMKernelDeviceUdev *self) { - if (self->priv->parent) + GUdevDevice *new_parent; + GUdevDevice *parent; + + if (self->priv->interface) return; - if (self->priv->device) - self->priv->parent = g_udev_device_get_parent (self->priv->device); + + if (!self->priv->device) + return; + + ensure_physdev (self); + + parent = g_udev_device_get_parent (self->priv->device); + while (1) { + /* Abort if no parent found */ + if (!parent) + break; + + /* Look for the first parent that is a USB interface (i.e. has + * bInterfaceClass) */ + if (g_udev_device_has_sysfs_attr (parent, "bInterfaceClass")) { + self->priv->interface = parent; + break; + } + + /* If unknown physdev, just stop right away */ + if (!self->priv->physdev || parent == self->priv->physdev) { + g_object_unref (parent); + break; + } + + new_parent = g_udev_device_get_parent (parent); + g_object_unref (parent); + parent = new_parent; + } } /*****************************************************************************/ @@ -494,8 +524,8 @@ kernel_device_get_interface_class (MMKernelDevice *_self) g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), -1); self = MM_KERNEL_DEVICE_UDEV (_self); - ensure_parent (self); - return (self->priv->parent ? g_udev_device_get_sysfs_attr_as_int (self->priv->parent, "bInterfaceClass") : -1); + ensure_interface (self); + return (self->priv->interface ? g_udev_device_get_sysfs_attr_as_int (self->priv->interface, "bInterfaceClass") : -1); } static gint @@ -506,8 +536,8 @@ kernel_device_get_interface_subclass (MMKernelDevice *_self) g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), -1); self = MM_KERNEL_DEVICE_UDEV (_self); - ensure_parent (self); - return (self->priv->parent ? g_udev_device_get_sysfs_attr_as_int (self->priv->parent, "bInterfaceSubClass") : -1); + ensure_interface (self); + return (self->priv->interface ? g_udev_device_get_sysfs_attr_as_int (self->priv->interface, "bInterfaceSubClass") : -1); } static gint @@ -518,8 +548,8 @@ kernel_device_get_interface_protocol (MMKernelDevice *_self) g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), -1); self = MM_KERNEL_DEVICE_UDEV (_self); - ensure_parent (self); - return (self->priv->parent ? g_udev_device_get_sysfs_attr_as_int (self->priv->parent, "bInterfaceProtocol") : -1); + ensure_interface (self); + return (self->priv->interface ? g_udev_device_get_sysfs_attr_as_int (self->priv->interface, "bInterfaceProtocol") : -1); } static const gchar * @@ -530,8 +560,8 @@ kernel_device_get_interface_sysfs_path (MMKernelDevice *_self) g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), NULL); self = MM_KERNEL_DEVICE_UDEV (_self); - ensure_parent (self); - return (self->priv->parent ? g_udev_device_get_sysfs_path (self->priv->parent) : NULL); + ensure_interface (self); + return (self->priv->interface ? g_udev_device_get_sysfs_path (self->priv->interface) : NULL); } static const gchar * @@ -542,8 +572,8 @@ kernel_device_get_interface_description (MMKernelDevice *_self) g_return_val_if_fail (MM_IS_KERNEL_DEVICE_UDEV (_self), NULL); self = MM_KERNEL_DEVICE_UDEV (_self); - ensure_parent (self); - return (self->priv->parent ? g_udev_device_get_sysfs_attr (self->priv->parent, "interface") : NULL); + ensure_interface (self); + return (self->priv->interface ? g_udev_device_get_sysfs_attr (self->priv->interface, "interface") : NULL); } static gboolean @@ -906,7 +936,7 @@ dispose (GObject *object) MMKernelDeviceUdev *self = MM_KERNEL_DEVICE_UDEV (object); g_clear_object (&self->priv->physdev); - g_clear_object (&self->priv->parent); + g_clear_object (&self->priv->interface); g_clear_object (&self->priv->device); g_clear_object (&self->priv->properties); From a6a721f3a8e010c0eefd7e38c4781f6e1a0c1e89 Mon Sep 17 00:00:00 2001 From: Milo Casagrande Date: Tue, 10 Mar 2020 20:16:15 +0100 Subject: [PATCH 011/675] l10n: Update Italian translation Signed-off-by: Milo Casagrande --- po/it.po | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/po/it.po b/po/it.po index a15f5039..91abf4a4 100644 --- a/po/it.po +++ b/po/it.po @@ -1,14 +1,14 @@ # Italian translation for ModemManager. -# Copyright (C) 2018 ModemManager's COPYRIGHT HOLDER +# Copyright (C) 2018, 2020 ModemManager's COPYRIGHT HOLDER # This file is distributed under the same license as the ModemManager package. -# Milo Casagrande , 2018. +# Milo Casagrande , 2018, 2020. # msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" "POT-Creation-Date: 2019-09-25 12:48+0200\n" -"PO-Revision-Date: 2018-09-11 11:25+0200\n" +"PO-Revision-Date: 2020-03-10 20:15+0100\n" "Last-Translator: Milo Casagrande \n" "Language-Team: Italian \n" "Language: it\n" @@ -16,7 +16,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -"X-Generator: Poedit 2.1.1\n" +"X-Generator: Poedit 2.2.4\n" #: data/org.freedesktop.ModemManager1.policy.in.in:13 msgid "Control the Modem Manager daemon" @@ -69,14 +69,13 @@ msgstr "La politica di sistema impedisce di effettuare chiamate vocali." #: data/org.freedesktop.ModemManager1.policy.in.in:58 msgid "Query network time and timezone information" -msgstr "" +msgstr "Interroga le informazioni sull'ora di rete e sul fuso orario" #: data/org.freedesktop.ModemManager1.policy.in.in:59 -#, fuzzy msgid "System policy prevents querying network time information." msgstr "" -"La politica di sistema impedisce di interrogare o di utilizzare le " -"informazioni e i servizi della rete." +"La politica di sistema impedisce di interrogare le informazioni sull'ora di " +"rete" #: data/org.freedesktop.ModemManager1.policy.in.in:67 msgid "Enable and view geographic location and positioning information" From 38f6e4eec920b2557ed7ba07310ce0160eab2cc9 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 16 Mar 2020 09:53:27 +0100 Subject: [PATCH 012/675] broadband-modem-mbim: fix segfault when loading capabilities If loading capabilities using QMI over MBIM returns NONE without an explicit error, the process would crash. Fix that by making the error optional when NONE is received. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/issues/185 --- src/mm-broadband-modem-mbim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index a6b6ec5f..931967f6 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -365,7 +365,7 @@ qmi_load_current_capabilities_ready (MMIfaceModem *self, ctx = g_task_get_task_data (task); ctx->current_qmi = mm_shared_qmi_load_current_capabilities_finish (self, res, &error); - if (!ctx->current_qmi) { + if (error) { mm_dbg ("Couldn't load currrent capabilities using QMI over MBIM: %s", error->message); g_clear_error (&error); } From 02f638d8d6d0eb67164dacb3477ff026621a319f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 21 Mar 2020 15:37:58 +0100 Subject: [PATCH 013/675] context: add ':' to the section titles So that --help-all print all sections in the same way as the Help and Application option groups. --- src/mm-context.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mm-context.c b/src/mm-context.c index 8630be02..08f08ff4 100644 --- a/src/mm-context.c +++ b/src/mm-context.c @@ -178,7 +178,7 @@ log_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("log", - "Logging options", + "Logging options:", "Show logging options", NULL, NULL); @@ -248,7 +248,7 @@ test_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("test", - "Test options", + "Test options:", "Show Test options", NULL, NULL); From f1e77cdbe632659302e72b2d22b3ee9414c25e1e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 21 Mar 2020 15:40:13 +0100 Subject: [PATCH 014/675] cli: context: add ':' to the section titles So that --help-all print all sections in the same way as the Help and Application option groups. --- cli/mmcli-bearer.c | 2 +- cli/mmcli-call.c | 2 +- cli/mmcli-manager.c | 2 +- cli/mmcli-modem-3gpp.c | 2 +- cli/mmcli-modem-cdma.c | 2 +- cli/mmcli-modem-firmware.c | 2 +- cli/mmcli-modem-location.c | 2 +- cli/mmcli-modem-messaging.c | 2 +- cli/mmcli-modem-oma.c | 2 +- cli/mmcli-modem-signal.c | 2 +- cli/mmcli-modem-simple.c | 2 +- cli/mmcli-modem-time.c | 2 +- cli/mmcli-modem-voice.c | 2 +- cli/mmcli-modem.c | 2 +- cli/mmcli-sim.c | 2 +- cli/mmcli-sms.c | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cli/mmcli-bearer.c b/cli/mmcli-bearer.c index cae68ea3..279e568a 100644 --- a/cli/mmcli-bearer.c +++ b/cli/mmcli-bearer.c @@ -68,7 +68,7 @@ mmcli_bearer_get_option_group (void) /* Status options */ group = g_option_group_new ("bearer", - "Bearer options", + "Bearer options:", "Show bearer options", NULL, NULL); diff --git a/cli/mmcli-call.c b/cli/mmcli-call.c index 7b4f5ecf..ecd1cb77 100644 --- a/cli/mmcli-call.c +++ b/cli/mmcli-call.c @@ -94,7 +94,7 @@ mmcli_call_get_option_group (void) /* Status options */ group = g_option_group_new ("call", - "Call options", + "Call options:", "Show call options", NULL, NULL); diff --git a/cli/mmcli-manager.c b/cli/mmcli-manager.c index e1e3c36c..950617b6 100644 --- a/cli/mmcli-manager.c +++ b/cli/mmcli-manager.c @@ -108,7 +108,7 @@ mmcli_manager_get_option_group (void) /* Status options */ group = g_option_group_new ("manager", - "Manager options", + "Manager options:", "Show manager options", NULL, NULL); diff --git a/cli/mmcli-modem-3gpp.c b/cli/mmcli-modem-3gpp.c index 21031d66..5136e3f9 100644 --- a/cli/mmcli-modem-3gpp.c +++ b/cli/mmcli-modem-3gpp.c @@ -103,7 +103,7 @@ mmcli_modem_3gpp_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("3gpp", - "3GPP options", + "3GPP options:", "Show 3GPP related options", NULL, NULL); diff --git a/cli/mmcli-modem-cdma.c b/cli/mmcli-modem-cdma.c index 58651b69..cba33a1d 100644 --- a/cli/mmcli-modem-cdma.c +++ b/cli/mmcli-modem-cdma.c @@ -70,7 +70,7 @@ mmcli_modem_cdma_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("cdma", - "CDMA options", + "CDMA options:", "Show CDMA related options", NULL, NULL); diff --git a/cli/mmcli-modem-firmware.c b/cli/mmcli-modem-firmware.c index 20dce4fe..34ceb420 100644 --- a/cli/mmcli-modem-firmware.c +++ b/cli/mmcli-modem-firmware.c @@ -71,7 +71,7 @@ mmcli_modem_firmware_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("firmware", - "Firmware options", + "Firmware options:", "Show Firmware options", NULL, NULL); diff --git a/cli/mmcli-modem-location.c b/cli/mmcli-modem-location.c index 6ef42b7a..cec3220a 100644 --- a/cli/mmcli-modem-location.c +++ b/cli/mmcli-modem-location.c @@ -163,7 +163,7 @@ mmcli_modem_location_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("location", - "Location options", + "Location options:", "Show Location options", NULL, NULL); diff --git a/cli/mmcli-modem-messaging.c b/cli/mmcli-modem-messaging.c index 681929a4..535cc909 100644 --- a/cli/mmcli-modem-messaging.c +++ b/cli/mmcli-modem-messaging.c @@ -82,7 +82,7 @@ mmcli_modem_messaging_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("messaging", - "Messaging options", + "Messaging options:", "Show Messaging options", NULL, NULL); diff --git a/cli/mmcli-modem-oma.c b/cli/mmcli-modem-oma.c index 13fdc5ab..e1a41ada 100644 --- a/cli/mmcli-modem-oma.c +++ b/cli/mmcli-modem-oma.c @@ -87,7 +87,7 @@ mmcli_modem_oma_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("oma", - "OMA options", + "OMA options:", "Show OMA options", NULL, NULL); diff --git a/cli/mmcli-modem-signal.c b/cli/mmcli-modem-signal.c index c5bf435e..506d7370 100644 --- a/cli/mmcli-modem-signal.c +++ b/cli/mmcli-modem-signal.c @@ -66,7 +66,7 @@ mmcli_modem_signal_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("signal", - "Signal options", + "Signal options:", "Show Signal options", NULL, NULL); diff --git a/cli/mmcli-modem-simple.c b/cli/mmcli-modem-simple.c index 35c85a8a..174f144b 100644 --- a/cli/mmcli-modem-simple.c +++ b/cli/mmcli-modem-simple.c @@ -65,7 +65,7 @@ mmcli_modem_simple_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("simple", - "Simple options", + "Simple options:", "Show Simple options", NULL, NULL); diff --git a/cli/mmcli-modem-time.c b/cli/mmcli-modem-time.c index 79f2a80c..98fa06e0 100644 --- a/cli/mmcli-modem-time.c +++ b/cli/mmcli-modem-time.c @@ -61,7 +61,7 @@ mmcli_modem_time_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("time", - "Time options", + "Time options:", "Show Time options", NULL, NULL); diff --git a/cli/mmcli-modem-voice.c b/cli/mmcli-modem-voice.c index 0f066b3f..ab216ea7 100644 --- a/cli/mmcli-modem-voice.c +++ b/cli/mmcli-modem-voice.c @@ -113,7 +113,7 @@ mmcli_modem_voice_get_option_group (void) GOptionGroup *group; group = g_option_group_new ("voice", - "Voice options", + "Voice options:", "Show Voice options", NULL, NULL); diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index e74c7936..88774b64 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -140,7 +140,7 @@ mmcli_modem_get_option_group (void) /* Status options */ group = g_option_group_new ("modem", - "Modem options", + "Modem options:", "Show modem options", NULL, NULL); diff --git a/cli/mmcli-sim.c b/cli/mmcli-sim.c index 75d3d075..efb15df3 100644 --- a/cli/mmcli-sim.c +++ b/cli/mmcli-sim.c @@ -83,7 +83,7 @@ mmcli_sim_get_option_group (void) /* Status options */ group = g_option_group_new ("sim", - "SIM options", + "SIM options:", "Show SIM options", NULL, NULL); diff --git a/cli/mmcli-sms.c b/cli/mmcli-sms.c index a5fa45bf..c468ed60 100644 --- a/cli/mmcli-sms.c +++ b/cli/mmcli-sms.c @@ -78,7 +78,7 @@ mmcli_sms_get_option_group (void) /* Status options */ group = g_option_group_new ("sms", - "SMS options", + "SMS options:", "Show SMS options", NULL, NULL); From e9d7a9acde7670f384bc8127ca141b185a57ad6f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 21 Mar 2020 15:48:49 +0100 Subject: [PATCH 015/675] context: remove empty whiteline in --version This also fixes the Copyright section in the troffit generated HTML output. --- src/mm-context.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mm-context.c b/src/mm-context.c index 08f08ff4..406c744a 100644 --- a/src/mm-context.c +++ b/src/mm-context.c @@ -279,8 +279,7 @@ mm_context_get_test_plugin_dir (void) static void print_version (void) { - g_print ("\n" - "ModemManager " MM_DIST_VERSION "\n" + g_print ("ModemManager " MM_DIST_VERSION "\n" "Copyright (C) 2008-2020 The ModemManager authors\n" "License GPLv2+: GNU GPL version 2 or later \n" "This is free software: you are free to change and redistribute it.\n" From 3643c1513368ae11c5608f223f7e8c4e51968a9c Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 21 Mar 2020 15:49:31 +0100 Subject: [PATCH 016/675] cli: remove empty whiteline in --version This also fixes the Copyright section in the troffit generated HTML output. --- cli/mmcli.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/mmcli.c b/cli/mmcli.c index 64a2c697..bf59867c 100644 --- a/cli/mmcli.c +++ b/cli/mmcli.c @@ -147,8 +147,7 @@ log_handler (const gchar *log_domain, static void print_version_and_exit (void) { - g_print ("\n" - PROGRAM_NAME " " PROGRAM_VERSION "\n" + g_print (PROGRAM_NAME " " PROGRAM_VERSION "\n" "Copyright (2011 - 2020) Aleksander Morgado\n" "License GPLv2+: GNU GPL version 2 or later \n" "This is free software: you are free to change and redistribute it.\n" From a309b089c9453455f9310ef4bfea217bcffc0721 Mon Sep 17 00:00:00 2001 From: mozzwald Date: Wed, 25 Mar 2020 12:35:41 -0500 Subject: [PATCH 017/675] quectel: add port type hints for EC25/EG25 #194 --- plugins/quectel/77-mm-quectel-port-types.rules | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/quectel/77-mm-quectel-port-types.rules b/plugins/quectel/77-mm-quectel-port-types.rules index 7368c134..71138580 100644 --- a/plugins/quectel/77-mm-quectel-port-types.rules +++ b/plugins/quectel/77-mm-quectel-port-types.rules @@ -37,4 +37,14 @@ ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0296", ENV{.MM_USBIFNUM}=="01", ENV{ ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0296", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0296", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +# Quectel EC25/EG25 +# ttyUSB0 (if #0): QCDM/DIAG port +# ttyUSB1 (if #1): GPS data port +# ttyUSB2 (if #2): AT primary port +# ttyUSB3 (if #3): AT secondary port +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_QCDM}="1" +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_PORT_TYPE_GPS}="1" +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" + LABEL="mm_quectel_port_types_end" From d22523ff098ea1ea5aab542ebc3ac83a03f04c90 Mon Sep 17 00:00:00 2001 From: Andika Triwidada Date: Tue, 31 Mar 2020 11:15:39 +0000 Subject: [PATCH 018/675] po: updated Indonesian translation --- po/id.po | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/po/id.po b/po/id.po index a6142a55..b0d09784 100644 --- a/po/id.po +++ b/po/id.po @@ -7,19 +7,19 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" -"PO-Revision-Date: 2018-03-04 20:31+0700\n" +"POT-Creation-Date: 2020-04-01 08:24+0200\n" +"PO-Revision-Date: 2020-03-31 18:14+0700\n" "Last-Translator: Andika Triwidada \n" "Language-Team: Indonesian \n" "Language: id\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.8.11\n" +"X-Generator: Poedit 2.3\n" #: data/org.freedesktop.ModemManager1.policy.in.in:13 msgid "Control the Modem Manager daemon" -msgstr "Kendalikan daemon Manajer Modem" +msgstr "Mengendalikan daemon Manajer Modem" #: data/org.freedesktop.ModemManager1.policy.in.in:14 msgid "System policy prevents controlling the Modem Manager." @@ -68,14 +68,11 @@ msgstr "Kebijakan sistem mencegah panggilan suara." #: data/org.freedesktop.ModemManager1.policy.in.in:58 msgid "Query network time and timezone information" -msgstr "" +msgstr "Tanyakan waktu jaringan dan informasi zona waktu" #: data/org.freedesktop.ModemManager1.policy.in.in:59 -#, fuzzy msgid "System policy prevents querying network time information." -msgstr "" -"Kebijakan sistem mencegah kueri atau pemanfaatan layanan dan informasi " -"jaringan." +msgstr "Kebijakan sistem mencegah kuiri informasi waktu jaringan." #: data/org.freedesktop.ModemManager1.policy.in.in:67 msgid "Enable and view geographic location and positioning information" @@ -90,23 +87,23 @@ msgstr "" #: data/org.freedesktop.ModemManager1.policy.in.in:76 msgid "Query and utilize network information and services" -msgstr "Kueri dan manfaatkan layanan dan informasi jaringan" +msgstr "Kuiri dan manfaatkan layanan dan informasi jaringan" #: data/org.freedesktop.ModemManager1.policy.in.in:77 msgid "" "System policy prevents querying or utilizing network information and " "services." msgstr "" -"Kebijakan sistem mencegah kueri atau pemanfaatan layanan dan informasi " +"Kebijakan sistem mencegah kuiri atau pemanfaatan layanan dan informasi " "jaringan." #: data/org.freedesktop.ModemManager1.policy.in.in:85 msgid "Query and manage firmware on a mobile broadband device" -msgstr "Kueri dan kelola firmware pada suatu peranti data seluler" +msgstr "Kuiri dan kelola firmware pada suatu peranti data seluler" #: data/org.freedesktop.ModemManager1.policy.in.in:86 msgid "System policy prevents querying or managing this device's firmware." -msgstr "Kebijakan sistem mencegah kueri atau pengelolaan firmware peranti ini." +msgstr "Kebijakan sistem mencegah kuiri atau pengelolaan firmware peranti ini." #: src/mm-sleep-monitor.c:114 msgid "ModemManager needs to reset devices" From faccb3b2b434d33936d4b7f1bc6bbeab8a14538f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=D0=B8=D0=B9=20=D0=A1=D1=83?= =?UTF-8?q?=D0=B4=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Sat, 4 Apr 2020 18:30:38 +0000 Subject: [PATCH 019/675] po: add Russian translation --- po/LINGUAS | 1 + po/ru.po | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 po/ru.po diff --git a/po/LINGUAS b/po/LINGUAS index 68225ab3..d09b7ccf 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -9,6 +9,7 @@ it lt pl pt_BR +ru sk sv tr diff --git a/po/ru.po b/po/ru.po new file mode 100644 index 00000000..8c0174d3 --- /dev/null +++ b/po/ru.po @@ -0,0 +1,117 @@ +# Russian translation for ModemManager. +# Copyright (C) 2020 ModemManager's COPYRIGHT HOLDER +# This file is distributed under the same license as the ModemManager package. +# Артемий Судаков , 2020. +# +msgid "" +msgstr "" +"Project-Id-Version: ModemManager master\n" +"Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" +"POT-Creation-Date: 2020-04-05 09:45+0200\n" +"PO-Revision-Date: 2020-04-04 21:26+0300\n" +"Last-Translator: Артемий Судаков \n" +"Language-Team: Russian \n" +"Language: ru\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"X-Generator: Poedit 2.3\n" + +#: data/org.freedesktop.ModemManager1.policy.in.in:13 +msgid "Control the Modem Manager daemon" +msgstr "Настроить сервис Modem Manager" + +#: data/org.freedesktop.ModemManager1.policy.in.in:14 +msgid "System policy prevents controlling the Modem Manager." +msgstr "Системная политика не позволяет управлять Modem Manager'ом." + +#: data/org.freedesktop.ModemManager1.policy.in.in:22 +msgid "Unlock and control a mobile broadband device" +msgstr "Разблокировка и управление мобильным широкополосным устройством" + +#: data/org.freedesktop.ModemManager1.policy.in.in:23 +msgid "" +"System policy prevents unlocking or controlling the mobile broadband device." +msgstr "" +"Системная политика предотвращает разблокировку или управление мобильным " +"широкополосным устройством." + +#: data/org.freedesktop.ModemManager1.policy.in.in:31 +msgid "Add, modify, and delete mobile broadband contacts" +msgstr "Добавить, изменить и удалить мобильные широкополосные контакты" + +#: data/org.freedesktop.ModemManager1.policy.in.in:32 +msgid "" +"System policy prevents adding, modifying, or deleting this device's contacts." +msgstr "" +"Системная политика запрещает добавление, изменение или удаление контактов " +"этого устройства." + +#: data/org.freedesktop.ModemManager1.policy.in.in:40 +msgid "Send, save, modify, and delete text messages" +msgstr "Отправить, сохранить, изменить и удалить текстовые сообщения" + +#: data/org.freedesktop.ModemManager1.policy.in.in:41 +msgid "" +"System policy prevents sending or manipulating this device's text messages." +msgstr "" +"Системная политика запрещает отправку или манипулирование текстовыми " +"сообщениями этого устройства." + +#: data/org.freedesktop.ModemManager1.policy.in.in:49 +msgid "Accept incoming voice calls or start outgoing voice calls." +msgstr "" +"Принимать входящие голосовые звонки или начать исходящие голосовые звонки." + +#: data/org.freedesktop.ModemManager1.policy.in.in:50 +msgid "System policy prevents voice calls." +msgstr "Системная политика запрещает голосовые звонки." + +#: data/org.freedesktop.ModemManager1.policy.in.in:58 +msgid "Query network time and timezone information" +msgstr "Запрос информации о времени и часовых поясах в сети" + +#: data/org.freedesktop.ModemManager1.policy.in.in:59 +msgid "System policy prevents querying network time information." +msgstr "Системная политика запрещает запрашивать информацию о времени в сети." + +#: data/org.freedesktop.ModemManager1.policy.in.in:67 +msgid "Enable and view geographic location and positioning information" +msgstr "" +"Включить и просмотреть географическое местоположение и информацию о " +"местоположении" + +#: data/org.freedesktop.ModemManager1.policy.in.in:68 +msgid "" +"System policy prevents enabling or viewing geographic location information." +msgstr "" +"Системная политика запрещает включение или просмотр информации о " +"географическом местоположении." + +#: data/org.freedesktop.ModemManager1.policy.in.in:76 +msgid "Query and utilize network information and services" +msgstr "Запрос, использование сетевой информации и услуг" + +#: data/org.freedesktop.ModemManager1.policy.in.in:77 +msgid "" +"System policy prevents querying or utilizing network information and " +"services." +msgstr "" +"Системная политика не позволяет запрашивать или использовать сетевую " +"информацию и сервисы." + +#: data/org.freedesktop.ModemManager1.policy.in.in:85 +msgid "Query and manage firmware on a mobile broadband device" +msgstr "Запрос и управление прошивкой на мобильном широкополосном устройстве" + +#: data/org.freedesktop.ModemManager1.policy.in.in:86 +msgid "System policy prevents querying or managing this device's firmware." +msgstr "" +"Системная политика не позволяет запрашивать или управлять прошивкой этого " +"устройства." + +#: src/mm-sleep-monitor.c:114 +msgid "ModemManager needs to reset devices" +msgstr "ModemManager'у необходимо перезагрузить устройства" From 9bcadea172cfba9317c55a9265012ff2f739cc96 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 08:06:41 +0100 Subject: [PATCH 020/675] log: new object logging support So that we can provide the specific object id in every log associated to a given object. --- .../tests/test-modem-helpers-cinterion.c | 3 +- .../huawei/tests/test-modem-helpers-huawei.c | 3 +- .../icera/tests/test-modem-helpers-icera.c | 3 +- .../tests/test-modem-helpers-linktop.c | 3 +- plugins/mbm/tests/test-modem-helpers-mbm.c | 3 +- .../sierra/tests/test-modem-helpers-sierra.c | 3 +- .../tests/test-modem-helpers-simtech.c | 3 +- .../telit/tests/test-mm-modem-helpers-telit.c | 3 +- plugins/tests/test-keyfiles.c | 3 +- plugins/tests/test-udev-rules.c | 3 +- .../tests/test-mm-modem-helpers-thuraya.c | 3 +- .../ublox/tests/test-modem-helpers-ublox.c | 3 +- plugins/xmm/tests/test-modem-helpers-xmm.c | 3 +- src/Makefile.am | 9 +- src/mm-log-object.c | 89 +++++++++++++++++++ src/mm-log-object.h | 38 ++++++++ src/mm-log.c | 10 ++- src/mm-log.h | 29 +++--- src/tests/test-at-serial-port.c | 3 +- src/tests/test-charsets.c | 3 +- src/tests/test-error-helpers.c | 3 +- src/tests/test-modem-helpers-qmi.c | 3 +- src/tests/test-modem-helpers.c | 3 +- src/tests/test-qcdm-serial-port.c | 3 +- src/tests/test-sms-part-3gpp.c | 3 +- src/tests/test-sms-part-cdma.c | 3 +- src/tests/test-udev-rules.c | 3 +- test/mmrules.c | 3 +- test/mmsmspdu.c | 3 +- test/mmtty.c | 3 +- 30 files changed, 203 insertions(+), 47 deletions(-) create mode 100644 src/mm-log-object.c create mode 100644 src/mm-log-object.h diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c index 78adf30a..f1d6cddb 100644 --- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c +++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c @@ -859,7 +859,8 @@ test_ctzu_urc_full (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/huawei/tests/test-modem-helpers-huawei.c b/plugins/huawei/tests/test-modem-helpers-huawei.c index b37c0b16..4f83f49c 100644 --- a/plugins/huawei/tests/test-modem-helpers-huawei.c +++ b/plugins/huawei/tests/test-modem-helpers-huawei.c @@ -1268,7 +1268,8 @@ test_hcsq (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/icera/tests/test-modem-helpers-icera.c b/plugins/icera/tests/test-modem-helpers-icera.c index 592b8b24..ef9d62cc 100644 --- a/plugins/icera/tests/test-modem-helpers-icera.c +++ b/plugins/icera/tests/test-modem-helpers-icera.c @@ -176,7 +176,8 @@ test_ipdpaddr (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/linktop/tests/test-modem-helpers-linktop.c b/plugins/linktop/tests/test-modem-helpers-linktop.c index 827d044f..396abaae 100644 --- a/plugins/linktop/tests/test-modem-helpers-linktop.c +++ b/plugins/linktop/tests/test-modem-helpers-linktop.c @@ -60,7 +60,8 @@ test_cfun_query_current_modes (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/mbm/tests/test-modem-helpers-mbm.c b/plugins/mbm/tests/test-modem-helpers-mbm.c index cca121b0..e64b25c2 100644 --- a/plugins/mbm/tests/test-modem-helpers-mbm.c +++ b/plugins/mbm/tests/test-modem-helpers-mbm.c @@ -254,7 +254,8 @@ test_cfun_query_current_modes (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/sierra/tests/test-modem-helpers-sierra.c b/plugins/sierra/tests/test-modem-helpers-sierra.c index 629572e4..ad25ec9b 100644 --- a/plugins/sierra/tests/test-modem-helpers-sierra.c +++ b/plugins/sierra/tests/test-modem-helpers-sierra.c @@ -116,7 +116,8 @@ test_scact_read_response_multiple (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/simtech/tests/test-modem-helpers-simtech.c b/plugins/simtech/tests/test-modem-helpers-simtech.c index 78a8a590..af93b7ba 100644 --- a/plugins/simtech/tests/test-modem-helpers-simtech.c +++ b/plugins/simtech/tests/test-modem-helpers-simtech.c @@ -318,7 +318,8 @@ test_rxdtmf_urc_one_cr (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/telit/tests/test-mm-modem-helpers-telit.c b/plugins/telit/tests/test-mm-modem-helpers-telit.c index e6bff0bc..7561dac2 100644 --- a/plugins/telit/tests/test-mm-modem-helpers-telit.c +++ b/plugins/telit/tests/test-mm-modem-helpers-telit.c @@ -571,7 +571,8 @@ test_telit_parse_qss_query (void) /******************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/tests/test-keyfiles.c b/plugins/tests/test-keyfiles.c index 35ec4b46..173893be 100644 --- a/plugins/tests/test-keyfiles.c +++ b/plugins/tests/test-keyfiles.c @@ -65,7 +65,8 @@ test_foxconn_t77w968 (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/tests/test-udev-rules.c b/plugins/tests/test-udev-rules.c index 83ba95ba..e12f07ac 100644 --- a/plugins/tests/test-udev-rules.c +++ b/plugins/tests/test-udev-rules.c @@ -163,7 +163,8 @@ test_fibocom (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c index dcd4ab24..a3e5f65f 100644 --- a/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c +++ b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c @@ -86,7 +86,8 @@ test_cpms_response_thuraya (void *f, gpointer d) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c index 17a46417..8f2f3664 100644 --- a/plugins/ublox/tests/test-modem-helpers-ublox.c +++ b/plugins/ublox/tests/test-modem-helpers-ublox.c @@ -980,7 +980,8 @@ test_ugcntrd_response (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/xmm/tests/test-modem-helpers-xmm.c b/plugins/xmm/tests/test-modem-helpers-xmm.c index b4a8b2b5..0e65c7cc 100644 --- a/plugins/xmm/tests/test-modem-helpers-xmm.c +++ b/plugins/xmm/tests/test-modem-helpers-xmm.c @@ -754,7 +754,8 @@ test_xlcsslp_queries (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/Makefile.am b/src/Makefile.am index 84c810d6..cb50d2b8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -97,6 +97,10 @@ mm-helper-enums-types.c: Makefile.am $(top_srcdir)/build-aux/mm-enums-template.c $(HELPER_ENUMS_INPUTS) > $@ libhelpers_la_SOURCES = \ + mm-log-object.h \ + mm-log-object.c \ + mm-log.c \ + mm-log.h \ mm-error-helpers.c \ mm-error-helpers.h \ mm-modem-helpers.c \ @@ -131,7 +135,6 @@ endif BUILT_SOURCES += $(HELPER_ENUMS_GENERATED) CLEANFILES += $(HELPER_ENUMS_GENERATED) - ################################################################################ # kerneldevice library ################################################################################ @@ -160,6 +163,7 @@ endif libkerneldevice_la_LIBADD = \ $(top_builddir)/libmm-glib/libmm-glib.la \ + $(builddir)/libhelpers.la \ $(NULL) ################################################################################ @@ -225,7 +229,6 @@ endif libport_la_LIBADD = \ $(top_builddir)/libqcdm/src/libqcdm.la \ $(top_builddir)/libmm-glib/libmm-glib.la \ - $(builddir)/libhelpers.la \ $(builddir)/libkerneldevice.la \ $(NULL) @@ -283,8 +286,6 @@ ModemManager_SOURCES = \ main.c \ mm-context.h \ mm-context.c \ - mm-log.c \ - mm-log.h \ mm-utils.h \ mm-private-boxed-types.h \ mm-private-boxed-types.c \ diff --git a/src/mm-log-object.c b/src/mm-log-object.c new file mode 100644 index 00000000..ed41355f --- /dev/null +++ b/src/mm-log-object.c @@ -0,0 +1,89 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2020 Aleksander Morgado + */ + +#include "mm-log-object.h" + +G_DEFINE_INTERFACE (MMLogObject, mm_log_object, G_TYPE_OBJECT) + +/*****************************************************************************/ +/* Private data context */ + +#define PRIVATE_TAG "log-object" +static GQuark private_quark; + +typedef struct { + gchar *owner_id; + gchar *id; +} Private; + +static void +private_free (Private *priv) +{ + g_free (priv->owner_id); + g_free (priv->id); + g_slice_free (Private, priv); +} + +static Private * +get_private (MMLogObject *self) +{ + Private *priv; + + if (G_UNLIKELY (!private_quark)) + private_quark = g_quark_from_static_string (PRIVATE_TAG); + + priv = g_object_get_qdata (G_OBJECT (self), private_quark); + if (!priv) { + priv = g_slice_new0 (Private); + g_object_set_qdata_full (G_OBJECT (self), private_quark, priv, (GDestroyNotify)private_free); + } + + return priv; +} + +const gchar * +mm_log_object_get_id (MMLogObject *self) +{ + Private *priv; + + priv = get_private (self); + if (!priv->id) { + gchar *self_id; + + self_id = MM_LOG_OBJECT_GET_IFACE (self)->build_id (self); + if (priv->owner_id) { + priv->id = g_strdup_printf ("%s/%s", priv->owner_id, self_id); + g_free (self_id); + } else + priv->id = self_id; + } + return priv->id; +} + +void +mm_log_object_set_owner_id (MMLogObject *self, + const gchar *owner_id) +{ + Private *priv; + + priv = get_private (self); + g_free (priv->owner_id); + priv->owner_id = g_strdup (owner_id); +} + +static void +mm_log_object_default_init (MMLogObjectInterface *iface) +{ +} diff --git a/src/mm-log-object.h b/src/mm-log-object.h new file mode 100644 index 00000000..21ffc05e --- /dev/null +++ b/src/mm-log-object.h @@ -0,0 +1,38 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2020 Aleksander Morgado + */ + +#ifndef MM_LOG_OBJECT_H +#define MM_LOG_OBJECT_H + +#include +#include + +#include "mm-log.h" + +#define MM_TYPE_LOG_OBJECT mm_log_object_get_type () +G_DECLARE_INTERFACE (MMLogObject, mm_log_object, MM, LOG_OBJECT, GObject) + +struct _MMLogObjectInterface +{ + GTypeInterface g_iface; + + gchar * (* build_id) (MMLogObject *self); +}; + +const gchar *mm_log_object_get_id (MMLogObject *self); +void mm_log_object_set_owner_id (MMLogObject *self, + const gchar *owner_id); + +#endif /* MM_LOG_OBJECT_H */ diff --git a/src/mm-log.c b/src/mm-log.c index 470f1881..f15ce5c9 100644 --- a/src/mm-log.c +++ b/src/mm-log.c @@ -10,7 +10,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2011 Red Hat, Inc. + * Copyright (C) 2011-2020 Red Hat, Inc. + * Copyright (C) 2020 Aleksander Morgado */ #define _GNU_SOURCE @@ -41,6 +42,7 @@ #endif #include "mm-log.h" +#include "mm-log-object.h" enum { TS_FLAG_NONE = 0, @@ -200,7 +202,8 @@ log_backend_systemd_journal (const char *loc, #endif void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, MMLogLevel level, const char *fmt, @@ -243,6 +246,9 @@ _mm_log (const char *loc, g_string_append_printf (msgbuf, "[%s] %s(): ", loc, func); #endif + if (obj) + g_string_append_printf (msgbuf, "[%s] ", mm_log_object_get_id (MM_LOG_OBJECT (obj))); + va_start (args, fmt); g_string_append_vprintf (msgbuf, fmt, args); va_end (args); diff --git a/src/mm-log.h b/src/mm-log.h index d9f11f27..934b41c2 100644 --- a/src/mm-log.h +++ b/src/mm-log.h @@ -10,7 +10,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2011 Red Hat, Inc. + * Copyright (C) 2011-2020 Red Hat, Inc. + * Copyright (C) 2020 Aleksander Morgado */ #ifndef MM_LOG_H @@ -26,26 +27,22 @@ typedef enum { MM_LOG_LEVEL_DEBUG = 0x00000008 } MMLogLevel; -#define mm_err(...) \ - _mm_log (G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_ERR, ## __VA_ARGS__ ) +#define mm_obj_err(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_ERR, ## __VA_ARGS__ ) +#define mm_obj_warn(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_WARN, ## __VA_ARGS__ ) +#define mm_obj_info(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_INFO, ## __VA_ARGS__ ) +#define mm_obj_dbg(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_DEBUG, ## __VA_ARGS__ ) -#define mm_warn(...) \ - _mm_log (G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_WARN, ## __VA_ARGS__ ) +#define mm_err(...) mm_obj_err (NULL, ## __VA_ARGS__ ) +#define mm_warn(...) mm_obj_warn (NULL, ## __VA_ARGS__ ) +#define mm_info(...) mm_obj_info (NULL, ## __VA_ARGS__ ) +#define mm_dbg(...) mm_obj_dbg (NULL, ## __VA_ARGS__ ) -#define mm_info(...) \ - _mm_log (G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_INFO, ## __VA_ARGS__ ) - -#define mm_dbg(...) \ - _mm_log (G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_DEBUG, ## __VA_ARGS__ ) - -#define mm_log(level, ...) \ - _mm_log (G_STRLOC, G_STRFUNC, level, ## __VA_ARGS__ ) - -void _mm_log (const char *loc, +void _mm_log (gpointer obj, + const char *loc, const char *func, MMLogLevel level, const char *fmt, - ...) __attribute__((__format__ (__printf__, 4, 5))); + ...) __attribute__((__format__ (__printf__, 5, 6))); gboolean mm_log_set_level (const char *level, GError **error); diff --git a/src/tests/test-at-serial-port.c b/src/tests/test-at-serial-port.c index c864701f..2d57d30e 100644 --- a/src/tests/test-at-serial-port.c +++ b/src/tests/test-at-serial-port.c @@ -65,7 +65,8 @@ at_serial_echo_removal (void) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c index 01a5b7a7..b8a92575 100644 --- a/src/tests/test-charsets.c +++ b/src/tests/test-charsets.c @@ -409,7 +409,8 @@ test_charset_can_covert_to (void) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-error-helpers.c b/src/tests/test-error-helpers.c index 228dfc02..ff67ed80 100644 --- a/src/tests/test-error-helpers.c +++ b/src/tests/test-error-helpers.c @@ -53,7 +53,8 @@ TEST_ERROR_HELPER (MESSAGE_ERROR, message_error, MessageError) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-modem-helpers-qmi.c b/src/tests/test-modem-helpers-qmi.c index d6b491c5..e14a2282 100644 --- a/src/tests/test-modem-helpers-qmi.c +++ b/src/tests/test-modem-helpers-qmi.c @@ -310,7 +310,8 @@ test_gobi3k_cdma (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index bd747448..551603df 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -4502,7 +4502,8 @@ test_bcd_to_string (void *f, gpointer d) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-qcdm-serial-port.c b/src/tests/test-qcdm-serial-port.c index c5233f9c..db20f9aa 100644 --- a/src/tests/test-qcdm-serial-port.c +++ b/src/tests/test-qcdm-serial-port.c @@ -438,7 +438,8 @@ test_pty_cleanup (TestData *d) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-sms-part-3gpp.c b/src/tests/test-sms-part-3gpp.c index d9152405..a2ad304e 100644 --- a/src/tests/test-sms-part-3gpp.c +++ b/src/tests/test-sms-part-3gpp.c @@ -841,7 +841,8 @@ test_text_split_two_pdu_ucs2 (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-sms-part-cdma.c b/src/tests/test-sms-part-cdma.c index e1559261..b1900fa8 100644 --- a/src/tests/test-sms-part-cdma.c +++ b/src/tests/test-sms-part-cdma.c @@ -505,7 +505,8 @@ test_create_pdu_text_unicode_encoding (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-udev-rules.c b/src/tests/test-udev-rules.c index 3398e419..cc594918 100644 --- a/src/tests/test-udev-rules.c +++ b/src/tests/test-udev-rules.c @@ -44,7 +44,8 @@ test_load_cleanup_core (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/test/mmrules.c b/test/mmrules.c index 17976d25..29b32fba 100644 --- a/test/mmrules.c +++ b/test/mmrules.c @@ -51,7 +51,8 @@ static GOptionEntry main_entries[] = { }; void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/test/mmsmspdu.c b/test/mmsmspdu.c index c5e9693d..787f98f5 100644 --- a/test/mmsmspdu.c +++ b/test/mmsmspdu.c @@ -164,7 +164,8 @@ show_part_info (MMSmsPart *part) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/test/mmtty.c b/test/mmtty.c index 966225c7..f7852cd4 100644 --- a/test/mmtty.c +++ b/test/mmtty.c @@ -84,7 +84,8 @@ signals_handler (int signum) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, From b7d728696396da9645aae508c565ea0e094915a5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 10:06:50 +0100 Subject: [PATCH 021/675] kerneldevice: port to object logging --- src/kerneldevice/mm-kernel-device-generic.c | 119 +++++--------------- src/kerneldevice/mm-kernel-device-udev.c | 6 +- src/kerneldevice/mm-kernel-device.c | 24 +++- 3 files changed, 54 insertions(+), 95 deletions(-) diff --git a/src/kerneldevice/mm-kernel-device-generic.c b/src/kerneldevice/mm-kernel-device-generic.c index b6e4e2df..254c505a 100644 --- a/src/kerneldevice/mm-kernel-device-generic.c +++ b/src/kerneldevice/mm-kernel-device-generic.c @@ -25,7 +25,7 @@ #include "mm-kernel-device-generic.h" #include "mm-kernel-device-generic-rules.h" -#include "mm-log.h" +#include "mm-log-object.h" #if !defined UDEVRULESDIR # error UDEVRULESDIR is not defined @@ -126,19 +126,16 @@ preload_sysfs_path (MMKernelDeviceGeneric *self) self->priv->sysfs_path = realpath (tmp, NULL); if (!self->priv->sysfs_path || !g_file_test (self->priv->sysfs_path, G_FILE_TEST_EXISTS)) { - mm_warn ("Invalid sysfs path read for %s/%s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties)); + mm_obj_warn (self, "invalid sysfs path read for %s/%s", + mm_kernel_event_properties_get_subsystem (self->priv->properties), + mm_kernel_event_properties_get_name (self->priv->properties)); g_clear_pointer (&self->priv->sysfs_path, g_free); } if (self->priv->sysfs_path) { const gchar *devpath; - mm_dbg ("(%s/%s) sysfs path: %s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->sysfs_path); + mm_obj_dbg (self, "sysfs path: %s", self->priv->sysfs_path); devpath = (g_str_has_prefix (self->priv->sysfs_path, "/sys") ? &self->priv->sysfs_path[4] : self->priv->sysfs_path); @@ -210,10 +207,7 @@ preload_interface_sysfs_path (MMKernelDeviceGeneric *self) } if (self->priv->interface_sysfs_path) - mm_dbg ("(%s/%s) interface sysfs path: %s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->interface_sysfs_path); + mm_obj_dbg (self, "interface sysfs path: %s", self->priv->interface_sysfs_path); } static void @@ -229,10 +223,7 @@ preload_physdev_sysfs_path (MMKernelDeviceGeneric *self) self->priv->physdev_sysfs_path = g_path_get_dirname (self->priv->interface_sysfs_path); if (self->priv->physdev_sysfs_path) - mm_dbg ("(%s/%s) physdev sysfs path: %s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->physdev_sysfs_path); + mm_obj_dbg (self, "physdev sysfs path: %s", self->priv->physdev_sysfs_path); } static void @@ -251,10 +242,7 @@ preload_driver (MMKernelDeviceGeneric *self) } if (self->priv->driver) - mm_dbg ("(%s/%s) driver: %s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->driver); + mm_obj_dbg (self, "driver: %s", self->priv->driver); } static void @@ -269,15 +257,10 @@ preload_physdev_vid (MMKernelDeviceGeneric *self) } if (self->priv->physdev_vid) { - mm_dbg ("(%s/%s) vid (ID_VENDOR_ID): 0x%04x", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->physdev_vid); + mm_obj_dbg (self, "vid (ID_VENDOR_ID): 0x%04x", self->priv->physdev_vid); g_object_set_data_full (G_OBJECT (self), "ID_VENDOR_ID", g_strdup_printf ("%04x", self->priv->physdev_vid), g_free); } else - mm_dbg ("(%s/%s) vid: unknown", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties)); + mm_obj_dbg (self, "vid: unknown"); } @@ -293,15 +276,10 @@ preload_physdev_pid (MMKernelDeviceGeneric *self) } if (self->priv->physdev_pid) { - mm_dbg ("(%s/%s) pid (ID_MODEL_ID): 0x%04x", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->physdev_pid); + mm_obj_dbg (self, "pid (ID_MODEL_ID): 0x%04x", self->priv->physdev_pid); g_object_set_data_full (G_OBJECT (self), "ID_MODEL_ID", g_strdup_printf ("%04x", self->priv->physdev_pid), g_free); } else - mm_dbg ("(%s/%s) pid: unknown", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties)); + mm_obj_dbg (self, "pid: unknown"); } static void @@ -316,15 +294,10 @@ preload_physdev_revision (MMKernelDeviceGeneric *self) } if (self->priv->physdev_revision) { - mm_dbg ("(%s/%s) revision (ID_REVISION): 0x%04x", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->physdev_revision); + mm_obj_dbg (self, "revision (ID_REVISION): 0x%04x", self->priv->physdev_revision); g_object_set_data_full (G_OBJECT (self), "ID_REVISION", g_strdup_printf ("%04x", self->priv->physdev_revision), g_free); } else - mm_dbg ("(%s/%s) revision: unknown", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties)); + mm_obj_dbg (self, "revision: unknown"); } static void @@ -341,10 +314,7 @@ preload_physdev_subsystem (MMKernelDeviceGeneric *self) g_free (aux); } - mm_dbg ("(%s/%s) subsystem: %s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->physdev_subsystem ? self->priv->physdev_subsystem : "unknown"); + mm_obj_dbg (self, "subsystem: %s", self->priv->physdev_subsystem ? self->priv->physdev_subsystem : "unknown"); } static void @@ -354,15 +324,10 @@ preload_manufacturer (MMKernelDeviceGeneric *self) self->priv->physdev_manufacturer = (self->priv->physdev_sysfs_path ? read_sysfs_property_as_string (self->priv->physdev_sysfs_path, "manufacturer") : NULL); if (self->priv->physdev_manufacturer) { - mm_dbg ("(%s/%s) manufacturer (ID_VENDOR): %s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->physdev_manufacturer); + mm_obj_dbg (self, "manufacturer (ID_VENDOR): %s", self->priv->physdev_manufacturer); g_object_set_data_full (G_OBJECT (self), "ID_VENDOR", g_strdup (self->priv->physdev_manufacturer), g_free); } else - mm_dbg ("(%s/%s) manufacturer: unknown", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties)); + mm_obj_dbg (self, "manufacturer: unknown"); } static void @@ -372,15 +337,10 @@ preload_product (MMKernelDeviceGeneric *self) self->priv->physdev_product = (self->priv->physdev_sysfs_path ? read_sysfs_property_as_string (self->priv->physdev_sysfs_path, "product") : NULL); if (self->priv->physdev_product) { - mm_dbg ("(%s/%s) product (ID_MODEL): %s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->physdev_product); + mm_obj_dbg (self, "product (ID_MODEL): %s", self->priv->physdev_product); g_object_set_data_full (G_OBJECT (self), "ID_MODEL", g_strdup (self->priv->physdev_product), g_free); } else - mm_dbg ("(%s/%s) product: unknown", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties)); + mm_obj_dbg (self, "product: unknown"); } @@ -388,40 +348,28 @@ static void preload_interface_class (MMKernelDeviceGeneric *self) { self->priv->interface_class = (self->priv->interface_sysfs_path ? read_sysfs_property_as_hex (self->priv->interface_sysfs_path, "bInterfaceClass") : 0x00); - mm_dbg ("(%s/%s) interface class: 0x%02x", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->interface_class); + mm_obj_dbg (self, "interface class: 0x%02x", self->priv->interface_class); } static void preload_interface_subclass (MMKernelDeviceGeneric *self) { self->priv->interface_subclass = (self->priv->interface_sysfs_path ? read_sysfs_property_as_hex (self->priv->interface_sysfs_path, "bInterfaceSubClass") : 0x00); - mm_dbg ("(%s/%s) interface subclass: 0x%02x", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->interface_subclass); + mm_obj_dbg (self, "interface subclass: 0x%02x", self->priv->interface_subclass); } static void preload_interface_protocol (MMKernelDeviceGeneric *self) { self->priv->interface_protocol = (self->priv->interface_sysfs_path ? read_sysfs_property_as_hex (self->priv->interface_sysfs_path, "bInterfaceProtocol") : 0x00); - mm_dbg ("(%s/%s) interface protocol: 0x%02x", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->interface_protocol); + mm_obj_dbg (self, "interface protocol: 0x%02x", self->priv->interface_protocol); } static void preload_interface_number (MMKernelDeviceGeneric *self) { self->priv->interface_number = (self->priv->interface_sysfs_path ? read_sysfs_property_as_hex (self->priv->interface_sysfs_path, "bInterfaceNumber") : 0x00); - mm_dbg ("(%s/%s) interface number (ID_USB_INTERFACE_NUM): 0x%02x", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->interface_number); + mm_obj_dbg (self, "interface number (ID_USB_INTERFACE_NUM): 0x%02x", self->priv->interface_number); g_object_set_data_full (G_OBJECT (self), "ID_USB_INTERFACE_NUM", g_strdup_printf ("%02x", self->priv->interface_number), g_free); } @@ -429,10 +377,7 @@ static void preload_interface_description (MMKernelDeviceGeneric *self) { self->priv->interface_description = (self->priv->interface_sysfs_path ? read_sysfs_property_as_string (self->priv->interface_sysfs_path, "interface") : NULL); - mm_dbg ("(%s/%s) interface description: %s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - self->priv->interface_description ? self->priv->interface_description : "unknown"); + mm_obj_dbg (self, "interface description: %s", self->priv->interface_description ? self->priv->interface_description : "unknown"); } static void @@ -768,7 +713,7 @@ check_condition (MMKernelDeviceGeneric *self, result = (g_str_equal (match->value, "?*") || ((mm_get_uint_from_hex_str (match->value, &val)) && ((self->priv->interface_number == val) == condition_equal))); else - mm_warn ("Unknown attribute: %s", attribute); + mm_obj_warn (self, "unknown attribute: %s", attribute); g_free (contents); g_free (attribute); @@ -790,7 +735,7 @@ check_condition (MMKernelDeviceGeneric *self, return result; } - mm_warn ("Unknown match condition parameter: %s", match->parameter); + mm_obj_warn (self, "unknown match condition parameter: %s", match->parameter); return FALSE; } @@ -833,11 +778,9 @@ check_rule (MMKernelDeviceGeneric *self, property_value_read = g_strdup_printf ("%02x", self->priv->interface_number); /* add new property */ - mm_dbg ("(%s/%s) property added: %s=%s", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties), - rule->result.content.property.name, - property_value_read ? property_value_read : rule->result.content.property.value); + mm_obj_dbg (self, "property added: %s=%s", + rule->result.content.property.name, + property_value_read ? property_value_read : rule->result.content.property.value); if (!property_value_read) /* NOTE: we keep a reference to the list of rules ourselves, so it isn't @@ -906,9 +849,7 @@ check_preload (MMKernelDeviceGeneric *self) if (g_strcmp0 (mm_kernel_event_properties_get_subsystem (self->priv->properties), "virtual") == 0) return; - mm_dbg ("(%s/%s) preloading contents and properties...", - mm_kernel_event_properties_get_subsystem (self->priv->properties), - mm_kernel_event_properties_get_name (self->priv->properties)); + mm_obj_dbg (self, "preloading contents and properties..."); preload_contents (self); preload_properties (self); } diff --git a/src/kerneldevice/mm-kernel-device-udev.c b/src/kerneldevice/mm-kernel-device-udev.c index 620d1441..f07c46bc 100644 --- a/src/kerneldevice/mm-kernel-device-udev.c +++ b/src/kerneldevice/mm-kernel-device-udev.c @@ -21,7 +21,7 @@ #include #include "mm-kernel-device-udev.h" -#include "mm-log.h" +#include "mm-log-object.h" static void initable_iface_init (GInitableIface *iface); @@ -177,9 +177,7 @@ ensure_device_ids (MMKernelDeviceUdev *self) return; if (!get_device_ids (self->priv->device, &self->priv->vendor, &self->priv->product, &self->priv->revision)) - mm_dbg ("(%s/%s) could not get vendor/product id", - g_udev_device_get_subsystem (self->priv->device), - g_udev_device_get_name (self->priv->device)); + mm_obj_dbg (self, "could not get vendor/product id"); } /*****************************************************************************/ diff --git a/src/kerneldevice/mm-kernel-device.c b/src/kerneldevice/mm-kernel-device.c index e52ae67e..abe0ddd0 100644 --- a/src/kerneldevice/mm-kernel-device.c +++ b/src/kerneldevice/mm-kernel-device.c @@ -16,10 +16,13 @@ #include #include -#include "mm-log.h" #include "mm-kernel-device.h" +#include "mm-log-object.h" -G_DEFINE_ABSTRACT_TYPE (MMKernelDevice, mm_kernel_device, G_TYPE_OBJECT) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MMKernelDevice, mm_kernel_device, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) /*****************************************************************************/ @@ -317,11 +320,28 @@ mm_kernel_device_get_global_property_as_int_hex (MMKernelDevice *self, /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMKernelDevice *self; + + self = MM_KERNEL_DEVICE (_self); + return g_strdup (mm_kernel_device_get_name (self)); +} + +/*****************************************************************************/ + static void mm_kernel_device_init (MMKernelDevice *self) { } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_kernel_device_class_init (MMKernelDeviceClass *klass) { From 3a2466a3638390260a6149f15f81f3129371d7fd Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 16:08:02 +0100 Subject: [PATCH 022/675] port-serial: assert on totally unexpected serial settings The bits/parity/stopbits serial settings are set by the daemon, so if any of them are not expected, assert, not just warn. --- src/mm-port-serial.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c index 5e8db484..d5980189 100644 --- a/src/mm-port-serial.c +++ b/src/mm-port-serial.c @@ -290,7 +290,7 @@ parse_baudrate (guint baudrate_num, static int parse_bits (guint i) { - int bits; + int bits = -1; switch (i) { case 5: @@ -306,8 +306,7 @@ parse_bits (guint i) bits = CS8; break; default: - mm_warn ("Invalid bits (%d). Valid values are 5, 6, 7, 8.", i); - bits = CS8; + g_assert_not_reached (); } return bits; @@ -316,7 +315,7 @@ parse_bits (guint i) static int parse_parity (char c) { - int parity; + int parity = -1; switch (c) { case 'n': @@ -332,8 +331,7 @@ parse_parity (char c) parity = PARENB | PARODD; break; default: - mm_warn ("Invalid parity (%c). Valid values are n, e, o", c); - parity = 0; + g_assert_not_reached (); } return parity; @@ -342,7 +340,7 @@ parse_parity (char c) static int parse_stopbits (guint i) { - int stopbits; + int stopbits = -1; switch (i) { case 1: @@ -352,8 +350,7 @@ parse_stopbits (guint i) stopbits = CSTOPB; break; default: - mm_warn ("Invalid stop bits (%d). Valid values are 1 and 2)", i); - stopbits = 0; + g_assert_not_reached (); } return stopbits; From 850d302d24a7c0bdf58b1a0a38a2ef04a5bc862d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 16:14:22 +0100 Subject: [PATCH 023/675] ports: port to object logging --- src/mm-port-mbim.c | 43 ++++++-------- src/mm-port-qmi.c | 53 +++++++++-------- src/mm-port-serial-at.c | 13 +++-- src/mm-port-serial-gps.c | 11 ++-- src/mm-port-serial-qcdm.c | 11 ++-- src/mm-port-serial.c | 118 ++++++++++++++------------------------ src/mm-port-serial.h | 8 +-- src/mm-port.c | 32 +++++++++-- 8 files changed, 144 insertions(+), 145 deletions(-) diff --git a/src/mm-port-mbim.c b/src/mm-port-mbim.c index 1778e783..8e848e4d 100644 --- a/src/mm-port-mbim.c +++ b/src/mm-port-mbim.c @@ -26,7 +26,7 @@ #include #include "mm-port-mbim.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortMbim, mm_port_mbim, MM_TYPE_PORT) @@ -176,18 +176,14 @@ qmi_device_open_ready (QmiDevice *dev, self = g_task_get_source_object (task); if (!qmi_device_open_finish (dev, res, &error)) { - mm_dbg ("[%s] error: couldn't open QmiDevice: %s", - mm_port_get_device (MM_PORT (self)), - error->message); + mm_obj_dbg (self, "error: couldn't open QmiDevice: %s", error->message); g_error_free (error); g_clear_object (&self->priv->qmi_device); /* Ignore error and complete */ - mm_info ("[%s] MBIM device is not QMI capable", - mm_port_get_device (MM_PORT (self))); + mm_obj_info (self, "MBIM device is not QMI capable"); self->priv->qmi_supported = FALSE; } else { - mm_info ("[%s] MBIM device is QMI capable", - mm_port_get_device (MM_PORT (self))); + mm_obj_info (self, "MBIM device is QMI capable"); } self->priv->in_progress = FALSE; @@ -207,13 +203,10 @@ qmi_device_new_ready (GObject *unused, self->priv->qmi_device = qmi_device_new_finish (res, &error); if (!self->priv->qmi_device) { - mm_dbg ("[%s] error: couldn't create QmiDevice: %s", - mm_port_get_device (MM_PORT (self)), - error->message); + mm_obj_dbg (self, "error: couldn't create QmiDevice: %s", error->message); g_error_free (error); /* Ignore error and complete */ - mm_info ("[%s] MBIM device is not QMI capable", - mm_port_get_device (MM_PORT (self))); + mm_obj_info (self, "MBIM device is not QMI capable"); self->priv->qmi_supported = FALSE; self->priv->in_progress = FALSE; g_task_return_boolean (task, TRUE); @@ -222,8 +215,7 @@ qmi_device_new_ready (GObject *unused, } /* Try to open using QMI over MBIM */ - mm_dbg ("[%s] trying to open QMI over MBIM device...", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "trying to open QMI over MBIM device..."); qmi_device_open (self->priv->qmi_device, (QMI_DEVICE_OPEN_FLAGS_PROXY | QMI_DEVICE_OPEN_FLAGS_MBIM | @@ -272,7 +264,7 @@ mbim_query_device_services_ready (MbimDevice *device, mbim_device_service_element_array_free (device_services); } else { /* Ignore error */ - mm_dbg ("Couldn't query device services, will attempt QMI open anyway: %s", error->message); + mm_obj_dbg (self, "Couldn't query device services, will attempt QMI open anyway: %s", error->message); g_error_free (error); } @@ -283,8 +275,7 @@ mbim_query_device_services_ready (MbimDevice *device, file = G_FILE (g_task_get_task_data (task)); if (!file || !self->priv->qmi_supported) { - mm_info ("[%s] MBIM device is not QMI capable", - mm_port_get_device (MM_PORT (self))); + mm_obj_info (self, "MBIM device is not QMI capable"); self->priv->in_progress = FALSE; g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -292,8 +283,7 @@ mbim_query_device_services_ready (MbimDevice *device, } /* Attempt to create and open the QMI device */ - mm_dbg ("[%s] checking if QMI over MBIM is supported", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "checking if QMI over MBIM is supported..."); qmi_device_new (file, g_task_get_cancellable (task), (GAsyncReadyCallback) qmi_device_new_ready, @@ -338,8 +328,7 @@ mbim_device_open_ready (MbimDevice *mbim_device, return; } - mm_dbg ("[%s] MBIM device is now open", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "MBIM device is now open"); #if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED if (self->priv->qmi_supported) { @@ -507,10 +496,13 @@ qmi_device_close_ready (QmiDevice *qmi_device, GAsyncResult *res, GTask *task) { - GError *error = NULL; + GError *error = NULL; + MMPortMbim *self; + + self = g_task_get_source_object (task); if (!qmi_device_close_finish (qmi_device, res, &error)) { - mm_warn ("Couldn't properly close QMI device: %s", error->message); + mm_obj_warn (self, "Couldn't properly close QMI device: %s", error->message); g_error_free (error); } @@ -561,7 +553,8 @@ mm_port_mbim_close (MMPortMbim *self, for (l = self->priv->qmi_clients; l; l = g_list_next (l)) { QmiClient *qmi_client = QMI_CLIENT (l->data); - mm_dbg ("Releasing client for service '%s'...", qmi_service_get_string (qmi_client_get_service (qmi_client))); + mm_obj_dbg (self, "Releasing client for service '%s'...", + qmi_service_get_string (qmi_client_get_service (qmi_client))); qmi_device_release_client (self->priv->qmi_device, qmi_client, QMI_DEVICE_RELEASE_CLIENT_FLAGS_RELEASE_CID, diff --git a/src/mm-port-qmi.c b/src/mm-port-qmi.c index 75d3ee48..98dd8c44 100644 --- a/src/mm-port-qmi.c +++ b/src/mm-port-qmi.c @@ -22,7 +22,7 @@ #include #include "mm-port-qmi.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortQmi, mm_port_qmi, MM_TYPE_PORT) @@ -254,10 +254,13 @@ qmi_device_close_on_error_ready (QmiDevice *qmi_device, GAsyncResult *res, GTask *task) { - GError *error = NULL; + MMPortQmi *self; + GError *error = NULL; + + self = g_task_get_source_object (task); if (!qmi_device_close_finish (qmi_device, res, &error)) { - mm_warn ("Couldn't close QMI device after failed open sequence: %s", error->message); + mm_obj_warn (self, "Couldn't close QMI device after failed open sequence: %s", error->message); g_error_free (error); } @@ -285,12 +288,14 @@ qmi_device_close_to_reopen_ready (QmiDevice *qmi_device, GAsyncResult *res, GTask *task) { + MMPortQmi *self; PortOpenContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!qmi_device_close_finish (qmi_device, res, &ctx->error)) { - mm_warn ("Couldn't close QMI device to reopen it"); + mm_obj_warn (self, "Couldn't close QMI device to reopen it"); ctx->step = PORT_OPEN_STEP_LAST; } else ctx->step++; @@ -302,10 +307,12 @@ get_data_format_ready (QmiClientWda *client, GAsyncResult *res, GTask *task) { + MMPortQmi *self; PortOpenContext *ctx; QmiMessageWdaGetDataFormatOutput *output; g_autoptr(GError) error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); output = qmi_client_wda_get_data_format_finish (client, res, NULL); if (!output || @@ -316,7 +323,7 @@ get_data_format_ready (QmiClientWda *client, * When this happens, assume the device supports only raw-ip and be done * with it. */ if (error && g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_MISSING_ARGUMENT)) { - mm_dbg ("Querying data format failed: '%s', assuming raw-ip is only supported", error->message); + mm_obj_dbg (self, "Querying data format failed: '%s', assuming raw-ip is only supported", error->message); ctx->llp = QMI_WDA_LINK_LAYER_PROTOCOL_RAW_IP; ctx->step++; } else { @@ -406,12 +413,12 @@ port_open_step (GTask *task) ctx = g_task_get_task_data (task); switch (ctx->step) { case PORT_OPEN_STEP_FIRST: - mm_dbg ("Opening QMI device..."); + mm_obj_dbg (self, "Opening QMI device..."); ctx->step++; /* Fall through */ case PORT_OPEN_STEP_CHECK_OPENING: - mm_dbg ("Checking if QMI device already opening..."); + mm_obj_dbg (self, "Checking if QMI device already opening..."); if (self->priv->in_progress) { g_task_return_new_error (task, MM_CORE_ERROR, @@ -424,7 +431,7 @@ port_open_step (GTask *task) /* Fall through */ case PORT_OPEN_STEP_CHECK_ALREADY_OPEN: - mm_dbg ("Checking if QMI device already open..."); + mm_obj_dbg (self, "Checking if QMI device already open..."); if (self->priv->qmi_device) { g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -445,7 +452,7 @@ port_open_step (GTask *task) * that all callbacks go through the LAST step for completing. */ self->priv->in_progress = TRUE; - mm_dbg ("Creating QMI device..."); + mm_obj_dbg (self, "Creating QMI device..."); qmi_device_new (file, g_task_get_cancellable (task), (GAsyncReadyCallback) qmi_device_new_ready, @@ -458,7 +465,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_OPEN_WITHOUT_DATA_FORMAT: /* Now open the QMI device without any data format CTL flag */ - mm_dbg ("Opening device without data format update..."); + mm_obj_dbg (self, "Opening device without data format update..."); qmi_device_open (ctx->device, (QMI_DEVICE_OPEN_FLAGS_VERSION_INFO | QMI_DEVICE_OPEN_FLAGS_PROXY), @@ -469,7 +476,7 @@ port_open_step (GTask *task) return; case PORT_OPEN_STEP_GET_KERNEL_DATA_FORMAT: - mm_dbg ("Querying kernel data format..."); + mm_obj_dbg (self, "Querying kernel data format..."); /* Try to gather expected data format from the sysfs file */ ctx->kernel_data_format = qmi_device_get_expected_data_format (ctx->device, NULL); /* If data format cannot be retrieved, we fallback to 802.3 via CTL */ @@ -483,7 +490,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_ALLOCATE_WDA_CLIENT: /* Allocate WDA client */ - mm_dbg ("Allocating WDA client..."); + mm_obj_dbg (self, "Allocating WDA client..."); qmi_device_allocate_client (ctx->device, QMI_SERVICE_WDA, QMI_CID_NONE, @@ -496,7 +503,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_GET_WDA_DATA_FORMAT: /* If we have WDA client, query current data format */ g_assert (ctx->wda); - mm_dbg ("Querying device data format..."); + mm_obj_dbg (self, "Querying device data format..."); qmi_client_wda_get_data_format (QMI_CLIENT_WDA (ctx->wda), NULL, 10, @@ -508,9 +515,9 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_CHECK_DATA_FORMAT: /* We now have the WDA data format and the kernel data format, if they're * equal, we're done */ - mm_dbg ("Checking data format: kernel %s, device %s", - qmi_device_expected_data_format_get_string (ctx->kernel_data_format), - qmi_wda_link_layer_protocol_get_string (ctx->llp)); + mm_obj_dbg (self, "Checking data format: kernel %s, device %s", + qmi_device_expected_data_format_get_string (ctx->kernel_data_format), + qmi_wda_link_layer_protocol_get_string (ctx->llp)); if (ctx->kernel_data_format == QMI_DEVICE_EXPECTED_DATA_FORMAT_802_3 && ctx->llp == QMI_WDA_LINK_LAYER_PROTOCOL_802_3) { @@ -533,7 +540,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_SET_KERNEL_DATA_FORMAT: /* Update the data format to be expected by the kernel */ - mm_dbg ("Updating kernel data format: %s", qmi_wda_link_layer_protocol_get_string (ctx->llp)); + mm_obj_dbg (self, "Updating kernel data format: %s", qmi_wda_link_layer_protocol_get_string (ctx->llp)); if (ctx->llp == QMI_WDA_LINK_LAYER_PROTOCOL_802_3) { ctx->kernel_data_format = QMI_DEVICE_EXPECTED_DATA_FORMAT_802_3; self->priv->llp_is_raw_ip = FALSE; @@ -552,7 +559,7 @@ port_open_step (GTask *task) return; case PORT_OPEN_STEP_CLOSE_BEFORE_OPEN_WITH_DATA_FORMAT: - mm_dbg ("Closing device to reopen it right away..."); + mm_obj_dbg (self, "Closing device to reopen it right away..."); qmi_device_close_async (ctx->device, 5, g_task_get_cancellable (task), @@ -562,7 +569,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_OPEN_WITH_DATA_FORMAT: /* Need to reopen setting 802.3 using CTL */ - mm_dbg ("Reopening device with data format..."); + mm_obj_dbg (self, "Reopening device with data format..."); qmi_device_open (ctx->device, (QMI_DEVICE_OPEN_FLAGS_VERSION_INFO | QMI_DEVICE_OPEN_FLAGS_PROXY | @@ -576,7 +583,7 @@ port_open_step (GTask *task) case PORT_OPEN_STEP_LAST: if (ctx->error) { - mm_dbg ("QMI port open operation failed: %s", ctx->error->message); + mm_obj_dbg (self, "QMI port open operation failed: %s", ctx->error->message); if (ctx->device) { qmi_device_close_async (ctx->device, @@ -591,7 +598,7 @@ port_open_step (GTask *task) return; } - mm_dbg ("QMI port open operation finished successfully"); + mm_obj_dbg (self, "QMI port open operation finished successfully"); /* Store device in private info */ g_assert (ctx->device); @@ -721,7 +728,7 @@ mm_port_qmi_close (MMPortQmi *self, for (l = self->priv->services; l; l = g_list_next (l)) { ServiceInfo *info = l->data; - mm_dbg ("Releasing client for service '%s'...", qmi_service_get_string (info->service)); + mm_obj_dbg (self, "Releasing client for service '%s'...", qmi_service_get_string (info->service)); qmi_device_release_client (ctx->qmi_device, info->client, QMI_DEVICE_RELEASE_CLIENT_FLAGS_RELEASE_CID, diff --git a/src/mm-port-serial-at.c b/src/mm-port-serial-at.c index 67525af0..680c9297 100644 --- a/src/mm-port-serial-at.c +++ b/src/mm-port-serial-at.c @@ -22,7 +22,7 @@ #include #include "mm-port-serial-at.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortSerialAt, mm_port_serial_at, MM_TYPE_PORT_SERIAL) @@ -435,10 +435,13 @@ mm_port_serial_at_command (MMPortSerialAt *self, } static void -debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) +debug_log (MMPortSerial *self, + const gchar *prefix, + const gchar *buf, + gsize len) { static GString *debug = NULL; - const char *s; + const char *s; if (!debug) debug = g_string_sized_new (256); @@ -461,7 +464,7 @@ debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) } g_string_append_c (debug, '\''); - mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str); + mm_obj_dbg (self, "%s", debug->str); g_string_truncate (debug, 0); } @@ -497,7 +500,7 @@ mm_port_serial_at_run_init_sequence (MMPortSerialAt *self) if (!self->priv->init_sequence) return; - mm_dbg ("(%s): running init sequence...", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "running init sequence..."); /* Just queue the init commands, don't wait for reply */ for (i = 0; self->priv->init_sequence[i]; i++) { diff --git a/src/mm-port-serial-gps.c b/src/mm-port-serial-gps.c index b316d05e..ea404994 100644 --- a/src/mm-port-serial-gps.c +++ b/src/mm-port-serial-gps.c @@ -19,7 +19,7 @@ #include #include "mm-port-serial-gps.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortSerialGps, mm_port_serial_gps, MM_TYPE_PORT_SERIAL) @@ -135,10 +135,13 @@ parse_response (MMPortSerial *port, /*****************************************************************************/ static void -debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) +debug_log (MMPortSerial *self, + const gchar *prefix, + const gchar *buf, + gsize len) { static GString *debug = NULL; - const char *s; + const gchar *s; if (!debug) debug = g_string_sized_new (256); @@ -161,7 +164,7 @@ debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) } g_string_append_c (debug, '\''); - mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str); + mm_obj_dbg (self, "%s", debug->str); g_string_truncate (debug, 0); } diff --git a/src/mm-port-serial-qcdm.c b/src/mm-port-serial-qcdm.c index e723204b..e5bc94e6 100644 --- a/src/mm-port-serial-qcdm.c +++ b/src/mm-port-serial-qcdm.c @@ -27,7 +27,7 @@ #include "libqcdm/src/utils.h" #include "libqcdm/src/errors.h" #include "libqcdm/src/dm-commands.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPortSerialQcdm, mm_port_serial_qcdm, MM_TYPE_PORT_SERIAL) @@ -206,10 +206,13 @@ mm_port_serial_qcdm_command (MMPortSerialQcdm *self, } static void -debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) +debug_log (MMPortSerial *self, + const gchar *prefix, + const gchar *buf, + gsize len) { static GString *debug = NULL; - const char *s = buf; + const gchar *s = buf; if (!debug) debug = g_string_sized_new (512); @@ -219,7 +222,7 @@ debug_log (MMPortSerial *port, const char *prefix, const char *buf, gsize len) while (len--) g_string_append_printf (debug, " %02x", (guint8) (*s++ & 0xFF)); - mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str); + mm_obj_dbg (self, "%s", debug->str); g_string_truncate (debug, 0); } diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c index d5980189..b4ba6533 100644 --- a/src/mm-port-serial.c +++ b/src/mm-port-serial.c @@ -34,7 +34,7 @@ #include #include "mm-port-serial.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-helper-enums-types.h" static gboolean port_serial_queue_process (gpointer data); @@ -398,11 +398,9 @@ internal_tcsetattr (MMPortSerial *self, memset (&other, 0, sizeof (struct termios)); errno = 0; if (tcgetattr (fd, &other) != 0) - mm_dbg ("(%s): couldn't get serial port attributes after setting them: %s", - mm_port_get_device (MM_PORT (self)), g_strerror (errno)); + mm_obj_dbg (self, "couldn't get serial port attributes after setting them: %s", g_strerror (errno)); else if (memcmp (options, &other, sizeof (struct termios)) != 0) - mm_dbg ("(%s): port attributes not fully set", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "port attributes not fully set"); #undef MAX_TCSETATTR_RETRIES @@ -430,19 +428,19 @@ set_flow_control_termios (MMPortSerial *self, /* setup the requested flags */ switch (flow_control) { case MM_FLOW_CONTROL_XON_XOFF: - mm_dbg ("(%s): enabling XON/XOFF flow control", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "enabling XON/XOFF flow control"); options->c_iflag |= (IXON | IXOFF | IXANY); break; case MM_FLOW_CONTROL_RTS_CTS: - mm_dbg ("(%s): enabling RTS/CTS flow control", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "enabling RTS/CTS flow control"); options->c_cflag |= (CRTSCTS); break; case MM_FLOW_CONTROL_NONE: case MM_FLOW_CONTROL_UNKNOWN: if (had_xon_xoff) - mm_dbg ("(%s): disabling XON/XOFF flow control", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "disabling XON/XOFF flow control"); if (had_rts_cts) - mm_dbg ("(%s): disabling RTS/CTS flow control", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "disabling RTS/CTS flow control"); break; default: g_assert_not_reached (); @@ -464,13 +462,9 @@ real_config_fd (MMPortSerial *self, int fd, GError **error) if (mm_port_get_subsys (MM_PORT (self)) != MM_PORT_SUBSYS_TTY) return TRUE; - mm_dbg ("(%s): setting up baudrate: %u", - mm_port_get_device (MM_PORT (self)), - self->priv->baud); + mm_obj_dbg (self, "setting up baudrate: %u", self->priv->baud); if (!parse_baudrate (self->priv->baud, &speed) || speed == B0) { - mm_warn ("(%s): baudrate invalid: %u; defaulting to 57600", - mm_port_get_device (MM_PORT (self)), - self->priv->baud); + mm_obj_warn (self, "baudrate invalid: %u; defaulting to 57600", self->priv->baud); speed = B57600; } @@ -479,11 +473,8 @@ real_config_fd (MMPortSerial *self, int fd, GError **error) stopbits = parse_stopbits (self->priv->stopbits); memset (&stbuf, 0, sizeof (struct termios)); - if (tcgetattr (fd, &stbuf) != 0) { - mm_warn ("(%s): tcgetattr() error: %d", - mm_port_get_device (MM_PORT (self)), - errno); - } + if (tcgetattr (fd, &stbuf) != 0) + mm_obj_warn (self, "error getting serial port attributes: %s", g_strerror (errno)); stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | PARENB | PARODD | CRTSCTS); stbuf.c_iflag &= ~(IGNCR | ICRNL | IUCLC | INPCK | IXON | IXOFF | IXANY ); @@ -523,13 +514,10 @@ real_config_fd (MMPortSerial *self, int fd, GError **error) gchar *str; str = mm_flow_control_build_string_from_mask (self->priv->flow_control); - mm_dbg ("(%s): flow control explicitly requested for device is: %s", - mm_port_get_device (MM_PORT (self)), - str ? str : "unknown"); + mm_obj_dbg (self, "flow control explicitly requested for device is: %s", str ? str : "unknown"); g_free (str); } else - mm_dbg ("(%s): no flow control explicitly requested for device", - mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "no flow control explicitly requested for device"); set_flow_control_termios (self, self->priv->flow_control, &stbuf); @@ -537,7 +525,10 @@ real_config_fd (MMPortSerial *self, int fd, GError **error) } static void -serial_debug (MMPortSerial *self, const char *prefix, const char *buf, gsize len) +serial_debug (MMPortSerial *self, + const gchar *prefix, + const gchar *buf, + gsize len) { g_return_if_fail (len > 0); @@ -569,7 +560,7 @@ port_serial_process_command (MMPortSerial *self, /* Only print command the first time */ if (ctx->started == FALSE) { ctx->started = TRUE; - serial_debug (self, "-->", (const char *) ctx->command->data, ctx->command->len); + serial_debug (self, "-->", (const gchar *) ctx->command->data, ctx->command->len); } if (self->priv->send_delay == 0 || mm_port_get_subsys (MM_PORT (self)) != MM_PORT_SUBSYS_TTY) { @@ -616,7 +607,7 @@ port_serial_process_command (MMPortSerial *self, g_signal_emit (self, signals[TIMED_OUT], 0, self->priv->n_consecutive_timeouts); g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_FAILED, - "Sending command failed: '%s'", strerror (errno)); + "Sending command failed: '%s'", g_strerror (errno)); return FALSE; } break; @@ -651,7 +642,7 @@ port_serial_process_command (MMPortSerial *self, self->priv->n_consecutive_timeouts++; g_signal_emit (self, signals[TIMED_OUT], 0, self->priv->n_consecutive_timeouts); g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_FAILED, - "Sending command failed: '%s'", strerror (errno)); + "Sending command failed: '%s'", g_strerror (errno)); return FALSE; } @@ -959,15 +950,12 @@ common_input_available (MMPortSerial *self, gsize bytes_read; GIOStatus status = G_IO_STATUS_NORMAL; CommandContext *ctx; - const char *device; GError *error = NULL; gboolean iterate = TRUE; gboolean keep_source = G_SOURCE_CONTINUE; if (condition & G_IO_HUP) { - device = mm_port_get_device (MM_PORT (self)); - mm_dbg ("(%s) unexpected port hangup!", device); - + mm_obj_dbg (self, "unexpected port hangup!"); if (self->priv->response->len) g_byte_array_remove_range (self->priv->response, 0, self->priv->response->len); port_serial_close_force (self); @@ -995,11 +983,8 @@ common_input_available (MMPortSerial *self, &bytes_read, &error); if (status == G_IO_STATUS_ERROR) { - if (error) { - mm_warn ("(%s): read error: %s", - mm_port_get_device (MM_PORT (self)), - error->message); - } + if (error) + mm_obj_warn (self, "read error: %s", error->message); g_clear_error (&error); } } else if (self->priv->socket) { @@ -1016,9 +1001,7 @@ common_input_available (MMPortSerial *self, status = G_IO_STATUS_AGAIN; else status = G_IO_STATUS_ERROR; - mm_warn ("(%s): receive error: %s", - mm_port_get_device (MM_PORT (self)), - error->message); + mm_obj_warn (self, "receive error: %s", error->message); g_clear_error (&error); } else { bytes_read = (gsize) sbytes_read; @@ -1137,11 +1120,9 @@ port_connected (MMPortSerial *self, GParamSpec *pspec, gpointer user_data) connected = mm_port_get_connected (MM_PORT (self)); if (self->priv->fd >= 0 && ioctl (self->priv->fd, (connected ? TIOCNXCL : TIOCEXCL)) < 0) { - mm_warn ("(%s): could not %s serial port lock: (%d) %s", - mm_port_get_device (MM_PORT (self)), - connected ? "drop" : "re-acquire", - errno, - strerror (errno)); + mm_obj_warn (self, "could not %s serial port lock: %s", + connected ? "drop" : "re-acquire", + g_strerror (errno)); if (!connected) { // FIXME: do something here, maybe try again in a few seconds or // close the port and error out? @@ -1197,7 +1178,7 @@ mm_port_serial_open (MMPortSerial *self, GError **error) goto success; } - mm_dbg ("(%s) opening serial port...", device); + mm_obj_dbg (self, "opening serial port..."); g_get_current_time (&tv_start); @@ -1221,7 +1202,6 @@ mm_port_serial_open (MMPortSerial *self, GError **error) MM_SERIAL_ERROR, (errno == ENODEV) ? MM_SERIAL_ERROR_OPEN_FAILED_NO_DEVICE : MM_SERIAL_ERROR_OPEN_FAILED, "Could not open serial device %s: %s", device, strerror (errno_save)); - mm_warn ("(%s) could not open serial device (%d)", device, errno_save); return FALSE; } } @@ -1233,7 +1213,6 @@ mm_port_serial_open (MMPortSerial *self, GError **error) errno_save = errno; g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_OPEN_FAILED, "Could not lock serial device %s: %s", device, strerror (errno_save)); - mm_warn ("(%s) could not lock serial device (%d)", device, errno_save); goto error; } @@ -1247,21 +1226,20 @@ mm_port_serial_open (MMPortSerial *self, GError **error) if (ioctl (self->priv->fd, TIOCGSERIAL, &sinfo) == 0) { sinfo.closing_wait = ASYNC_CLOSING_WAIT_NONE; if (ioctl (self->priv->fd, TIOCSSERIAL, &sinfo) < 0) - mm_warn ("(%s): couldn't set serial port closing_wait to none: %s", - device, g_strerror (errno)); + mm_obj_warn (self, "couldn't set serial port closing_wait to none: %s", g_strerror (errno)); } } g_warn_if_fail (MM_PORT_SERIAL_GET_CLASS (self)->config_fd); if (self->priv->fd >= 0 && !MM_PORT_SERIAL_GET_CLASS (self)->config_fd (self, self->priv->fd, error)) { - mm_dbg ("(%s) failed to configure serial device", device); + mm_obj_dbg (self, "failed to configure serial device"); goto error; } g_get_current_time (&tv_end); if (tv_end.tv_sec - tv_start.tv_sec > 7) - mm_warn ("(%s): open blocked by driver for more than 7 seconds!", device); + mm_obj_warn (self, "open blocked by driver for more than 7 seconds!"); if (mm_port_get_subsys (MM_PORT (self)) != MM_PORT_SUBSYS_UNIX) { /* Create new GIOChannel */ @@ -1327,7 +1305,7 @@ mm_port_serial_open (MMPortSerial *self, GError **error) success: self->priv->open_count++; - mm_dbg ("(%s) device open count is %d (open)", device, self->priv->open_count); + mm_obj_dbg (self, "device open count is %d (open)", self->priv->open_count); /* Run additional port config if just opened */ if (self->priv->open_count == 1 && MM_PORT_SERIAL_GET_CLASS (self)->config) @@ -1336,7 +1314,7 @@ mm_port_serial_open (MMPortSerial *self, GError **error) return TRUE; error: - mm_warn ("(%s) failed to open serial device", device); + mm_obj_warn (self, "failed to open serial device"); if (self->priv->iochannel) { g_io_channel_unref (self->priv->iochannel); @@ -1369,8 +1347,7 @@ mm_port_serial_is_open (MMPortSerial *self) static void _close_internal (MMPortSerial *self, gboolean force) { - const char *device; - guint i; + guint i; g_return_if_fail (MM_IS_PORT_SERIAL (self)); @@ -1381,9 +1358,7 @@ _close_internal (MMPortSerial *self, gboolean force) self->priv->open_count--; } - device = mm_port_get_device (MM_PORT (self)); - - mm_dbg ("(%s) device open count is %d (close)", device, self->priv->open_count); + mm_obj_dbg (self, "device open count is %d (close)", self->priv->open_count); if (self->priv->open_count > 0) return; @@ -1402,7 +1377,7 @@ _close_internal (MMPortSerial *self, gboolean force) GTimeVal tv_start, tv_end; struct serial_struct sinfo = { 0 }; - mm_dbg ("(%s) closing serial port...", device); + mm_obj_dbg (self, "closing serial port..."); mm_port_set_connected (MM_PORT (self), FALSE); @@ -1415,11 +1390,10 @@ _close_internal (MMPortSerial *self, gboolean force) */ if (ioctl (self->priv->fd, TIOCGSERIAL, &sinfo) == 0) { if (sinfo.closing_wait != ASYNC_CLOSING_WAIT_NONE) { - mm_warn ("(%s): serial port closing_wait was reset!", device); + mm_obj_warn (self, "serial port closing_wait was reset!"); sinfo.closing_wait = ASYNC_CLOSING_WAIT_NONE; if (ioctl (self->priv->fd, TIOCSSERIAL, &sinfo) < 0) - mm_warn ("(%s): couldn't set serial port closing_wait to none: %s", - device, g_strerror (errno)); + mm_obj_warn (self, "couldn't set serial port closing_wait to none: %s", g_strerror (errno)); } } @@ -1452,7 +1426,7 @@ _close_internal (MMPortSerial *self, gboolean force) g_get_current_time (&tv_end); - mm_dbg ("(%s) serial port closed", device); + mm_obj_dbg (self, "serial port closed"); /* Some ports don't respond to data and when close is called * the serial layer waits up to 30 second (closing_wait) for @@ -1460,7 +1434,7 @@ _close_internal (MMPortSerial *self, gboolean force) * Log that. See GNOME bug #630670 for more details. */ if (tv_end.tv_sec - tv_start.tv_sec > 7) - mm_warn ("(%s): close blocked by driver for more than 7 seconds!", device); + mm_obj_warn (self, "close blocked by driver for more than 7 seconds!"); } /* Clear the command queue */ @@ -1514,7 +1488,7 @@ port_serial_close_force (MMPortSerial *self) if (self->priv->forced_close) return; - mm_dbg ("(%s) forced to close port", mm_port_get_device (MM_PORT (self))); + mm_obj_dbg (self, "forced to close port"); /* Mark as having forced the close, so that we don't warn about incorrect * open counts */ @@ -1651,9 +1625,7 @@ mm_port_serial_reopen (MMPortSerial *self, return; } - mm_dbg ("(%s) reopening port (%u)", - mm_port_get_device (MM_PORT (self)), - ctx->initial_open_count); + mm_obj_dbg (self, "reopening port (%u)", ctx->initial_open_count); for (i = 0; i < ctx->initial_open_count; i++) mm_port_serial_close (self); @@ -1896,16 +1868,14 @@ mm_port_serial_set_flow_control (MMPortSerial *self, /* Return if current settings are already what we want */ if (!set_flow_control_termios (self, flow_control, &options)) { - mm_dbg ("(%s): no need to change flow control settings: already %s", - mm_port_get_device (MM_PORT (self)), flow_control_str); + mm_obj_dbg (self, "no need to change flow control settings: already %s", flow_control_str); goto out; } if (!internal_tcsetattr (self, self->priv->fd, &options, &inner_error)) goto out; - mm_dbg ("(%s): flow control settings updated to %s", - mm_port_get_device (MM_PORT (self)), flow_control_str); + mm_obj_dbg (self, "flow control settings updated to %s", flow_control_str); out: g_free (flow_control_str); diff --git a/src/mm-port-serial.h b/src/mm-port-serial.h index b30bad77..e643d147 100644 --- a/src/mm-port-serial.h +++ b/src/mm-port-serial.h @@ -93,12 +93,12 @@ struct _MMPortSerialClass { /* Called to configure the serial port after it's opened. Errors, if any, * should get ignored. */ - void (*config) (MMPortSerial *self); + void (*config) (MMPortSerial *self); void (*debug_log) (MMPortSerial *self, - const char *prefix, - const char *buf, - gsize len); + const gchar *prefix, + const gchar *buf, + gsize len); /* Signals */ void (*buffer_full) (MMPortSerial *port, const GByteArray *buffer); diff --git a/src/mm-port.c b/src/mm-port.c index 0156f6e7..b9a80209 100644 --- a/src/mm-port.c +++ b/src/mm-port.c @@ -19,9 +19,13 @@ #include #include "mm-port.h" -#include "mm-log.h" +#include "mm-port-enums-types.h" +#include "mm-log-object.h" -G_DEFINE_TYPE (MMPort, mm_port, G_TYPE_OBJECT) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMPort, mm_port, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -88,10 +92,7 @@ mm_port_set_connected (MMPort *self, gboolean connected) if (self->priv->connected != connected) { self->priv->connected = connected; g_object_notify (G_OBJECT (self), MM_PORT_CONNECTED); - - mm_dbg ("(%s): port now %s", - self->priv->device, - connected ? "connected" : "disconnected"); + mm_obj_dbg (self, "port now %s", connected ? "connected" : "disconnected"); } } @@ -105,6 +106,19 @@ mm_port_peek_kernel_device (MMPort *self) /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMPort *self; + + self = MM_PORT (_self); + return g_strdup_printf ("%s/%s", + mm_port_get_device (self), + mm_modem_port_type_get_string (mm_port_get_port_type (self))); +} + +/*****************************************************************************/ + static void mm_port_init (MMPort *self) { @@ -194,6 +208,12 @@ dispose (GObject *object) G_OBJECT_CLASS (mm_port_parent_class)->dispose (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_port_class_init (MMPortClass *klass) { From 9e50dda400e0d5109e2901d7dfe8b49cebeffa56 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 16:31:01 +0100 Subject: [PATCH 024/675] base-modem: set dbus id as soon as object is created --- src/mm-base-modem.c | 12 ++++++++++++ src/mm-base-modem.h | 2 ++ src/mm-device.c | 5 ++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index 322fb892..d028be7b 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -61,6 +61,7 @@ static GParamSpec *properties[PROP_LAST]; struct _MMBaseModemPrivate { /* The connection to the system bus */ GDBusConnection *connection; + guint dbus_id; /* Modem-wide cancellable. If it ever gets cancelled, no further operations * should be done by the modem. */ @@ -113,6 +114,12 @@ struct _MMBaseModemPrivate { #endif }; +guint +mm_base_modem_get_dbus_id (MMBaseModem *self) +{ + return self->priv->dbus_id; +} + static gchar * get_hash_key (const gchar *subsys, const gchar *name) @@ -1518,11 +1525,16 @@ teardown_ports_table (MMBaseModem *self) static void mm_base_modem_init (MMBaseModem *self) { + static guint id = 0; + /* Initialize private data */ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_BASE_MODEM, MMBaseModemPrivate); + /* Each modem is given a unique id to build its own DBus path */ + self->priv->dbus_id = id++; + /* Setup authorization provider */ self->priv->authp = mm_auth_provider_get (); self->priv->authp_cancellable = g_cancellable_new (); diff --git a/src/mm-base-modem.h b/src/mm-base-modem.h index e4001f2b..0c4b95f2 100644 --- a/src/mm-base-modem.h +++ b/src/mm-base-modem.h @@ -105,6 +105,8 @@ struct _MMBaseModemClass { GType mm_base_modem_get_type (void); +guint mm_base_modem_get_dbus_id (MMBaseModem *self); + gboolean mm_base_modem_grab_port (MMBaseModem *self, MMKernelDevice *kernel_device, MMPortType ptype, diff --git a/src/mm-device.c b/src/mm-device.c index 86baf7c7..f3b0726d 100644 --- a/src/mm-device.c +++ b/src/mm-device.c @@ -251,8 +251,7 @@ static void export_modem (MMDevice *self) { GDBusConnection *connection = NULL; - static guint32 id = 0; - gchar *path; + gchar *path; g_assert (MM_IS_BASE_MODEM (self->priv->modem)); g_assert (G_IS_DBUS_OBJECT_MANAGER (self->priv->object_manager)); @@ -275,7 +274,7 @@ export_modem (MMDevice *self) /* No outstanding port tasks, so if the modem is valid we can export it */ - path = g_strdup_printf (MM_DBUS_MODEM_PREFIX "/%d", id++); + path = g_strdup_printf (MM_DBUS_MODEM_PREFIX "/%d", mm_base_modem_get_dbus_id (self->priv->modem)); g_object_get (self->priv->object_manager, "connection", &connection, NULL); From 875ef11a57e1f6eedc3ca1aa4065d6ffca84073f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 16:45:31 +0100 Subject: [PATCH 025/675] base-modem: port to use object logging Also link all grabbed ports as owned by the modem. --- src/mm-base-modem.c | 85 +++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index d028be7b..0805cedb 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -31,12 +31,15 @@ #include "mm-context.h" #include "mm-base-modem.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-port-enums-types.h" #include "mm-serial-parsers.h" #include "mm-modem-helpers.h" -G_DEFINE_ABSTRACT_TYPE (MMBaseModem, mm_base_modem, MM_GDBUS_TYPE_OBJECT_SKELETON); +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MMBaseModem, mm_base_modem, MM_GDBUS_TYPE_OBJECT_SKELETON, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) /* If we get 10 consecutive timeouts in a serial port, we consider the modem * invalid and we request re-probing. */ @@ -134,22 +137,17 @@ serial_port_timed_out_cb (MMPortSerial *port, { /* If reached the maximum number of timeouts, invalidate modem */ if (n_consecutive_timeouts >= self->priv->max_timeouts) { - mm_err ("(%s/%s) %s port timed out %u consecutive times, marking modem '%s' as invalid", - mm_port_subsys_get_string (mm_port_get_subsys (MM_PORT (port))), - mm_port_get_device (MM_PORT (port)), - mm_port_type_get_string (mm_port_get_port_type (MM_PORT (port))), - n_consecutive_timeouts, - g_dbus_object_get_object_path (G_DBUS_OBJECT (self))); + mm_obj_err (self, "port %s timed out %u consecutive times, marking modem as invalid", + mm_port_get_device (MM_PORT (port)), + n_consecutive_timeouts); g_cancellable_cancel (self->priv->cancellable); return; } if (n_consecutive_timeouts > 1) - mm_warn ("(%s/%s) %s port timed out %u consecutive times", - mm_port_subsys_get_string (mm_port_get_subsys (MM_PORT (port))), - mm_port_get_device (MM_PORT (port)), - mm_port_type_get_string (mm_port_get_port_type (MM_PORT (port))), - n_consecutive_timeouts); + mm_obj_warn (self, "port %s timed out %u consecutive times", + mm_port_get_device (MM_PORT (port)), + n_consecutive_timeouts); } gboolean @@ -228,13 +226,13 @@ mm_base_modem_grab_port (MMBaseModem *self, /* Prefer plugin-provided flags to the generic ones */ if (at_pflags == MM_PORT_SERIAL_AT_FLAG_NONE) { if (mm_kernel_device_get_property_as_boolean (kernel_device, ID_MM_PORT_TYPE_AT_PRIMARY)) { - mm_dbg ("AT port '%s/%s' flagged as primary", subsys, name); + mm_obj_dbg (self, "AT port '%s/%s' flagged as primary", subsys, name); at_pflags = MM_PORT_SERIAL_AT_FLAG_PRIMARY; } else if (mm_kernel_device_get_property_as_boolean (kernel_device, ID_MM_PORT_TYPE_AT_SECONDARY)) { - mm_dbg ("AT port '%s/%s' flagged as secondary", subsys, name); + mm_obj_dbg (self, "AT port '%s/%s' flagged as secondary", subsys, name); at_pflags = MM_PORT_SERIAL_AT_FLAG_SECONDARY; } else if (mm_kernel_device_get_property_as_boolean (kernel_device, ID_MM_PORT_TYPE_AT_PPP)) { - mm_dbg ("AT port '%s/%s' flagged as PPP", subsys, name); + mm_obj_dbg (self, "AT port '%s/%s' flagged as PPP", subsys, name); at_pflags = MM_PORT_SERIAL_AT_FLAG_PPP; } } @@ -276,8 +274,8 @@ mm_base_modem_grab_port (MMBaseModem *self, flow_control = mm_flow_control_from_string (flow_control_tag, &inner_error); if (flow_control == MM_FLOW_CONTROL_UNKNOWN) { - mm_warn ("(%s/%s) unsupported flow control settings in port: %s", - subsys, name, inner_error->message); + mm_obj_warn (self, "unsupported flow control settings in port %s: %s", + name, inner_error->message); g_error_free (inner_error); } else { g_object_set (port, @@ -346,10 +344,7 @@ mm_base_modem_grab_port (MMBaseModem *self, /* We already filter out before all non-tty, non-net, non-cdc-wdm ports */ g_assert_not_reached (); - mm_dbg ("(%s) type '%s' claimed by %s", - name, - mm_port_type_get_string (ptype), - mm_base_modem_get_device (self)); + mm_obj_dbg (self, "grabbed port '%s/%s'", name, mm_port_type_get_string (ptype)); /* Add it to the tracking HT. * Note: 'key' and 'port' now owned by the HT. */ @@ -360,6 +355,9 @@ mm_base_modem_grab_port (MMBaseModem *self, MM_PORT_KERNEL_DEVICE, kernel_device, NULL); + /* Set owner ID */ + mm_log_object_set_owner_id (MM_LOG_OBJECT (port), mm_log_object_get_id (MM_LOG_OBJECT (self))); + return TRUE; } @@ -1022,7 +1020,7 @@ initialize_ready (MMBaseModem *self, GError *error = NULL; if (mm_base_modem_initialize_finish (self, res, &error)) { - mm_dbg ("modem properly initialized"); + mm_obj_dbg (self, "modem initialized"); mm_base_modem_set_valid (self, TRUE); return; } @@ -1032,8 +1030,7 @@ initialize_ready (MMBaseModem *self, /* Even with initialization errors, we do set the state to valid, so * that the modem gets exported and the failure notified to the user. */ - mm_dbg ("Couldn't finish initialization in the current state: '%s'", - error->message); + mm_obj_dbg (self, "couldn't finish initialization in the current state: '%s'", error->message); g_error_free (error); mm_base_modem_set_valid (self, TRUE); return; @@ -1041,7 +1038,7 @@ initialize_ready (MMBaseModem *self, /* Really fatal, we cannot even export the failed modem (e.g. error before * even trying to enable the Modem interface */ - mm_warn ("couldn't initialize the modem: '%s'", error->message); + mm_obj_warn (self, "couldn't initialize: '%s'", error->message); g_error_free (error); } @@ -1049,11 +1046,10 @@ static inline void log_port (MMBaseModem *self, MMPort *port, const char *desc) { if (port) { - mm_dbg ("(%s) %s/%s %s", - self->priv->device, - mm_port_subsys_get_string (mm_port_get_subsys (port)), - mm_port_get_device (port), - desc); + mm_obj_dbg (self, "%s/%s %s", + mm_port_subsys_get_string (mm_port_get_subsys (port)), + mm_port_get_device (port), + desc); } } @@ -1474,9 +1470,9 @@ static void cleanup_modem_port (MMBaseModem *self, MMPort *port) { - mm_dbg ("cleaning up port '%s/%s'...", - mm_port_subsys_get_string (mm_port_get_subsys (MM_PORT (port))), - mm_port_get_device (MM_PORT (port))); + mm_obj_dbg (self, "cleaning up port '%s/%s'...", + mm_port_subsys_get_string (mm_port_get_subsys (MM_PORT (port))), + mm_port_get_device (MM_PORT (port))); /* Cleanup for serial ports */ if (MM_IS_PORT_SERIAL (port)) { @@ -1522,6 +1518,17 @@ teardown_ports_table (MMBaseModem *self) /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMBaseModem *self; + + self = MM_BASE_MODEM (_self); + return g_strdup_printf ("modem%u", self->priv->dbus_id); +} + +/*****************************************************************************/ + static void mm_base_modem_init (MMBaseModem *self) { @@ -1652,9 +1659,7 @@ finalize (GObject *object) g_assert (!self->priv->enable_tasks); g_assert (!self->priv->disable_tasks); - mm_dbg ("Modem (%s) '%s' completely disposed", - self->priv->plugin, - self->priv->device); + mm_obj_dbg (self, "completely disposed"); g_free (self->priv->device); g_strfreev (self->priv->drivers); @@ -1703,6 +1708,12 @@ dispose (GObject *object) G_OBJECT_CLASS (mm_base_modem_parent_class)->dispose (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_base_modem_class_init (MMBaseModemClass *klass) { From ee454643299a59416a3ae799f958e676893afb0e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 17:51:44 +0100 Subject: [PATCH 026/675] broadband-modem: port to use object logging --- src/mm-broadband-modem.c | 666 +++++++++++++++++++-------------------- 1 file changed, 333 insertions(+), 333 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 6b7687f3..05da641a 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -48,7 +48,7 @@ #include "mm-sms-part-3gpp.h" #include "mm-call-list.h" #include "mm-base-sim.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-error-helpers.h" #include "mm-port-serial-qcdm.h" @@ -427,7 +427,7 @@ modem_create_bearer (MMIfaceModem *self, task = g_task_new (self, NULL, callback, user_data); /* We just create a MMBroadbandBearer */ - mm_dbg ("Creating Broadband bearer in broadband modem"); + mm_obj_dbg (self, "creating broadband bearer in broadband modem..."); mm_broadband_bearer_new (MM_BROADBAND_MODEM (self), props, NULL, /* cancellable */ @@ -760,6 +760,7 @@ mode_pref_qcdm_ready (MMPortSerialQcdm *port, GAsyncResult *res, GTask *task) { + MMBroadbandModem *self; LoadCapabilitiesContext *ctx; QcdmResult *result; gint err = QCDM_SUCCESS; @@ -767,12 +768,13 @@ mode_pref_qcdm_ready (MMPortSerialQcdm *port, GError *error = NULL; GByteArray *response; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { /* Fall back to AT checking */ - mm_dbg ("Failed to load NV ModePref: %s", error->message); + mm_obj_dbg (self, "failed to load NV ModePref: %s", error->message); g_error_free (error); goto at_caps; } @@ -783,7 +785,7 @@ mode_pref_qcdm_ready (MMPortSerialQcdm *port, &err); g_byte_array_unref (response); if (!result) { - mm_dbg ("Failed to parse NV ModePref result: %d", err); + mm_obj_dbg (self, "failed to parse NV ModePref result: %d", err); g_byte_array_unref (response); goto at_caps; } @@ -791,7 +793,7 @@ mode_pref_qcdm_ready (MMPortSerialQcdm *port, err = qcdm_result_get_u8 (result, QCDM_CMD_NV_GET_MODE_PREF_ITEM_MODE_PREF, &pref); qcdm_result_unref (result); if (err) { - mm_dbg ("Failed to read NV ModePref: %d", err); + mm_obj_dbg (self, "failed to read NV ModePref: %d", err); goto at_caps; } @@ -847,8 +849,7 @@ load_current_capabilities_qcdm (GTask *task) g_assert (ctx->qcdm_port); if (!mm_port_serial_open (MM_PORT_SERIAL (ctx->qcdm_port), &error)) { - mm_dbg ("Failed to open QCDM port for NV ModePref request: %s", - error->message); + mm_obj_dbg (self, "failed to open QCDM port for NV ModePref request: %s", error->message); g_error_free (error); ctx->qcdm_port = NULL; load_current_capabilities_at (task); @@ -878,11 +879,10 @@ modem_load_current_capabilities (MMIfaceModem *self, LoadCapabilitiesContext *ctx; GTask *task; - mm_dbg ("loading current capabilities..."); - - ctx = g_slice_new0 (LoadCapabilitiesContext); + mm_obj_dbg (self, "loading current capabilities..."); task = g_task_new (self, NULL, callback, user_data); + ctx = g_slice_new0 (LoadCapabilitiesContext); g_task_set_task_data (task, ctx, (GDestroyNotify)load_capabilities_context_free); if (mm_base_modem_peek_port_qcdm (MM_BASE_MODEM (self))) @@ -920,7 +920,7 @@ modem_load_manufacturer_finish (MMIfaceModem *self, result = mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, error); if (result) { manufacturer = sanitize_info_reply (result, "GMI:"); - mm_dbg ("loaded manufacturer: %s", manufacturer); + mm_obj_dbg (self, "loaded manufacturer: %s", manufacturer); } return manufacturer; } @@ -936,7 +936,7 @@ modem_load_manufacturer (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading manufacturer..."); + mm_obj_dbg (self, "loading manufacturer..."); mm_base_modem_at_sequence ( MM_BASE_MODEM (self), manufacturers, @@ -960,7 +960,7 @@ modem_load_model_finish (MMIfaceModem *self, result = mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, error); if (result) { model = sanitize_info_reply (result, "GMM:"); - mm_dbg ("loaded model: %s", model); + mm_obj_dbg (self, "loaded model: %s", model); } return model; } @@ -976,7 +976,7 @@ modem_load_model (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading model..."); + mm_obj_dbg (self, "loading model..."); mm_base_modem_at_sequence ( MM_BASE_MODEM (self), models, @@ -1000,7 +1000,7 @@ modem_load_revision_finish (MMIfaceModem *self, result = mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, error); if (result) { revision = sanitize_info_reply (result, "GMR:"); - mm_dbg ("loaded revision: %s", revision); + mm_obj_dbg (self, "loaded revision: %s", revision); } return revision; } @@ -1016,7 +1016,7 @@ modem_load_revision (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading revision..."); + mm_obj_dbg (self, "loading revision..."); mm_base_modem_at_sequence ( MM_BASE_MODEM (self), revisions, @@ -1060,7 +1060,7 @@ modem_load_equipment_identifier_finish (MMIfaceModem *self, } else { /* Leave whatever the modem returned alone */ } - mm_dbg ("loaded equipment identifier: %s", equip_id); + mm_obj_dbg (self, "loaded equipment identifier: %s", equip_id); } return equip_id; } @@ -1078,7 +1078,7 @@ modem_load_equipment_identifier (MMIfaceModem *self, { const MMBaseModemAtCommand *commands = equipment_identifiers; - mm_dbg ("loading equipment identifier..."); + mm_obj_dbg (self, "loading equipment identifier..."); /* On CDMA-only (non-3GPP) modems, just try +GSN */ if (mm_iface_modem_is_cdma_only (self)) @@ -1129,7 +1129,7 @@ modem_load_device_identifier_finish (MMIfaceModem *self, MM_BROADBAND_MODEM (self), ((DeviceIdentifierContext *)ctx)->ati, ((DeviceIdentifierContext *)ctx)->ati1)); - mm_dbg ("loaded device identifier: %s", device_identifier); + mm_obj_dbg (self, "loaded device identifier: %s", device_identifier); return device_identifier; } @@ -1166,7 +1166,7 @@ modem_load_device_identifier (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading device identifier..."); + mm_obj_dbg (self, "loading device identifier..."); mm_base_modem_at_sequence ( MM_BASE_MODEM (self), device_identifier_steps, @@ -1327,9 +1327,9 @@ modem_load_own_numbers (MMIfaceModem *self, if (mm_port_serial_open (MM_PORT_SERIAL (ctx->qcdm), &error)) { ctx->qcdm = g_object_ref (ctx->qcdm); } else { - mm_dbg ("Couldn't open QCDM port: (%d) %s", - error ? error->code : -1, - error ? error->message : "(unknown)"); + mm_obj_dbg (self, "couldn't open QCDM port: (%d) %s", + error ? error->code : -1, + error ? error->message : "(unknown)"); ctx->qcdm = NULL; } } @@ -1337,7 +1337,7 @@ modem_load_own_numbers (MMIfaceModem *self, task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, ctx, (GDestroyNotify)own_numbers_context_free); - mm_dbg ("loading own numbers..."); + mm_obj_dbg (self, "loading own numbers..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+CNUM", 3, @@ -1448,13 +1448,13 @@ modem_load_unlock_required (MMIfaceModem *self, /* CDMA-only modems don't need this */ if (mm_iface_modem_is_cdma_only (self)) { - mm_dbg ("Skipping unlock check in CDMA-only modem..."); + mm_obj_dbg (self, "skipping unlock check in CDMA-only modem..."); g_task_return_int (task, MM_MODEM_LOCK_NONE); g_object_unref (task); return; } - mm_dbg ("checking if unlock required..."); + mm_obj_dbg (self, "checking if unlock required..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+CPIN?", 10, @@ -1514,17 +1514,17 @@ csim_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (self, res, &error); if (!response) { - mm_dbg ("Couldn't load retry count for lock '%s': %s", - mm_modem_lock_get_string (unlock_retries_map[ctx->i].lock), - error->message); + mm_obj_dbg (self, "couldn't load retry count for lock '%s': %s", + mm_modem_lock_get_string (unlock_retries_map[ctx->i].lock), + error->message); goto next; } val = mm_parse_csim_response (response, &error); if (val < 0) { - mm_dbg ("Couldn't parse retry count value for lock '%s': %s", - mm_modem_lock_get_string (unlock_retries_map[ctx->i].lock), - error->message); + mm_obj_dbg (self, "couldn't parse retry count value for lock '%s': %s", + mm_modem_lock_get_string (unlock_retries_map[ctx->i].lock), + error->message); goto next; } @@ -1640,7 +1640,7 @@ supported_modes_gcap_ready (MMBaseModem *_self, self->priv->modem_cdma_evdo_network_supported = TRUE; g_object_notify (G_OBJECT (self), MM_IFACE_MODEM_CDMA_EVDO_NETWORK_SUPPORTED); } - mm_dbg ("Device allows (CDMA) 3G network mode"); + mm_obj_dbg (self, "device allows (CDMA) 3G network mode"); mode |= MM_MODEM_MODE_3G; } /* IS-707 is the 1xRTT family, which we consider as 2G */ @@ -1649,7 +1649,7 @@ supported_modes_gcap_ready (MMBaseModem *_self, self->priv->modem_cdma_cdma1x_network_supported = TRUE; g_object_notify (G_OBJECT (self), MM_IFACE_MODEM_CDMA_CDMA1X_NETWORK_SUPPORTED); } - mm_dbg ("Device allows (CDMA) 2G network mode"); + mm_obj_dbg (self, "device allows (CDMA) 2G network mode"); mode |= MM_MODEM_MODE_2G; } } @@ -1668,16 +1668,16 @@ supported_modes_gcap_ready (MMBaseModem *_self, } if (error) { - mm_dbg ("Generic query of supported CDMA networks failed: '%s'", error->message); + mm_obj_dbg (self, "generic query of supported CDMA networks failed: '%s'", error->message); g_error_free (error); /* Use defaults */ if (self->priv->modem_cdma_cdma1x_network_supported) { - mm_dbg ("Assuming device allows (CDMA) 2G network mode"); + mm_obj_dbg (self, "assuming device allows (CDMA) 2G network mode"); ctx->mode |= MM_MODEM_MODE_2G; } if (self->priv->modem_cdma_evdo_network_supported) { - mm_dbg ("Assuming device allows (CDMA) 3G network mode"); + mm_obj_dbg (self, "assuming device allows (CDMA) 3G network mode"); ctx->mode |= MM_MODEM_MODE_3G; } } @@ -1702,14 +1702,14 @@ supported_modes_ws46_test_ready (MMBroadbandModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (error) { - mm_dbg ("Generic query of supported 3GPP networks with WS46=? failed: '%s'", error->message); + mm_obj_dbg (self, "generic query of supported 3GPP networks with WS46=? failed: '%s'", error->message); g_error_free (error); goto out; } modes = mm_3gpp_parse_ws46_test_response (response, &error); if (!modes) { - mm_dbg ("Parsing WS46=? response failed: '%s'", error->message); + mm_obj_dbg (self, "parsing WS46=? response failed: '%s'", error->message); g_error_free (error); goto out; } @@ -1723,7 +1723,7 @@ supported_modes_ws46_test_ready (MMBroadbandModem *self, ctx->mode |= mode; str = mm_modem_mode_build_string_from_mask (mode); - mm_dbg ("Device allows (3GPP) mode combination: %s", str); + mm_obj_dbg (self, "device allows (3GPP) mode combination: %s", str); g_free (str); } @@ -1756,7 +1756,7 @@ supported_modes_cnti_ready (MMBroadbandModem *self, if (g_strstr_len (lower, -1, "gsm") || g_strstr_len (lower, -1, "gprs") || g_strstr_len (lower, -1, "edge")) { - mm_dbg ("Device allows (3GPP) 2G networks"); + mm_obj_dbg (self, "device allows (3GPP) 2G networks"); mode |= MM_MODEM_MODE_2G; } @@ -1764,12 +1764,12 @@ supported_modes_cnti_ready (MMBroadbandModem *self, g_strstr_len (lower, -1, "hsdpa") || g_strstr_len (lower, -1, "hsupa") || g_strstr_len (lower, -1, "hspa+")) { - mm_dbg ("Device allows (3GPP) 3G networks"); + mm_obj_dbg (self, "device allows (3GPP) 3G networks"); mode |= MM_MODEM_MODE_3G; } if (g_strstr_len (lower, -1, "lte")) { - mm_dbg ("Device allows (3GPP) 4G networks"); + mm_obj_dbg (self, "device allows (3GPP) 4G networks"); mode |= MM_MODEM_MODE_4G; } @@ -1777,11 +1777,11 @@ supported_modes_cnti_ready (MMBroadbandModem *self, /* If no expected ID found, log error */ if (mode == MM_MODEM_MODE_NONE) - mm_dbg ("Invalid list of supported networks reported by *CNTI: '%s'", response); + mm_obj_dbg (self, "invalid list of supported networks reported by *CNTI: '%s'", response); else ctx->mode |= mode; } else { - mm_dbg ("Generic query of supported 3GPP networks with *CNTI failed: '%s'", error->message); + mm_obj_dbg (self, "generic query of supported 3GPP networks with *CNTI failed: '%s'", error->message); g_error_free (error); } @@ -1853,7 +1853,7 @@ modem_load_supported_modes (MMIfaceModem *self, LoadSupportedModesContext *ctx; GTask *task; - mm_dbg ("loading supported modes..."); + mm_obj_dbg (self, "loading supported modes..."); ctx = g_new0 (LoadSupportedModesContext, 1); ctx->mode = MM_MODEM_MODE_NONE; @@ -1928,7 +1928,7 @@ modem_load_supported_ip_families (MMIfaceModem *self, { GTask *task; - mm_dbg ("loading supported IP families..."); + mm_obj_dbg (self, "loading supported IP families..."); task = g_task_new (self, NULL, callback, user_data); if (mm_iface_modem_is_cdma_only (self)) { @@ -1982,7 +1982,7 @@ qcdm_evdo_pilot_sets_log_handle (MMPortSerialQcdm *port, &pilot_pn, &pilot_energy, &rssi_dbm)) { - mm_dbg ("EVDO active pilot RSSI: %ddBm", rssi_dbm); + mm_obj_dbg (self, "EVDO active pilot RSSI: %ddBm", rssi_dbm); self->priv->evdo_pilot_rssi = rssi_dbm; } @@ -2134,14 +2134,11 @@ signal_quality_cind_ready (MMBroadbandModem *self, GAsyncResult *res, GTask *task) { - SignalQualityContext *ctx; GError *error = NULL; const gchar *result; GByteArray *indicators; guint quality = 0; - ctx = g_task_get_task_data (task); - result = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (error) { g_clear_error (&error); @@ -2150,19 +2147,17 @@ signal_quality_cind_ready (MMBroadbandModem *self, indicators = mm_3gpp_parse_cind_read_response (result, &error); if (!indicators) { - mm_dbg ("(%s) Could not parse CIND signal quality results: %s", - mm_port_get_device (MM_PORT (ctx->at_port)), - error->message); + mm_obj_dbg (self, "could not parse CIND signal quality results: %s", error->message); g_clear_error (&error); goto try_csq; } if (indicators->len < self->priv->modem_cind_indicator_signal_quality) { - mm_dbg ("(%s) Could not parse CIND signal quality results; signal " - "index (%u) outside received range (0-%u)", - mm_port_get_device (MM_PORT (ctx->at_port)), - self->priv->modem_cind_indicator_signal_quality, - indicators->len); + mm_obj_dbg (self, + "could not parse CIND signal quality results; signal " + "index (%u) outside received range (0-%u)", + self->priv->modem_cind_indicator_signal_quality, + indicators->len); } else { quality = g_array_index (indicators, guint8, @@ -2317,7 +2312,7 @@ modem_load_signal_quality (MMIfaceModem *_self, GError *error = NULL; GTask *task; - mm_dbg ("loading signal quality..."); + mm_obj_dbg (self, "loading signal quality..."); ctx = g_new0 (SignalQualityContext, 1); task = g_task_new (self, NULL, callback, user_data); @@ -2348,7 +2343,7 @@ modem_load_signal_quality (MMIfaceModem *_self, } ctx->qcdm_port = NULL; - mm_dbg ("Couldn't open QCDM port: %s", error->message); + mm_obj_dbg (self, "couldn't open QCDM port: %s", error->message); } /* Return the error we got when getting best AT port */ @@ -2408,24 +2403,25 @@ access_tech_context_free (AccessTechContext *ctx) } static AccessTechAndMask * -access_tech_and_mask_new (AccessTechContext *ctx) +access_tech_and_mask_new (MMBroadbandModem *self, + AccessTechContext *ctx) { AccessTechAndMask *tech; MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; guint mask = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; if (ctx->fallback_mask) { - mm_dbg ("Fallback access technology: 0x%08x", ctx->fallback_act); + mm_obj_dbg (self, "fallback access technology: 0x%08x", ctx->fallback_act); act = ctx->fallback_act; mask = ctx->fallback_mask; goto done; } - mm_dbg ("QCDM operating mode: %d", ctx->opmode); - mm_dbg ("QCDM system mode: %d", ctx->sysmode); - mm_dbg ("QCDM hybrid pref: %d", ctx->hybrid); - mm_dbg ("QCDM WCDMA open: %d", ctx->wcdma_open); - mm_dbg ("QCDM EVDO open: %d", ctx->evdo_open); + mm_obj_dbg (self, "QCDM operating mode: %d", ctx->opmode); + mm_obj_dbg (self, "QCDM system mode: %d", ctx->sysmode); + mm_obj_dbg (self, "QCDM hybrid pref: %d", ctx->hybrid); + mm_obj_dbg (self, "QCDM WCDMA open: %d", ctx->wcdma_open); + mm_obj_dbg (self, "QCDM EVDO open: %d", ctx->evdo_open); if (ctx->opmode == QCDM_CMD_CM_SUBSYS_STATE_INFO_OPERATING_MODE_ONLINE) { switch (ctx->sysmode) { @@ -2481,6 +2477,7 @@ access_tech_qcdm_wcdma_ready (MMPortSerialQcdm *port, GAsyncResult *res, GTask *task) { + MMBroadbandModem *self; AccessTechContext *ctx; QcdmResult *result; gint err = QCDM_SUCCESS; @@ -2495,6 +2492,7 @@ access_tech_qcdm_wcdma_ready (MMPortSerialQcdm *port, return; } + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); /* Parse the response */ @@ -2513,7 +2511,9 @@ access_tech_qcdm_wcdma_ready (MMPortSerialQcdm *port, ctx->wcdma_open = TRUE; } - g_task_return_pointer (task, access_tech_and_mask_new (ctx), g_free); + g_task_return_pointer (task, + access_tech_and_mask_new (MM_BROADBAND_MODEM (self), ctx), + g_free); g_object_unref (task); } @@ -2581,6 +2581,7 @@ access_tech_qcdm_hdr_ready (MMPortSerialQcdm *port, GAsyncResult *res, GTask *task) { + MMBroadbandModem *self; AccessTechContext *ctx; QcdmResult *result; gint err = QCDM_SUCCESS; @@ -2596,7 +2597,8 @@ access_tech_qcdm_hdr_ready (MMPortSerialQcdm *port, return; } - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* Parse the response */ result = qcdm_cmd_hdr_subsys_state_info_result ((const gchar *) response->data, @@ -2614,7 +2616,7 @@ access_tech_qcdm_hdr_ready (MMPortSerialQcdm *port, ctx->evdo_open = TRUE; } - g_task_return_pointer (task, access_tech_and_mask_new (ctx), g_free); + g_task_return_pointer (task, access_tech_and_mask_new (self, ctx), g_free); g_object_unref (task); } @@ -2697,9 +2699,9 @@ access_tech_from_cdma_registration_state (MMBroadbandModem *self, ctx->fallback_mask = MM_IFACE_MODEM_CDMA_ALL_ACCESS_TECHNOLOGIES_MASK; } - mm_dbg ("EVDO registration: %d", self->priv->modem_cdma_evdo_registration_state); - mm_dbg ("CDMA1x registration: %d", self->priv->modem_cdma_cdma1x_registration_state); - mm_dbg ("Fallback access tech: 0x%08x", ctx->fallback_act); + mm_obj_dbg (self, "EVDO registration: %d", self->priv->modem_cdma_evdo_registration_state); + mm_obj_dbg (self, "CDMA1x registration: %d", self->priv->modem_cdma_cdma1x_registration_state); + mm_obj_dbg (self, "fallback access tech: 0x%08x", ctx->fallback_act); } static void @@ -2727,7 +2729,7 @@ modem_load_access_technologies (MMIfaceModem *self, if (mm_port_serial_open (MM_PORT_SERIAL (ctx->port), &error)) { g_object_ref (ctx->port); - mm_dbg ("loading access technologies via QCDM..."); + mm_obj_dbg (self, "loading access technologies via QCDM..."); /* FIXME: we may want to run both the CDMA and 3GPP in sequence to ensure * that a multi-mode device that's in CDMA-mode but still has 3GPP capabilities @@ -2768,7 +2770,7 @@ modem_load_access_technologies (MMIfaceModem *self, } ctx->port = NULL; - mm_dbg ("Couldn't open QCDM port: %s", error->message); + mm_obj_dbg (self, "couldn't open QCDM port: %s", error->message); g_clear_error (&error); } @@ -2778,7 +2780,9 @@ modem_load_access_technologies (MMIfaceModem *self, * guess access technologies from the registration information. */ access_tech_from_cdma_registration_state (MM_BROADBAND_MODEM (self), ctx); - g_task_return_pointer (task, access_tech_and_mask_new (ctx), g_free); + g_task_return_pointer (task, + access_tech_and_mask_new (MM_BROADBAND_MODEM (self), ctx), + g_free); } else { g_task_return_new_error (task, MM_CORE_ERROR, @@ -2818,7 +2822,7 @@ bearer_report_disconnected (MMBaseBearer *bearer, if (mm_base_bearer_get_status (bearer) == MM_BEARER_STATUS_DISCONNECTED) return; - mm_info ("Bearer %s: explicitly disconnected", mm_base_bearer_get_path (bearer)); + mm_obj_info (bearer, "explicitly disconnected"); mm_base_bearer_report_connection_status (bearer, MM_BEARER_CONNECTION_STATUS_DISCONNECTED); } @@ -2845,13 +2849,13 @@ cgev_process_detach (MMBroadbandModem *self, MM3gppCgev type) { if (type == MM_3GPP_CGEV_NW_DETACH) { - mm_info ("network forced PS detach: all contexts have been deactivated"); + mm_obj_info (self, "network forced PS detach: all contexts have been deactivated"); bearer_list_report_disconnections (self, 0); return; } if (type == MM_3GPP_CGEV_ME_DETACH) { - mm_info ("mobile equipment forced PS detach: all contexts have been deactivated"); + mm_obj_info (self, "mobile equipment forced PS detach: all contexts have been deactivated"); bearer_list_report_disconnections (self, 0); return; } @@ -2868,24 +2872,24 @@ cgev_process_primary (MMBroadbandModem *self, guint cid = 0; if (!mm_3gpp_parse_cgev_indication_primary (str, type, &cid, &error)) { - mm_warn ("couldn't parse cid info from +CGEV indication '%s': %s", str, error->message); + mm_obj_warn (self, "couldn't parse cid info from +CGEV indication '%s': %s", str, error->message); g_error_free (error); return; } switch (type) { case MM_3GPP_CGEV_NW_ACT_PRIMARY: - mm_info ("network request to activate context (cid %u)", cid); + mm_obj_info (self, "network request to activate context (cid %u)", cid); break; case MM_3GPP_CGEV_ME_ACT_PRIMARY: - mm_info ("mobile equipment request to activate context (cid %u)", cid); + mm_obj_info (self, "mobile equipment request to activate context (cid %u)", cid); break; case MM_3GPP_CGEV_NW_DEACT_PRIMARY: - mm_info ("network request to deactivate context (cid %u)", cid); + mm_obj_info (self, "network request to deactivate context (cid %u)", cid); bearer_list_report_disconnections (self, cid); break; case MM_3GPP_CGEV_ME_DEACT_PRIMARY: - mm_info ("mobile equipment request to deactivate context (cid %u)", cid); + mm_obj_info (self, "mobile equipment request to deactivate context (cid %u)", cid); bearer_list_report_disconnections (self, cid); break; case MM_3GPP_CGEV_UNKNOWN: @@ -2919,24 +2923,24 @@ cgev_process_secondary (MMBroadbandModem *self, guint cid = 0; if (!mm_3gpp_parse_cgev_indication_secondary (str, type, &p_cid, &cid, NULL, &error)) { - mm_warn ("couldn't parse p_cid/cid info from +CGEV indication '%s': %s", str, error->message); + mm_obj_warn (self, "couldn't parse p_cid/cid info from +CGEV indication '%s': %s", str, error->message); g_error_free (error); return; } switch (type) { case MM_3GPP_CGEV_NW_ACT_SECONDARY: - mm_info ("network request to activate secondary context (cid %u, primary cid %u)", cid, p_cid); + mm_obj_info (self, "network request to activate secondary context (cid %u, primary cid %u)", cid, p_cid); break; case MM_3GPP_CGEV_ME_ACT_SECONDARY: - mm_info ("mobile equipment request to activate secondary context (cid %u, primary cid %u)", cid, p_cid); + mm_obj_info (self, "mobile equipment request to activate secondary context (cid %u, primary cid %u)", cid, p_cid); break; case MM_3GPP_CGEV_NW_DEACT_SECONDARY: - mm_info ("network request to deactivate secondary context (cid %u, primary cid %u)", cid, p_cid); + mm_obj_info (self, "network request to deactivate secondary context (cid %u, primary cid %u)", cid, p_cid); bearer_list_report_disconnections (self, cid); break; case MM_3GPP_CGEV_ME_DEACT_SECONDARY: - mm_info ("mobile equipment request to deactivate secondary context (cid %u, primary cid %u)", cid, p_cid); + mm_obj_info (self, "mobile equipment request to deactivate secondary context (cid %u, primary cid %u)", cid, p_cid); bearer_list_report_disconnections (self, cid); break; case MM_3GPP_CGEV_UNKNOWN: @@ -2971,35 +2975,35 @@ cgev_process_pdp (MMBroadbandModem *self, guint cid = 0; if (!mm_3gpp_parse_cgev_indication_pdp (str, type, &pdp_type, &pdp_addr, &cid, &error)) { - mm_warn ("couldn't parse PDP info from +CGEV indication '%s': %s", str, error->message); + mm_obj_warn (self, "couldn't parse PDP info from +CGEV indication '%s': %s", str, error->message); g_error_free (error); return; } switch (type) { case MM_3GPP_CGEV_REJECT: - mm_info ("network request to activate context (type %s, address %s) has been automatically rejected", pdp_type, pdp_addr); + mm_obj_info (self, "network request to activate context (type %s, address %s) has been automatically rejected", pdp_type, pdp_addr); break; case MM_3GPP_CGEV_NW_REACT: /* NOTE: we don't currently notify about automatic reconnections like this one */ if (cid) - mm_info ("network request to reactivate context (type %s, address %s, cid %u)", pdp_type, pdp_addr, cid); + mm_obj_info (self, "network request to reactivate context (type %s, address %s, cid %u)", pdp_type, pdp_addr, cid); else - mm_info ("network request to reactivate context (type %s, address %s, cid unknown)", pdp_type, pdp_addr); + mm_obj_info (self, "network request to reactivate context (type %s, address %s, cid unknown)", pdp_type, pdp_addr); break; case MM_3GPP_CGEV_NW_DEACT_PDP: if (cid) { - mm_info ("network request to deactivate context (type %s, address %s, cid %u)", pdp_type, pdp_addr, cid); + mm_obj_info (self, "network request to deactivate context (type %s, address %s, cid %u)", pdp_type, pdp_addr, cid); bearer_list_report_disconnections (self, cid); } else - mm_info ("network request to deactivate context (type %s, address %s, cid unknown)", pdp_type, pdp_addr); + mm_obj_info (self, "network request to deactivate context (type %s, address %s, cid unknown)", pdp_type, pdp_addr); break; case MM_3GPP_CGEV_ME_DEACT_PDP: if (cid) { - mm_info ("mobile equipment request to deactivate context (type %s, address %s, cid %u)", pdp_type, pdp_addr, cid); + mm_obj_info (self, "mobile equipment request to deactivate context (type %s, address %s, cid %u)", pdp_type, pdp_addr, cid); bearer_list_report_disconnections (self, cid); } else - mm_info ("mobile equipment request to deactivate context (type %s, address %s, cid unknown)", pdp_type, pdp_addr); + mm_obj_info (self, "mobile equipment request to deactivate context (type %s, address %s, cid unknown)", pdp_type, pdp_addr); break; case MM_3GPP_CGEV_UNKNOWN: case MM_3GPP_CGEV_NW_DETACH: @@ -3070,7 +3074,7 @@ cgev_received (MMPortSerialAt *port, break; case MM_3GPP_CGEV_UNKNOWN: default: - mm_dbg ("unhandled +CGEV indication: %s", str); + mm_obj_dbg (self, "unhandled +CGEV indication: %s", str); break; } @@ -3095,9 +3099,9 @@ set_cgev_unsolicited_events_handlers (MMBroadbandModem *self, continue; /* Set/unset unsolicited CGEV event handler */ - mm_dbg ("(%s) %s 3GPP +CGEV unsolicited events handlers", - mm_port_get_device (MM_PORT (ports[i])), - enable ? "Setting" : "Removing"); + mm_obj_dbg (self, "%s 3GPP +CGEV unsolicited events handlers in %s", + enable ? "setting" : "removing", + mm_port_get_device (MM_PORT (ports[i]))); mm_port_serial_at_add_unsolicited_msg_handler ( ports[i], cgev_regex, @@ -3116,7 +3120,7 @@ ciev_signal_received (MMBroadbandModem *self, guint quality; if (!mm_get_uint_from_match_info (match_info, 2, &quality)) { - mm_dbg ("Couldn't parse signal quality value from +CIEV"); + mm_obj_dbg (self, "couldn't parse signal quality value from +CIEV"); return; } @@ -3171,9 +3175,9 @@ set_ciev_unsolicited_events_handlers (MMBroadbandModem *self, continue; /* Set/unset unsolicited CIEV event handler */ - mm_dbg ("(%s) %s 3GPP +CIEV unsolicited events handlers", - mm_port_get_device (MM_PORT (ports[i])), - enable ? "Setting" : "Removing"); + mm_obj_dbg (self, "%s 3GPP +CIEV unsolicited events handlers in %s", + enable ? "setting" : "removing", + mm_port_get_device (MM_PORT (ports[i]))); mm_port_serial_at_add_unsolicited_msg_handler ( ports[i], ciev_regex, @@ -3214,12 +3218,13 @@ cgerep_format_check_ready (MMBroadbandModem *self, result = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!result) { - mm_dbg ("+CGEREP check failed, marking packet domain event reporting as unsupported: '%s'", error->message); + mm_obj_dbg (self, "+CGEREP check failed: %s", error->message); + mm_obj_dbg (self, "packet domain event reporting is unsupported"); g_error_free (error); goto out; } - mm_dbg ("Modem supports packet domain event reporting"); + mm_obj_dbg (self, "packet domain event reporting is supported"); self->priv->modem_cgerep_supported = TRUE; out: @@ -3240,17 +3245,18 @@ cmer_format_check_ready (MMBroadbandModem *self, result = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (error || !mm_3gpp_parse_cmer_test_response (result, &supported_modes, &supported_inds, &error)) { - mm_dbg ("+CMER check failed, marking indications as unsupported: '%s'", error->message); + mm_obj_dbg (self, "+CMER check failed: %s", error->message); + mm_obj_dbg (self, "generic indications are unsupported"); g_error_free (error); goto out; } aux = mm_3gpp_cmer_mode_build_string_from_mask (supported_modes); - mm_dbg ("Supported +CMER modes: %s", aux); + mm_obj_dbg (self, "supported +CMER modes: %s", aux); g_free (aux); aux = mm_3gpp_cmer_ind_build_string_from_mask (supported_inds); - mm_dbg ("Supported +CMER indication settings: %s", aux); + mm_obj_dbg (self, "supported +CMER indication settings: %s", aux); g_free (aux); /* Flag +CMER supported values */ @@ -3263,14 +3269,14 @@ cmer_format_check_ready (MMBroadbandModem *self, self->priv->modem_cmer_enable_mode = MM_3GPP_CMER_MODE_DISCARD_URCS_IF_LINK_RESERVED; aux = mm_3gpp_cmer_mode_build_string_from_mask (self->priv->modem_cmer_enable_mode); - mm_dbg ("+CMER enable mode: %s", aux); + mm_obj_dbg (self, "+CMER enable mode: %s", aux); g_free (aux); if (supported_modes & MM_3GPP_CMER_MODE_DISCARD_URCS) self->priv->modem_cmer_disable_mode = MM_3GPP_CMER_MODE_DISCARD_URCS; aux = mm_3gpp_cmer_mode_build_string_from_mask (self->priv->modem_cmer_disable_mode); - mm_dbg ("+CMER disable mode: %s", aux); + mm_obj_dbg (self, "+CMER disable mode: %s", aux); g_free (aux); if (supported_inds & MM_3GPP_CMER_IND_ENABLE_NOT_CAUSED_BY_CIND) @@ -3279,7 +3285,7 @@ cmer_format_check_ready (MMBroadbandModem *self, self->priv->modem_cmer_ind = MM_3GPP_CMER_IND_ENABLE_ALL; aux = mm_3gpp_cmer_ind_build_string_from_mask (self->priv->modem_cmer_ind); - mm_dbg ("+CMER indication setting: %s", aux); + mm_obj_dbg (self, "+CMER indication setting: %s", aux); g_free (aux); out: @@ -3301,7 +3307,8 @@ cind_format_check_ready (MMBroadbandModem *self, if (error || !(indicators = mm_3gpp_parse_cind_test_response (result, &error))) { /* unsupported indications */ - mm_dbg ("+CIND check failed, marking indications as unsupported: '%s'", error->message); + mm_obj_dbg (self, "+CIND check failed: %s", error->message); + mm_obj_dbg (self, "generic indications are unsupported"); g_error_free (error); /* go on with remaining checks */ check_and_setup_3gpp_urc_support (task); @@ -3319,11 +3326,10 @@ cind_format_check_ready (MMBroadbandModem *self, self->priv->modem_cind_min_signal_quality = mm_3gpp_cind_response_get_min (r); self->priv->modem_cind_max_signal_quality = mm_3gpp_cind_response_get_max (r); - mm_dbg ("Modem supports signal quality indications via CIND at index '%u'" - "(min: %u, max: %u)", - self->priv->modem_cind_indicator_signal_quality, - self->priv->modem_cind_min_signal_quality, - self->priv->modem_cind_max_signal_quality); + mm_obj_dbg (self, "signal quality indications via CIND are supported at index '%u' (min: %u, max: %u)", + self->priv->modem_cind_indicator_signal_quality, + self->priv->modem_cind_min_signal_quality, + self->priv->modem_cind_max_signal_quality); } else self->priv->modem_cind_indicator_signal_quality = CIND_INDICATOR_INVALID; @@ -3331,8 +3337,8 @@ cind_format_check_ready (MMBroadbandModem *self, r = g_hash_table_lookup (indicators, "roam"); if (r) { self->priv->modem_cind_indicator_roaming = mm_3gpp_cind_response_get_index (r); - mm_dbg ("Modem supports roaming indications via CIND at index '%u'", - self->priv->modem_cind_indicator_roaming); + mm_obj_dbg (self, "roaming indications via CIND are supported at index '%u'", + self->priv->modem_cind_indicator_roaming); } else self->priv->modem_cind_indicator_roaming = CIND_INDICATOR_INVALID; @@ -3340,8 +3346,8 @@ cind_format_check_ready (MMBroadbandModem *self, r = g_hash_table_lookup (indicators, "service"); if (r) { self->priv->modem_cind_indicator_service = mm_3gpp_cind_response_get_index (r); - mm_dbg ("Modem supports service indications via CIND at index '%u'", - self->priv->modem_cind_indicator_service); + mm_obj_dbg (self, "service indications via CIND are supported at index '%u'", + self->priv->modem_cind_indicator_service); } else self->priv->modem_cind_indicator_service = CIND_INDICATOR_INVALID; @@ -3365,7 +3371,7 @@ check_and_setup_3gpp_urc_support (GTask *task) /* Check support for +CIEV indications, managed with +CIND/+CMER */ if (!self->priv->modem_cind_disabled && !self->priv->modem_cind_support_checked) { - mm_dbg ("Checking indicator support..."); + mm_obj_dbg (self, "checking indicator support..."); self->priv->modem_cind_support_checked = TRUE; mm_base_modem_at_command (MM_BASE_MODEM (self), "+CIND=?", @@ -3378,7 +3384,7 @@ check_and_setup_3gpp_urc_support (GTask *task) /* Check support for +CGEV indications, managed with +CGEREP */ if (!self->priv->modem_cgerep_support_checked) { - mm_dbg ("Checking packet domain event reporting..."); + mm_obj_dbg (self, "checking packet domain event reporting..."); self->priv->modem_cgerep_support_checked = TRUE; mm_base_modem_at_command (MM_BASE_MODEM (self), "+CGEREP=?", @@ -3471,9 +3477,9 @@ unsolicited_events_setup_ready (MMBroadbandModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error)) { - mm_dbg ("Couldn't %s event reporting: '%s'", - ctx->enable ? "enable" : "disable", - error->message); + mm_obj_dbg (self, "couldn't %s event reporting: '%s'", + ctx->enable ? "enable" : "disable", + error->message); g_error_free (error); } @@ -3494,28 +3500,28 @@ run_unsolicited_events_setup (GTask *task) /* CMER on primary port */ if (!ctx->cmer_primary_done && ctx->cmer_command && ctx->primary && !self->priv->modem_cind_disabled) { - mm_dbg ("%s +CIND event reporting in primary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CIND event reporting in primary port...", ctx->enable ? "enabling" : "disabling"); ctx->cmer_primary_done = TRUE; command = ctx->cmer_command; port = ctx->primary; } /* CMER on secondary port */ else if (!ctx->cmer_secondary_done && ctx->cmer_command && ctx->secondary && !self->priv->modem_cind_disabled) { - mm_dbg ("%s +CIND event reporting in secondary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CIND event reporting in secondary port...", ctx->enable ? "enabling" : "disabling"); ctx->cmer_secondary_done = TRUE; command = ctx->cmer_command; port = ctx->secondary; } /* CGEREP on primary port */ else if (!ctx->cgerep_primary_done && ctx->cgerep_command && ctx->primary) { - mm_dbg ("%s +CGEV event reporting in primary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CGEV event reporting in primary port...", ctx->enable ? "enabling" : "disabling"); ctx->cgerep_primary_done = TRUE; command = ctx->cgerep_command; port = ctx->primary; } /* CGEREP on secondary port */ else if (!ctx->cgerep_secondary_done && ctx->cgerep_command && ctx->secondary) { - mm_dbg ("%s +CGEV event reporting in secondary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CGEV event reporting in secondary port...", ctx->enable ? "enabling" : "disabling"); ctx->cgerep_secondary_done = TRUE; port = ctx->secondary; command = ctx->cgerep_command; @@ -3796,7 +3802,7 @@ modem_load_supported_charsets (MMIfaceModem *self, /* CDMA-only modems don't need this */ if (mm_iface_modem_is_cdma_only (self)) { - mm_dbg ("Skipping supported charset loading in CDMA-only modem..."); + mm_obj_dbg (self, "skipping supported charset loading in CDMA-only modem..."); g_task_return_int (task, MM_MODEM_CHARSET_UNKNOWN); g_object_unref (task); return; @@ -3872,7 +3878,7 @@ ifc_test_ready (MMBaseModem *_self, return; } - mm_dbg ("Flow control settings explicitly requested (%s)", flow_control_requested_str); + mm_obj_dbg (self, "flow control settings explicitly requested: %s", flow_control_requested_str); flow_control_selected = flow_control_requested; flow_control_selected_str = flow_control_requested_str; } else { @@ -3891,7 +3897,7 @@ ifc_test_ready (MMBaseModem *_self, else g_assert_not_reached (); flow_control_selected_str = mm_flow_control_build_string_from_mask (flow_control_selected); - mm_dbg ("Flow control settings automatically selected (%s)", flow_control_selected_str); + mm_obj_dbg (self, "flow control settings automatically selected: %s", flow_control_selected_str); } /* Select flow control for all connections */ @@ -3921,7 +3927,7 @@ ifc_test_ready (MMBaseModem *_self, /* Ignore errors */ if (error) { - mm_dbg ("couldn't load supported flow control methods: %s", error->message); + mm_obj_dbg (self, "couldn't load supported flow control methods: %s", error->message); g_error_free (error); } @@ -3995,13 +4001,13 @@ modem_load_power_state (MMIfaceModem *self, /* CDMA-only modems don't need this */ if (mm_iface_modem_is_cdma_only (self)) { - mm_dbg ("Assuming full power state in CDMA-only modem..."); + mm_obj_dbg (self, "assuming full power state in CDMA-only modem..."); g_task_return_int (task, MM_MODEM_POWER_STATE_ON); g_object_unref (task); return; } - mm_dbg ("loading power state..."); + mm_obj_dbg (self, "loading power state..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+CFUN?", 3, @@ -4033,7 +4039,7 @@ modem_power_up (MMIfaceModem *self, /* CDMA-only modems don't need this */ if (mm_iface_modem_is_cdma_only (self)) - mm_dbg ("Skipping Power-up in CDMA-only modem..."); + mm_obj_dbg (self, "skipping power-up in CDMA-only modem..."); else mm_base_modem_at_command (MM_BASE_MODEM (self), "+CFUN=1", @@ -4095,21 +4101,21 @@ load_sim_identifier_ready (MMBaseSim *sim, } if (ctx->retries > 0) { - mm_warn ("could not load SIM identifier: %s (%d retries left)", - error->message, ctx->retries); + mm_obj_warn (self, "could not load SIM identifier: %s (%d retries left)", + error->message, ctx->retries); --ctx->retries; g_clear_error (&error); g_timeout_add_seconds (1, (GSourceFunc) load_sim_identifier, task); return; } - mm_warn ("could not load SIM identifier: %s", error->message); + mm_obj_warn (self, "could not load SIM identifier: %s", error->message); g_task_return_error (task, error); goto out; } if (g_strcmp0 (current_simid, cached_simid) != 0) { - mm_info ("sim identifier has changed: possible SIM swap during power down/low"); + mm_obj_info (self, "sim identifier has changed: possible SIM swap during power down/low"); mm_broadband_modem_update_sim_hot_swap_detected (self); } @@ -4141,7 +4147,7 @@ modem_check_for_sim_swap (MMIfaceModem *self, GTask *task; SimSwapContext *ctx; - mm_dbg ("Checking if SIM was swapped..."); + mm_obj_dbg (self, "checking if SIM was swapped..."); task = g_task_new (self, NULL, callback, user_data); ctx = g_slice_new0 (SimSwapContext); @@ -4217,7 +4223,7 @@ modem_3gpp_load_imei_finish (MMIfaceModem3gpp *self, result = mm_strip_tag (result, "+CGSN:"); mm_parse_gsn (result, &imei, NULL, NULL); - mm_dbg ("loaded IMEI: %s", imei); + mm_obj_dbg (self, "loaded IMEI: %s", imei); return imei; } @@ -4226,7 +4232,7 @@ modem_3gpp_load_imei (MMIfaceModem3gpp *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading IMEI..."); + mm_obj_dbg (self, "loading IMEI..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+CGSN", 3, @@ -4360,7 +4366,7 @@ clck_test_ready (MMBaseModem *self, gchar *str; str = mm_modem_3gpp_facility_build_string_from_mask (MM_BROADBAND_MODEM (self)->priv->modem_3gpp_ignored_facility_locks); - mm_dbg ("Ignoring facility locks: '%s'", str); + mm_obj_dbg (self, "ignoring facility locks: '%s'", str); g_free (str); ctx->facilities &= ~MM_BROADBAND_MODEM (self)->priv->modem_3gpp_ignored_facility_locks; @@ -4386,7 +4392,7 @@ modem_3gpp_load_enabled_facility_locks (MMIfaceModem3gpp *self, task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, ctx, g_free); - mm_dbg ("loading enabled facility locks..."); + mm_obj_dbg (self, "loading enabled facility locks..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+CLCK=?", 3, @@ -4420,7 +4426,7 @@ modem_3gpp_load_operator_code_finish (MMIfaceModem3gpp *self, mm_3gpp_normalize_operator (&operator_code, MM_BROADBAND_MODEM (self)->priv->modem_current_charset); if (operator_code) - mm_dbg ("loaded Operator Code: %s", operator_code); + mm_obj_dbg (self, "loaded Operator Code: %s", operator_code); return operator_code; } @@ -4429,7 +4435,7 @@ modem_3gpp_load_operator_code (MMIfaceModem3gpp *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading Operator Code..."); + mm_obj_dbg (self, "loading Operator Code..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+COPS=3,2", 3, FALSE, NULL, NULL); mm_base_modem_at_command (MM_BASE_MODEM (self), "+COPS?", 3, FALSE, callback, user_data); } @@ -4459,7 +4465,7 @@ modem_3gpp_load_operator_name_finish (MMIfaceModem3gpp *self, mm_3gpp_normalize_operator (&operator_name, MM_BROADBAND_MODEM (self)->priv->modem_current_charset); if (operator_name) - mm_dbg ("loaded Operator Name: %s", operator_name); + mm_obj_dbg (self, "loaded Operator Name: %s", operator_name); return operator_name; } @@ -4468,7 +4474,7 @@ modem_3gpp_load_operator_name (MMIfaceModem3gpp *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading Operator Name..."); + mm_obj_dbg (self, "loading Operator Name..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+COPS=3,0", 3, FALSE, NULL, NULL); mm_base_modem_at_command (MM_BASE_MODEM (self), "+COPS?", 3, FALSE, callback, user_data); } @@ -4496,7 +4502,7 @@ modem_3gpp_load_eps_ue_mode_operation (MMIfaceModem3gpp *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading UE mode of operation for EPS..."); + mm_obj_dbg (self, "loading UE mode of operation for EPS..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+CEMODE?", 3, @@ -4524,7 +4530,7 @@ modem_3gpp_set_eps_ue_mode_operation (MMIfaceModem3gpp *self, { gchar *cmd; - mm_dbg ("updating UE mode of operation for EPS..."); + mm_obj_dbg (self, "updating UE mode of operation for EPS..."); cmd = mm_3gpp_build_cemode_set_request (mode); mm_base_modem_at_command (MM_BASE_MODEM (self), cmd, @@ -4566,8 +4572,8 @@ registration_state_changed (MMPortSerialAt *port, &cgreg, &cereg, &error)) { - mm_warn ("error parsing unsolicited registration: %s", - error && error->message ? error->message : "(unknown)"); + mm_obj_warn (self, "error parsing unsolicited registration: %s", + error && error->message ? error->message : "(unknown)"); g_clear_error (&error); return; } @@ -4623,8 +4629,8 @@ modem_3gpp_setup_unsolicited_registration_events (MMIfaceModem3gpp *self, if (!ports[i]) continue; - mm_dbg ("(%s) setting up 3GPP unsolicited registration messages handlers", - mm_port_get_device (MM_PORT (ports[i]))); + mm_obj_dbg (self, "setting up 3GPP unsolicited registration messages handlers in %s", + mm_port_get_device (MM_PORT (ports[i]))); for (j = 0; j < array->len; j++) { mm_port_serial_at_add_unsolicited_msg_handler ( MM_PORT_SERIAL_AT (ports[i]), @@ -4672,9 +4678,8 @@ modem_3gpp_cleanup_unsolicited_registration_events (MMIfaceModem3gpp *self, if (!ports[i]) continue; - mm_dbg ("(%s) cleaning up unsolicited registration messages handlers", - mm_port_get_device (MM_PORT (ports[i]))); - + mm_obj_dbg (self, "cleaning up unsolicited registration messages handlers in %s", + mm_port_get_device (MM_PORT (ports[i]))); for (j = 0; j < array->len; j++) { mm_port_serial_at_add_unsolicited_msg_handler ( MM_PORT_SERIAL_AT (ports[i]), @@ -4995,17 +5000,17 @@ registration_status_check_ready (MMBroadbandModem *self, */ if (cgreg) { if (ctx->running_cs) - mm_dbg ("Got PS registration state when checking CS registration state"); + mm_obj_dbg (self, "got PS registration state when checking CS registration state"); else if (ctx->running_eps) - mm_dbg ("Got PS registration state when checking EPS registration state"); + mm_obj_dbg (self, "got PS registration state when checking EPS registration state"); mm_iface_modem_3gpp_update_ps_registration_state (MM_IFACE_MODEM_3GPP (self), state); } else if (cereg) { tac = lac; lac = 0; if (ctx->running_cs) - mm_dbg ("Got EPS registration state when checking CS registration state"); + mm_obj_dbg (self, "got EPS registration state when checking CS registration state"); else if (ctx->running_ps) - mm_dbg ("Got EPS registration state when checking PS registration state"); + mm_obj_dbg (self, "got EPS registration state when checking PS registration state"); mm_iface_modem_3gpp_update_eps_registration_state (MM_IFACE_MODEM_3GPP (self), state); } else { if (act == MM_MODEM_ACCESS_TECHNOLOGY_LTE) { @@ -5013,9 +5018,9 @@ registration_status_check_ready (MMBroadbandModem *self, lac = 0; } if (ctx->running_ps) - mm_dbg ("Got CS registration state when checking PS registration state"); + mm_obj_dbg (self, "got CS registration state when checking PS registration state"); else if (ctx->running_eps) - mm_dbg ("Got CS registration state when checking EPS registration state"); + mm_obj_dbg (self, "got CS registration state when checking EPS registration state"); mm_iface_modem_3gpp_update_cs_registration_state (MM_IFACE_MODEM_3GPP (self), state); } @@ -5301,9 +5306,9 @@ unsolicited_registration_events_sequence_ready (MMBroadbandModem *self, mm_base_modem_at_command_full_finish (MM_BASE_MODEM (self), res, &error); if (error) { - mm_dbg ("%s unsolicited registration events in secondary port failed: '%s'", - ctx->enable ? "Enabling" : "Disabling", - error->message); + mm_obj_dbg (self, "%s unsolicited registration events in secondary port failed: %s", + ctx->enable ? "enabling" : "disabling", + error->message); /* Keep errors reported */ if (ctx->running_cs && !ctx->cs_error) ctx->cs_error = error; @@ -5341,9 +5346,9 @@ unsolicited_registration_events_sequence_ready (MMBroadbandModem *self, error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "AT sequence failed"); - mm_dbg ("%s unsolicited registration events in primary port failed: '%s'", - ctx->enable ? "Enabling" : "Disabling", - error->message); + mm_obj_dbg (self, "%s unsolicited registration events in primary port failed: %s", + ctx->enable ? "enabling" : "disabling", + error->message); /* Keep errors reported */ if (ctx->running_cs) ctx->cs_error = error; @@ -5619,7 +5624,7 @@ ussd_send_command_ready (MMBaseModem *_self, response = mm_base_modem_at_command_finish (_self, res, &error); if (error) { /* Some immediate error happened when sending the USSD request */ - mm_dbg ("Error sending USSD request: '%s'", error->message); + mm_obj_dbg (self, "error sending USSD request: '%s'", error->message); g_error_free (error); if (self->priv->pending_ussd_action) { @@ -5629,17 +5634,17 @@ ussd_send_command_ready (MMBaseModem *_self, } if (!self->priv->pending_ussd_action) { - mm_dbg ("USSD operation finished already via URCs"); + mm_obj_dbg (self, "USSD operation finished already via URCs"); return; } /* Cache the hint for the next time we send something */ ctx = g_task_get_task_data (self->priv->pending_ussd_action); if (!self->priv->use_unencoded_ussd && ctx->current_is_unencoded) { - mm_dbg ("Will assume we want unencoded USSD commands"); + mm_obj_dbg (self, "will assume we want unencoded USSD commands"); self->priv->use_unencoded_ussd = TRUE; } else if (self->priv->use_unencoded_ussd && !ctx->current_is_unencoded) { - mm_dbg ("Will assume we want encoded USSD commands"); + mm_obj_dbg (self, "will assume we want encoded USSD commands"); self->priv->use_unencoded_ussd = FALSE; } @@ -5984,7 +5989,7 @@ cusd_process_string (MMBroadbandModem *self, /* If no pending task, just report the error */ if (error) { - mm_warn ("Invalid USSD message: %s", error->message); + mm_obj_warn (self, "invalid USSD message: %s", error->message); g_error_free (error); } @@ -5998,7 +6003,7 @@ cusd_received (MMPortSerialAt *port, { gchar *str; - mm_dbg ("Unsolicited USSD URC received"); + mm_obj_dbg (self, "unsolicited USSD URC received"); str = g_match_info_fetch (info, 1); cusd_process_string (self, str); g_free (str); @@ -6024,9 +6029,9 @@ set_unsolicited_result_code_handlers (MMIfaceModem3gppUssd *self, if (!ports[i]) continue; /* Set/unset unsolicited CUSD event handler */ - mm_dbg ("(%s) %s unsolicited result code handlers", - mm_port_get_device (MM_PORT (ports[i])), - enable ? "Setting" : "Removing"); + mm_obj_dbg (self, "%s unsolicited result code handlers in %s", + enable ? "setting" : "removing", + mm_port_get_device (MM_PORT (ports[i]))); mm_port_serial_at_add_unsolicited_msg_handler ( ports[i], cusd_regex, @@ -6366,14 +6371,14 @@ cpms_query_ready (MMBroadbandModem *self, self->priv->current_sms_mem1_storage = mem1; self->priv->current_sms_mem2_storage = mem2; - mm_dbg ("Current storages initialized:"); + mm_obj_dbg (self, "current storages initialized:"); aux = mm_common_build_sms_storages_string (&mem1, 1); - mm_dbg (" mem1 (list/read/delete) storages: '%s'", aux); + mm_obj_dbg (self, " mem1 (list/read/delete) storages: '%s'", aux); g_free (aux); aux = mm_common_build_sms_storages_string (&mem2, 1); - mm_dbg (" mem2 (write/send) storages: '%s'", aux); + mm_obj_dbg (self, " mem2 (write/send) storages: '%s'", aux); g_free (aux); g_task_return_boolean (task, TRUE); @@ -6532,8 +6537,8 @@ mm_broadband_modem_lock_sms_storages (MMBroadbandModem *self, self->priv->current_sms_mem1_storage = mem1; self->priv->mem1_storage_locked = TRUE; } else if (self->priv->current_sms_mem1_storage != MM_SMS_STORAGE_UNKNOWN) { - mm_dbg ("Given sms mem1 storage is unknown. Using current sms mem1 storage value '%s' instead", - mm_sms_storage_get_string (self->priv->current_sms_mem1_storage)); + mm_obj_dbg (self, "given sms mem1 storage is unknown. Using current sms mem1 storage value '%s' instead", + mm_sms_storage_get_string (self->priv->current_sms_mem1_storage)); } else { g_task_return_new_error (task, MM_CORE_ERROR, @@ -6557,9 +6562,8 @@ mm_broadband_modem_lock_sms_storages (MMBroadbandModem *self, g_assert (mem1_str != NULL); /* We don't touch 'mem3' here */ - mm_dbg ("Locking SMS storages to: mem1 (%s), mem2 (%s)...", - mem1_str, - mem2_str ? mem2_str : "none"); + mm_obj_dbg (self, "locking SMS storages to: mem1 (%s), mem2 (%s)...", + mem1_str, mem2_str ? mem2_str : "none"); if (mem2_str) cmd = g_strdup_printf ("+CPMS=\"%s\",\"%s\"", mem1_str, mem2_str); @@ -6668,13 +6672,12 @@ cmgf_set_ready (MMBroadbandModem *self, mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (error) { - mm_dbg ("Failed to set preferred SMS mode: '%s'; assuming text mode'", - error->message); + mm_obj_dbg (self, "failed to set preferred SMS mode: %s; assuming text mode'", error->message); g_error_free (error); self->priv->modem_messaging_sms_pdu_mode = FALSE; } else - mm_dbg ("Successfully set preferred SMS mode: '%s'", - self->priv->modem_messaging_sms_pdu_mode ? "PDU" : "text"); + mm_obj_dbg (self, "successfully set preferred SMS mode: '%s'", + self->priv->modem_messaging_sms_pdu_mode ? "PDU" : "text"); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -6713,8 +6716,7 @@ cmgf_format_check_ready (MMBroadbandModem *self, &sms_pdu_supported, &sms_text_supported, &error)) { - mm_dbg ("Failed to query supported SMS modes: '%s'", - error->message); + mm_obj_dbg (self, "failed to query supported SMS modes: %s", error->message); g_error_free (error); } @@ -6722,11 +6724,11 @@ cmgf_format_check_ready (MMBroadbandModem *self, self->priv->modem_messaging_sms_pdu_mode = TRUE; if (!sms_pdu_supported) { if (sms_text_supported) { - mm_dbg ("PDU mode not supported, will try to use Text mode"); + mm_obj_dbg (self, "PDU mode not supported, will try to use Text mode"); self->priv->modem_messaging_sms_pdu_mode = FALSE; } else - mm_dbg ("Neither PDU nor Text modes are reported as supported; " - "will anyway default to PDU mode"); + mm_obj_dbg (self, "neither PDU nor Text modes are reported as supported; " + "will anyway default to PDU mode"); } self->priv->sms_supported_modes_checked = TRUE; @@ -6792,8 +6794,7 @@ sms_part_ready (MMBroadbandModem *self, if (error) { /* We're really ignoring this error afterwards, as we don't have a callback * passed to the async operation, so just log the error here. */ - mm_warn ("Couldn't retrieve SMS part: '%s'", - error->message); + mm_obj_warn (self, "couldn't retrieve SMS part: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -6803,8 +6804,7 @@ sms_part_ready (MMBroadbandModem *self, info = mm_3gpp_parse_cmgr_read_response (response, ctx->idx, &error); if (!info) { - mm_warn ("Couldn't parse SMS part: '%s'", - error->message); + mm_obj_warn (self, "couldn't parse SMS part: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -6812,14 +6812,14 @@ sms_part_ready (MMBroadbandModem *self, part = mm_sms_part_3gpp_new_from_pdu (info->index, info->pdu, &error); if (part) { - mm_dbg ("Correctly parsed PDU (%d)", ctx->idx); + mm_obj_dbg (self, "correctly parsed PDU (%d)", ctx->idx); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), part, MM_SMS_STATE_RECEIVED, self->priv->modem_messaging_sms_default_storage); } else { /* Don't treat the error as critical */ - mm_dbg ("Error parsing PDU (%d): %s", ctx->idx, error->message); + mm_obj_dbg (self, "error parsing PDU (%d): %s", ctx->idx, error->message); g_error_free (error); } @@ -6878,7 +6878,7 @@ cmti_received (MMPortSerialAt *port, str = mm_get_string_unquoted_from_match_info (info, 1); storage = mm_common_get_sms_storage_from_string (str, NULL); if (storage == MM_SMS_STORAGE_UNKNOWN) { - mm_dbg ("Skipping CMTI indication, unknown storage '%s' reported", str); + mm_obj_dbg (self, "skipping CMTI indication, unknown storage '%s' reported", str); g_free (str); return; } @@ -6888,7 +6888,7 @@ cmti_received (MMPortSerialAt *port, if (mm_sms_list_has_part (self->priv->modem_messaging_sms_list, storage, idx)) { - mm_dbg ("Skipping CMTI indication, part already processed"); + mm_obj_dbg (self, "skipping CMTI indication, part already processed"); return; } @@ -6916,7 +6916,7 @@ cds_received (MMPortSerialAt *port, guint length; gchar *pdu; - mm_dbg ("Got new non-stored message indication"); + mm_obj_dbg (self, "got new non-stored message indication"); if (!mm_get_uint_from_match_info (info, 1, &length)) return; @@ -6927,14 +6927,14 @@ cds_received (MMPortSerialAt *port, part = mm_sms_part_3gpp_new_from_pdu (SMS_PART_INVALID_INDEX, pdu, &error); if (part) { - mm_dbg ("Correctly parsed non-stored PDU"); + mm_obj_dbg (self, "correctly parsed non-stored PDU"); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), part, MM_SMS_STATE_RECEIVED, MM_SMS_STORAGE_UNKNOWN); } else { /* Don't treat the error as critical */ - mm_dbg ("Error parsing non-stored PDU: %s", error->message); + mm_obj_dbg (self, "error parsing non-stored PDU: %s", error->message); g_error_free (error); } } @@ -6962,9 +6962,9 @@ set_messaging_unsolicited_events_handlers (MMIfaceModemMessaging *self, continue; /* Set/unset unsolicited CMTI event handler */ - mm_dbg ("(%s) %s messaging unsolicited events handlers", - mm_port_get_device (MM_PORT (ports[i])), - enable ? "Setting" : "Removing"); + mm_obj_dbg (self, "%s messaging unsolicited events handlers in %s", + enable ? "setting" : "removing", + mm_port_get_device (MM_PORT (ports[i]))); mm_port_serial_at_add_unsolicited_msg_handler ( ports[i], cmti_regex, @@ -7065,14 +7065,14 @@ modem_messaging_enable_unsolicited_events_secondary_ready (MMBaseModem *self, /* Since the secondary is not required, we don't propagate the error anywhere */ mm_base_modem_at_sequence_full_finish (MM_BASE_MODEM (self), res, NULL, &inner_error); if (inner_error) { - mm_dbg ("(%s) Unable to enable messaging unsolicited events on modem secondary: %s", - mm_port_get_device (MM_PORT (secondary)), - inner_error->message); + mm_obj_dbg (self, "failed to enable messaging unsolicited events on secondary port %s: %s", + mm_port_get_device (MM_PORT (secondary)), + inner_error->message); g_error_free (inner_error); } - mm_dbg ("(%s) Messaging unsolicited events enabled on secondary", - mm_port_get_device (MM_PORT (secondary))); + mm_obj_dbg (self, "messaging unsolicited events enabled on secondary port %s", + mm_port_get_device (MM_PORT (secondary))); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -7097,13 +7097,13 @@ modem_messaging_enable_unsolicited_events_primary_ready (MMBaseModem *self, return; } - mm_dbg ("(%s) Messaging unsolicited events enabled on primary", - mm_port_get_device (MM_PORT (primary))); + mm_obj_dbg (self, "messaging unsolicited events enabled on primary port %s", + mm_port_get_device (MM_PORT (primary))); /* Try to enable unsolicited events for secondary port */ if (secondary) { - mm_dbg ("(%s) Enabling messaging unsolicited events on secondary port", - mm_port_get_device (MM_PORT (secondary))); + mm_obj_dbg (self, "enabling messaging unsolicited events on secondary port %s", + mm_port_get_device (MM_PORT (secondary))); mm_base_modem_at_sequence_full ( MM_BASE_MODEM (self), secondary, @@ -7132,8 +7132,8 @@ modem_messaging_enable_unsolicited_events (MMIfaceModemMessaging *self, primary = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); /* Enable unsolicited events for primary port */ - mm_dbg ("(%s) Enabling messaging unsolicited events on primary port", - mm_port_get_device (MM_PORT (primary))); + mm_obj_dbg (self, "enabling messaging unsolicited events on primary port %s", + mm_port_get_device (MM_PORT (primary))); mm_base_modem_at_sequence_full ( MM_BASE_MODEM (self), primary, @@ -7235,26 +7235,26 @@ sms_text_part_list_ready (MMBroadbandModem *self, matches = g_match_info_get_match_count (match_info); if (matches != 7) { - mm_dbg ("Failed to match entire CMGL response (count %d)", matches); + mm_obj_dbg (self, "failed to match entire CMGL response (count %d)", matches); goto next; } if (!mm_get_uint_from_match_info (match_info, 1, &idx)) { - mm_dbg ("Failed to convert message index"); + mm_obj_dbg (self, "failed to convert message index"); goto next; } /* Get part state */ stat = mm_get_string_unquoted_from_match_info (match_info, 2); if (!stat) { - mm_dbg ("Failed to get part status"); + mm_obj_dbg (self, "failed to get part status"); goto next; } /* Get and parse number */ number = mm_get_string_unquoted_from_match_info (match_info, 3); if (!number) { - mm_dbg ("Failed to get message sender number"); + mm_obj_dbg (self, "failed to get message sender number"); g_free (stat); goto next; } @@ -7287,7 +7287,7 @@ sms_text_part_list_ready (MMBroadbandModem *self, mm_sms_part_take_data (part, raw); mm_sms_part_set_class (part, -1); - mm_dbg ("Correctly parsed SMS list entry (%d)", idx); + mm_obj_dbg (self, "correctly parsed SMS list entry (%d)", idx); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), part, sms_state_from_str (stat), @@ -7357,14 +7357,14 @@ sms_pdu_part_list_ready (MMBroadbandModem *self, part = mm_sms_part_3gpp_new_from_pdu (info->index, info->pdu, &error); if (part) { - mm_dbg ("Correctly parsed PDU (%d)", info->index); + mm_obj_dbg (self, "correctly parsed PDU (%d)", info->index); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), part, sms_state_from_index (info->status), ctx->list_storage); } else { /* Don't treat the error as critical */ - mm_dbg ("Error parsing PDU (%d): %s", info->index, error->message); + mm_obj_dbg (self, "error parsing PDU (%d): %s", info->index, error->message); g_clear_error (&error); } } @@ -7422,8 +7422,7 @@ modem_messaging_load_initial_sms_parts (MMIfaceModemMessaging *self, task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, ctx, g_free); - mm_dbg ("Listing SMS parts in storage '%s'", - mm_sms_storage_get_string (storage)); + mm_obj_dbg (self, "listing SMS parts in storage '%s'", mm_sms_storage_get_string (storage)); /* First, request to set the proper storage to read from */ mm_broadband_modem_lock_sms_storages (MM_BROADBAND_MODEM (self), @@ -7618,7 +7617,7 @@ in_call_event_received (MMPortSerialAt *port, call_info.number = NULL; str = g_match_info_fetch (info, 1); - mm_dbg ("Call terminated: %s", str); + mm_obj_dbg (self, "call terminated: %s", str); g_free (str); mm_iface_modem_voice_report_call (MM_IFACE_MODEM_VOICE (self), &call_info); @@ -7644,9 +7643,9 @@ set_voice_in_call_unsolicited_events_handlers (MMBroadbandModem *self, if (!ports[i]) continue; - mm_dbg ("(%s) %s voice in-call unsolicited events handlers", - mm_port_get_device (MM_PORT (ports[i])), - enable ? "Setting" : "Removing"); + mm_obj_dbg (self, "%s voice in-call unsolicited events handlers in %s", + enable ? "setting" : "removing", + mm_port_get_device (MM_PORT (ports[i]))); mm_port_serial_at_add_unsolicited_msg_handler ( ports[i], in_call_event_regex, @@ -7671,7 +7670,7 @@ modem_voice_setup_in_call_unsolicited_events (MMIfaceModemVoice *_self, if (!self->priv->in_call_ports_ctx) { PortsContext *ctx; - mm_dbg ("Setting up in-call ports context"); + mm_obj_dbg (self, "setting up in-call ports context"); ctx = ports_context_new (); if (!ports_context_open (self, ctx, FALSE, TRUE, FALSE, &error)) { ports_context_unref (ctx); @@ -7681,7 +7680,7 @@ modem_voice_setup_in_call_unsolicited_events (MMIfaceModemVoice *_self, self->priv->in_call_ports_ctx = ctx; } } else - mm_dbg ("In-call ports context already set up"); + mm_obj_dbg (self, "in-call ports context already set up"); task = g_task_new (self, NULL, callback, user_data); if (error) @@ -7701,11 +7700,11 @@ modem_voice_cleanup_in_call_unsolicited_events (MMIfaceModemVoice *_self, self = MM_BROADBAND_MODEM (_self); if (self->priv->in_call_ports_ctx) { - mm_dbg ("Cleaning up in-call ports context"); + mm_obj_dbg (self, "cleaning up in-call ports context"); set_voice_in_call_unsolicited_events_handlers (self, self->priv->in_call_ports_ctx, FALSE); g_clear_pointer (&self->priv->in_call_ports_ctx, (GDestroyNotify) ports_context_unref); } else - mm_dbg ("In-call ports context already cleaned up"); + mm_obj_dbg (self, "in-call ports context already cleaned up"); task = g_task_new (self, NULL, callback, user_data); g_task_return_boolean (task, TRUE); @@ -7735,7 +7734,7 @@ ccwa_received (MMPortSerialAt *port, call_info.state = MM_CALL_STATE_WAITING; call_info.number = mm_get_string_unquoted_from_match_info (info, 1); - mm_dbg ("Call waiting (%s)", call_info.number); + mm_obj_dbg (self, "call waiting (%s)", call_info.number); mm_iface_modem_voice_report_call (MM_IFACE_MODEM_VOICE (self), &call_info); g_free (call_info.number); @@ -7753,7 +7752,7 @@ ring_received (MMPortSerialAt *port, call_info.state = MM_CALL_STATE_RINGING_IN; call_info.number = NULL; - mm_dbg ("Ringing"); + mm_obj_dbg (self, "ringing"); mm_iface_modem_voice_report_call (MM_IFACE_MODEM_VOICE (self), &call_info); } @@ -7767,7 +7766,7 @@ cring_received (MMPortSerialAt *port, /* We could have "VOICE" or "DATA". Now consider only "VOICE" */ str = mm_get_string_unquoted_from_match_info (info, 1); - mm_dbg ("Ringing (%s)", str); + mm_obj_dbg (self, "ringing (%s)", str); g_free (str); call_info.index = 0; @@ -7790,7 +7789,7 @@ clip_received (MMPortSerialAt *port, call_info.state = MM_CALL_STATE_RINGING_IN; call_info.number = mm_get_string_unquoted_from_match_info (info, 1); - mm_dbg ("Ringing (%s)", call_info.number); + mm_obj_dbg (self, "ringing (%s)", call_info.number); mm_iface_modem_voice_report_call (MM_IFACE_MODEM_VOICE (self), &call_info); g_free (call_info.number); @@ -7823,9 +7822,9 @@ set_voice_unsolicited_events_handlers (MMIfaceModemVoice *self, continue; /* Set/unset unsolicited CMTI event handler */ - mm_dbg ("(%s) %s voice unsolicited events handlers", - mm_port_get_device (MM_PORT (ports[i])), - enable ? "Setting" : "Removing"); + mm_obj_dbg (self, "%s voice unsolicited events handlers in %s", + enable ? "setting" : "removing", + mm_port_get_device (MM_PORT (ports[i]))); mm_port_serial_at_add_unsolicited_msg_handler ( ports[i], cring_regex, @@ -7928,9 +7927,9 @@ voice_unsolicited_events_setup_ready (MMBroadbandModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error)) { - mm_dbg ("Couldn't %s voice event reporting: '%s'", - ctx->enable ? "enable" : "disable", - error->message); + mm_obj_dbg (self, "couldn't %s voice event reporting: '%s'", + ctx->enable ? "enable" : "disable", + error->message); g_error_free (error); } @@ -7951,42 +7950,42 @@ run_voice_unsolicited_events_setup (GTask *task) /* CLIP on primary port */ if (!ctx->clip_primary_done && ctx->clip_command && ctx->primary) { - mm_dbg ("%s +CLIP calling line reporting in primary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CLIP calling line reporting in primary port...", ctx->enable ? "enabling" : "disabling"); ctx->clip_primary_done = TRUE; command = ctx->clip_command; port = ctx->primary; } /* CLIP on secondary port */ else if (!ctx->clip_secondary_done && ctx->clip_command && ctx->secondary) { - mm_dbg ("%s +CLIP calling line reporting in secondary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CLIP calling line reporting in secondary port...", ctx->enable ? "enabling" : "disabling"); ctx->clip_secondary_done = TRUE; command = ctx->clip_command; port = ctx->secondary; } /* CRC on primary port */ else if (!ctx->crc_primary_done && ctx->crc_command && ctx->primary) { - mm_dbg ("%s +CRC extended format of incoming call indications in primary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CRC extended format of incoming call indications in primary port...", ctx->enable ? "enabling" : "disabling"); ctx->crc_primary_done = TRUE; command = ctx->crc_command; port = ctx->primary; } /* CRC on secondary port */ else if (!ctx->crc_secondary_done && ctx->crc_command && ctx->secondary) { - mm_dbg ("%s +CRC extended format of incoming call indications in secondary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CRC extended format of incoming call indications in secondary port...", ctx->enable ? "enabling" : "disabling"); ctx->crc_secondary_done = TRUE; command = ctx->crc_command; port = ctx->secondary; } /* CCWA on primary port */ else if (!ctx->ccwa_primary_done && ctx->ccwa_command && ctx->primary) { - mm_dbg ("%s +CCWA call waiting indications in primary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CCWA call waiting indications in primary port...", ctx->enable ? "enabling" : "disabling"); ctx->ccwa_primary_done = TRUE; command = ctx->ccwa_command; port = ctx->primary; } /* CCWA on secondary port */ else if (!ctx->ccwa_secondary_done && ctx->ccwa_command && ctx->secondary) { - mm_dbg ("%s +CCWA call waiting indications in secondary port...", ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CCWA call waiting indications in secondary port...", ctx->enable ? "enabling" : "disabling"); ctx->ccwa_secondary_done = TRUE; command = ctx->ccwa_command; port = ctx->secondary; @@ -8346,7 +8345,7 @@ modem_cdma_load_esn_finish (MMIfaceModemCdma *self, result = mm_strip_tag (result, "+GSN:"); mm_parse_gsn (result, NULL, NULL, &esn); - mm_dbg ("loaded ESN: %s", esn); + mm_obj_dbg (self, "loaded ESN: %s", esn); return esn; } @@ -8355,7 +8354,7 @@ modem_cdma_load_esn (MMIfaceModemCdma *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading ESN..."); + mm_obj_dbg (self, "loading ESN..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+GSN", 3, @@ -8381,7 +8380,7 @@ modem_cdma_load_meid_finish (MMIfaceModemCdma *self, result = mm_strip_tag (result, "+GSN:"); mm_parse_gsn (result, NULL, &meid, NULL); - mm_dbg ("loaded MEID: %s", meid); + mm_obj_dbg (self, "loaded MEID: %s", meid); return meid; } @@ -8391,7 +8390,7 @@ modem_cdma_load_meid (MMIfaceModemCdma *self, gpointer user_data) { /* Some devices return both the MEID and the ESN in the +GSN response */ - mm_dbg ("loading MEID..."); + mm_obj_dbg (self, "loading MEID..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+GSN", 3, @@ -9011,6 +9010,7 @@ qcdm_cdma_status_ready (MMPortSerialQcdm *port, GAsyncResult *res, GTask *task) { + MMBroadbandModem *self; QcdmResult *result = NULL; guint32 sid = MM_MODEM_CDMA_SID_UNKNOWN; guint32 nid = MM_MODEM_CDMA_NID_UNKNOWN; @@ -9019,9 +9019,11 @@ qcdm_cdma_status_ready (MMPortSerialQcdm *port, GError *error = NULL; GByteArray *response; + self = g_task_get_source_object (task); + response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { - mm_dbg ("Failed to get cdma status: %s", error->message); + mm_obj_dbg (self, "failed to get cdma status: %s", error->message); g_clear_error (&error); /* Fall back to AT+CSS */ @@ -9034,7 +9036,7 @@ qcdm_cdma_status_ready (MMPortSerialQcdm *port, &err); if (!result) { if (err != QCDM_SUCCESS) - mm_dbg ("Failed to parse cdma status command result: %d", err); + mm_obj_dbg (self, "failed to parse cdma status command result: %d", err); g_byte_array_unref (response); /* Fall back to AT+CSS */ @@ -9055,9 +9057,9 @@ qcdm_cdma_status_ready (MMPortSerialQcdm *port, nid = MM_MODEM_CDMA_NID_UNKNOWN; } - mm_dbg ("CDMA 1x Status RX state: %d", rxstate); - mm_dbg ("CDMA 1x Status SID: %d", sid); - mm_dbg ("CDMA 1x Status NID: %d", nid); + mm_obj_dbg (self, "CDMA 1x Status RX state: %d", rxstate); + mm_obj_dbg (self, "CDMA 1x Status SID: %d", sid); + mm_obj_dbg (self, "CDMA 1x Status NID: %d", nid); cdma1x_serving_system_complete_and_free (task, sid, @@ -9086,7 +9088,7 @@ modem_cdma_get_cdma1x_serving_system (MMIfaceModemCdma *self, } if (!mm_port_serial_open (MM_PORT_SERIAL (qcdm), &error)) { - mm_dbg ("Failed to open QCDM port for serving-system request: %s", error->message); + mm_obj_dbg (self, "failed to open QCDM port for serving-system request: %s", error->message); g_error_free (error); /* Fall back to AT+CSS */ @@ -9258,7 +9260,7 @@ speri_ready (MMIfaceModemCdma *self, response = mm_strip_tag (response, "$SPERI:"); if (!response || !mm_cdma_parse_eri (response, &roaming, NULL, NULL)) { - mm_warn ("Couldn't parse SPERI response '%s'", response); + mm_obj_warn (self, "couldn't parse SPERI response '%s'", response); g_task_return_pointer (task, detailed_registration_state_result_new (ctx), g_free); @@ -9416,7 +9418,7 @@ setup_registration_checks_results_new (MMBroadbandModem *self, /* Skip QCDM steps if no QCDM port */ if (!ctx->has_qcdm_port) { - mm_dbg ("Will skip all QCDM-based registration checks"); + mm_obj_dbg (self, "will skip all QCDM-based registration checks"); results->skip_qcdm_call_manager_step = TRUE; results->skip_qcdm_hdr_step = TRUE; } @@ -9430,14 +9432,12 @@ setup_registration_checks_results_new (MMBroadbandModem *self, * for the specific step, or subclass this setup and return * FALSE themselves. */ if (ctx->has_sprint_commands) { - mm_dbg ("Will skip CDMA1x Serving System check, " - "we do have Sprint commands"); + mm_obj_dbg (self, "will skip CDMA1x Serving System check, we do have Sprint commands"); results->skip_at_cdma1x_serving_system_step = TRUE; } else { /* If there aren't Sprint specific commands, and the detailed * registration state getter wasn't subclassed, skip the step */ - mm_dbg ("Will skip generic detailed registration check, we " - "don't have Sprint commands"); + mm_obj_dbg (self, "will skip generic detailed registration check, we don't have Sprint commands"); results->skip_detailed_registration_state = TRUE; } } @@ -9640,7 +9640,7 @@ run_cdma_registration_checks_ready (MMBroadbandModem *self, mm_iface_modem_cdma_run_registration_checks_finish (MM_IFACE_MODEM_CDMA (self), res, &error); if (error) { - mm_dbg ("CDMA registration check failed: '%s'", error->message); + mm_obj_dbg (self, "CDMA registration check failed: %s", error->message); mm_iface_modem_cdma_update_cdma1x_registration_state ( MM_IFACE_MODEM_CDMA (self), MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, @@ -9661,10 +9661,9 @@ run_cdma_registration_checks_ready (MMBroadbandModem *self, /* If we got registered in at least one CDMA network, end registration checks */ if (REG_IS_DONE (self->priv->modem_cdma_cdma1x_registration_state) || REG_IS_DONE (self->priv->modem_cdma_evdo_registration_state)) { - mm_dbg ("Modem is currently registered in a CDMA network " - "(CDMA1x: '%s', EV-DO: '%s')", - REG_IS_DONE (self->priv->modem_cdma_cdma1x_registration_state) ? "yes" : "no", - REG_IS_DONE (self->priv->modem_cdma_evdo_registration_state) ? "yes" : "no"); + mm_obj_dbg (self, "registered in a CDMA network (CDMA1x: '%s', EV-DO: '%s')", + REG_IS_DONE (self->priv->modem_cdma_cdma1x_registration_state) ? "yes" : "no", + REG_IS_DONE (self->priv->modem_cdma_evdo_registration_state) ? "yes" : "no"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -9672,7 +9671,7 @@ run_cdma_registration_checks_ready (MMBroadbandModem *self, /* Don't spend too much time waiting to get registered */ if (g_timer_elapsed (ctx->timer, NULL) > ctx->max_registration_time) { - mm_dbg ("CDMA registration check timed out"); + mm_obj_dbg (self, "CDMA registration check timed out"); mm_iface_modem_cdma_update_cdma1x_registration_state ( MM_IFACE_MODEM_CDMA (self), MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, @@ -9691,7 +9690,7 @@ run_cdma_registration_checks_ready (MMBroadbandModem *self, } /* Check again in a few seconds. */ - mm_dbg ("Modem not yet registered in a CDMA network... will recheck soon"); + mm_obj_dbg (self, "not yet registered in a CDMA network... will recheck soon"); g_timeout_add_seconds (3, (GSourceFunc)run_cdma_registration_checks_again, task); @@ -10237,7 +10236,7 @@ enabling_modem_init_ready (MMBroadbandModem *self, self->priv->modem_init_run = TRUE; /* After the modem init sequence, give a 500ms period for the modem to settle */ - mm_dbg ("Giving some time to settle the modem..."); + mm_obj_dbg (self, "giving some time to settle the modem..."); g_timeout_add (500, (GSourceFunc)enabling_after_modem_init_timeout, task); } @@ -10261,7 +10260,7 @@ enabling_flash_done (MMPortSerial *port, ctx = g_task_get_task_data (task); if (ctx->modem_init_required) { - mm_dbg ("Running modem initialization sequence..."); + mm_obj_dbg (self, "running initialization sequence..."); MM_BROADBAND_MODEM_GET_CLASS (self)->enabling_modem_init (self, (GAsyncReadyCallback)enabling_modem_init_ready, task); @@ -10290,13 +10289,13 @@ enabling_started (MMBroadbandModem *self, * did it (i.e. don't reinitialize if the modem got disabled and enabled * again) */ if (self->priv->modem_init_run) - mm_dbg ("Skipping modem initialization: not first enabling"); + mm_obj_dbg (self, "skipping initialization: not first enabling"); else if (mm_base_modem_get_hotplugged (MM_BASE_MODEM (self))) { self->priv->modem_init_run = TRUE; - mm_dbg ("Skipping modem initialization: device hotplugged"); + mm_obj_dbg (self, "skipping initialization: device hotplugged"); } else if (!MM_BROADBAND_MODEM_GET_CLASS (self)->enabling_modem_init || !MM_BROADBAND_MODEM_GET_CLASS (self)->enabling_modem_init_finish) - mm_dbg ("Skipping modem initialization: not required"); + mm_obj_dbg (self, "skipping initialization: not required"); else ctx->modem_init_required = TRUE; @@ -10312,7 +10311,7 @@ enabling_started (MMBroadbandModem *self, } /* Ports were correctly opened, now flash the primary port */ - mm_dbg ("Flashing primary AT port before enabling..."); + mm_obj_dbg (self, "flashing primary AT port before enabling..."); mm_port_serial_flash (MM_PORT_SERIAL (ctx->ports->primary), 100, FALSE, @@ -10330,11 +10329,11 @@ modem_3gpp_run_registration_checks_ready (MMIfaceModem3gpp *self, GError *error = NULL; if (!mm_iface_modem_3gpp_run_registration_checks_finish (self, res, &error)) { - mm_warn ("Initial 3GPP registration check failed: %s", error->message); + mm_obj_warn (self, "initial 3GPP registration check failed: %s", error->message); g_error_free (error); return; } - mm_dbg ("Initial 3GPP registration checks finished"); + mm_obj_dbg (self, "initial 3GPP registration checks finished"); } static void @@ -10344,11 +10343,11 @@ modem_cdma_run_registration_checks_ready (MMIfaceModemCdma *self, GError *error = NULL; if (!mm_iface_modem_cdma_run_registration_checks_finish (self, res, &error)) { - mm_warn ("Initial CDMA registration check failed: %s", error->message); + mm_obj_warn (self, "initial CDMA registration check failed: %s", error->message); g_error_free (error); return; } - mm_dbg ("Initial CDMA registration checks finished"); + mm_obj_dbg (self, "initial CDMA registration checks finished"); } static gboolean @@ -10410,7 +10409,7 @@ disabling_context_free (DisablingContext *ctx) if (MM_BROADBAND_MODEM_GET_CLASS (ctx->self)->disabling_stopped && !MM_BROADBAND_MODEM_GET_CLASS (ctx->self)->disabling_stopped (ctx->self, &error)) { - mm_warn ("Error when stopping the disabling sequence: %s", error->message); + mm_obj_warn (ctx->self, "error when stopping the disabling sequence: %s", error->message); g_error_free (error); } @@ -10456,8 +10455,8 @@ disable_finish (MMBaseModem *self, return; \ } \ \ - mm_dbg ("Couldn't disable interface: '%s'", \ - error->message); \ + mm_obj_dbg (self, "couldn't disable interface: %s", \ + error->message); \ g_error_free (error); \ return; \ } \ @@ -10596,7 +10595,7 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_VOICE: if (ctx->self->priv->modem_voice_dbus_skeleton) { - mm_dbg ("Modem has voice capabilities, disabling the Voice interface..."); + mm_obj_dbg (ctx->self, "modem has voice capabilities, disabling the Voice interface..."); /* Disabling the Modem Voice interface */ mm_iface_modem_voice_disable (MM_IFACE_MODEM_VOICE (ctx->self), (GAsyncReadyCallback)iface_modem_voice_disable_ready, @@ -10608,7 +10607,7 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_SIGNAL: if (ctx->self->priv->modem_signal_dbus_skeleton) { - mm_dbg ("Modem has extended signal reporting capabilities, disabling the Signal interface..."); + mm_obj_dbg (ctx->self, "modem has extended signal reporting capabilities, disabling the Signal interface..."); /* Disabling the Modem Signal interface */ mm_iface_modem_signal_disable (MM_IFACE_MODEM_SIGNAL (ctx->self), (GAsyncReadyCallback)iface_modem_signal_disable_ready, @@ -10620,7 +10619,7 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_OMA: if (ctx->self->priv->modem_oma_dbus_skeleton) { - mm_dbg ("Modem has OMA capabilities, disabling the OMA interface..."); + mm_obj_dbg (ctx->self, "modem has OMA capabilities, disabling the OMA interface..."); /* Disabling the Modem Oma interface */ mm_iface_modem_oma_disable (MM_IFACE_MODEM_OMA (ctx->self), (GAsyncReadyCallback)iface_modem_oma_disable_ready, @@ -10632,7 +10631,7 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_TIME: if (ctx->self->priv->modem_time_dbus_skeleton) { - mm_dbg ("Modem has time capabilities, disabling the Time interface..."); + mm_obj_dbg (ctx->self, "modem has time capabilities, disabling the Time interface..."); /* Disabling the Modem Time interface */ mm_iface_modem_time_disable (MM_IFACE_MODEM_TIME (ctx->self), (GAsyncReadyCallback)iface_modem_time_disable_ready, @@ -10644,7 +10643,7 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_MESSAGING: if (ctx->self->priv->modem_messaging_dbus_skeleton) { - mm_dbg ("Modem has messaging capabilities, disabling the Messaging interface..."); + mm_obj_dbg (ctx->self, "modem has messaging capabilities, disabling the Messaging interface..."); /* Disabling the Modem Messaging interface */ mm_iface_modem_messaging_disable (MM_IFACE_MODEM_MESSAGING (ctx->self), (GAsyncReadyCallback)iface_modem_messaging_disable_ready, @@ -10656,7 +10655,7 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_LOCATION: if (ctx->self->priv->modem_location_dbus_skeleton) { - mm_dbg ("Modem has location capabilities, disabling the Location interface..."); + mm_obj_dbg (ctx->self, "modem has location capabilities, disabling the Location interface..."); /* Disabling the Modem Location interface */ mm_iface_modem_location_disable (MM_IFACE_MODEM_LOCATION (ctx->self), (GAsyncReadyCallback)iface_modem_location_disable_ready, @@ -10668,7 +10667,7 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_CDMA: if (ctx->self->priv->modem_cdma_dbus_skeleton) { - mm_dbg ("Modem has CDMA capabilities, disabling the Modem CDMA interface..."); + mm_obj_dbg (ctx->self, "modem has CDMA capabilities, disabling the Modem CDMA interface..."); /* Disabling the Modem CDMA interface */ mm_iface_modem_cdma_disable (MM_IFACE_MODEM_CDMA (ctx->self), (GAsyncReadyCallback)iface_modem_cdma_disable_ready, @@ -10680,7 +10679,7 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_3GPP_USSD: if (ctx->self->priv->modem_3gpp_ussd_dbus_skeleton) { - mm_dbg ("Modem has 3GPP/USSD capabilities, disabling the Modem 3GPP/USSD interface..."); + mm_obj_dbg (ctx->self, "modem has 3GPP/USSD capabilities, disabling the Modem 3GPP/USSD interface..."); /* Disabling the Modem 3GPP USSD interface */ mm_iface_modem_3gpp_ussd_disable (MM_IFACE_MODEM_3GPP_USSD (ctx->self), (GAsyncReadyCallback)iface_modem_3gpp_ussd_disable_ready, @@ -10692,7 +10691,7 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_3GPP: if (ctx->self->priv->modem_3gpp_dbus_skeleton) { - mm_dbg ("Modem has 3GPP capabilities, disabling the Modem 3GPP interface..."); + mm_obj_dbg (ctx->self, "modem has 3GPP capabilities, disabling the Modem 3GPP interface..."); /* Disabling the Modem 3GPP interface */ mm_iface_modem_3gpp_disable (MM_IFACE_MODEM_3GPP (ctx->self), (GAsyncReadyCallback)iface_modem_3gpp_disable_ready, @@ -10823,8 +10822,8 @@ enable_finish (MMBaseModem *self, return; \ } \ \ - mm_dbg ("Couldn't enable interface: '%s'", \ - error->message); \ + mm_obj_dbg (self, "couldn't enable interface: '%s'", \ + error->message); \ g_error_free (error); \ } \ \ @@ -10946,7 +10945,7 @@ enabling_step (GTask *task) case ENABLING_STEP_IFACE_3GPP: if (ctx->self->priv->modem_3gpp_dbus_skeleton) { - mm_dbg ("Modem has 3GPP capabilities, enabling the Modem 3GPP interface..."); + mm_obj_dbg (ctx->self, "modem has 3GPP capabilities, enabling the Modem 3GPP interface..."); /* Enabling the Modem 3GPP interface */ mm_iface_modem_3gpp_enable (MM_IFACE_MODEM_3GPP (ctx->self), g_task_get_cancellable (task), @@ -10959,7 +10958,7 @@ enabling_step (GTask *task) case ENABLING_STEP_IFACE_3GPP_USSD: if (ctx->self->priv->modem_3gpp_ussd_dbus_skeleton) { - mm_dbg ("Modem has 3GPP/USSD capabilities, enabling the Modem 3GPP/USSD interface..."); + mm_obj_dbg (ctx->self, "modem has 3GPP/USSD capabilities, enabling the Modem 3GPP/USSD interface..."); mm_iface_modem_3gpp_ussd_enable (MM_IFACE_MODEM_3GPP_USSD (ctx->self), (GAsyncReadyCallback)iface_modem_3gpp_ussd_enable_ready, task); @@ -10970,7 +10969,7 @@ enabling_step (GTask *task) case ENABLING_STEP_IFACE_CDMA: if (ctx->self->priv->modem_cdma_dbus_skeleton) { - mm_dbg ("Modem has CDMA capabilities, enabling the Modem CDMA interface..."); + mm_obj_dbg (ctx->self, "modem has CDMA capabilities, enabling the Modem CDMA interface..."); /* Enabling the Modem CDMA interface */ mm_iface_modem_cdma_enable (MM_IFACE_MODEM_CDMA (ctx->self), g_task_get_cancellable (task), @@ -10983,7 +10982,7 @@ enabling_step (GTask *task) case ENABLING_STEP_IFACE_LOCATION: if (ctx->self->priv->modem_location_dbus_skeleton) { - mm_dbg ("Modem has location capabilities, enabling the Location interface..."); + mm_obj_dbg (ctx->self, "modem has location capabilities, enabling the Location interface..."); /* Enabling the Modem Location interface */ mm_iface_modem_location_enable (MM_IFACE_MODEM_LOCATION (ctx->self), g_task_get_cancellable (task), @@ -10996,7 +10995,7 @@ enabling_step (GTask *task) case ENABLING_STEP_IFACE_MESSAGING: if (ctx->self->priv->modem_messaging_dbus_skeleton) { - mm_dbg ("Modem has messaging capabilities, enabling the Messaging interface..."); + mm_obj_dbg (ctx->self, "modem has messaging capabilities, enabling the Messaging interface..."); /* Enabling the Modem Messaging interface */ mm_iface_modem_messaging_enable (MM_IFACE_MODEM_MESSAGING (ctx->self), g_task_get_cancellable (task), @@ -11009,7 +11008,7 @@ enabling_step (GTask *task) case ENABLING_STEP_IFACE_TIME: if (ctx->self->priv->modem_time_dbus_skeleton) { - mm_dbg ("Modem has time capabilities, enabling the Time interface..."); + mm_obj_dbg (ctx->self, "modem has time capabilities, enabling the Time interface..."); /* Enabling the Modem Time interface */ mm_iface_modem_time_enable (MM_IFACE_MODEM_TIME (ctx->self), g_task_get_cancellable (task), @@ -11022,7 +11021,7 @@ enabling_step (GTask *task) case ENABLING_STEP_IFACE_SIGNAL: if (ctx->self->priv->modem_signal_dbus_skeleton) { - mm_dbg ("Modem has extended signal reporting capabilities, enabling the Signal interface..."); + mm_obj_dbg (ctx->self, "modem has extended signal reporting capabilities, enabling the Signal interface..."); /* Enabling the Modem Signal interface */ mm_iface_modem_signal_enable (MM_IFACE_MODEM_SIGNAL (ctx->self), g_task_get_cancellable (task), @@ -11035,7 +11034,7 @@ enabling_step (GTask *task) case ENABLING_STEP_IFACE_OMA: if (ctx->self->priv->modem_oma_dbus_skeleton) { - mm_dbg ("Modem has OMA capabilities, enabling the OMA interface..."); + mm_obj_dbg (ctx->self, "modem has OMA capabilities, enabling the OMA interface..."); /* Enabling the Modem Oma interface */ mm_iface_modem_oma_enable (MM_IFACE_MODEM_OMA (ctx->self), g_task_get_cancellable (task), @@ -11048,7 +11047,7 @@ enabling_step (GTask *task) case ENABLING_STEP_IFACE_VOICE: if (ctx->self->priv->modem_voice_dbus_skeleton) { - mm_dbg ("Modem has voice capabilities, enabling the Voice interface..."); + mm_obj_dbg (ctx->self, "modem has voice capabilities, enabling the Voice interface..."); /* Enabling the Modem Voice interface */ mm_iface_modem_voice_enable (MM_IFACE_MODEM_VOICE (ctx->self), g_task_get_cancellable (task), @@ -11198,7 +11197,7 @@ initialize_context_free (InitializeContext *ctx) if (ctx->ports_ctx && MM_BROADBAND_MODEM_GET_CLASS (ctx->self)->initialization_stopped && !MM_BROADBAND_MODEM_GET_CLASS (ctx->self)->initialization_stopped (ctx->self, ctx->ports_ctx, &error)) { - mm_warn ("Error when stopping the initialization sequence: %s", error->message); + mm_obj_warn (ctx->self, "error when stopping the initialization sequence: %s", error->message); g_error_free (error); } @@ -11228,7 +11227,7 @@ initialization_started_ready (MMBroadbandModem *self, /* May return NULL without error */ ports_ctx = MM_BROADBAND_MODEM_GET_CLASS (self)->initialization_started_finish (self, result, &error); if (error) { - mm_warn ("Couldn't start initialization: %s", error->message); + mm_obj_warn (self, "couldn't start initialization: %s", error->message); g_error_free (error); /* There is no Modem interface yet, so just update the variable directly */ @@ -11264,7 +11263,7 @@ iface_modem_initialize_ready (MMBroadbandModem *self, MMModemStateFailedReason failed_reason = MM_MODEM_STATE_FAILED_REASON_UNKNOWN; /* Report the new FAILED state */ - mm_warn ("Modem couldn't be initialized: %s", error->message); + mm_obj_warn (self, "modem couldn't be initialized: %s", error->message); if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, @@ -11323,8 +11322,8 @@ iface_modem_initialize_ready (MMBroadbandModem *self, \ if (!mm_##NAME##_initialize_finish (TYPE (self), result, &error)) { \ if (FATAL_ERRORS) { \ - mm_warn ("Couldn't initialize interface: '%s'", \ - error->message); \ + mm_obj_warn (self, "couldn't initialize interface: '%s'", \ + error->message); \ g_error_free (error); \ \ /* Report the new FAILED state */ \ @@ -11337,8 +11336,8 @@ iface_modem_initialize_ready (MMBroadbandModem *self, return; \ } \ \ - mm_dbg ("Couldn't initialize interface: '%s'", \ - error->message); \ + mm_obj_dbg (self, "couldn't initialize interface: '%s'", \ + error->message); \ /* Just shutdown this interface */ \ mm_##NAME##_shutdown (TYPE (self)); \ g_error_free (error); \ @@ -11528,15 +11527,16 @@ initialize_step (GTask *task) if (is_sim_hot_swap_supported) { if (!is_sim_hot_swap_configured) { - mm_warn ("SIM hot swap supported but not configured. Skipping opening ports"); + mm_obj_warn (ctx->self, "SIM hot swap supported but not configured. Skipping opening ports"); } else { PortsContext *ports; GError *error = NULL; - mm_dbg ("Creating ports context for SIM hot swap"); + mm_obj_dbg (ctx->self, "creating ports context for SIM hot swap"); ports = ports_context_new (); if (!ports_context_open (ctx->self, ports, FALSE, FALSE, FALSE, &error)) { - mm_warn ("Couldn't open ports during Modem SIM hot swap enabling: %s", error? error->message : "unknown reason"); + mm_obj_warn (ctx->self, "couldn't open ports during Modem SIM hot swap enabling: %s", + error ? error->message : "unknown reason"); g_error_free (error); } else { ctx->self->priv->sim_hot_swap_ports_ctx = ports_context_ref (ports); @@ -11546,7 +11546,7 @@ initialize_step (GTask *task) } } } else - mm_dbg ("Ports context for SIM hot swap already available"); + mm_obj_dbg (ctx->self, "ports context for SIM hot swap already available"); ctx->step++; /* fall through */ @@ -11584,13 +11584,13 @@ initialize_step (GTask *task) if (reason == MM_MODEM_STATE_FAILED_REASON_SIM_MISSING) { if (!is_sim_hot_swap_supported) { - mm_dbg ("SIM is missing, but this modem does not support SIM hot swap."); + mm_obj_dbg (ctx->self, "SIM is missing, but this modem does not support SIM hot swap."); } else if (!is_sim_hot_swap_configured) { - mm_warn ("SIM is missing, but SIM hot swap could not be configured."); + mm_obj_warn (ctx->self, "SIM is missing, but SIM hot swap could not be configured."); } else if (!ctx->self->priv->sim_hot_swap_ports_ctx) { - mm_err ("SIM is missing and SIM hot swap is configured, but ports are not opened."); + mm_obj_err (ctx->self, "SIM is missing and SIM hot swap is configured, but ports are not opened."); } else { - mm_dbg ("SIM is missing, but SIM hot swap is enabled. Waiting for SIM..."); + mm_obj_dbg (ctx->self, "SIM is missing, but SIM hot swap is enabled; waiting for SIM..."); error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, "Modem is unusable due to SIM missing, " @@ -11780,20 +11780,20 @@ after_hotswap_event_disable_ready (MMBaseModem *self, gpointer user_data) { GError *error = NULL; + mm_base_modem_disable_finish (self, res, &error); if (error) { - mm_err ("Disable modem error: %s", error->message); + mm_obj_err (self, "failed to disable after hotswap event: %s", error->message); g_error_free (error); - } else { + } else mm_base_modem_set_valid (self, FALSE); - } } void mm_broadband_modem_update_sim_hot_swap_detected (MMBroadbandModem *self) { if (self->priv->sim_hot_swap_ports_ctx) { - mm_dbg ("Releasing SIM hot swap ports context"); + mm_obj_dbg (self, "releasing SIM hot swap ports context"); ports_context_unref (self->priv->sim_hot_swap_ports_ctx); self->priv->sim_hot_swap_ports_ctx = NULL; } From 40a542be497e7269d79a7d6799eca5997d17a0f6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 18:12:27 +0100 Subject: [PATCH 027/675] broadband-modem-qmi: port to use object logging --- src/mm-broadband-modem-qmi.c | 418 +++++++++++++++++++---------------- 1 file changed, 228 insertions(+), 190 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 7c6f4eb5..17630579 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -241,7 +241,7 @@ modem_load_manufacturer (MMIfaceModem *self, callback, user_data)) return; - mm_dbg ("loading manufacturer..."); + mm_obj_dbg (self, "loading manufacturer..."); qmi_client_dms_get_manufacturer (QMI_CLIENT_DMS (client), NULL, 5, @@ -301,7 +301,7 @@ modem_load_model (MMIfaceModem *self, callback, user_data)) return; - mm_dbg ("loading model..."); + mm_obj_dbg (self, "loading model..."); qmi_client_dms_get_model (QMI_CLIENT_DMS (client), NULL, 5, @@ -361,7 +361,7 @@ modem_load_revision (MMIfaceModem *self, callback, user_data)) return; - mm_dbg ("loading revision..."); + mm_obj_dbg (self, "loading revision..."); qmi_client_dms_get_revision (QMI_CLIENT_DMS (client), NULL, 5, @@ -421,7 +421,7 @@ modem_load_hardware_revision (MMIfaceModem *self, callback, user_data)) return; - mm_dbg ("loading hardware revision..."); + mm_obj_dbg (self, "loading hardware revision..."); qmi_client_dms_get_hardware_revision (QMI_CLIENT_DMS (client), NULL, 5, @@ -492,7 +492,7 @@ dms_get_ids_ready (QmiClientDms *client, else if (len == 8) self->priv->esn = g_strdup (str); else - mm_dbg ("Invalid ESN reported: '%s' (unexpected length)", str); + mm_obj_dbg (self, "invalid ESN reported: '%s' (unexpected length)", str); } if (qmi_message_dms_get_ids_output_get_meid (output, &str, NULL) && @@ -502,7 +502,7 @@ dms_get_ids_ready (QmiClientDms *client, if (len == 14) self->priv->meid = g_strdup (str); else - mm_dbg ("Invalid MEID reported: '%s' (unexpected length)", str); + mm_obj_dbg (self, "invalid MEID reported: '%s' (unexpected length)", str); } if (self->priv->imei) @@ -532,7 +532,7 @@ modem_load_equipment_identifier (MMIfaceModem *self, callback, user_data)) return; - mm_dbg ("loading equipment identifier..."); + mm_obj_dbg (self, "loading equipment identifier..."); qmi_client_dms_get_ids (QMI_CLIENT_DMS (client), NULL, 5, @@ -560,7 +560,7 @@ modem_load_device_identifier (MMIfaceModem *self, gchar *device_identifier; GTask *task; - mm_dbg ("loading device identifier..."); + mm_obj_dbg (self, "loading device identifier..."); /* Just use dummy ATI/ATI1 replies, all the other internal info should be * enough for uniqueness */ @@ -625,7 +625,7 @@ modem_load_own_numbers (MMIfaceModem *self, callback, user_data)) return; - mm_dbg ("loading own numbers..."); + mm_obj_dbg (self, "loading own numbers..."); qmi_client_dms_get_msisdn (QMI_CLIENT_DMS (client), NULL, 5, @@ -671,7 +671,8 @@ static void load_unlock_required_context_step (GTask *task); /* Used also when loading unlock retries left */ static gboolean -uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, +uim_get_card_status_output_parse (MMBroadbandModemQmi *self, + QmiMessageUimGetCardStatusOutput *output, MMModemLock *o_lock, guint *o_pin1_retries, guint *o_puk1_retries, @@ -715,7 +716,7 @@ uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, } if (cards->len > 1) - mm_dbg ("Multiple cards reported: %u", cards->len); + mm_obj_dbg (self, "multiple cards reported: %u", cards->len); /* All KNOWN applications in all cards will need to be in READY state for us * to consider UNLOCKED */ @@ -728,24 +729,24 @@ uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, gboolean sim_usim_found = FALSE; if (card->applications->len == 0) { - mm_dbg ("No applications reported in card [%u]", i); + mm_obj_dbg (self, "no applications reported in card [%u]", i); n_invalid++; break; } if (card->applications->len > 1) - mm_dbg ("Multiple applications reported in card [%u]: %u", i, card->applications->len); + mm_obj_dbg (self, "multiple applications reported in card [%u]: %u", i, card->applications->len); for (j = 0; j < card->applications->len; j++) { app = &g_array_index (card->applications, QmiMessageUimGetCardStatusOutputCardStatusCardsElementApplicationsElement, j); if (app->type == QMI_UIM_CARD_APPLICATION_TYPE_UNKNOWN) { - mm_dbg ("Unknown application [%u] found in card [%u]: %s. Ignored.", + mm_obj_dbg (self, "mnknown application [%u] found in card [%u]: %s; ignored.", j, i, qmi_uim_card_application_state_get_string (app->state)); continue; } - mm_dbg ("Application '%s' [%u] in card [%u]: %s", + mm_obj_dbg (self, "application '%s' [%u] in card [%u]: %s", qmi_uim_card_application_type_get_string (app->type), j, i, qmi_uim_card_application_state_get_string (app->state)); if (app->type == QMI_UIM_CARD_APPLICATION_TYPE_SIM || app->type == QMI_UIM_CARD_APPLICATION_TYPE_USIM) { @@ -761,7 +762,7 @@ uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, } if (!sim_usim_found) { - mm_dbg ("No SIM/USIM application found in card [%u]", i); + mm_obj_dbg (self, "no SIM/USIM application found in card [%u]", i); n_invalid++; } @@ -769,7 +770,7 @@ uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, } case QMI_UIM_CARD_STATE_ABSENT: - mm_dbg ("Card '%u' is absent", i); + mm_obj_dbg (self, "card '%u' is absent", i); n_absent++; break; @@ -777,9 +778,9 @@ uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, default: n_error++; if (qmi_uim_card_error_get_string (card->error_code) != NULL) - mm_warn ("Card '%u' is unusable: %s", i, qmi_uim_card_error_get_string (card->error_code)); + mm_obj_warn (self, "card '%u' is unusable: %s", i, qmi_uim_card_error_get_string (card->error_code)); else - mm_warn ("Card '%u' is unusable: unknown error", i); + mm_obj_warn (self, "card '%u' is unusable: unknown error", i); break; } @@ -819,7 +820,7 @@ uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, app->state != QMI_UIM_CARD_APPLICATION_STATE_PIN1_OR_UPIN_PIN_REQUIRED && app->state != QMI_UIM_CARD_APPLICATION_STATE_PUK1_OR_UPIN_PUK_REQUIRED && app->state != QMI_UIM_CARD_APPLICATION_STATE_PIN1_BLOCKED) { - mm_dbg ("Neither SIM nor USIM are ready"); + mm_obj_dbg (self, "neither SIM nor USIM are ready"); g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_RETRY, "SIM not ready yet (retry)"); return FALSE; @@ -883,7 +884,7 @@ uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, if (lock == MM_MODEM_LOCK_NONE) { switch (app->pin2_state) { case QMI_UIM_PIN_STATE_NOT_INITIALIZED: - mm_warn ("SIM PIN2/PUK2 status not known yet"); + mm_obj_warn (self, "SIM PIN2/PUK2 status not known yet"); break; case QMI_UIM_PIN_STATE_ENABLED_NOT_VERIFIED: @@ -891,7 +892,7 @@ uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, break; case QMI_UIM_PIN_STATE_PERMANENTLY_BLOCKED: - mm_warn ("PUK2 permanently blocked"); + mm_obj_warn (self, "PUK2 permanently blocked"); /* Fall through */ case QMI_UIM_PIN_STATE_BLOCKED: lock = MM_MODEM_LOCK_SIM_PUK2; @@ -902,7 +903,7 @@ uim_get_card_status_output_parse (QmiMessageUimGetCardStatusOutput *output, break; default: - mm_warn ("Unknown SIM PIN2/PUK2 status"); + mm_obj_warn (self, "unknown SIM PIN2/PUK2 status"); break; } } @@ -916,11 +917,13 @@ unlock_required_uim_get_card_status_ready (QmiClientUim *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; LoadUnlockRequiredContext *ctx; QmiMessageUimGetCardStatusOutput *output; GError *error = NULL; MMModemLock lock = MM_MODEM_LOCK_UNKNOWN; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); output = qmi_client_uim_get_card_status_finish (client, res, &error); @@ -931,7 +934,8 @@ unlock_required_uim_get_card_status_ready (QmiClientUim *client, return; } - if (!uim_get_card_status_output_parse (output, + if (!uim_get_card_status_output_parse (self, + output, &lock, NULL, NULL, NULL, NULL, &error)) { @@ -1069,7 +1073,7 @@ load_unlock_required_context_step (GTask *task) case LOAD_UNLOCK_REQUIRED_STEP_CDMA: /* CDMA-only modems don't need this */ if (mm_iface_modem_is_cdma_only (MM_IFACE_MODEM (self))) { - mm_dbg ("Skipping unlock check in CDMA-only modem..."); + mm_obj_dbg (self, "skipping unlock check in CDMA-only modem..."); g_task_return_int (task, MM_MODEM_LOCK_NONE); g_object_unref (task); return; @@ -1090,7 +1094,7 @@ load_unlock_required_context_step (GTask *task) return; } - mm_dbg ("loading unlock required (DMS)..."); + mm_obj_dbg (self, "loading unlock required (DMS)..."); qmi_client_dms_uim_get_pin_status (QMI_CLIENT_DMS (client), NULL, 5, @@ -1114,7 +1118,7 @@ load_unlock_required_context_step (GTask *task) return; } - mm_dbg ("loading unlock required (UIM)..."); + mm_obj_dbg (self, "loading unlock required (UIM)..."); qmi_client_uim_get_card_status (QMI_CLIENT_UIM (client), NULL, 5, @@ -1163,6 +1167,7 @@ unlock_retries_uim_get_card_status_ready (QmiClientUim *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; QmiMessageUimGetCardStatusOutput *output; GError *error = NULL; guint pin1_retries = 0; @@ -1171,6 +1176,8 @@ unlock_retries_uim_get_card_status_ready (QmiClientUim *client, guint puk2_retries = 0; MMUnlockRetries *retries; + self = g_task_get_source_object (task); + output = qmi_client_uim_get_card_status_finish (client, res, &error); if (!output) { g_prefix_error (&error, "QMI operation failed: "); @@ -1179,7 +1186,8 @@ unlock_retries_uim_get_card_status_ready (QmiClientUim *client, return; } - if (!uim_get_card_status_output_parse (output, + if (!uim_get_card_status_output_parse (self, + output, NULL, &pin1_retries, &puk1_retries, &pin2_retries, &puk2_retries, @@ -1330,7 +1338,7 @@ modem_load_unlock_retries (MMIfaceModem *_self, self = MM_BROADBAND_MODEM_QMI (_self); task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("loading unlock retries..."); + mm_obj_dbg (self, "loading unlock retries..."); if (!self->priv->dms_uim_deprecated) dms_uim_load_unlock_retries (MM_BROADBAND_MODEM_QMI (self), task); else @@ -1447,7 +1455,7 @@ common_signal_info_get_quality (gint8 cdma1x_rssi, * order to report always the one with the maximum value. */ if (cdma1x_rssi < 0) { - mm_dbg ("RSSI (CDMA): %d dBm", cdma1x_rssi); + mm_obj_dbg (self, "RSSI (CDMA): %d dBm", cdma1x_rssi); if (qmi_dbm_valid (cdma1x_rssi, QMI_NAS_RADIO_INTERFACE_CDMA_1X)) { rssi_max = MAX (cdma1x_rssi, rssi_max); signal_info_radio_interface = QMI_NAS_RADIO_INTERFACE_CDMA_1X; @@ -1455,7 +1463,7 @@ common_signal_info_get_quality (gint8 cdma1x_rssi, } if (evdo_rssi < 0) { - mm_dbg ("RSSI (HDR): %d dBm", evdo_rssi); + mm_obj_dbg (self, "RSSI (HDR): %d dBm", evdo_rssi); if (qmi_dbm_valid (evdo_rssi, QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO)) { rssi_max = MAX (evdo_rssi, rssi_max); signal_info_radio_interface = QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO; @@ -1463,7 +1471,7 @@ common_signal_info_get_quality (gint8 cdma1x_rssi, } if (gsm_rssi < 0) { - mm_dbg ("RSSI (GSM): %d dBm", gsm_rssi); + mm_obj_dbg (self, "RSSI (GSM): %d dBm", gsm_rssi); if (qmi_dbm_valid (gsm_rssi, QMI_NAS_RADIO_INTERFACE_GSM)) { rssi_max = MAX (gsm_rssi, rssi_max); signal_info_radio_interface = QMI_NAS_RADIO_INTERFACE_GSM; @@ -1471,7 +1479,7 @@ common_signal_info_get_quality (gint8 cdma1x_rssi, } if (wcdma_rssi < 0) { - mm_dbg ("RSSI (WCDMA): %d dBm", wcdma_rssi); + mm_obj_dbg (self, "RSSI (WCDMA): %d dBm", wcdma_rssi); if (qmi_dbm_valid (wcdma_rssi, QMI_NAS_RADIO_INTERFACE_UMTS)) { rssi_max = MAX (wcdma_rssi, rssi_max); signal_info_radio_interface = QMI_NAS_RADIO_INTERFACE_UMTS; @@ -1479,7 +1487,7 @@ common_signal_info_get_quality (gint8 cdma1x_rssi, } if (lte_rssi < 0) { - mm_dbg ("RSSI (LTE): %d dBm", lte_rssi); + mm_obj_dbg (self, "RSSI (LTE): %d dBm", lte_rssi); if (qmi_dbm_valid (lte_rssi, QMI_NAS_RADIO_INTERFACE_LTE)) { rssi_max = MAX (lte_rssi, rssi_max); signal_info_radio_interface = QMI_NAS_RADIO_INTERFACE_LTE; @@ -1491,7 +1499,7 @@ common_signal_info_get_quality (gint8 cdma1x_rssi, *out_quality = STRENGTH_TO_QUALITY (rssi_max); *out_act = mm_modem_access_technology_from_qmi_radio_interface (signal_info_radio_interface); - mm_dbg ("RSSI: %d dBm --> %u%%", rssi_max, *out_quality); + mm_obj_dbg (self, "RSSI: %d dBm --> %u%%", rssi_max, *out_quality); return TRUE; } @@ -1587,9 +1595,9 @@ signal_strength_get_quality_and_access_tech (MMBroadbandModemQmi *self, /* The mandatory one is always present */ qmi_message_nas_get_signal_strength_output_get_signal_strength (output, &signal_max, &main_interface, NULL); - mm_dbg ("Signal strength (%s): %d dBm", - qmi_nas_radio_interface_get_string (main_interface), - signal_max); + mm_obj_dbg (self, "signal strength (%s): %d dBm", + qmi_nas_radio_interface_get_string (main_interface), + signal_max); /* Treat results as invalid if main signal strength is invalid */ if (!qmi_dbm_valid (signal_max, main_interface)) @@ -1606,9 +1614,9 @@ signal_strength_get_quality_and_access_tech (MMBroadbandModemQmi *self, element = &g_array_index (array, QmiMessageNasGetSignalStrengthOutputStrengthListElement, i); - mm_dbg ("Signal strength (%s): %d dBm", - qmi_nas_radio_interface_get_string (element->radio_interface), - element->strength); + mm_obj_dbg (self, "signal strength (%s): %d dBm", + qmi_nas_radio_interface_get_string (element->radio_interface), + element->strength); if (qmi_dbm_valid (element->strength, element->radio_interface)) { signal_max = MAX (element->strength, signal_max); @@ -1622,7 +1630,7 @@ signal_strength_get_quality_and_access_tech (MMBroadbandModemQmi *self, *o_quality = STRENGTH_TO_QUALITY (signal_max); *o_act = act; - mm_dbg ("Signal strength: %d dBm --> %u%%", signal_max, *o_quality); + mm_obj_dbg (self, "signal strength: %d dBm --> %u%%", signal_max, *o_quality); } return (signal_max < 0); @@ -1693,7 +1701,7 @@ load_signal_quality (MMIfaceModem *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("loading signal quality..."); + mm_obj_dbg (self, "loading signal quality..."); #if defined WITH_NEWEST_QMI_COMMANDS /* Signal info introduced in NAS 1.8 */ @@ -1755,16 +1763,18 @@ dms_set_fcc_authentication_ready (QmiClientDms *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; SetOperatingModeContext *ctx; QmiMessageDmsSetFccAuthenticationOutput *output = NULL; GError *error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); output = qmi_client_dms_set_fcc_authentication_finish (client, res, &error); if (!output || !qmi_message_dms_set_fcc_authentication_output_get_result (output, &error)) { /* No hard errors */ - mm_dbg ("Couldn't set FCC authentication: %s", error->message); + mm_obj_dbg (self, "couldn't set FCC authentication: %s", error->message); g_error_free (error); } @@ -1781,17 +1791,19 @@ dms_set_operating_mode_ready (QmiClientDms *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; SetOperatingModeContext *ctx; QmiMessageDmsSetOperatingModeOutput *output = NULL; GError *error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); output = qmi_client_dms_set_operating_mode_finish (client, res, &error); if (!output) { /* If unsupported, just go out without errors */ if (g_error_matches (error, QMI_CORE_ERROR, QMI_CORE_ERROR_UNSUPPORTED)) { - mm_dbg ("Device doesn't support operating mode setting. Ignoring power update."); + mm_obj_dbg (self, "device doesn't support operating mode setting; ignoring power update."); g_error_free (error); ctx->step = SET_OPERATING_MODE_STEP_LAST; set_operating_mode_context_step (task); @@ -1847,13 +1859,15 @@ dms_set_operating_mode_ready (QmiClientDms *client, static void set_operating_mode_context_step (GTask *task) { + MMBroadbandModemQmi *self; SetOperatingModeContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); switch (ctx->step) { case SET_OPERATING_MODE_STEP_FIRST: - mm_dbg ("Setting device operating mode..."); + mm_obj_dbg (self, "setting device operating mode..."); qmi_client_dms_set_operating_mode (QMI_CLIENT_DMS (ctx->client), ctx->input, 20, @@ -1862,7 +1876,7 @@ set_operating_mode_context_step (GTask *task) task); return; case SET_OPERATING_MODE_STEP_FCC_AUTH: - mm_dbg ("Setting FCC auth..."); + mm_obj_dbg (self, "setting FCC auth..."); qmi_client_dms_set_fcc_authentication (QMI_CLIENT_DMS (ctx->client), NULL, 5, @@ -1871,7 +1885,7 @@ set_operating_mode_context_step (GTask *task) task); return; case SET_OPERATING_MODE_STEP_RETRY: - mm_dbg ("Setting device operating mode (retry)..."); + mm_obj_dbg (self, "setting device operating mode (retry)..."); qmi_client_dms_set_operating_mode (QMI_CLIENT_DMS (ctx->client), ctx->input, 20, @@ -2036,7 +2050,7 @@ load_power_state (MMIfaceModem *self, callback, user_data)) return; - mm_dbg ("Getting device operating mode..."); + mm_obj_dbg (self, "getting device operating mode..."); qmi_client_dms_get_operating_mode (QMI_CLIENT_DMS (client), NULL, 5, @@ -2140,16 +2154,18 @@ get_sim_lock_status_via_pin_status_ready (QmiClientDms *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; LoadEnabledFacilityLocksContext *ctx; QmiMessageDmsUimGetPinStatusOutput *output; gboolean enabled; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); output = qmi_client_dms_uim_get_pin_status_finish (client, res, NULL); if (!output || !qmi_message_dms_uim_get_pin_status_output_get_result (output, NULL)) { - mm_dbg ("Couldn't query PIN status, assuming SIM PIN is disabled"); + mm_obj_dbg (self, "couldn't query PIN status, assuming SIM PIN is disabled"); enabled = FALSE; } else { QmiDmsUimPinStatus current_status; @@ -2161,9 +2177,9 @@ get_sim_lock_status_via_pin_status_ready (QmiClientDms *client, NULL, /* unblock_retries_left */ NULL)) { enabled = mm_pin_enabled_from_qmi_uim_pin_status (current_status); - mm_dbg ("PIN is reported %s", (enabled ? "enabled" : "disabled")); + mm_obj_dbg (self, "PIN is reported %s", (enabled ? "enabled" : "disabled")); } else { - mm_dbg ("Couldn't find PIN1 status in the result, assuming SIM PIN is disabled"); + mm_obj_dbg (self, "couldn't find PIN1 status in the result, assuming SIM PIN is disabled"); enabled = FALSE; } } @@ -2187,11 +2203,13 @@ get_sim_lock_status_via_pin_status_ready (QmiClientDms *client, static void get_sim_lock_status_via_pin_status (GTask *task) { + MMBroadbandModemQmi *self; LoadEnabledFacilityLocksContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); - mm_dbg ("Retrieving PIN status to check for enabled PIN"); + mm_obj_dbg (self, "retrieving PIN status to check for enabled PIN"); /* if the SIM is locked or not can only be queried by locking at * the PIN status */ qmi_client_dms_uim_get_pin_status (QMI_CLIENT_DMS (ctx->client), @@ -2207,17 +2225,20 @@ dms_uim_get_ck_status_ready (QmiClientDms *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; LoadEnabledFacilityLocksContext *ctx; gchar *facility_str; QmiMessageDmsUimGetCkStatusOutput *output; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); + facility_str = mm_modem_3gpp_facility_build_string_from_mask (1 << ctx->current); output = qmi_client_dms_uim_get_ck_status_finish (client, res, NULL); if (!output || !qmi_message_dms_uim_get_ck_status_output_get_result (output, NULL)) { /* On errors, we'll just assume disabled */ - mm_dbg ("Couldn't query facility '%s' status, assuming disabled", facility_str); + mm_obj_dbg (self, "couldn't query facility '%s' status, assuming disabled", facility_str); ctx->locks &= ~(1 << ctx->current); } else { QmiDmsUimFacilityState state; @@ -2231,7 +2252,7 @@ dms_uim_get_ck_status_ready (QmiClientDms *client, &unblock_retries_left, NULL); - mm_dbg ("Facility '%s' is: '%s'", + mm_obj_dbg (self, "facility '%s' is: '%s'", facility_str, qmi_dms_uim_facility_state_get_string (state)); @@ -2471,7 +2492,7 @@ modem_3gpp_scan_networks (MMIfaceModem3gpp *self, callback, user_data)) return; - mm_dbg ("Scanning networks..."); + mm_obj_dbg (self, "scanning networks..."); qmi_client_nas_network_scan (QMI_CLIENT_NAS (client), NULL, 300, @@ -2619,11 +2640,11 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, if (selected_network == QMI_NAS_NETWORK_TYPE_3GPP || (selected_network == QMI_NAS_NETWORK_TYPE_UNKNOWN && (mm_access_technologies & MM_IFACE_MODEM_3GPP_ALL_ACCESS_TECHNOLOGIES_MASK))) { - mm_dbg ("Processing 3GPP info..."); + mm_obj_dbg (self, "processing 3GPP info..."); } else { MMModem3gppRegistrationState reg_state_3gpp; - mm_dbg ("No 3GPP info given..."); + mm_obj_dbg (self, "no 3GPP info given..."); g_free (self->priv->current_operator_id); self->priv->current_operator_id = NULL; g_free (self->priv->current_operator_description); @@ -2925,7 +2946,7 @@ process_gsm_info (QmiMessageNasGetSystemInfoOutput *response_output, NULL, NULL, /* egprs support */ NULL, NULL, /* dtm_support */ NULL)) { - mm_dbg ("No GSM service reported"); + mm_obj_dbg (self, "no GSM service reported"); /* No GSM service */ return FALSE; } @@ -2949,7 +2970,7 @@ process_gsm_info (QmiMessageNasGetSystemInfoOutput *response_output, NULL, NULL, /* egprs support */ NULL, NULL, /* dtm_support */ NULL)) { - mm_dbg ("No GSM service reported"); + mm_obj_dbg (self, "no GSM service reported"); /* No GSM service */ return FALSE; } @@ -2969,7 +2990,7 @@ process_gsm_info (QmiMessageNasGetSystemInfoOutput *response_output, NULL, mm_cid, mm_operator_id)) { - mm_dbg ("No GSM service registered"); + mm_obj_dbg (self, "no GSM service registered"); return FALSE; } @@ -3033,7 +3054,7 @@ process_wcdma_info (QmiMessageNasGetSystemInfoOutput *response_output, &hs_service_valid, &hs_service, NULL, NULL, /* primary_scrambling_code */ NULL)) { - mm_dbg ("No WCDMA service reported"); + mm_obj_dbg (self, "no WCDMA service reported"); /* No GSM service */ return FALSE; } @@ -3058,7 +3079,7 @@ process_wcdma_info (QmiMessageNasGetSystemInfoOutput *response_output, &hs_service_valid, &hs_service, NULL, NULL, /* primary_scrambling_code */ NULL)) { - mm_dbg ("No WCDMA service reported"); + mm_obj_dbg (self, "no WCDMA service reported"); /* No GSM service */ return FALSE; } @@ -3078,7 +3099,7 @@ process_wcdma_info (QmiMessageNasGetSystemInfoOutput *response_output, NULL, mm_cid, mm_operator_id)) { - mm_dbg ("No WCDMA service registered"); + mm_obj_dbg (self, "no WCDMA service registered"); return FALSE; } @@ -3142,7 +3163,7 @@ process_lte_info (QmiMessageNasGetSystemInfoOutput *response_output, &network_id_valid, &mcc, &mnc, &tac_valid, &tac, NULL)) { - mm_dbg ("No LTE service reported"); + mm_obj_dbg (self, "no LTE service reported"); /* No GSM service */ return FALSE; } @@ -3165,7 +3186,7 @@ process_lte_info (QmiMessageNasGetSystemInfoOutput *response_output, &network_id_valid, &mcc, &mnc, &tac_valid, &tac, NULL)) { - mm_dbg ("No LTE service reported"); + mm_obj_dbg (self, "no LTE service reported"); /* No GSM service */ return FALSE; } @@ -3185,7 +3206,7 @@ process_lte_info (QmiMessageNasGetSystemInfoOutput *response_output, mm_tac, mm_cid, mm_operator_id)) { - mm_dbg ("No LTE service registered"); + mm_obj_dbg (self, "no LTE service registered"); return FALSE; } @@ -3236,7 +3257,7 @@ common_process_system_info_3gpp (MMBroadbandModemQmi *self, &lac, &cid, &operator_id)) { - mm_dbg ("No service (GSM, WCDMA or LTE) reported"); + mm_obj_dbg (self, "no service (GSM, WCDMA or LTE) reported"); } /* Cache current operator ID */ @@ -3386,10 +3407,10 @@ ri_serving_system_or_system_info_ready (QmiClientNas *client, output = qmi_client_nas_register_indications_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: '%s'", error->message); + mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); g_error_free (error); } else if (!qmi_message_nas_register_indications_output_get_result (output, &error)) { - mm_dbg ("Couldn't register indications: '%s'", error->message); + mm_obj_dbg (self, "couldn't register indications: '%s'", error->message); g_error_free (error); } @@ -3520,7 +3541,7 @@ modem_3gpp_enable_unsolicited_registration_events (MMIfaceModem3gpp *_self, } /* Devices with NAS < 1.2 will just always issue serving system indications */ - mm_dbg ("Assuming serving system indications are always enabled"); + mm_obj_dbg (self, "assuming serving system indications are always enabled"); self->priv->unsolicited_registration_events_enabled = TRUE; g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -3595,9 +3616,9 @@ common_process_serving_system_cdma (MMBroadbandModemQmi *self, if (selected_network == QMI_NAS_NETWORK_TYPE_3GPP2 || (selected_network == QMI_NAS_NETWORK_TYPE_UNKNOWN && (mm_access_technologies & MM_IFACE_MODEM_CDMA_ALL_ACCESS_TECHNOLOGIES_MASK))) { - mm_dbg ("Processing CDMA info..."); + mm_obj_dbg (self, "processing CDMA info..."); } else { - mm_dbg ("No CDMA info given..."); + mm_obj_dbg (self, "no CDMA info given..."); mm_iface_modem_cdma_update_cdma1x_registration_state (MM_IFACE_MODEM_CDMA (self), MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, 0, 0); @@ -3966,13 +3987,15 @@ activate_manual_get_msisdn_ready (QmiClientDms *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; CdmaActivationContext *ctx; QmiMessageDmsGetMsisdnOutput *output = NULL; GError *error = NULL; const gchar *current_mdn = NULL; const gchar *expected_mdn = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); qmi_message_dms_activate_manual_input_get_info (ctx->input_manual, NULL, /* spc */ @@ -3986,7 +4009,7 @@ activate_manual_get_msisdn_ready (QmiClientDms *client, qmi_message_dms_get_msisdn_output_get_result (output, NULL) && qmi_message_dms_get_msisdn_output_get_msisdn (output, ¤t_mdn, NULL) && g_str_equal (current_mdn, expected_mdn)) { - mm_dbg ("MDN successfully updated to '%s'", expected_mdn); + mm_obj_dbg (self, "MDN successfully updated to '%s'", expected_mdn); qmi_message_dms_get_msisdn_output_unref (output); /* And go on to next step */ ctx->step++; @@ -3999,7 +4022,7 @@ activate_manual_get_msisdn_ready (QmiClientDms *client, if (ctx->n_mdn_check_retries < MAX_MDN_CHECK_RETRIES) { /* Retry after some time */ - mm_dbg ("MDN not yet updated, retrying..."); + mm_obj_dbg (self, "MDN not yet updated, retrying..."); g_timeout_add (1, (GSourceFunc) retry_msisdn_check_cb, task); return; } @@ -4025,15 +4048,15 @@ activation_event_report_indication_cb (QmiClientDms *client, if (!qmi_indication_dms_event_report_output_get_activation_state (output, &state, NULL)) return; - mm_dbg ("Activation state update: '%s'", + mm_obj_dbg (self, "activation state update: '%s'", qmi_dms_activation_state_get_string (state)); new = mm_modem_cdma_activation_state_from_qmi_activation_state (state); if (self->priv->activation_state != new) - mm_info ("Activation state changed: '%s'-->'%s'", - mm_modem_cdma_activation_state_get_string (self->priv->activation_state), - mm_modem_cdma_activation_state_get_string (new)); + mm_obj_info (self, "activation state changed: '%s'-->'%s'", + mm_modem_cdma_activation_state_get_string (self->priv->activation_state), + mm_modem_cdma_activation_state_get_string (new)); /* Cache the new value */ self->priv->activation_state = new; @@ -4073,7 +4096,7 @@ activation_event_report_indication_cb (QmiClientDms *client, return; } - mm_dbg ("Activation process still ongoing..."); + mm_obj_dbg (self, "activation process still ongoing..."); } static void @@ -4218,8 +4241,7 @@ cdma_activation_context_step (GTask *task) if (ctx->input_automatic) { QmiMessageDmsSetEventReportInput *input; - mm_info ("Activation step [1/5]: enabling indications"); - + mm_obj_info (ctx->self, "activation step [1/5]: enabling indications"); input = qmi_message_dms_set_event_report_input_new (); qmi_message_dms_set_event_report_input_set_activation_state_reporting (input, TRUE, NULL); qmi_client_dms_set_event_report ( @@ -4235,15 +4257,14 @@ cdma_activation_context_step (GTask *task) /* Manual activation, no indications needed */ g_assert (ctx->input_manual != NULL); - mm_info ("Activation step [1/5]: indications not needed in manual activation"); + mm_obj_info (ctx->self, "activation step [1/5]: indications not needed in manual activation"); ctx->step++; /* Fall through */ case CDMA_ACTIVATION_STEP_REQUEST_ACTIVATION: /* Automatic activation */ if (ctx->input_automatic) { - mm_info ("Activation step [2/5]: requesting automatic (OTA) activation"); - + mm_obj_info (ctx->self, "activation step [2/5]: requesting automatic (OTA) activation"); qmi_client_dms_activate_automatic (ctx->client, ctx->input_automatic, 10, @@ -4256,10 +4277,10 @@ cdma_activation_context_step (GTask *task) /* Manual activation */ g_assert (ctx->input_manual != NULL); if (!ctx->segments) - mm_info ("Activation step [2/5]: requesting manual activation"); + mm_obj_info (ctx->self, "activation step [2/5]: requesting manual activation"); else { - mm_info ("Activation step [2/5]: requesting manual activation (PRL segment %u/%u)", - (ctx->segment_i + 1), ctx->n_segments); + mm_obj_info (ctx->self, "activation step [2/5]: requesting manual activation (PRL segment %u/%u)", + (ctx->segment_i + 1), ctx->n_segments); qmi_message_dms_activate_manual_input_set_prl ( ctx->input_manual, (guint16)ctx->total_segments_size, @@ -4280,14 +4301,14 @@ cdma_activation_context_step (GTask *task) /* Automatic activation */ if (ctx->input_automatic) { /* State updates via unsolicited messages */ - mm_info ("Activation step [3/5]: waiting for activation state updates"); + mm_obj_info (ctx->self, "activation step [3/5]: waiting for activation state updates"); return; } /* Manual activation; needs MSISDN checks */ g_assert (ctx->input_manual != NULL); ctx->n_mdn_check_retries++; - mm_info ("Activation step [3/5]: checking MDN update (retry %u)", ctx->n_mdn_check_retries); + mm_obj_info (ctx->self, "activation step [3/5]: checking MDN update (retry %u)", ctx->n_mdn_check_retries); qmi_client_dms_get_msisdn (ctx->client, NULL, 5, @@ -4297,14 +4318,14 @@ cdma_activation_context_step (GTask *task) return; case CDMA_ACTIVATION_STEP_RESET: - mm_info ("Activation step [4/5]: power-cycling..."); + mm_obj_info (ctx->self, "activation step [4/5]: power-cycling..."); mm_shared_qmi_reset (MM_IFACE_MODEM (ctx->self), (GAsyncReadyCallback)activation_reset_ready, task); return; case CDMA_ACTIVATION_STEP_LAST: - mm_info ("Activation step [5/5]: finished"); + mm_obj_info (ctx->self, "activation step [5/5]: finished"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -4518,7 +4539,7 @@ common_setup_cleanup_unsolicited_registration_events (MMBroadbandModemQmi *self, task = g_task_new (self, NULL, callback, user_data); if (enable == self->priv->unsolicited_registration_events_setup) { - mm_dbg ("Unsolicited registration events already %s; skipping", + mm_obj_dbg (self, "unsolicited registration events already %s; skipping", enable ? "setup" : "cleanup"); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -4707,10 +4728,10 @@ ser_signal_strength_ready (QmiClientNas *client, output = qmi_client_nas_set_event_report_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: '%s'", error->message); + mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); g_error_free (error); } else if (!qmi_message_nas_set_event_report_output_get_result (output, &error)) { - mm_dbg ("Couldn't set event report: '%s'", error->message); + mm_obj_dbg (self, "couldn't set event report: '%s'", error->message); g_error_free (error); } @@ -4777,10 +4798,10 @@ ri_signal_info_ready (QmiClientNas *client, output = qmi_client_nas_register_indications_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: '%s'", error->message); + mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); g_error_free (error); } else if (!qmi_message_nas_register_indications_output_get_result (output, &error)) { - mm_dbg ("Couldn't register indications: '%s'", error->message); + mm_obj_dbg (self, "couldn't register indications: '%s'", error->message); g_error_free (error); } @@ -4822,10 +4843,10 @@ config_signal_info_ready (QmiClientNas *client, output = qmi_client_nas_config_signal_info_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: '%s'", error->message); + mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); g_error_free (error); } else if (!qmi_message_nas_config_signal_info_output_get_result (output, &error)) { - mm_dbg ("Couldn't config signal info: '%s'", error->message); + mm_obj_dbg (self, "couldn't config signal info: '%s'", error->message); g_error_free (error); } @@ -4895,8 +4916,8 @@ common_enable_disable_unsolicited_events (MMBroadbandModemQmi *self, task = g_task_new (self, NULL, callback, user_data); if (enable == self->priv->unsolicited_events_enabled) { - mm_dbg ("Unsolicited events already %s; skipping", - enable ? "enabled" : "disabled"); + mm_obj_dbg (self, "unsolicited events already %s; skipping", + enable ? "enabled" : "disabled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -5014,10 +5035,10 @@ event_report_indication_cb (QmiClientNas *client, /* This signal strength comes as negative dBms */ quality = STRENGTH_TO_QUALITY (signal_strength); - mm_dbg ("Signal strength indication (%s): %d dBm --> %u%%", - qmi_nas_radio_interface_get_string (signal_strength_radio_interface), - signal_strength, - quality); + mm_obj_dbg (self, "signal strength indication (%s): %d dBm --> %u%%", + qmi_nas_radio_interface_get_string (signal_strength_radio_interface), + signal_strength, + quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); mm_iface_modem_update_access_technologies ( @@ -5025,9 +5046,9 @@ event_report_indication_cb (QmiClientNas *client, mm_modem_access_technology_from_qmi_radio_interface (signal_strength_radio_interface), (MM_IFACE_MODEM_3GPP_ALL_ACCESS_TECHNOLOGIES_MASK | MM_IFACE_MODEM_CDMA_ALL_ACCESS_TECHNOLOGIES_MASK)); } else { - mm_dbg ("Ignoring invalid signal strength (%s): %d dBm", - qmi_nas_radio_interface_get_string (signal_strength_radio_interface), - signal_strength); + mm_obj_dbg (self, "ignoring invalid signal strength (%s): %d dBm", + qmi_nas_radio_interface_get_string (signal_strength_radio_interface), + signal_strength); } } } @@ -5087,8 +5108,8 @@ common_setup_cleanup_unsolicited_events (MMBroadbandModemQmi *self, task = g_task_new (self, NULL, callback, user_data); if (enable == self->priv->unsolicited_events_setup) { - mm_dbg ("Unsolicited events already %s; skipping", - enable ? "setup" : "cleanup"); + mm_obj_dbg (self, "unsolicited events already %s; skipping", + enable ? "setup" : "cleanup"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -5246,7 +5267,7 @@ messaging_check_support (MMIfaceModemMessaging *self, return; } - mm_dbg ("Messaging capabilities supported"); + mm_obj_dbg (self, "messaging capabilities supported"); g_task_return_boolean (task, TRUE); g_object_unref (task); } @@ -5419,7 +5440,7 @@ messaging_set_default_storage (MMIfaceModemMessaging *_self, g_array_append_val (routes_array, route); qmi_message_wms_set_routes_input_set_route_list (input, routes_array, NULL); - mm_dbg ("setting default messaging routes..."); + mm_obj_dbg (self, "setting default messaging routes..."); qmi_client_wms_set_routes (QMI_CLIENT_WMS (client), input, 5, @@ -5517,22 +5538,22 @@ add_new_read_sms_part (MMIfaceModemMessaging *self, &error); break; case QMI_WMS_MESSAGE_FORMAT_MWI: - mm_dbg ("Don't know how to process 'message waiting indicator' messages"); + mm_obj_dbg (self, "don't know how to process 'message waiting indicator' messages"); break; default: - mm_dbg ("Unhandled message format '%u'", format); + mm_obj_dbg (self, "unhandled message format '%u'", format); break; } if (part) { - mm_dbg ("Correctly parsed PDU (%d)", index); + mm_obj_dbg (self, "correctly parsed PDU (%d)", index); mm_iface_modem_messaging_take_part (self, part, mm_sms_state_from_qmi_message_tag (tag), mm_sms_storage_from_qmi_storage_type (storage)); } else if (error) { /* Don't treat the error as critical */ - mm_dbg ("Error parsing PDU (%d): %s", index, error->message); + mm_obj_dbg (self, "error parsing PDU (%d): %s", index, error->message); g_error_free (error); } } @@ -5554,10 +5575,10 @@ wms_raw_read_ready (QmiClientWms *client, output = qmi_client_wms_raw_read_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: %s", error->message); + mm_obj_dbg (self, "QMI operation failed: %s", error->message); g_error_free (error); } else if (!qmi_message_wms_raw_read_output_get_result (output, &error)) { - mm_dbg ("Couldn't read raw message: %s", error->message); + mm_obj_dbg (self, "couldn't read raw message: %s", error->message); g_error_free (error); } else { QmiWmsMessageTagType tag; @@ -5654,12 +5675,14 @@ wms_list_messages_ready (QmiClientWms *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; LoadInitialSmsPartsContext *ctx; QmiMessageWmsListMessagesOutput *output = NULL; GError *error = NULL; GArray *message_array; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); output = qmi_client_wms_list_messages_finish (client, res, &error); if (!output) { @@ -5671,7 +5694,7 @@ wms_list_messages_ready (QmiClientWms *client, if (!qmi_message_wms_list_messages_output_get_result (output, &error)) { /* Ignore error, keep on */ - mm_dbg ("Couldn't read SMS messages: %s", error->message); + mm_obj_dbg (self, "couldn't read SMS messages: %s", error->message); g_error_free (error); ctx->step++; load_initial_sms_parts_step (task); @@ -5724,34 +5747,34 @@ load_initial_sms_parts_step (GTask *task) /* Fall through */ case LOAD_INITIAL_SMS_PARTS_STEP_3GPP_LIST_ALL: - mm_dbg ("loading all 3GPP messages from storage '%s'...", + mm_obj_dbg (self, "loading all 3GPP messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); mode = QMI_WMS_MESSAGE_MODE_GSM_WCDMA; break; case LOAD_INITIAL_SMS_PARTS_STEP_3GPP_LIST_MT_READ: - mm_dbg ("loading 3GPP MT-read messages from storage '%s'...", + mm_obj_dbg (self, "loading 3GPP MT-read messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); tag_type = QMI_WMS_MESSAGE_TAG_TYPE_MT_READ; mode = QMI_WMS_MESSAGE_MODE_GSM_WCDMA; break; case LOAD_INITIAL_SMS_PARTS_STEP_3GPP_LIST_MT_NOT_READ: - mm_dbg ("loading 3GPP MT-not-read messages from storage '%s'...", + mm_obj_dbg (self, "loading 3GPP MT-not-read messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); tag_type = QMI_WMS_MESSAGE_TAG_TYPE_MT_NOT_READ; mode = QMI_WMS_MESSAGE_MODE_GSM_WCDMA; break; case LOAD_INITIAL_SMS_PARTS_STEP_3GPP_LIST_MO_SENT: - mm_dbg ("loading 3GPP MO-sent messages from storage '%s'...", + mm_obj_dbg (self, "loading 3GPP MO-sent messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); tag_type = QMI_WMS_MESSAGE_TAG_TYPE_MO_SENT; mode = QMI_WMS_MESSAGE_MODE_GSM_WCDMA; break; case LOAD_INITIAL_SMS_PARTS_STEP_3GPP_LIST_MO_NOT_SENT: - mm_dbg ("loading 3GPP MO-not-sent messages from storage '%s'...", + mm_obj_dbg (self, "loading 3GPP MO-not-sent messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); tag_type = QMI_WMS_MESSAGE_TAG_TYPE_MO_NOT_SENT; mode = QMI_WMS_MESSAGE_MODE_GSM_WCDMA; @@ -5772,34 +5795,34 @@ load_initial_sms_parts_step (GTask *task) /* Fall through */ case LOAD_INITIAL_SMS_PARTS_STEP_CDMA_LIST_ALL: - mm_dbg ("loading all CDMA messages from storage '%s'...", + mm_obj_dbg (self, "loading all CDMA messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); mode = QMI_WMS_MESSAGE_MODE_CDMA; break; case LOAD_INITIAL_SMS_PARTS_STEP_CDMA_LIST_MT_READ: - mm_dbg ("loading CDMA MT-read messages from storage '%s'...", + mm_obj_dbg (self, "loading CDMA MT-read messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); tag_type = QMI_WMS_MESSAGE_TAG_TYPE_MT_READ; mode = QMI_WMS_MESSAGE_MODE_CDMA; break; case LOAD_INITIAL_SMS_PARTS_STEP_CDMA_LIST_MT_NOT_READ: - mm_dbg ("loading CDMA MT-not-read messages from storage '%s'...", + mm_obj_dbg (self, "loading CDMA MT-not-read messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); tag_type = QMI_WMS_MESSAGE_TAG_TYPE_MT_NOT_READ; mode = QMI_WMS_MESSAGE_MODE_CDMA; break; case LOAD_INITIAL_SMS_PARTS_STEP_CDMA_LIST_MO_SENT: - mm_dbg ("loading CDMA MO-sent messages from storage '%s'...", + mm_obj_dbg (self, "loading CDMA MO-sent messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); tag_type = QMI_WMS_MESSAGE_TAG_TYPE_MO_SENT; mode = QMI_WMS_MESSAGE_MODE_CDMA; break; case LOAD_INITIAL_SMS_PARTS_STEP_CDMA_LIST_MO_NOT_SENT: - mm_dbg ("loading CDMA MO-not-sent messages from storage '%s'...", + mm_obj_dbg (self, "loading CDMA MO-not-sent messages from storage '%s'...", mm_sms_storage_get_string (ctx->storage)); tag_type = QMI_WMS_MESSAGE_TAG_TYPE_MO_NOT_SENT; mode = QMI_WMS_MESSAGE_MODE_CDMA; @@ -5907,10 +5930,10 @@ wms_indication_raw_read_ready (QmiClientWms *client, output = qmi_client_wms_raw_read_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: %s", error->message); + mm_obj_dbg (ctx->self, "QMI operation failed: %s", error->message); g_error_free (error); } else if (!qmi_message_wms_raw_read_output_get_result (output, &error)) { - mm_dbg ("Couldn't read raw message: %s", error->message); + mm_obj_dbg (ctx->self, "couldn't read raw message: %s", error->message); g_error_free (error); } else { QmiWmsMessageTagType tag; @@ -6036,8 +6059,8 @@ common_setup_cleanup_messaging_unsolicited_events (MMBroadbandModemQmi *self, task = g_task_new (self, NULL, callback, user_data); if (enable == self->priv->messaging_unsolicited_events_setup) { - mm_dbg ("Messaging unsolicited events already %s; skipping", - enable ? "setup" : "cleanup"); + mm_obj_dbg (self, "messaging unsolicited events already %s; skipping", + enable ? "setup" : "cleanup"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -6152,10 +6175,10 @@ ser_messaging_indicator_ready (QmiClientWms *client, output = qmi_client_wms_set_event_report_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: '%s'", error->message); + mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); g_error_free (error); } else if (!qmi_message_wms_set_event_report_output_get_result (output, &error)) { - mm_dbg ("Couldn't set event report: '%s'", error->message); + mm_obj_dbg (self, "couldn't set event report: '%s'", error->message); g_error_free (error); } @@ -6187,8 +6210,8 @@ common_enable_disable_messaging_unsolicited_events (MMBroadbandModemQmi *self, task = g_task_new (self, NULL, callback, user_data); if (enable == self->priv->messaging_unsolicited_events_enabled) { - mm_dbg ("Messaging unsolicited events already %s; skipping", - enable ? "enabled" : "disabled"); + mm_obj_dbg (self, "messaging unsolicited events already %s; skipping", + enable ? "enabled" : "disabled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -6489,10 +6512,10 @@ oma_check_support (MMIfaceModemOma *self, QMI_SERVICE_OMA, MM_PORT_QMI_FLAG_DEFAULT, NULL)) { - mm_dbg ("OMA capabilities not supported"); + mm_obj_dbg (self, "OMA capabilities not supported"); g_task_return_boolean (task, FALSE); } else { - mm_dbg ("OMA capabilities supported"); + mm_obj_dbg (self, "OMA capabilities supported"); g_task_return_boolean (task, TRUE); } @@ -6877,7 +6900,7 @@ oma_event_report_indication_cb (QmiClientNas *client, session_type = mm_oma_session_type_from_qmi_oma_session_type (network_initiated_alert_session_type); if (session_type == MM_OMA_SESSION_TYPE_UNKNOWN) - mm_warn ("Unknown QMI OMA session type '%u'", network_initiated_alert_session_type); + mm_obj_warn (self, "unknown QMI OMA session type '%u'", network_initiated_alert_session_type); else mm_iface_modem_oma_add_pending_network_initiated_session ( MM_IFACE_MODEM_OMA (self), @@ -6911,8 +6934,8 @@ common_setup_cleanup_oma_unsolicited_events (MMBroadbandModemQmi *self, task = g_task_new (self, NULL, callback, user_data); if (enable == self->priv->oma_unsolicited_events_setup) { - mm_dbg ("OMA unsolicited events already %s; skipping", - enable ? "setup" : "cleanup"); + mm_obj_dbg (self, "OMA unsolicited events already %s; skipping", + enable ? "setup" : "cleanup"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -6991,10 +7014,10 @@ ser_oma_indicator_ready (QmiClientOma *client, output = qmi_client_oma_set_event_report_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: '%s'", error->message); + mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); g_error_free (error); } else if (!qmi_message_oma_set_event_report_output_get_result (output, &error)) { - mm_dbg ("Couldn't set event report: '%s'", error->message); + mm_obj_dbg (self, "couldn't set event report: '%s'", error->message); g_error_free (error); } @@ -7026,8 +7049,8 @@ common_enable_disable_oma_unsolicited_events (MMBroadbandModemQmi *self, task = g_task_new (self, NULL, callback, user_data); if (enable == self->priv->oma_unsolicited_events_enabled) { - mm_dbg ("OMA unsolicited events already %s; skipping", - enable ? "enabled" : "disabled"); + mm_obj_dbg (self, "OMA unsolicited events already %s; skipping", + enable ? "enabled" : "disabled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -7134,9 +7157,9 @@ store_preloaded_firmware_image_info (MMBroadbandModemQmi *self, /* If this is is also the running image, keep an extra reference to it */ if (running) { if (self->priv->current_firmware) - mm_warn ("A running firmware is already set (%s), not setting '%s'", - mm_firmware_properties_get_unique_id (self->priv->current_firmware), - mm_firmware_properties_get_unique_id (firmware)); + mm_obj_warn (self, "a running firmware is already set (%s), not setting '%s'", + mm_firmware_properties_get_unique_id (self->priv->current_firmware), + mm_firmware_properties_get_unique_id (firmware)); else self->priv->current_firmware = g_object_ref (firmware); } @@ -7165,8 +7188,8 @@ get_pri_image_info_ready (QmiClientDms *client, if (g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_INVALID_QMI_COMMAND)) ctx->skip_image_info = TRUE; else - mm_dbg ("couldn't get detailed info for PRI image with build ID '%s': %s", - ctx->current_pair->build_id, error->message); + mm_obj_dbg (self, "couldn't get detailed info for PRI image with build ID '%s': %s", + ctx->current_pair->build_id, error->message); g_error_free (error); goto out; } @@ -7344,7 +7367,8 @@ match_images (const gchar *pri_id, const gchar *modem_id) } static GList * -find_image_pairs (QmiMessageDmsListStoredImagesOutputListImage *image_pri, +find_image_pairs (MMBroadbandModemQmi *self, + QmiMessageDmsListStoredImagesOutputListImage *image_pri, QmiMessageDmsListStoredImagesOutputListImage *image_modem, GError **error) { @@ -7368,7 +7392,7 @@ find_image_pairs (QmiMessageDmsListStoredImagesOutputListImage *image_pri, if (match_images (subimage_pri->build_id, subimage_modem->build_id)) { FirmwarePair *pair; - mm_dbg ("Found pairing PRI+MODEM images with build ID '%s'", subimage_pri->build_id); + mm_obj_dbg (self, "found pairing PRI+MODEM images with build ID '%s'", subimage_pri->build_id); pair = g_slice_new (FirmwarePair); pair->build_id = g_strdup (subimage_pri->build_id); pair->modem_unique_id = g_array_ref (subimage_modem->unique_id); @@ -7387,7 +7411,7 @@ find_image_pairs (QmiMessageDmsListStoredImagesOutputListImage *image_pri, } if (j == image_modem->sublist->len) - mm_dbg ("Pairing for PRI image with build ID '%s' not found", subimage_pri->build_id); + mm_obj_dbg (self, "pairing for PRI image with build ID '%s' not found", subimage_pri->build_id); } if (!pairs) @@ -7397,7 +7421,8 @@ find_image_pairs (QmiMessageDmsListStoredImagesOutputListImage *image_pri, } static gboolean -find_image_type_indices (GArray *array, +find_image_type_indices (MMBroadbandModemQmi *self, + GArray *array, QmiMessageDmsListStoredImagesOutputListImage **image_pri, QmiMessageDmsListStoredImagesOutputListImage **image_modem, GError **error) @@ -7422,13 +7447,13 @@ find_image_type_indices (GArray *array, switch (image->type) { case QMI_DMS_FIRMWARE_IMAGE_TYPE_PRI: if (*image_pri != NULL) - mm_dbg ("Multiple array elements found with PRI type: ignoring additional list at index %u", i); + mm_obj_dbg (self, "multiple array elements found with PRI type: ignoring additional list at index %u", i); else *image_pri = image; break; case QMI_DMS_FIRMWARE_IMAGE_TYPE_MODEM: if (*image_modem != NULL) - mm_dbg ("Multiple array elements found with MODEM type: ignoring additional list at index %u", i); + mm_obj_dbg (self, "multiple array elements found with MODEM type: ignoring additional list at index %u", i); else *image_modem = image; break; @@ -7453,6 +7478,7 @@ list_stored_images_ready (QmiClientDms *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; FirmwareListPreloadContext *ctx; GArray *array; QmiMessageDmsListStoredImagesOutputListImage *image_pri; @@ -7460,7 +7486,8 @@ list_stored_images_ready (QmiClientDms *client, QmiMessageDmsListStoredImagesOutput *output; GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* Read array from output */ output = qmi_client_dms_list_stored_images_finish (client, res, &error); @@ -7473,14 +7500,14 @@ list_stored_images_ready (QmiClientDms *client, } /* Find which index corresponds to each image type */ - if (!find_image_type_indices (array, &image_pri, &image_modem, &error)) { + if (!find_image_type_indices (self, array, &image_pri, &image_modem, &error)) { g_task_return_error (task, error); g_object_unref (task); goto out; } /* Build firmware PRI+MODEM pair list */ - ctx->pairs = find_image_pairs (image_pri, image_modem, &error); + ctx->pairs = find_image_pairs (self, image_pri, image_modem, &error); if (!ctx->pairs) { g_task_return_error (task, error); g_object_unref (task); @@ -7516,7 +7543,7 @@ firmware_list_preload (MMBroadbandModemQmi *self, task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, ctx, (GDestroyNotify)firmware_list_preload_context_free); - mm_dbg ("loading firmware images..."); + mm_obj_dbg (self, "loading firmware images..."); qmi_client_dms_list_stored_images (QMI_CLIENT_DMS (client), NULL, 10, @@ -7568,7 +7595,7 @@ firmware_list_preload_ready (MMBroadbandModemQmi *self, GError *error = NULL; if (!firmware_list_preload_finish (self, res, &error)) { - mm_dbg ("firmware list loading failed: %s", error ? error->message : "unsupported"); + mm_obj_dbg (self, "firmware list loading failed: %s", error ? error->message : "unsupported"); g_clear_error (&error); } @@ -7800,7 +7827,7 @@ firmware_change_current (MMIfaceModemFirmware *_self, if (self->priv->current_firmware && g_str_equal (mm_firmware_properties_get_unique_id (self->priv->current_firmware), mm_firmware_properties_get_unique_id (ctx->firmware))) { - mm_dbg ("Modem is already running firmware image '%s'", + mm_obj_dbg (self, "modem is already running firmware image '%s'", mm_firmware_properties_get_unique_id (self->priv->current_firmware)); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -7829,10 +7856,10 @@ firmware_change_current (MMIfaceModemFirmware *_self, goto out; } - mm_dbg ("Changing Gobi firmware to MODEM '%s' and PRI '%s' with Build ID '%s'...", - mm_firmware_properties_get_gobi_modem_unique_id (ctx->firmware), - mm_firmware_properties_get_gobi_pri_unique_id (ctx->firmware), - unique_id); + mm_obj_dbg (self, "changing Gobi firmware to MODEM '%s' and PRI '%s' with Build ID '%s'...", + mm_firmware_properties_get_gobi_modem_unique_id (ctx->firmware), + mm_firmware_properties_get_gobi_pri_unique_id (ctx->firmware), + unique_id); /* Build array of image IDs */ array = g_array_sized_new (FALSE, FALSE, sizeof (QmiMessageDmsSetFirmwarePreferenceInputListImage), 2); @@ -7884,10 +7911,10 @@ signal_check_support (MMIfaceModemSignal *self, QMI_SERVICE_NAS, MM_PORT_QMI_FLAG_DEFAULT, NULL)) { - mm_dbg ("Extended signal capabilities not supported"); + mm_obj_dbg (self, "extended signal capabilities not supported"); g_task_return_boolean (task, FALSE); } else { - mm_dbg ("Extended signal capabilities supported"); + mm_obj_dbg (self, "extended signal capabilities supported"); g_task_return_boolean (task, TRUE); } g_object_unref (task); @@ -7942,7 +7969,8 @@ signal_load_values_context_free (SignalLoadValuesContext *ctx) } static gdouble -get_db_from_sinr_level (QmiNasEvdoSinrLevel level) +get_db_from_sinr_level (MMBroadbandModemQmi *self, + QmiNasEvdoSinrLevel level) { switch (level) { case QMI_NAS_EVDO_SINR_LEVEL_0: return -9.0; @@ -7955,7 +7983,7 @@ get_db_from_sinr_level (QmiNasEvdoSinrLevel level) case QMI_NAS_EVDO_SINR_LEVEL_7: return 6; case QMI_NAS_EVDO_SINR_LEVEL_8: return +9; default: - mm_warn ("Invalid SINR level '%u'", level); + mm_obj_warn (self, "invalid SINR level '%u'", level); return -G_MAXDOUBLE; } } @@ -7992,6 +8020,7 @@ signal_load_values_get_signal_strength_ready (QmiClientNas *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; SignalLoadValuesContext *ctx; QmiMessageNasGetSignalStrengthOutput *output; GArray *array; @@ -8001,7 +8030,9 @@ signal_load_values_get_signal_strength_ready (QmiClientNas *client, QmiNasRadioInterface radio_interface; QmiNasEvdoSinrLevel sinr; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); + output = qmi_client_nas_get_signal_strength_finish (client, res, NULL); if (!output || !qmi_message_nas_get_signal_strength_output_get_result (output, NULL)) { /* No hard errors, go on to next step */ @@ -8131,7 +8162,7 @@ signal_load_values_get_signal_strength_ready (QmiClientNas *client, /* SINR (EV-DO) */ if (qmi_message_nas_get_signal_strength_output_get_sinr (output, &sinr, NULL)) { if (ctx->values_result->evdo) - mm_signal_set_sinr (ctx->values_result->evdo, get_db_from_sinr_level (sinr)); + mm_signal_set_sinr (ctx->values_result->evdo, get_db_from_sinr_level (self, sinr)); } qmi_message_nas_get_signal_strength_output_unref (output); @@ -8146,6 +8177,7 @@ signal_load_values_get_signal_info_ready (QmiClientNas *client, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; SignalLoadValuesContext *ctx; QmiMessageNasGetSignalInfoOutput *output; gint8 rssi; @@ -8156,7 +8188,9 @@ signal_load_values_get_signal_info_ready (QmiClientNas *client, gint16 rsrp; gint16 snr; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + output = qmi_client_nas_get_signal_info_finish (client, res, NULL); if (!output || !qmi_message_nas_get_signal_info_output_get_result (output, NULL)) { /* No hard errors, go on to next step */ @@ -8190,7 +8224,7 @@ signal_load_values_get_signal_info_ready (QmiClientNas *client, ctx->values_result->evdo = mm_signal_new (); mm_signal_set_rssi (ctx->values_result->evdo, (gdouble)rssi); mm_signal_set_ecio (ctx->values_result->evdo, ((gdouble)ecio) * (-0.5)); - mm_signal_set_sinr (ctx->values_result->evdo, get_db_from_sinr_level (sinr_level)); + mm_signal_set_sinr (ctx->values_result->evdo, get_db_from_sinr_level (self, sinr_level)); mm_signal_set_io (ctx->values_result->evdo, (gdouble)io); } @@ -8334,7 +8368,7 @@ signal_load_values (MMIfaceModemSignal *self, GTask *task; QmiClient *client = NULL; - mm_dbg ("loading extended signal information..."); + mm_obj_dbg (self, "loading extended signal information..."); if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), QMI_SERVICE_NAS, &client, @@ -8377,7 +8411,7 @@ parent_enabling_started_ready (MMBroadbandModem *self, &error)) { /* Don't treat this as fatal. Parent enabling may fail if it cannot grab a primary * AT port, which isn't really an issue in QMI-based modems */ - mm_dbg ("Couldn't start parent enabling: %s", error->message); + mm_obj_dbg (self, "couldn't start parent enabling: %s", error->message); g_error_free (error); } @@ -8450,7 +8484,7 @@ parent_initialization_started_ready (MMBroadbandModem *self, if (error) { /* Don't treat this as fatal. Parent initialization may fail if it cannot grab a primary * AT port, which isn't really an issue in QMI-based modems */ - mm_dbg ("Couldn't start parent initialization: %s", error->message); + mm_obj_dbg (self, "couldn't start parent initialization: %s", error->message); g_error_free (error); } @@ -8476,8 +8510,8 @@ qmi_device_removed_cb (QmiDevice *device, MMBroadbandModemQmi *self) { /* Reprobe the modem here so we can get notifications back. */ - mm_info ("Connection to qmi-proxy for %s lost, reprobing", - qmi_device_get_path_display (device)); + mm_obj_info (self, "connection to qmi-proxy for %s lost, reprobing", + qmi_device_get_path_display (device)); g_signal_handler_disconnect (device, self->priv->qmi_device_removed_id); self->priv->qmi_device_removed_id = 0; @@ -8526,15 +8560,17 @@ qmi_port_allocate_client_ready (MMPortQmi *qmi, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; InitializationStartedContext *ctx; GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!mm_port_qmi_allocate_client_finish (qmi, res, &error)) { - mm_dbg ("Couldn't allocate client for service '%s': %s", - qmi_service_get_string (qmi_services[ctx->service_index]), - error->message); + mm_obj_dbg (self, "couldn't allocate client for service '%s': %s", + qmi_service_get_string (qmi_services[ctx->service_index]), + error->message); g_error_free (error); } @@ -8589,10 +8625,12 @@ qmi_port_open_ready (MMPortQmi *qmi, GAsyncResult *res, GTask *task) { + MMBroadbandModemQmi *self; InitializationStartedContext *ctx; GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!mm_port_qmi_open_finish (qmi, res, &error)) { /* Really, really old devices (Gobi 1K, 2008-era firmware) may not @@ -8600,7 +8638,7 @@ qmi_port_open_ready (MMPortQmi *qmi, * try without it. The qmi_wwan driver will fix up any issues that * the device might have between raw-ip and 802.3 mode anyway. */ - mm_dbg ("Couldn't open QMI port with data format update: %s", error->message); + mm_obj_dbg (self, "couldn't open QMI port with data format update: %s", error->message); g_error_free (error); mm_port_qmi_open (ctx->qmi, FALSE, From 46405afdf3450744599c3962b9ec6a07dc62d6f8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 18:23:08 +0100 Subject: [PATCH 028/675] broadband-modem-mbim: port to use object logging --- src/mm-broadband-modem-mbim.c | 207 +++++++++++++++++++--------------- 1 file changed, 113 insertions(+), 94 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 931967f6..fac54504 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -28,7 +28,7 @@ #include "mm-sms-mbim.h" #include "ModemManager.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-errors-types.h" #include "mm-error-helpers.h" #include "mm-modem-helpers.h" @@ -258,11 +258,11 @@ complete_current_capabilities (GTask *task) qmi_caps_str = mm_common_build_capabilities_string ((const MMModemCapability *)&(ctx->current_qmi), 1); if ((ctx->current_mbim & ctx->current_qmi) != ctx->current_mbim) - mm_warn ("MBIM reported current capabilities (%s) not found in QMI-over-MBIM reported ones (%s)", - mbim_caps_str, qmi_caps_str); + mm_obj_warn (self, "MBIM reported current capabilities (%s) not found in QMI-over-MBIM reported ones (%s)", + mbim_caps_str, qmi_caps_str); else - mm_dbg ("MBIM reported current capabilities (%s) is a subset of the QMI-over-MBIM reported ones (%s)", - mbim_caps_str, qmi_caps_str); + mm_obj_dbg (self, "MBIM reported current capabilities (%s) is a subset of the QMI-over-MBIM reported ones (%s)", + mbim_caps_str, qmi_caps_str); g_free (mbim_caps_str); g_free (qmi_caps_str); @@ -278,7 +278,7 @@ complete_current_capabilities (GTask *task) * capability and mode related operations are going to be done via QMI as well, so that we * don't mix both logics */ if (self->priv->qmi_capability_and_mode_switching) - mm_info ("QMI-based capability and mode switching support enabled"); + mm_obj_info (self, "QMI-based capability and mode switching support enabled"); } #else result = ctx->current_mbim; @@ -336,12 +336,14 @@ device_caps_query_ready (MbimDevice *device, static void load_current_capabilities_mbim (GTask *task) { + MMBroadbandModemMbim *self; MbimMessage *message; LoadCurrentCapabilitiesContext *ctx; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); - mm_dbg ("loading current capabilities..."); + mm_obj_dbg (self, "loading current capabilities..."); message = mbim_message_device_caps_query_new (NULL); mbim_device_command (ctx->device, message, @@ -366,7 +368,7 @@ qmi_load_current_capabilities_ready (MMIfaceModem *self, ctx->current_qmi = mm_shared_qmi_load_current_capabilities_finish (self, res, &error); if (error) { - mm_dbg ("Couldn't load currrent capabilities using QMI over MBIM: %s", error->message); + mm_obj_dbg (self, "couldn't load currrent capabilities using QMI over MBIM: %s", error->message); g_clear_error (&error); } @@ -1401,14 +1403,17 @@ set_fcc_authentication_ready (QmiClientDms *qmi_client_dms, GAsyncResult *res, GTask *task) { + MMBroadbandModemMbim *self; PowerUpContext *ctx; QmiMessageDmsSetFccAuthenticationOutput *output; GError *error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); + output = qmi_client_dms_set_fcc_authentication_finish (qmi_client_dms, res, &error); if (!output || !qmi_message_dms_set_fcc_authentication_output_get_result (output, &error)) { - mm_dbg ("error: couldn't set FCC auth: %s", error->message); + mm_obj_dbg (self, "couldn't set FCC auth: %s", error->message); g_error_free (error); g_assert (ctx->saved_error); g_task_return_error (task, ctx->saved_error); @@ -1455,6 +1460,7 @@ radio_state_set_up_ready (MbimDevice *device, MbimRadioSwitchState software_radio_state; ctx = g_task_get_task_data (task); + response = mbim_device_command_finish (device, res, &error); if (response && mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error) && @@ -1486,8 +1492,11 @@ radio_state_set_up_ready (MbimDevice *device, #if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED /* Only the first attempt isn't fatal, if we have a QMI DMS client */ if ((ctx->step == POWER_UP_CONTEXT_STEP_FIRST) && ctx->qmi_client_dms) { + MMBroadbandModemMbim *self; + /* Warn and keep, will retry */ - mm_warn ("%s", error->message); + self = g_task_get_source_object (task); + mm_obj_warn (self, "%s", error->message); g_assert (!ctx->saved_error); ctx->saved_error = error; ctx->step++; @@ -1751,8 +1760,8 @@ intel_firmware_update_modem_reboot_set_ready (MbimDevice *device, GAsyncResult *res, GTask *task) { - MbimMessage *response; - GError *error = NULL; + MbimMessage *response; + GError *error = NULL; response = mbim_device_command_finish (device, res, &error); if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { @@ -1760,7 +1769,7 @@ intel_firmware_update_modem_reboot_set_ready (MbimDevice *device, /* We don't really expect the Intel firmware update service to be * available in QMI modems, but doesn't harm to fallback to the QMI * implementation here */ - mm_dbg ("Couldn't run intel reset: %s", error->message); + mm_obj_dbg (g_task_get_source_object (task), "couldn't run intel reset: %s", error->message); g_error_free (error); modem_reset_shared_qmi (task); #else @@ -1901,7 +1910,7 @@ modem_create_bearer (MMIfaceModem *_self, } /* We just create a MMBearerMbim */ - mm_dbg ("Creating MBIM bearer in MBIM modem"); + mm_obj_dbg (self, "creating MBIM bearer in MBIM modem"); bearer = mm_bearer_mbim_new (self, properties, (guint)session_id); @@ -1956,7 +1965,7 @@ parent_enabling_started_ready (MMBroadbandModem *self, &error)) { /* Don't treat this as fatal. Parent enabling may fail if it cannot grab a primary * AT port, which isn't really an issue in MBIM-based modems */ - mm_dbg ("Couldn't start parent enabling: %s", error->message); + mm_obj_dbg (self, "couldn't start parent enabling: %s", error->message); g_error_free (error); } @@ -2019,7 +2028,7 @@ parent_initialization_started_ready (MMBroadbandModem *self, if (error) { /* Don't treat this as fatal. Parent initialization may fail if it cannot grab a primary * AT port, which isn't really an issue in MBIM-based modems */ - mm_dbg ("Couldn't start parent initialization: %s", error->message); + mm_obj_dbg (self, "couldn't start parent initialization: %s", error->message); g_error_free (error); } @@ -2057,13 +2066,15 @@ mbim_port_allocate_qmi_client_ready (MMPortMbim *mbim, GAsyncResult *res, GTask *task) { + MMBroadbandModemMbim *self; InitializationStartedContext *ctx; GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!mm_port_mbim_allocate_qmi_client_finish (mbim, res, &error)) { - mm_dbg ("Couldn't allocate QMI client for service '%s': %s", + mm_obj_dbg (self, "couldn't allocate QMI client for service '%s': %s", qmi_service_get_string (qmi_services[ctx->qmi_service_index]), error->message); g_error_free (error); @@ -2128,10 +2139,10 @@ query_device_services_ready (MbimDevice *device, if (service == MBIM_SERVICE_MS_BASIC_CONNECT_EXTENSIONS) { for (j = 0; j < device_services[i]->cids_count; j++) { if (device_services[i]->cids[j] == MBIM_CID_MS_BASIC_CONNECT_EXTENSIONS_PCO) { - mm_dbg ("PCO is supported"); + mm_obj_dbg (self, "PCO is supported"); self->priv->is_pco_supported = TRUE; } else if (device_services[i]->cids[j] == MBIM_CID_MS_BASIC_CONNECT_EXTENSIONS_LTE_ATTACH_STATUS) { - mm_dbg ("LTE attach status is supported"); + mm_obj_dbg (self, "LTE attach status is supported"); self->priv->is_lte_attach_status_supported = TRUE; } } @@ -2141,7 +2152,7 @@ query_device_services_ready (MbimDevice *device, if (service == MBIM_SERVICE_USSD) { for (j = 0; j < device_services[i]->cids_count; j++) { if (device_services[i]->cids[j] == MBIM_CID_USSD) { - mm_dbg ("USSD is supported"); + mm_obj_dbg (self, "USSD is supported"); self->priv->is_ussd_supported = TRUE; break; } @@ -2152,10 +2163,10 @@ query_device_services_ready (MbimDevice *device, if (service == MBIM_SERVICE_ATDS) { for (j = 0; j < device_services[i]->cids_count; j++) { if (device_services[i]->cids[j] == MBIM_CID_ATDS_LOCATION) { - mm_dbg ("ATDS location is supported"); + mm_obj_dbg (self, "ATDS location is supported"); self->priv->is_atds_location_supported = TRUE; } else if (device_services[i]->cids[j] == MBIM_CID_ATDS_SIGNAL) { - mm_dbg ("ATDS signal is supported"); + mm_obj_dbg (self, "ATDS signal is supported"); self->priv->is_atds_signal_supported = TRUE; } } @@ -2165,7 +2176,7 @@ query_device_services_ready (MbimDevice *device, if (service == MBIM_SERVICE_INTEL_FIRMWARE_UPDATE) { for (j = 0; j < device_services[i]->cids_count; j++) { if (device_services[i]->cids[j] == MBIM_CID_INTEL_FIRMWARE_UPDATE_MODEM_REBOOT) { - mm_dbg ("Intel reset is supported"); + mm_obj_dbg (self, "Intel reset is supported"); self->priv->is_intel_reset_supported = TRUE; } } @@ -2177,7 +2188,7 @@ query_device_services_ready (MbimDevice *device, mbim_device_service_element_array_free (device_services); } else { /* Ignore error */ - mm_warn ("Couldn't query device services: %s", error->message); + mm_obj_warn (self, "couldn't query device services: %s", error->message); g_error_free (error); } @@ -2194,15 +2205,19 @@ query_device_services_ready (MbimDevice *device, static void query_device_services (GTask *task) { + MMBroadbandModem *self; InitializationStartedContext *ctx; MbimMessage *message; MbimDevice *device; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); + device = mm_port_mbim_peek_device (ctx->mbim); g_assert (device); - mm_dbg ("querying device services..."); + mm_obj_dbg (self, "querying device services..."); + message = mbim_message_device_services_query_new (NULL); mbim_device_command (device, message, @@ -2219,8 +2234,8 @@ mbim_device_removed_cb (MbimDevice *device, { /* We have to do a full re-probe here because simply reopening the device * and restarting mbim-proxy will leave us without MBIM notifications. */ - mm_info ("Connection to mbim-proxy for %s lost, reprobing", - mbim_device_get_path_display (device)); + mm_obj_info (self, "connection to mbim-proxy for %s lost, reprobing", + mbim_device_get_path_display (device)); g_signal_handler_disconnect (device, self->priv->mbim_device_removed_id); @@ -2764,6 +2779,7 @@ before_set_lte_attach_configuration_query_ready (MbimDevice *device, GAsyncResult *res, GTask *task) { + MMBroadbandModemMbim *self; MbimMessage *request; MbimMessage *response; GError *error = NULL; @@ -2772,6 +2788,7 @@ before_set_lte_attach_configuration_query_ready (MbimDevice *device, MbimLteAttachConfiguration **configurations = NULL; guint i; + self = g_task_get_source_object (task); config = g_task_get_task_data (task); response = mbim_device_command_finish (device, res, &error); @@ -2804,7 +2821,7 @@ before_set_lte_attach_configuration_query_ready (MbimDevice *device, configurations[i]->ip_type = mm_bearer_ip_family_to_mbim_context_ip_type (ip_family, &error); if (error) { configurations[i]->ip_type = MBIM_CONTEXT_IP_TYPE_DEFAULT; - mm_warn ("unexpected IP type settings requested: %s", error->message); + mm_obj_warn (self, "unexpected IP type settings requested: %s", error->message); g_clear_error (&error); } } @@ -2816,7 +2833,7 @@ before_set_lte_attach_configuration_query_ready (MbimDevice *device, configurations[i]->auth_protocol = mm_bearer_allowed_auth_to_mbim_auth_protocol (auth, &error); if (error) { configurations[i]->auth_protocol = MBIM_AUTH_PROTOCOL_NONE; - mm_warn ("unexpected auth settings requested: %s", error->message); + mm_obj_warn (self, "unexpected auth settings requested: %s", error->message); g_clear_error (&error); } } @@ -2918,7 +2935,7 @@ basic_connect_notification_signal_state (MMBroadbandModemMbim *self, /* Normalize the quality. 99 means unknown, we default it to 0 */ quality = MM_CLAMP_HIGH (rssi == 99 ? 0 : rssi, 31) * 100 / 31; - mm_dbg ("Signal state indication: %u --> %u%%", rssi, quality); + mm_obj_dbg (self, "signal state indication: %u --> %u%%", rssi, quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); } } @@ -3008,7 +3025,8 @@ basic_connect_notification_register_state (MMBroadbandModemMbim *self, } typedef struct { - guint32 session_id; + MMBroadbandModemMbim *self; + guint32 session_id; } ReportDisconnectedStatusContext; static void @@ -3019,7 +3037,7 @@ bearer_list_report_disconnected_status (MMBaseBearer *bearer, if (MM_IS_BEARER_MBIM (bearer) && mm_bearer_mbim_get_session_id (MM_BEARER_MBIM (bearer)) == ctx->session_id) { - mm_dbg ("Bearer '%s' was disconnected.", mm_base_bearer_get_path (bearer)); + mm_obj_dbg (ctx->self, "bearer '%s' was disconnected.", mm_base_bearer_get_path (bearer)); mm_base_bearer_report_connection_status (bearer, MM_BEARER_CONNECTION_STATUS_DISCONNECTED); } } @@ -3056,7 +3074,8 @@ basic_connect_notification_connect (MMBroadbandModemMbim *self, activation_state == MBIM_ACTIVATION_STATE_DEACTIVATED) { ReportDisconnectedStatusContext ctx; - mm_dbg ("Session ID '%u' was deactivated.", session_id); + mm_obj_dbg (self, "session ID '%u' was deactivated.", session_id); + ctx.self = self; ctx.session_id = session_id; mm_bearer_list_foreach (bearer_list, (MMBearerListForeachFunc)bearer_list_report_disconnected_status, @@ -3093,7 +3112,7 @@ basic_connect_notification_subscriber_ready_status (MMBroadbandModemMbim *self, (self->priv->last_ready_state == MBIM_SUBSCRIBER_READY_STATE_SIM_NOT_INSERTED && ready_state != MBIM_SUBSCRIBER_READY_STATE_SIM_NOT_INSERTED)) { /* SIM has been removed or reinserted, re-probe to ensure correct interfaces are exposed */ - mm_dbg ("SIM hot swap detected"); + mm_obj_dbg (self, "SIM hot swap detected"); mm_broadband_modem_update_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); } @@ -3121,8 +3140,8 @@ basic_connect_notification_packet_service (MMBroadbandModemMbim *self, } str = mbim_data_class_build_string_from_mask (highest_available_data_class); - mm_dbg ("Packet service state: '%s', data class: '%s'", - mbim_packet_service_state_get_string (packet_service_state), str); + mm_obj_dbg (self, "packet service state: '%s', data class: '%s'", + mbim_packet_service_state_get_string (packet_service_state), str); g_free (str); if (packet_service_state == MBIM_PACKET_SERVICE_STATE_ATTACHED) { @@ -3223,7 +3242,7 @@ alert_sms_read_query_ready (MbimDevice *device, } if (error) { - mm_dbg ("Flash message reading failed: %s", error->message); + mm_obj_dbg (self, "flash message reading failed: %s", error->message); g_error_free (error); } @@ -3248,7 +3267,7 @@ sms_notification_read_stored_sms (MMBroadbandModemMbim *self, if (!device) return; - mm_dbg ("Reading new SMS at index '%u'", index); + mm_obj_dbg (self, "reading new SMS at index '%u'", index); message = mbim_message_sms_read_query_new (MBIM_SMS_FORMAT_PDU, MBIM_SMS_FLAG_INDEX, index, @@ -3283,7 +3302,7 @@ sms_notification (MMBroadbandModemMbim *self, &flag, &index, NULL)) { - mm_dbg ("Received SMS store status update: '%s'", mbim_sms_status_flag_get_string (flag)); + mm_obj_dbg (self, "received SMS store status update: '%s'", mbim_sms_status_flag_get_string (flag)); if (flag == MBIM_SMS_STATUS_FLAG_NEW_MESSAGE) sms_notification_read_stored_sms (self, index); } @@ -3309,18 +3328,18 @@ ms_basic_connect_extensions_notification_pco (MMBroadbandModemMbim *self, notification, &pco_value, &error)) { - mm_warn ("Couldn't parse PCO notification: %s", error->message); + mm_obj_warn (self, "couldn't parse PCO notification: %s", error->message); g_error_free (error); return; } pco_data_hex = mm_utils_bin2hexstr (pco_value->pco_data_buffer, pco_value->pco_data_size); - mm_dbg ("Received PCO: session ID=%u type=%s size=%u data=%s", - pco_value->session_id, - mbim_pco_type_get_string (pco_value->pco_data_type), - pco_value->pco_data_size, - pco_data_hex); + mm_obj_dbg (self, "received PCO: session ID=%u type=%s size=%u data=%s", + pco_value->session_id, + mbim_pco_type_get_string (pco_value->pco_data_type), + pco_value->pco_data_size, + pco_data_hex); g_free (pco_data_hex); pco = mm_pco_new (); @@ -3350,7 +3369,7 @@ ms_basic_connect_extensions_notification_lte_attach_status (MMBroadbandModemMbim notification, &status, &error)) { - mm_warn ("Couldn't parse LTE attach status notification: %s", error->message); + mm_obj_warn (self, "couldn't parse LTE attach status notification: %s", error->message); g_error_free (error); return; } @@ -3390,7 +3409,7 @@ ussd_notification (MMBroadbandModemMbim *self, MbimMessage *notification) { if (mbim_message_indicate_status_get_cid (notification) != MBIM_CID_USSD) { - mm_warn ("unexpected USSD notification (cid %u)", mbim_message_indicate_status_get_cid (notification)); + mm_obj_warn (self, "unexpected USSD notification (cid %u)", mbim_message_indicate_status_get_cid (notification)); return; } @@ -3408,10 +3427,10 @@ device_notification_cb (MbimDevice *device, MbimService service; service = mbim_message_indicate_status_get_service (notification); - mm_dbg ("Received notification (service '%s', command '%s')", - mbim_service_get_string (service), - mbim_cid_get_printable (service, - mbim_message_indicate_status_get_cid (notification))); + mm_obj_dbg (self, "received notification (service '%s', command '%s')", + mbim_service_get_string (service), + mbim_cid_get_printable (service, + mbim_message_indicate_status_get_cid (notification))); switch (service) { case MBIM_SERVICE_BASIC_CONNECT: @@ -3451,16 +3470,16 @@ common_setup_cleanup_unsolicited_events_sync (MMBroadbandModemMbim *self, if (!device) return; - mm_dbg ("Supported notifications: signal (%s), registration (%s), sms (%s), connect (%s), subscriber (%s), packet (%s), pco (%s), ussd (%s), lte attach status (%s)", - self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_SIGNAL_QUALITY ? "yes" : "no", - self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_REGISTRATION_UPDATES ? "yes" : "no", - self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_SMS_READ ? "yes" : "no", - self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_CONNECT ? "yes" : "no", - self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_SUBSCRIBER_INFO ? "yes" : "no", - self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_PACKET_SERVICE ? "yes" : "no", - self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_PCO ? "yes" : "no", - self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_USSD ? "yes" : "no", - self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_LTE_ATTACH_STATUS ? "yes" : "no"); + mm_obj_dbg (self, "supported notifications: signal (%s), registration (%s), sms (%s), connect (%s), subscriber (%s), packet (%s), pco (%s), ussd (%s), lte attach status (%s)", + self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_SIGNAL_QUALITY ? "yes" : "no", + self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_REGISTRATION_UPDATES ? "yes" : "no", + self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_SMS_READ ? "yes" : "no", + self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_CONNECT ? "yes" : "no", + self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_SUBSCRIBER_INFO ? "yes" : "no", + self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_PACKET_SERVICE ? "yes" : "no", + self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_PCO ? "yes" : "no", + self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_USSD ? "yes" : "no", + self->priv->setup_flags & PROCESS_NOTIFICATION_FLAG_LTE_ATTACH_STATUS ? "yes" : "no"); if (setup) { /* Don't re-enable it if already there */ @@ -3632,16 +3651,16 @@ common_enable_disable_unsolicited_events (MMBroadbandModemMbim *self, if (!peek_device (self, &device, callback, user_data)) return; - mm_dbg ("Enabled notifications: signal (%s), registration (%s), sms (%s), connect (%s), subscriber (%s), packet (%s), pco (%s), ussd (%s), lte attach status (%s)", - self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_SIGNAL_QUALITY ? "yes" : "no", - self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_REGISTRATION_UPDATES ? "yes" : "no", - self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_SMS_READ ? "yes" : "no", - self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_CONNECT ? "yes" : "no", - self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_SUBSCRIBER_INFO ? "yes" : "no", - self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_PACKET_SERVICE ? "yes" : "no", - self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_PCO ? "yes" : "no", - self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_USSD ? "yes" : "no", - self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_LTE_ATTACH_STATUS ? "yes" : "no"); + mm_obj_dbg (self, "enabled notifications: signal (%s), registration (%s), sms (%s), connect (%s), subscriber (%s), packet (%s), pco (%s), ussd (%s), lte attach status (%s)", + self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_SIGNAL_QUALITY ? "yes" : "no", + self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_REGISTRATION_UPDATES ? "yes" : "no", + self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_SMS_READ ? "yes" : "no", + self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_CONNECT ? "yes" : "no", + self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_SUBSCRIBER_INFO ? "yes" : "no", + self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_PACKET_SERVICE ? "yes" : "no", + self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_PCO ? "yes" : "no", + self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_USSD ? "yes" : "no", + self->priv->enable_flags & PROCESS_NOTIFICATION_FLAG_LTE_ATTACH_STATUS ? "yes" : "no"); entries = g_new0 (MbimEventEntry *, 5); @@ -3778,7 +3797,7 @@ enable_subscriber_info_unsolicited_events_ready (MMBroadbandModemMbim *self, GError *error = NULL; if (!common_enable_disable_unsolicited_events_finish (self, res, &error)) { - mm_dbg ("Failed to enable subscriber info events: %s", error->message); + mm_obj_dbg (self, "failed to enable subscriber info events: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -3796,7 +3815,7 @@ setup_subscriber_info_unsolicited_events_ready (MMBroadbandModemMbim *self, GError *error = NULL; if (!common_setup_cleanup_unsolicited_events_finish (self, res, &error)) { - mm_dbg ("Failed to set up subscriber info events: %s", error->message); + mm_obj_dbg (self, "failed to set up subscriber info events: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -4248,7 +4267,7 @@ modem_3gpp_scan_networks (MMIfaceModem3gpp *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("scanning networks..."); + mm_obj_dbg (self, "scanning networks..."); message = mbim_message_visible_providers_query_new (MBIM_VISIBLE_PROVIDERS_ACTION_FULL_SCAN, NULL); mbim_device_command (device, message, @@ -4710,7 +4729,7 @@ process_ussd_message (MMBroadbandModemMbim *self, /* If no pending task, just report the error */ if (error) { - mm_dbg ("Network reported USSD message: %s", error->message); + mm_obj_dbg (self, "network reported USSD message: %s", error->message); g_error_free (error); } @@ -4734,11 +4753,11 @@ process_ussd_notification (MMBroadbandModemMbim *self, &data_size, &data, NULL)) { - mm_dbg ("Received USSD indication: %s, session state: %s, scheme: 0x%x, data size: %u bytes", - mbim_ussd_response_get_string (ussd_response), - mbim_ussd_session_state_get_string (ussd_session_state), - scheme, - data_size); + mm_obj_dbg (self, "received USSD indication: %s, session state: %s, scheme: 0x%x, data size: %u bytes", + mbim_ussd_response_get_string (ussd_response), + mbim_ussd_session_state_get_string (ussd_session_state), + scheme, + data_size); process_ussd_message (self, ussd_response, ussd_session_state, scheme, data_size, data); } } @@ -4874,11 +4893,11 @@ ussd_send_ready (MbimDevice *device, &data_size, &data, &error)) { - mm_dbg ("Received USSD response: %s, session state: %s, scheme: 0x%x, data size: %u bytes", - mbim_ussd_response_get_string (ussd_response), - mbim_ussd_session_state_get_string (ussd_session_state), - scheme, - data_size); + mm_obj_dbg (self, "received USSD response: %s, session state: %s, scheme: 0x%x, data size: %u bytes", + mbim_ussd_response_get_string (ussd_response), + mbim_ussd_session_state_get_string (ussd_session_state), + scheme, + data_size); process_ussd_message (self, ussd_response, ussd_session_state, scheme, data_size, data); } else { /* Report error in the cached task, if any */ @@ -4890,7 +4909,7 @@ ussd_send_ready (MbimDevice *device, g_task_return_error (task, error); g_object_unref (task); } else { - mm_dbg ("Failed to parse USSD response: %s", error->message); + mm_obj_dbg (self, "failed to parse USSD response: %s", error->message); g_clear_error (&error); } } @@ -5079,10 +5098,10 @@ messaging_check_support (MMIfaceModemMessaging *_self, /* We only handle 3GPP messaging (PDU based) currently */ if (self->priv->caps_sms & MBIM_SMS_CAPS_PDU_RECEIVE && self->priv->caps_sms & MBIM_SMS_CAPS_PDU_SEND) { - mm_dbg ("Messaging capabilities supported"); + mm_obj_dbg (self, "messaging capabilities supported"); g_task_return_boolean (task, TRUE); } else { - mm_dbg ("Messaging capabilities not supported by this modem"); + mm_obj_dbg (self, "messaging capabilities not supported by this modem"); g_task_return_boolean (task, FALSE); } g_object_unref (task); @@ -5144,16 +5163,16 @@ add_sms_part (MMBroadbandModemMbim *self, pdu->pdu_data_size, &error); if (part) { - mm_dbg ("Correctly parsed PDU (%d)", pdu->message_index); + mm_obj_dbg (self, "correctly parsed PDU (%d)", pdu->message_index); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), part, mm_sms_state_from_mbim_message_status (pdu->message_status), MM_SMS_STORAGE_MT); } else { /* Don't treat the error as critical */ - mm_dbg ("Error parsing PDU (%d): %s", - pdu->message_index, - error->message); + mm_obj_dbg (self, "error parsing PDU (%d): %s", + pdu->message_index, + error->message); g_error_free (error); } } @@ -5213,7 +5232,7 @@ load_initial_sms_parts (MMIfaceModemMessaging *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("loading SMS parts..."); + mm_obj_dbg (self, "loading SMS parts..."); message = mbim_message_sms_read_query_new (MBIM_SMS_FORMAT_PDU, MBIM_SMS_FLAG_ALL, 0, /* message index, unused */ From 6dff5ba673dfb838a290f3dc201a405017417a43 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 18:33:23 +0100 Subject: [PATCH 029/675] shared-qmi: port to use object logging --- src/mm-shared-qmi.c | 145 +++++++++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 62 deletions(-) diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 7c3575eb..13b873f2 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -25,7 +25,7 @@ #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-iface-modem.h" #include "mm-iface-modem-3gpp.h" #include "mm-iface-modem-location.h" @@ -795,11 +795,11 @@ load_current_capabilities_get_technology_preference_ready (QmiClientNas *client, output = qmi_client_nas_get_technology_preference_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: %s", error->message); + mm_obj_dbg (self, "QMI operation failed: %s", error->message); g_error_free (error); priv->feature_nas_technology_preference = FEATURE_UNSUPPORTED; } else if (!qmi_message_nas_get_technology_preference_output_get_result (output, &error)) { - mm_dbg ("Couldn't get technology preference: %s", error->message); + mm_obj_dbg (self, "couldn't get technology preference: %s", error->message); g_error_free (error); priv->feature_nas_technology_preference = FEATURE_SUPPORTED; } else { @@ -835,11 +835,11 @@ load_current_capabilities_get_system_selection_preference_ready (QmiClientNas *c output = qmi_client_nas_get_system_selection_preference_finish (client, res, &error); if (!output) { - mm_dbg ("QMI operation failed: %s", error->message); + mm_obj_dbg (self, "QMI operation failed: %s", error->message); g_error_free (error); priv->feature_nas_system_selection_preference = FEATURE_UNSUPPORTED; } else if (!qmi_message_nas_get_system_selection_preference_output_get_result (output, &error)) { - mm_dbg ("Couldn't get system selection preference: %s", error->message); + mm_obj_dbg (self, "couldn't get system selection preference: %s", error->message); g_error_free (error); priv->feature_nas_system_selection_preference = FEATURE_SUPPORTED; } else { @@ -1946,14 +1946,17 @@ reset_set_operating_mode_reset_ready (QmiClientDms *client, GAsyncResult *res, GTask *task) { + MMSharedQmi *self; QmiMessageDmsSetOperatingModeOutput *output; - GError *error = NULL; + GError *error = NULL; + + self = g_task_get_source_object (task); output = qmi_client_dms_set_operating_mode_finish (client, res, &error); if (!output || !qmi_message_dms_set_operating_mode_output_get_result (output, &error)) { g_task_return_error (task, error); } else { - mm_info ("Modem is being rebooted now"); + mm_obj_info (self, "rebooting now"); g_task_return_boolean (task, TRUE); } @@ -2093,7 +2096,7 @@ mm_shared_qmi_factory_reset (MMIfaceModem *self, return; } - mm_dbg ("performing a factory reset..."); + mm_obj_dbg (self, "performing a factory reset..."); qmi_client_dms_restore_factory_defaults (QMI_CLIENT_DMS (client), input, 10, @@ -2381,7 +2384,7 @@ find_requested_carrier_config (GTask *task) /* Match generic configuration */ config_fallback = g_key_file_get_string (ctx->keyfile, group, GENERIC_CONFIG_FALLBACK, NULL); - mm_dbg ("Fallback carrier configuration %sfound in group '%s'", config_fallback ? "" : "not ", group); + mm_obj_dbg (self, "fallback carrier configuration %sfound in group '%s'", config_fallback ? "" : "not ", group); /* First, try to match 6 MCCMNC digits (3-digit MNCs) */ strncpy (mccmnc, ctx->imsi, 6); @@ -2392,8 +2395,8 @@ find_requested_carrier_config (GTask *task) mccmnc[5] = '\0'; ctx->config_requested = g_key_file_get_string (ctx->keyfile, group, mccmnc, NULL); } - mm_dbg ("Requested carrier configuration %sfound for '%s' in group '%s': %s", - ctx->config_requested ? "" : "not ", mccmnc, group, ctx->config_requested ? ctx->config_requested : "n/a"); + mm_obj_dbg (self, "requested carrier configuration %sfound for '%s' in group '%s': %s", + ctx->config_requested ? "" : "not ", mccmnc, group, ctx->config_requested ? ctx->config_requested : "n/a"); if (!ctx->config_requested && !config_fallback) { setup_carrier_config_abort (task, g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_NOT_FOUND, @@ -2410,16 +2413,16 @@ find_requested_carrier_config (GTask *task) config = &g_array_index (priv->config_list, ConfigInfo, i); if (ctx->config_requested && !g_strcmp0 (ctx->config_requested, config->description)) { - mm_dbg ("Requested carrier configuration '%s' is available (version 0x%08x, size %u bytes)", - config->description, config->version, config->total_size); + mm_obj_dbg (self, "requested carrier configuration '%s' is available (version 0x%08x, size %u bytes)", + config->description, config->version, config->total_size); if (ctx->config_requested_i < 0) ctx->config_requested_i = i; else ctx->config_requested_i = select_newest_carrier_config (self, ctx->config_requested_i, i); } if (config_fallback && !g_strcmp0 (config_fallback, config->description)) { - mm_dbg ("Fallback carrier configuration '%s' is available (version 0x%08x, size %u bytes)", - config->description, config->version, config->total_size); + mm_obj_dbg (self, "fallback carrier configuration '%s' is available (version 0x%08x, size %u bytes)", + config->description, config->version, config->total_size); if (config_fallback_i < 0) config_fallback_i = i; else @@ -2444,8 +2447,8 @@ find_requested_carrier_config (GTask *task) g_assert (config_fallback_i >= 0); config = &g_array_index (priv->config_list, ConfigInfo, config_fallback_i); - mm_info ("Using fallback carrier configuration '%s' (version 0x%08x, size %u bytes)", - config->description, config->version, config->total_size); + mm_obj_info (self, "using fallback carrier configuration '%s' (version 0x%08x, size %u bytes)", + config->description, config->version, config->total_size); g_free (ctx->config_requested); ctx->config_requested = config_fallback; @@ -2455,8 +2458,8 @@ find_requested_carrier_config (GTask *task) ConfigInfo *config; config = &g_array_index (priv->config_list, ConfigInfo, ctx->config_requested_i); - mm_dbg ("Using requested carrier configuration '%s' (version 0x%08x, size %u bytes)", - config->description, config->version, config->total_size); + mm_obj_dbg (self, "using requested carrier configuration '%s' (version 0x%08x, size %u bytes)", + config->description, config->version, config->total_size); } ctx->step++; @@ -2470,11 +2473,13 @@ find_requested_carrier_config (GTask *task) static void setup_carrier_config_step (GTask *task) { + MMSharedQmi *self; SetupCarrierConfigContext *ctx; Private *priv; - ctx = g_task_get_task_data (task); - priv = get_private (g_task_get_source_object (task)); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + priv = get_private (self); switch (ctx->step) { case SETUP_CARRIER_CONFIG_STEP_FIRST: @@ -2489,7 +2494,7 @@ setup_carrier_config_step (GTask *task) g_assert (ctx->config_requested_i >= 0); g_assert (priv->config_active_i >= 0 || priv->config_active_default); if (ctx->config_requested_i == priv->config_active_i) { - mm_info ("Carrier config switching not needed: already using '%s'", ctx->config_requested); + mm_obj_info (self, "carrier config switching not needed: already using '%s'", ctx->config_requested); ctx->step = SETUP_CARRIER_CONFIG_STEP_LAST; setup_carrier_config_step (task); return; @@ -2506,8 +2511,8 @@ setup_carrier_config_step (GTask *task) requested_config = &g_array_index (priv->config_list, ConfigInfo, ctx->config_requested_i); active_config = (priv->config_active_default ? NULL : &g_array_index (priv->config_list, ConfigInfo, priv->config_active_i)); - mm_warn ("Carrier config switching needed: '%s' -> '%s'", - active_config ? active_config->description : DEFAULT_CONFIG_DESCRIPTION, requested_config->description); + mm_obj_warn (self, "carrier config switching needed: '%s' -> '%s'", + active_config ? active_config->description : DEFAULT_CONFIG_DESCRIPTION, requested_config->description); type_and_id.config_type = requested_config->config_type;; type_and_id.id = requested_config->id; @@ -2730,13 +2735,15 @@ get_selected_config_indication (QmiClientPdc *client, QmiIndicationPdcGetSelectedConfigOutput *output, GTask *task) { + MMSharedQmi *self; LoadCarrierConfigContext *ctx; GArray *active_id = NULL; GError *error = NULL; guint16 error_code = 0; guint i; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!qmi_indication_pdc_get_selected_config_output_get_indication_result (output, &error_code, &error)) { load_carrier_config_abort (task, error); @@ -2753,7 +2760,7 @@ get_selected_config_indication (QmiClientPdc *client, qmi_indication_pdc_get_selected_config_output_get_active_id (output, &active_id, NULL); if (!active_id) { - mm_dbg ("no carrier config currently selected (default in use)"); + mm_obj_dbg (self, "no carrier config currently selected (default in use)"); ctx->config_active_default = TRUE; goto next; } @@ -2889,13 +2896,15 @@ list_configs_indication (QmiClientPdc *client, QmiIndicationPdcListConfigsOutput *output, GTask *task) { + MMSharedQmi *self; LoadCarrierConfigContext *ctx; GError *error = NULL; GArray *configs = NULL; guint i; guint16 error_code = 0; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!qmi_indication_pdc_list_configs_output_get_indication_result (output, &error_code, &error)) { load_carrier_config_abort (task, error); @@ -2923,7 +2932,7 @@ list_configs_indication (QmiClientPdc *client, } /* Preallocate config list and request details for each */ - mm_dbg ("found %u carrier configurations...", configs->len); + mm_obj_dbg (self, "found %u carrier configurations...", configs->len); ctx->config_list = g_array_sized_new (FALSE, TRUE, sizeof (ConfigInfo), configs->len); g_array_set_size (ctx->config_list, configs->len); g_array_set_clear_func (ctx->config_list, (GDestroyNotify) config_info_clear); @@ -3828,15 +3837,15 @@ pds_location_event_report_indication_cb (QmiClientPds *clie output, &session_status, NULL)) { - mm_dbg ("[GPS] session status changed: '%s'", - qmi_pds_position_session_status_get_string (session_status)); + mm_obj_dbg (self, "[GPS] session status changed: '%s'", + qmi_pds_position_session_status_get_string (session_status)); } if (qmi_indication_pds_event_report_output_get_nmea_position ( output, &nmea, NULL)) { - mm_dbg ("[NMEA] %s", nmea); + mm_obj_dbg (self, "[NMEA] %s", nmea); mm_iface_modem_location_gps_update (MM_IFACE_MODEM_LOCATION (self), nmea); } } @@ -3852,7 +3861,7 @@ loc_location_nmea_indication_cb (QmiClientLoc *client, if (!nmea) return; - mm_dbg ("[NMEA] %s", nmea); + mm_obj_dbg (self, "[NMEA] %s", nmea); mm_iface_modem_location_gps_update (MM_IFACE_MODEM_LOCATION (self), nmea); } @@ -4182,11 +4191,13 @@ pds_set_default_tracking_session_ready (QmiClientPds *client, GAsyncResult *res, GTask *task) { + MMSharedQmi *self; SetGpsOperationModeContext *ctx; QmiMessagePdsSetDefaultTrackingSessionOutput *output; GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); output = qmi_client_pds_set_default_tracking_session_finish (client, res, &error); if (!output) { @@ -4208,13 +4219,13 @@ pds_set_default_tracking_session_ready (QmiClientPds *client, switch (ctx->mode) { case GPS_OPERATION_MODE_AGPS_MSA: - mm_dbg ("MSA A-GPS operation mode enabled"); + mm_obj_dbg (self, "MSA A-GPS operation mode enabled"); break; case GPS_OPERATION_MODE_AGPS_MSB: - mm_dbg ("MSB A-GPS operation mode enabled"); + mm_obj_dbg (self, "MSB A-GPS operation mode enabled"); break; case GPS_OPERATION_MODE_STANDALONE: - mm_dbg ("Standalone mode enabled (A-GPS disabled)"); + mm_obj_dbg (self, "standalone mode enabled (A-GPS disabled)"); break; case GPS_OPERATION_MODE_UNKNOWN: default: @@ -4229,6 +4240,7 @@ pds_get_default_tracking_session_ready (QmiClientPds *client, GAsyncResult *res, GTask *task) { + MMSharedQmi *self; SetGpsOperationModeContext *ctx; QmiMessagePdsSetDefaultTrackingSessionInput *input; QmiMessagePdsGetDefaultTrackingSessionOutput *output; @@ -4238,6 +4250,9 @@ pds_get_default_tracking_session_ready (QmiClientPds *client, guint32 interval; guint32 accuracy_threshold; + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + output = qmi_client_pds_get_default_tracking_session_finish (client, res, &error); if (!output) { g_prefix_error (&error, "QMI operation failed: "); @@ -4254,8 +4269,6 @@ pds_get_default_tracking_session_ready (QmiClientPds *client, return; } - ctx = g_task_get_task_data (task); - qmi_message_pds_get_default_tracking_session_output_get_info ( output, &session_operation, @@ -4268,30 +4281,30 @@ pds_get_default_tracking_session_ready (QmiClientPds *client, if (ctx->mode == GPS_OPERATION_MODE_AGPS_MSA) { if (session_operation == QMI_PDS_OPERATING_MODE_MS_ASSISTED) { - mm_dbg ("MSA A-GPS already enabled"); + mm_obj_dbg (self, "MSA A-GPS already enabled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } - mm_dbg ("Need to enable MSA A-GPS"); + mm_obj_dbg (self, "need to enable MSA A-GPS"); session_operation = QMI_PDS_OPERATING_MODE_MS_ASSISTED; } else if (ctx->mode == GPS_OPERATION_MODE_AGPS_MSB) { if (session_operation == QMI_PDS_OPERATING_MODE_MS_BASED) { - mm_dbg ("MSB A-GPS already enabled"); + mm_obj_dbg (self, "MSB A-GPS already enabled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } - mm_dbg ("Need to enable MSB A-GPS"); + mm_obj_dbg (self, "need to enable MSB A-GPS"); session_operation = QMI_PDS_OPERATING_MODE_MS_BASED; } else if (ctx->mode == GPS_OPERATION_MODE_STANDALONE) { if (session_operation == QMI_PDS_OPERATING_MODE_STANDALONE) { - mm_dbg ("A-GPS already disabled"); + mm_obj_dbg (self, "A-GPS already disabled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } - mm_dbg ("Need to disable A-GPS"); + mm_obj_dbg (self, "need to disable A-GPS"); session_operation = QMI_PDS_OPERATING_MODE_STANDALONE; } else g_assert_not_reached (); @@ -4333,11 +4346,13 @@ loc_location_set_operation_mode_indication_cb (QmiClientLoc QmiIndicationLocSetOperationModeOutput *output, GTask *task) { + MMSharedQmi *self; SetGpsOperationModeContext *ctx; QmiLocIndicationStatus status; GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!qmi_indication_loc_set_operation_mode_output_get_indication_status (output, &status, &error)) { g_prefix_error (&error, "QMI operation failed: "); @@ -4354,13 +4369,13 @@ loc_location_set_operation_mode_indication_cb (QmiClientLoc switch (ctx->mode) { case GPS_OPERATION_MODE_AGPS_MSA: - mm_dbg ("MSA A-GPS operation mode enabled"); + mm_obj_dbg (self, "MSA A-GPS operation mode enabled"); break; case GPS_OPERATION_MODE_AGPS_MSB: - mm_dbg ("MSB A-GPS operation mode enabled"); + mm_obj_dbg (self, "MSB A-GPS operation mode enabled"); break; case GPS_OPERATION_MODE_STANDALONE: - mm_dbg ("Standalone mode enabled (A-GPS disabled)"); + mm_obj_dbg (self, "standalone mode enabled (A-GPS disabled)"); break; case GPS_OPERATION_MODE_UNKNOWN: default: @@ -4414,13 +4429,15 @@ loc_location_get_operation_mode_indication_cb (QmiClientLoc QmiIndicationLocGetOperationModeOutput *output, GTask *task) { + MMSharedQmi *self; SetGpsOperationModeContext *ctx; QmiLocIndicationStatus status; GError *error = NULL; QmiLocOperationMode mode = QMI_LOC_OPERATION_MODE_DEFAULT; QmiMessageLocSetOperationModeInput *input; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!qmi_indication_loc_get_operation_mode_output_get_indication_status (output, &status, &error)) { g_prefix_error (&error, "QMI operation failed: "); @@ -4439,30 +4456,30 @@ loc_location_get_operation_mode_indication_cb (QmiClientLoc if (ctx->mode == GPS_OPERATION_MODE_AGPS_MSA) { if (mode == QMI_LOC_OPERATION_MODE_MSA) { - mm_dbg ("MSA A-GPS already enabled"); + mm_obj_dbg (self, "MSA A-GPS already enabled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } - mm_dbg ("Need to enable MSA A-GPS"); + mm_obj_dbg (self, "need to enable MSA A-GPS"); mode = QMI_LOC_OPERATION_MODE_MSA; } else if (ctx->mode == GPS_OPERATION_MODE_AGPS_MSB) { if (mode == QMI_LOC_OPERATION_MODE_MSB) { - mm_dbg ("MSB A-GPS already enabled"); + mm_obj_dbg (self, "MSB A-GPS already enabled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } - mm_dbg ("Need to enable MSB A-GPS"); + mm_obj_dbg (self, "need to enable MSB A-GPS"); mode = QMI_LOC_OPERATION_MODE_MSB; } else if (ctx->mode == GPS_OPERATION_MODE_STANDALONE) { if (mode == QMI_LOC_OPERATION_MODE_STANDALONE) { - mm_dbg ("A-GPS already disabled"); + mm_obj_dbg (self, "A-GPS already disabled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } - mm_dbg ("Need to disable A-GPS"); + mm_obj_dbg (self, "need to disable A-GPS"); mode = QMI_LOC_OPERATION_MODE_STANDALONE; } else g_assert_not_reached (); @@ -5254,13 +5271,15 @@ inject_xtra_data_ready (QmiClientLoc *client, static void inject_xtra_data_next (GTask *task) { + MMSharedQmi *self; QmiMessageLocInjectXtraDataInput *input; InjectAssistanceDataContext *ctx; goffset total_bytes_left; gsize count; GArray *data; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); g_assert (ctx->data_size >= ctx->i); total_bytes_left = ctx->data_size - ctx->i; @@ -5295,8 +5314,8 @@ inject_xtra_data_next (GTask *task) ctx->i += count; - mm_info ("injecting xtra data: %" G_GSIZE_FORMAT " bytes (%u/%u)", - count, (guint) ctx->n_part, (guint) ctx->total_parts); + mm_obj_info (self, "injecting xtra data: %" G_GSIZE_FORMAT " bytes (%u/%u)", + count, (guint) ctx->n_part, (guint) ctx->total_parts); qmi_client_loc_inject_xtra_data (ctx->client, input, 10, @@ -5401,13 +5420,15 @@ inject_predicted_orbits_data_ready (QmiClientLoc *client, static void inject_assistance_data_next (GTask *task) { + MMSharedQmi *self; QmiMessageLocInjectPredictedOrbitsDataInput *input; InjectAssistanceDataContext *ctx; goffset total_bytes_left; gsize count; GArray *data; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); g_assert (ctx->data_size >= ctx->i); total_bytes_left = ctx->data_size - ctx->i; @@ -5446,8 +5467,8 @@ inject_assistance_data_next (GTask *task) ctx->i += count; - mm_info ("injecting predicted orbits data: %" G_GSIZE_FORMAT " bytes (%u/%u)", - count, (guint) ctx->n_part, (guint) ctx->total_parts); + mm_obj_info (self, "injecting predicted orbits data: %" G_GSIZE_FORMAT " bytes (%u/%u)", + count, (guint) ctx->n_part, (guint) ctx->total_parts); qmi_client_loc_inject_predicted_orbits_data (ctx->client, input, 10, @@ -5498,7 +5519,7 @@ mm_shared_qmi_location_inject_assistance_data (MMIfaceModemLocation *self, ctx->total_parts++; g_assert (ctx->total_parts <= G_MAXUINT16); - mm_dbg ("Injecting gpsOneXTRA data (%" G_GOFFSET_FORMAT " bytes)...", ctx->data_size); + mm_obj_dbg (self, "injecting gpsOneXTRA data (%" G_GOFFSET_FORMAT " bytes)...", ctx->data_size); inject_assistance_data_next (task); } From aa5a77ce05cf7819482a02e1377e23166ab3ed3b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 18:46:42 +0100 Subject: [PATCH 030/675] iface-modem: port to use object logging --- src/mm-iface-modem.c | 188 ++++++++++++++++++++----------------------- 1 file changed, 88 insertions(+), 100 deletions(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index b2272cb9..a8577493 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -26,7 +26,7 @@ #include "mm-base-modem-at.h" #include "mm-base-sim.h" #include "mm-bearer-list.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-context.h" #define SIGNAL_QUALITY_RECENT_TIMEOUT_SEC 60 @@ -310,7 +310,7 @@ load_unlock_required_ready (MMIfaceModem *self, lock = MM_IFACE_MODEM_GET_INTERFACE (self)->load_unlock_required_finish (self, res, &error); if (error) { - mm_dbg ("Couldn't check if unlock required: '%s'", error->message); + mm_obj_dbg (self, "couldn't check if unlock required: %s", error->message); /* For several kinds of errors, just return them directly */ if (error->domain == MM_SERIAL_ERROR || @@ -334,7 +334,7 @@ load_unlock_required_ready (MMIfaceModem *self, /* For the remaining ones, retry if possible */ if (ctx->retries < MAX_RETRIES) { ctx->retries++; - mm_dbg ("Retrying (%u) unlock required check", ctx->retries); + mm_obj_dbg (self, "retrying (%u) unlock required check", ctx->retries); g_assert (ctx->pin_check_timeout_id == 0); ctx->pin_check_timeout_id = g_timeout_add_seconds (2, @@ -990,10 +990,9 @@ mm_iface_modem_update_access_technologies (MMIfaceModem *self, /* Log */ old_access_tech_string = mm_modem_access_technology_build_string_from_mask (old_access_tech); new_access_tech_string = mm_modem_access_technology_build_string_from_mask (built_access_tech); - mm_dbg ("Modem %s: access technology changed (%s -> %s)", - g_dbus_object_get_object_path (G_DBUS_OBJECT (self)), - old_access_tech_string, - new_access_tech_string); + mm_obj_dbg (self, "access technology changed (%s -> %s)", + old_access_tech_string, + new_access_tech_string); g_free (old_access_tech_string); g_free (new_access_tech_string); } @@ -1038,9 +1037,8 @@ expire_signal_quality (MMIfaceModem *self) /* If value is already not recent, we're done */ if (recent) { - mm_dbg ("Signal quality value not updated in %us, " - "marking as not being recent", - SIGNAL_QUALITY_RECENT_TIMEOUT_SEC); + mm_obj_dbg (self, "signal quality value not updated in %us, marking as not being recent", + SIGNAL_QUALITY_RECENT_TIMEOUT_SEC); mm_gdbus_modem_set_signal_quality (skeleton, g_variant_new ("(ub)", signal_quality, @@ -1063,7 +1061,6 @@ update_signal_quality (MMIfaceModem *self, { SignalQualityUpdateContext *ctx; MmGdbusModem *skeleton = NULL; - const gchar *dbus_path; g_object_get (self, MM_IFACE_MODEM_DBUS_SKELETON, &skeleton, @@ -1098,10 +1095,7 @@ update_signal_quality (MMIfaceModem *self, signal_quality, expire)); - dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self)); - mm_dbg ("Modem %s: signal quality updated (%u)", - dbus_path, - signal_quality); + mm_obj_dbg (self, "signal quality updated (%u)", signal_quality); /* Remove any previous expiration refresh timeout */ if (ctx->recent_timeout_source) { @@ -1233,12 +1227,12 @@ access_technologies_check_ready (MMIfaceModem *self, &error)) { /* Did the plugin report that polling access technology is unsupported? */ if (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED)) { - mm_dbg ("Polling to refresh access technologies is unsupported"); + mm_obj_dbg (self, "polling to refresh access technologies is unsupported"); ctx->access_technology_polling_supported = FALSE; } /* Ignore logging any message if the error is in 'in-progress' */ else if (!g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_IN_PROGRESS)) - mm_dbg ("Couldn't refresh access technologies: '%s'", error->message); + mm_obj_dbg (self, "couldn't refresh access technologies: %s", error->message); g_error_free (error); } /* We may have been disabled while this command was running. */ @@ -1263,12 +1257,12 @@ signal_quality_check_ready (MMIfaceModem *self, if (error) { /* Did the plugin report that polling signal quality is unsupported? */ if (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED)) { - mm_dbg ("Polling to refresh signal quality is unsupported"); + mm_obj_dbg (self, "polling to refresh signal quality is unsupported"); ctx->signal_quality_polling_supported = FALSE; } /* Ignore logging any message if the error is in 'in-progress' */ else if (!g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_IN_PROGRESS)) - mm_dbg ("Couldn't refresh signal quality: '%s'", error->message); + mm_obj_dbg (self, "couldn't refresh signal quality: %s", error->message); g_error_free (error); } /* We may have been disabled while this command was running. */ @@ -1322,7 +1316,7 @@ peridic_signal_check_step (MMIfaceModem *self) /* If we have been disabled while we were running the steps, we don't * do anything else. */ if (!ctx->enabled) { - mm_dbg ("Periodic signal quality and access technology checks not rescheduled: disabled"); + mm_obj_dbg (self, "periodic signal quality and access technology checks not rescheduled: disabled"); return; } @@ -1353,12 +1347,12 @@ peridic_signal_check_step (MMIfaceModem *self) if (ctx->initial_check_done && (!ctx->signal_quality_polling_supported || ctx->signal_quality_polling_disabled) && (!ctx->access_technology_polling_supported || ctx->access_technology_polling_disabled)) { - mm_dbg ("Periodic signal quality and access technology checks not rescheduled: unneeded or unsupported"); + mm_obj_dbg (self, "periodic signal quality and access technology checks not rescheduled: unneeded or unsupported"); periodic_signal_check_disable (self, FALSE); return; } - mm_dbg ("Periodic signal quality and access technology checks scheduled"); + mm_obj_dbg (self, "periodic signal quality and access technology checks scheduled"); g_assert (!ctx->timeout_source); ctx->timeout_source = g_timeout_add_seconds (ctx->initial_check_done ? SIGNAL_CHECK_TIMEOUT_SEC : SIGNAL_CHECK_INITIAL_TIMEOUT_SEC, (GSourceFunc) periodic_signal_check_cb, @@ -1399,17 +1393,17 @@ mm_iface_modem_refresh_signal (MMIfaceModem *self) /* Don't refresh polling if we're not enabled */ ctx = get_signal_check_context (self); if (!ctx->enabled) { - mm_dbg ("Periodic signal check refresh ignored: checks not enabled"); + mm_obj_dbg (self, "periodic signal check refresh ignored: checks not enabled"); return; } /* Don't refresh if we're already doing it */ if (ctx->running_step != SIGNAL_CHECK_STEP_NONE) { - mm_dbg ("Periodic signal check refresh ignored: check already running"); + mm_obj_dbg (self, "periodic signal check refresh ignored: check already running"); return; } - mm_dbg ("Periodic signal check refresh requested"); + mm_obj_dbg (self, "periodic signal check refresh requested"); /* Remove the scheduled timeout as we're going to refresh * right away */ @@ -1452,7 +1446,7 @@ periodic_signal_check_disable (MMIfaceModem *self, } ctx->enabled = FALSE; - mm_dbg ("Periodic signal checks disabled"); + mm_obj_dbg (self, "periodic signal checks disabled"); } static void @@ -1465,13 +1459,13 @@ periodic_signal_check_enable (MMIfaceModem *self) /* If polling access technology and signal quality not supported, don't even * bother trying. */ if (!ctx->signal_quality_polling_supported && !ctx->access_technology_polling_supported) { - mm_dbg ("Not enabling periodic signal checks: unsupported"); + mm_obj_dbg (self, "not enabling periodic signal checks: unsupported"); return; } /* Log and flag as enabled */ if (!ctx->enabled) { - mm_dbg ("Periodic signal checks enabled"); + mm_obj_dbg (self, "periodic signal checks enabled"); ctx->enabled = TRUE; } @@ -1535,14 +1529,9 @@ __iface_modem_update_state_internal (MMIfaceModem *self, /* Update state only if different */ if (new_state != old_state) { - const gchar *dbus_path; - - dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self)); - mm_info ("Modem%s%s: state changed (%s -> %s)", - dbus_path ? " " : "", - dbus_path ? dbus_path : "", - mm_modem_state_get_string (old_state), - mm_modem_state_get_string (new_state)); + mm_obj_info (self, "state changed (%s -> %s)", + mm_modem_state_get_string (old_state), + mm_modem_state_get_string (new_state)); /* The property in the interface is bound to the property * in the skeleton, so just updating here is enough */ @@ -1707,8 +1696,7 @@ get_updated_consolidated_state (MMIfaceModem *self, if (i == subsystem_states->len) { SubsystemState s; - mm_dbg ("Will start keeping track of state for subsystem '%s'", - subsystem); + mm_obj_dbg (self, "will start keeping track of state for subsystem '%s'", subsystem); s.subsystem = g_strdup (subsystem); s.state = subsystem_state; g_array_append_val (subsystem_states, s); @@ -2233,7 +2221,7 @@ handle_set_current_capabilities_auth_ready (MMBaseModem *self, } capabilities_string = mm_modem_capability_build_string_from_mask (ctx->capabilities); - mm_dbg ("Setting new list of capabilities: '%s'", capabilities_string); + mm_obj_dbg (self, "setting new list of capabilities: %s", capabilities_string); g_free (capabilities_string); MM_IFACE_MODEM_GET_INTERFACE (self)->set_current_capabilities ( @@ -2337,14 +2325,14 @@ after_set_load_current_bands_ready (MMIfaceModem *self, if (!current_bands) { /* If we can retry, do it */ if (ctx->retries > 0) { - mm_dbg ("couldn't load current bands: '%s' (will retry)", error->message); + mm_obj_dbg (self, "couldn't load current bands: %s (will retry)", error->message); g_clear_error (&error); set_current_bands_reload_schedule (task); goto out; } /* Errors when reloading bands won't be critical */ - mm_warn ("couldn't load current bands: '%s'", error->message); + mm_obj_warn (self, "couldn't load current bands: %s", error->message); g_clear_error (&error); set_current_bands_complete_with_defaults (task); goto out; @@ -2362,7 +2350,7 @@ after_set_load_current_bands_ready (MMIfaceModem *self, /* If we can retry, do it */ if (ctx->retries > 0) { - mm_dbg ("reloaded current bands different to the requested ones (will retry)"); + mm_obj_dbg (self, "reloaded current bands different to the requested ones (will retry)"); set_current_bands_reload_schedule (task); goto out; } @@ -2580,8 +2568,7 @@ mm_iface_modem_set_current_bands (MMIfaceModem *self, current_bands_array = (mm_common_bands_variant_to_garray ( mm_gdbus_modem_get_current_bands (ctx->skeleton))); if (mm_common_bands_garray_cmp (ctx->bands_array, current_bands_array)) { - mm_dbg ("Requested list of bands (%s) is equal to the current ones, skipping re-set", - bands_string); + mm_obj_dbg (self, "requested list of bands (%s) is equal to the current ones, skipping re-set", bands_string); g_free (bands_string); g_array_unref (current_bands_array); g_task_return_boolean (task, TRUE); @@ -2600,8 +2587,7 @@ mm_iface_modem_set_current_bands (MMIfaceModem *self, if (!validate_bands (ctx->supported_bands_array, ctx->bands_array, &error)) { - mm_dbg ("Requested list of bands (%s) cannot be handled", - bands_string); + mm_obj_dbg (self, "requested list of bands (%s) cannot be handled", bands_string); g_free (bands_string); g_array_unref (current_bands_array); g_task_return_error (task, error); @@ -2609,7 +2595,7 @@ mm_iface_modem_set_current_bands (MMIfaceModem *self, return; } - mm_dbg ("Setting new list of bands: '%s'", bands_string); + mm_obj_dbg (self, "setting new list of bands: %s", bands_string); MM_IFACE_MODEM_GET_INTERFACE (self)->set_current_bands ( self, ctx->bands_array, @@ -2754,14 +2740,14 @@ after_set_load_current_modes_ready (MMIfaceModem *self, &error)) { /* If we can retry, do it */ if (ctx->retries > 0) { - mm_dbg ("couldn't load current allowed/preferred modes: '%s'", error->message); + mm_obj_dbg (self, "couldn't load current allowed/preferred modes: %s", error->message); g_error_free (error); set_current_modes_reload_schedule (task); return; } /* Errors when getting allowed/preferred won't be critical */ - mm_warn ("couldn't load current allowed/preferred modes: '%s'", error->message); + mm_obj_warn (self, "couldn't load current allowed/preferred modes: %s", error->message); g_clear_error (&error); /* If errors getting allowed modes, default to the ones we asked for */ @@ -2782,7 +2768,7 @@ after_set_load_current_modes_ready (MMIfaceModem *self, /* If we can retry, do it */ if (ctx->retries > 0) { - mm_dbg ("reloaded current modes different to the requested ones (will retry)"); + mm_obj_dbg (self, "reloaded current modes different to the requested ones (will retry)"); set_current_modes_reload_schedule (task); return; } @@ -3103,7 +3089,7 @@ reinitialize_ready (MMBaseModem *self, mm_base_modem_initialize_finish (self, res, &error); if (error) { - mm_warn ("Modem reinitialization failed: '%s'", error->message); + mm_obj_warn (self, "reinitialization failed: %s", error->message); g_error_free (error); } } @@ -3294,7 +3280,7 @@ load_unlock_retries_ready (MMIfaceModem *self, unlock_retries = MM_IFACE_MODEM_GET_INTERFACE (self)->load_unlock_retries_finish (self, res, &error); if (!unlock_retries) { - mm_warn ("Couldn't load unlock retries: '%s'", error->message); + mm_obj_warn (self, "couldn't load unlock retries: %s", error->message); g_error_free (error); } else { /* Update the dictionary in the DBus interface */ @@ -3317,7 +3303,7 @@ modem_after_sim_unlock_ready (MMIfaceModem *self, GError *error = NULL; if (!MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_sim_unlock_finish (self, res, &error)) { - mm_warn ("After SIM unlock failed setup: '%s'", error->message); + mm_obj_warn (self, "after SIM unlock failed: %s", error->message); g_error_free (error); } @@ -3370,11 +3356,11 @@ internal_load_unlock_required_ready (MMIfaceModem *self, } /* For mixed 3GPP+3GPP2 devices, skip SIM errors */ - mm_dbg ("Skipping SIM error in 3GPP2-capable device, assuming no lock is needed"); + mm_obj_dbg (self, "skipping SIM error in 3GPP2-capable device, assuming no lock is needed"); g_error_free (error); ctx->lock = MM_MODEM_LOCK_NONE; } else { - mm_dbg ("Couldn't check if unlock required: '%s'", error->message); + mm_obj_dbg (self, "couldn't check if unlock required: %s", error->message); g_error_free (error); ctx->lock = MM_MODEM_LOCK_UNKNOWN; } @@ -3431,7 +3417,7 @@ update_lock_info_context_step (GTask *task) ctx->lock == MM_MODEM_LOCK_SIM_PUK2)) { if (MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_sim_unlock != NULL && MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_sim_unlock_finish != NULL) { - mm_dbg ("SIM is ready, running after SIM unlock step..."); + mm_obj_dbg (self, "SIM is ready, running after SIM unlock step..."); MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_sim_unlock ( self, (GAsyncReadyCallback)modem_after_sim_unlock_ready, @@ -3440,7 +3426,7 @@ update_lock_info_context_step (GTask *task) } /* If no way to run after SIM unlock step, we're done */ - mm_dbg ("SIM is ready, and no need for the after SIM unlock step..."); + mm_obj_dbg (self, "SIM is ready, and no need for the after SIM unlock step..."); } ctx->step++; /* fall-through */ @@ -3561,7 +3547,7 @@ modem_power_up_ready (MMIfaceModem *self, return; } - mm_dbg ("Modem set in full-power mode..."); + mm_obj_dbg (self, "set in full-power mode..."); mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->power_state); /* If we have something to do just after power-up, do it */ @@ -3596,7 +3582,7 @@ modem_power_down_ready (MMIfaceModem *self, mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->previous_real_power_state); g_task_return_error (task, error); } else { - mm_dbg ("Modem set in low-power mode..."); + mm_obj_dbg (self, "set in low-power mode..."); mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->power_state); g_task_return_boolean (task, TRUE); } @@ -3621,7 +3607,7 @@ modem_power_off_ready (MMIfaceModem *self, mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->previous_real_power_state); g_task_return_error (task, error); } else { - mm_info ("Modem powered off... may no longer be accessible"); + mm_obj_info (self, "powered off... may no longer be accessible"); mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->power_state); g_task_return_boolean (task, TRUE); } @@ -3640,8 +3626,8 @@ set_power_state (GTask *task) /* Already done if we're in the desired power state */ if (ctx->previous_real_power_state == ctx->power_state) { - mm_dbg ("No need to change power state: already in '%s' power state", - mm_modem_power_state_get_string (ctx->power_state)); + mm_obj_dbg (self, "no need to change power state: already in '%s' power state", + mm_modem_power_state_get_string (ctx->power_state)); /* If the real and cached ones are different, set the real one */ if (ctx->previous_cached_power_state != ctx->previous_real_power_state) mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->previous_real_power_state); @@ -3725,7 +3711,7 @@ set_power_state_load_ready (MMIfaceModem *self, ctx->previous_real_power_state = MM_IFACE_MODEM_GET_INTERFACE (self)->load_power_state_finish (self, res, &error); if (error) { - mm_dbg ("Couldn't reload current power state: %s", error->message); + mm_obj_dbg (self, "couldn't reload current power state: %s", error->message); g_error_free (error); /* Default to the cached one */ ctx->previous_real_power_state = ctx->previous_cached_power_state; @@ -3875,7 +3861,7 @@ check_for_sim_swap_ready (MMIfaceModem *self, GError *error = NULL; if (!MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish (self, res, &error)) { - mm_warn ("Error checking if SIM was swapped: '%s'", error->message); + mm_obj_warn (self, "failed to check if SIM was swapped: %s", error->message); g_error_free (error); } @@ -3919,7 +3905,7 @@ load_supported_charsets_ready (MMIfaceModem *self, ctx->supported_charsets = MM_IFACE_MODEM_GET_INTERFACE (self)->load_supported_charsets_finish (self, res, &error); if (error) { - mm_warn ("couldn't load Supported Charsets: '%s'", error->message); + mm_obj_warn (self, "couldn't load supported charsets: %s", error->message); g_error_free (error); } @@ -3939,9 +3925,9 @@ setup_charset_ready (MMIfaceModem *self, ctx = g_task_get_task_data (task); if (!MM_IFACE_MODEM_GET_INTERFACE (self)->setup_charset_finish (self, res, &error)) { - mm_dbg ("couldn't set charset '%s': '%s'", - mm_modem_charset_to_string (*ctx->current_charset), - error->message); + mm_obj_dbg (self, "couldn't set charset '%s': %s", + mm_modem_charset_to_string (*ctx->current_charset), + error->message); g_error_free (error); /* Will retry step with some other charset type */ @@ -4172,7 +4158,7 @@ initialization_context_free (InitializationContext *ctx) g_free (val); \ \ if (error) { \ - mm_warn ("couldn't load %s: '%s'", DISPLAY, error->message); \ + mm_obj_warn (self, "couldn't load %s: %s", DISPLAY, error->message); \ g_error_free (error); \ } \ \ @@ -4198,7 +4184,7 @@ initialization_context_free (InitializationContext *ctx) MM_IFACE_MODEM_GET_INTERFACE (self)->load_##NAME##_finish (self, res, &error)); \ \ if (error) { \ - mm_warn ("couldn't load %s: '%s'", DISPLAY, error->message); \ + mm_obj_warn (self, "couldn't load %s: %s", DISPLAY, error->message); \ g_error_free (error); \ } \ \ @@ -4232,7 +4218,7 @@ current_capabilities_internal_load_unlock_required_ready (MMIfaceModem *self, MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG)) { MMModemCapability caps; - mm_dbg ("Multimode device without SIM, no 3GPP capabilities"); + mm_obj_dbg (self, "multimode device without SIM, no 3GPP capabilities"); caps = mm_gdbus_modem_get_current_capabilities (ctx->skeleton); caps &= ~MM_MODEM_CAPABILITY_GSM_UMTS; caps &= ~MM_MODEM_CAPABILITY_LTE; @@ -4273,7 +4259,7 @@ load_current_capabilities_ready (MMIfaceModem *self, /* If LTE capability is reported, enable EPS network registration checks */ if (caps & MM_MODEM_CAPABILITY_LTE) { - mm_dbg ("Setting EPS network as supported"); + mm_obj_dbg (self, "setting EPS network as supported"); g_object_set (G_OBJECT (self), MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED, TRUE, NULL); @@ -4281,7 +4267,7 @@ load_current_capabilities_ready (MMIfaceModem *self, /* If LTE capability is the only one reported, disable all other network registration checks */ if (caps == MM_MODEM_CAPABILITY_LTE) { - mm_dbg ("Setting CS/PS/CDMA1x/EVDO networks as unsupported"); + mm_obj_dbg (self, "setting CS/PS/CDMA1x/EVDO networks as unsupported"); g_object_set (G_OBJECT (self), MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED, FALSE, MM_IFACE_MODEM_3GPP_PS_NETWORK_SUPPORTED, FALSE, @@ -4299,7 +4285,7 @@ load_current_capabilities_ready (MMIfaceModem *self, * SIM or not. */ if (caps & MM_MODEM_CAPABILITY_CDMA_EVDO && (caps & MM_MODEM_CAPABILITY_GSM_UMTS || caps & MM_MODEM_CAPABILITY_LTE)) { - mm_dbg ("Checking if multimode device has a SIM..."); + mm_obj_dbg (self, "checking if multimode device has a SIM..."); internal_load_unlock_required ( self, (GAsyncReadyCallback)current_capabilities_internal_load_unlock_required_ready, @@ -4341,12 +4327,12 @@ load_supported_capabilities_ready (MMIfaceModem *self, interface_initialization_step (task); } -STR_REPLY_READY_FN (manufacturer, "Manufacturer") -STR_REPLY_READY_FN (model, "Model") -STR_REPLY_READY_FN (revision, "Revision") -STR_REPLY_READY_FN (hardware_revision, "HardwareRevision") -STR_REPLY_READY_FN (equipment_identifier, "Equipment Identifier") -STR_REPLY_READY_FN (device_identifier, "Device Identifier") +STR_REPLY_READY_FN (manufacturer, "manufacturer") +STR_REPLY_READY_FN (model, "model") +STR_REPLY_READY_FN (revision, "revision") +STR_REPLY_READY_FN (hardware_revision, "hardware revision") +STR_REPLY_READY_FN (equipment_identifier, "equipment identifier") +STR_REPLY_READY_FN (device_identifier, "device identifier") static void load_supported_modes_ready (MMIfaceModem *self, @@ -4367,7 +4353,7 @@ load_supported_modes_ready (MMIfaceModem *self, } if (error) { - mm_warn ("couldn't load Supported Modes: '%s'", error->message); + mm_obj_warn (self, "couldn't load supported modes: %s", error->message); g_error_free (error); } @@ -4396,7 +4382,7 @@ load_supported_bands_ready (MMIfaceModem *self, } if (error) { - mm_warn ("couldn't load Supported Bands: '%s'", error->message); + mm_obj_warn (self, "couldn't load supported bands: %s", error->message); g_error_free (error); } @@ -4422,7 +4408,7 @@ load_supported_ip_families_ready (MMIfaceModem *self, mm_gdbus_modem_set_supported_ip_families (ctx->skeleton, ip_families); if (error) { - mm_warn ("couldn't load Supported IP families: '%s'", error->message); + mm_obj_warn (self, "couldn't load supported IP families: %s", error->message); g_error_free (error); } @@ -4431,7 +4417,7 @@ load_supported_ip_families_ready (MMIfaceModem *self, interface_initialization_step (task); } -UINT_REPLY_READY_FN (power_state, "Power State") +UINT_REPLY_READY_FN (power_state, "power state") static void modem_update_lock_info_ready (MMIfaceModem *self, @@ -4471,7 +4457,7 @@ sim_new_ready (GAsyncInitable *initable, sim = MM_IFACE_MODEM_GET_INTERFACE (self)->create_sim_finish (self, res, &error); if (error) { - mm_warn ("couldn't create SIM: '%s'", error->message); + mm_obj_warn (self, "couldn't create SIM: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -4500,14 +4486,16 @@ sim_reinit_ready (MMBaseSim *sim, GAsyncResult *res, GTask *task) { + MMIfaceModem *self; InitializationContext *ctx; - GError *error = NULL; + GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); if (!mm_base_sim_initialize_finish (sim, res, &error)) { - mm_warn ("SIM re-initialization failed: '%s'", - error ? error->message : "Unknown error"); + mm_obj_warn (self, "SIM re-initialization failed: %s", + error ? error->message : "Unknown error"); g_clear_error (&error); } @@ -4527,7 +4515,7 @@ setup_carrier_config_ready (MMIfaceModem *self, ctx = g_task_get_task_data (task); if (!MM_IFACE_MODEM_GET_INTERFACE (self)->setup_carrier_config_finish (self, res, &error)) { - mm_warn ("couldn't setup carrier config: '%s'", error->message); + mm_obj_warn (self, "couldn't setup carrier config: %s", error->message); g_error_free (error); } @@ -4549,7 +4537,7 @@ load_carrier_config_ready (MMIfaceModem *self, ctx = g_task_get_task_data (task); if (!MM_IFACE_MODEM_GET_INTERFACE (self)->load_carrier_config_finish (self, res, &name, &revision, &error)) { - mm_warn ("couldn't load carrier config: '%s'", error->message); + mm_obj_warn (self, "couldn't load carrier config: %s", error->message); g_error_free (error); } else { mm_gdbus_modem_set_carrier_configuration (ctx->skeleton, name); @@ -4591,7 +4579,7 @@ load_own_numbers_ready (MMIfaceModem *self, str_list = MM_IFACE_MODEM_GET_INTERFACE (self)->load_own_numbers_finish (self, res, &error); if (error) { - mm_warn ("couldn't load list of Own Numbers: '%s'", error->message); + mm_obj_warn (self, "couldn't load list of own numbers: %s", error->message); g_error_free (error); } @@ -4623,7 +4611,7 @@ load_current_modes_ready (MMIfaceModem *self, &preferred, &error)) { /* Errors when getting allowed/preferred won't be critical */ - mm_warn ("couldn't load current allowed/preferred modes: '%s'", error->message); + mm_obj_warn (self, "couldn't load current allowed/preferred modes: %s", error->message); g_error_free (error); } else mm_gdbus_modem_set_current_modes (ctx->skeleton, g_variant_new ("(uu)", allowed, preferred)); @@ -4647,7 +4635,7 @@ load_current_bands_ready (MMIfaceModem *self, current_bands = MM_IFACE_MODEM_GET_INTERFACE (self)->load_current_bands_finish (self, res, &error); if (!current_bands) { /* Errors when getting current bands won't be critical */ - mm_warn ("couldn't load current Bands: '%s'", error->message); + mm_obj_warn (self, "couldn't load current bands: %s", error->message); g_error_free (error); } else { GArray *filtered_bands; @@ -4688,10 +4676,10 @@ setup_sim_hot_swap_ready (MMIfaceModem *self, MM_IFACE_MODEM_GET_INTERFACE (self)->setup_sim_hot_swap_finish (self, res, &error); if (error) { - mm_warn ("Iface modem: SIM hot swap setup failed: '%s'", error->message); + mm_obj_warn (self, "SIM hot swap setup failed: %s", error->message); g_error_free (error); } else { - mm_dbg ("Iface modem: SIM hot swap setup succeeded"); + mm_obj_dbg (self, "SIM hot swap setup succeeded"); g_object_set (self, MM_IFACE_MODEM_SIM_HOT_SWAP_CONFIGURED, TRUE, NULL); @@ -4853,7 +4841,7 @@ interface_initialization_step (GTask *task) /* The maximum number of available/connected modems is guessed from * the size of the data ports list. */ n = g_list_length (mm_base_modem_peek_data_ports (MM_BASE_MODEM (self))); - mm_dbg ("Modem allows up to %u bearers", n); + mm_obj_dbg (self, "allowed up to %u bearers", n); /* Create new default list */ list = mm_bearer_list_new (n, n); @@ -5158,9 +5146,9 @@ interface_initialization_step (GTask *task) /* If we have a SIM object, and carrier config switching is supported, * validate whether we're already using the best config or not. */ if (!sim) - mm_dbg ("not setting up carrier config: SIM not found"); + mm_obj_dbg (self, "not setting up carrier config: SIM not found"); else if (!carrier_config_mapping) - mm_dbg ("not setting up carrier config: mapping file not configured"); + mm_obj_dbg (self, "not setting up carrier config: mapping file not configured"); else { const gchar *imsi; @@ -5175,7 +5163,7 @@ interface_initialization_step (GTask *task) g_free (carrier_config_mapping); return; } - mm_warn ("couldn't setup carrier config: unknown IMSI"); + mm_obj_warn (self, "couldn't setup carrier config: unknown IMSI"); } g_clear_object (&sim); g_free (carrier_config_mapping); From 89a0adb962d4852324e297ce5b24a37aefdc5842 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 16:21:42 +0200 Subject: [PATCH 031/675] iface-modem-3gpp: port to use object logging --- src/mm-iface-modem-3gpp.c | 105 ++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 55 deletions(-) diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index 3e04f957..fc8cdc79 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -199,8 +199,8 @@ get_consolidated_reg_state (MMIfaceModem3gpp *self) priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_SMS_ONLY || priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_HOME_CSFB_NOT_PREFERRED || priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_CSFB_NOT_PREFERRED) { - mm_warn ("3GPP CSFB registration state is consolidated: %s", - mm_modem_3gpp_registration_state_get_string (priv->cs)); + mm_obj_warn (self, "3GPP CSFB registration state is consolidated: %s", + mm_modem_3gpp_registration_state_get_string (priv->cs)); consolidated = priv->cs; goto out; } @@ -214,11 +214,11 @@ get_consolidated_reg_state (MMIfaceModem3gpp *self) } out: - mm_dbg ("building consolidated registration state: cs '%s', ps '%s', eps '%s' --> '%s'", - mm_modem_3gpp_registration_state_get_string (priv->cs), - mm_modem_3gpp_registration_state_get_string (priv->ps), - mm_modem_3gpp_registration_state_get_string (priv->eps), - mm_modem_3gpp_registration_state_get_string (consolidated)); + mm_obj_dbg (self, "building consolidated registration state: cs '%s', ps '%s', eps '%s' --> '%s'", + mm_modem_3gpp_registration_state_get_string (priv->cs), + mm_modem_3gpp_registration_state_get_string (priv->ps), + mm_modem_3gpp_registration_state_get_string (priv->eps), + mm_modem_3gpp_registration_state_get_string (consolidated)); return consolidated; } @@ -298,7 +298,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self, mm_iface_modem_3gpp_run_registration_checks_finish (MM_IFACE_MODEM_3GPP (self), res, &error); if (error) { - mm_dbg ("3GPP registration check failed: '%s'", error->message); + mm_obj_dbg (self, "3GPP registration check failed: %s", error->message); register_in_network_context_complete_failed (task, error); return; } @@ -308,7 +308,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self, /* If we got a final state and it's denied, we can assume the registration is * finished */ if (current_registration_state == MM_MODEM_3GPP_REGISTRATION_STATE_DENIED) { - mm_dbg ("Registration denied"); + mm_obj_dbg (self, "registration denied"); register_in_network_context_complete_failed ( task, mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_NOT_ALLOWED)); @@ -322,7 +322,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self, * wouldn't be an explicit refresh triggered from the modem interface as * the modem never got un-registered during the sequence. */ mm_iface_modem_refresh_signal (MM_IFACE_MODEM (ctx->self)); - mm_dbg ("Modem is currently registered in a 3GPP network"); + mm_obj_dbg (self, "currently registered in a 3GPP network"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -330,7 +330,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self, /* Don't spend too much time waiting to get registered */ if (g_timer_elapsed (ctx->timer, NULL) > ctx->max_registration_time) { - mm_dbg ("3GPP registration check timed out"); + mm_obj_dbg (self, "3GPP registration check timed out"); register_in_network_context_complete_failed ( task, mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT)); @@ -343,7 +343,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self, * This 3s timeout will catch results from automatic registrations as * well. */ - mm_dbg ("Modem not yet registered in a 3GPP network... will recheck soon"); + mm_obj_dbg (self, "not yet registered in a 3GPP network... will recheck soon"); g_timeout_add_seconds (3, (GSourceFunc)run_registration_checks, task); } @@ -441,16 +441,15 @@ mm_iface_modem_3gpp_register_in_network (MMIfaceModem3gpp *self, (g_strcmp0 (current_operator_code, ctx->operator_id) == 0) && REG_STATE_IS_REGISTERED (reg_state) && priv->manual_registration) { - mm_dbg ("Already registered manually in selected network '%s'," - " manual registration not launched...", - current_operator_code); + mm_obj_dbg (self, "already registered manually in selected network '%s', manual registration not launched...", + current_operator_code); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } /* Manual registration to a new operator required */ - mm_dbg ("Launching manual network registration (%s)...", ctx->operator_id); + mm_obj_dbg (self, "launching manual network registration (%s)...", ctx->operator_id); g_free (priv->manual_registration_operator_id); priv->manual_registration_operator_id = g_strdup (ctx->operator_id); priv->manual_registration = TRUE; @@ -462,16 +461,16 @@ mm_iface_modem_3gpp_register_in_network (MMIfaceModem3gpp *self, if (!force_registration && (current_operator_code || REG_STATE_IS_REGISTERED (reg_state)) && !priv->manual_registration) { - mm_dbg ("Already registered automatically in network '%s'," - " automatic registration not launched...", - current_operator_code); + mm_obj_dbg (self, "already registered automatically in network '%s'," + " automatic registration not launched...", + current_operator_code); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } /* Automatic registration to a new operator requested */ - mm_dbg ("Launching automatic network registration..."); + mm_obj_dbg (self, "launching automatic network registration..."); g_clear_pointer (&priv->manual_registration_operator_id, g_free); priv->manual_registration = FALSE; } @@ -1154,10 +1153,10 @@ mm_iface_modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED, &eps_supported, NULL); - mm_dbg ("Running registration checks (CS: '%s', PS: '%s', EPS: '%s')", - cs_supported ? "yes" : "no", - ps_supported ? "yes" : "no", - eps_supported ? "yes" : "no"); + mm_obj_dbg (self, "running registration checks (CS: '%s', PS: '%s', EPS: '%s')", + cs_supported ? "yes" : "no", + ps_supported ? "yes" : "no", + eps_supported ? "yes" : "no"); MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->run_registration_checks (self, cs_supported, @@ -1206,7 +1205,7 @@ load_operator_name_ready (MMIfaceModem3gpp *self, str = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_operator_name_finish (self, res, &error); if (error) { - mm_warn ("Couldn't load Operator Name: '%s'", error->message); + mm_obj_warn (self, "couldn't load operator name: %s", error->message); g_error_free (error); } @@ -1233,9 +1232,9 @@ load_operator_code_ready (MMIfaceModem3gpp *self, str = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_operator_code_finish (self, res, &error); if (error) { - mm_warn ("Couldn't load Operator Code: '%s'", error->message); + mm_obj_warn (self, "couldn't load operator code: %s", error->message); } else if (!mm_3gpp_parse_operator_id (str, &mcc, &mnc, &error)) { - mm_dbg ("Unexpected MCC/MNC string '%s': '%s'", str, error->message); + mm_obj_dbg (self, "unexpected operator code string '%s': %s", str, error->message); g_clear_pointer (&str, g_free); } g_clear_error (&error); @@ -1417,9 +1416,8 @@ update_registration_reload_current_registration_info_ready (MMIfaceModem3gpp *se new_state = GPOINTER_TO_UINT (user_data); - mm_info ("Modem %s: 3GPP Registration state changed (registering -> %s)", - g_dbus_object_get_object_path (G_DBUS_OBJECT (self)), - mm_modem_3gpp_registration_state_get_string (new_state)); + mm_obj_info (self, "3GPP Registration state changed (registering -> %s)", + mm_modem_3gpp_registration_state_get_string (new_state)); /* The property in the interface is bound to the property * in the skeleton, so just updating here is enough */ @@ -1494,14 +1492,12 @@ update_registration_state (MMIfaceModem3gpp *self, MM_IFACE_MODEM_STATE, &modem_state, NULL); if (modem_state < MM_MODEM_STATE_ENABLED) { - mm_dbg ("Modem %s: 3GPP Registration state change ignored as modem isn't enabled", - g_dbus_object_get_object_path (G_DBUS_OBJECT (self))); + mm_obj_dbg (self, "3GPP registration state change ignored as modem isn't enabled"); return; } - mm_info ("Modem %s: 3GPP Registration state changed (%s -> registering)", - g_dbus_object_get_object_path (G_DBUS_OBJECT (self)), - mm_modem_3gpp_registration_state_get_string (old_state)); + mm_obj_info (self, "3GPP Registration state changed (%s -> registering)", + mm_modem_3gpp_registration_state_get_string (old_state)); /* Reload current registration info. ONLY update the state to REGISTERED * after having loaded operator code/name/subscription state */ @@ -1513,10 +1509,9 @@ update_registration_state (MMIfaceModem3gpp *self, return; } - mm_info ("Modem %s: 3GPP Registration state changed (%s -> %s)", - g_dbus_object_get_object_path (G_DBUS_OBJECT (self)), - mm_modem_3gpp_registration_state_get_string (old_state), - mm_modem_3gpp_registration_state_get_string (new_state)); + mm_obj_info (self, "3GPP Registration state changed (%s -> %s)", + mm_modem_3gpp_registration_state_get_string (old_state), + mm_modem_3gpp_registration_state_get_string (new_state)); update_non_registered_state (self, old_state, new_state); } @@ -1594,7 +1589,7 @@ periodic_registration_checks_ready (MMIfaceModem3gpp *self, mm_iface_modem_3gpp_run_registration_checks_finish (self, res, &error); if (error) { - mm_dbg ("Couldn't refresh 3GPP registration status: '%s'", error->message); + mm_obj_dbg (self, "couldn't refresh 3GPP registration status: %s", error->message); g_error_free (error); } @@ -1633,7 +1628,7 @@ periodic_registration_check_disable (MMIfaceModem3gpp *self) g_source_remove (priv->check_timeout_source); priv->check_timeout_source = 0; - mm_dbg ("Periodic 3GPP registration checks disabled"); + mm_obj_dbg (self, "periodic 3GPP registration checks disabled"); } static void @@ -1648,7 +1643,7 @@ periodic_registration_check_enable (MMIfaceModem3gpp *self) return; /* Create context and keep it as object data */ - mm_dbg ("Periodic 3GPP registration checks enabled"); + mm_obj_dbg (self, "periodic 3GPP registration checks enabled"); priv->check_timeout_source = g_timeout_add_seconds (REGISTRATION_CHECK_TIMEOUT_SEC, (GSourceFunc)periodic_registration_check, self); @@ -1705,7 +1700,7 @@ mm_iface_modem_3gpp_update_initial_eps_bearer (MMIfaceModem3gpp *self, if (properties) { MMBaseBearer *new_bearer; - mm_dbg ("updating initial EPS bearer..."); + mm_obj_dbg (self, "updating initial EPS bearer..."); g_assert (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_initial_eps_bearer); new_bearer = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_initial_eps_bearer (self, properties); g_object_set (self, @@ -1714,7 +1709,7 @@ mm_iface_modem_3gpp_update_initial_eps_bearer (MMIfaceModem3gpp *self, mm_gdbus_modem3gpp_set_initial_eps_bearer (skeleton, mm_base_bearer_get_path (new_bearer)); g_object_unref (new_bearer); } else { - mm_dbg ("clearing initial EPS bearer..."); + mm_obj_dbg (self, "clearing initial EPS bearer..."); g_object_set (self, MM_IFACE_MODEM_3GPP_INITIAL_EPS_BEARER, NULL, NULL); @@ -1776,7 +1771,7 @@ mm_iface_modem_3gpp_disable_finish (MMIfaceModem3gpp *self, \ MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->NAME##_finish (self, res, &error); \ if (error) { \ - mm_dbg ("Couldn't %s: '%s'", DISPLAY, error->message); \ + mm_obj_dbg (self, "couldn't %s: %s", DISPLAY, error->message); \ g_error_free (error); \ } \ \ @@ -1979,7 +1974,7 @@ setup_unsolicited_events_ready (MMIfaceModem3gpp *self, MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->setup_unsolicited_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Setting up unsolicited events failed: '%s'", error->message); + mm_obj_dbg (self, "setting up unsolicited events failed: %s", error->message); g_error_free (error); /* If we get an error setting up unsolicited events, don't even bother trying to @@ -2005,7 +2000,7 @@ enable_unsolicited_events_ready (MMIfaceModem3gpp *self, MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->enable_unsolicited_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Enabling unsolicited events failed: '%s'", error->message); + mm_obj_dbg (self, "enabling unsolicited events failed: %s", error->message); g_error_free (error); } @@ -2028,7 +2023,7 @@ setup_unsolicited_registration_events_ready (MMIfaceModem3gpp *self, MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->setup_unsolicited_registration_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Setting up unsolicited registration events failed: '%s'", error->message); + mm_obj_dbg (self, "setting up unsolicited registration events failed: %s", error->message); g_error_free (error); /* If we get an error setting up unsolicited events, don't even bother trying to @@ -2056,7 +2051,7 @@ enable_unsolicited_registration_events_ready (MMIfaceModem3gpp *self, MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->enable_unsolicited_registration_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Enabling unsolicited registration events failed: '%s'", error->message); + mm_obj_dbg (self, "enabling unsolicited registration events failed: %s", error->message); g_error_free (error); /* If error, setup periodic registration checks */ periodic_registration_check_enable (self); @@ -2081,7 +2076,7 @@ load_initial_eps_bearer_ready (MMIfaceModem3gpp *self, properties = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer_finish (self, res, &error); if (!properties) { - mm_dbg ("couldn't load initial default bearer properties: '%s'", error->message); + mm_obj_dbg (self, "couldn't load initial default bearer properties: %s", error->message); g_error_free (error); goto out; } @@ -2293,7 +2288,7 @@ load_initial_eps_bearer_settings_ready (MMIfaceModem3gpp *self, config = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer_settings_finish (self, res, &error); if (!config) { - mm_warn ("couldn't load initial EPS bearer settings: '%s'", error->message); + mm_obj_warn (self, "couldn't load initial EPS bearer settings: %s", error->message); g_error_free (error); } else { GVariant *dictionary; @@ -2325,7 +2320,7 @@ load_eps_ue_mode_operation_ready (MMIfaceModem3gpp *self, mm_gdbus_modem3gpp_set_eps_ue_mode_operation (ctx->skeleton, uemode); if (error) { - mm_warn ("couldn't load UE mode of operation for EPS: '%s'", error->message); + mm_obj_warn (self, "couldn't load UE mode of operation for EPS: %s", error->message); g_error_free (error); } @@ -2349,7 +2344,7 @@ load_enabled_facility_locks_ready (MMIfaceModem3gpp *self, mm_gdbus_modem3gpp_set_enabled_facility_locks (ctx->skeleton, facilities); if (error) { - mm_warn ("couldn't load facility locks: '%s'", error->message); + mm_obj_warn (self, "couldn't load facility locks: %s", error->message); g_error_free (error); } else { MMBaseSim *sim = NULL; @@ -2389,7 +2384,7 @@ load_imei_ready (MMIfaceModem3gpp *self, g_free (imei); if (error) { - mm_warn ("couldn't load IMEI: '%s'", error->message); + mm_obj_warn (self, "couldn't load IMEI: %s", error->message); g_error_free (error); } @@ -2552,7 +2547,7 @@ mm_iface_modem_3gpp_initialize (MMIfaceModem3gpp *self, /* If the modem is *only* LTE, we assume that CS network is not * supported */ if (mm_iface_modem_is_3gpp_lte_only (MM_IFACE_MODEM (self))) { - mm_dbg ("Modem is LTE-only, assuming CS network is not supported"); + mm_obj_dbg (self, "LTE-only device, assuming CS network is not supported"); g_object_set (self, MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED, FALSE, NULL); From 301c984a872ecfadd8ef62706b7093078c70e842 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 16:23:39 +0200 Subject: [PATCH 032/675] iface-modem-3gpp-ussd: port to use object logging --- src/mm-iface-modem-3gpp-ussd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mm-iface-modem-3gpp-ussd.c b/src/mm-iface-modem-3gpp-ussd.c index fd029230..e649a40f 100644 --- a/src/mm-iface-modem-3gpp-ussd.c +++ b/src/mm-iface-modem-3gpp-ussd.c @@ -26,7 +26,7 @@ #include "mm-iface-modem-3gpp-ussd.h" #include "mm-base-modem.h" #include "mm-modem-helpers.h" -#include "mm-log.h" +#include "mm-log-object.h" #define SUPPORT_CHECKED_TAG "3gpp-ussd-support-checked-tag" #define SUPPORTED_TAG "3gpp-ussd-supported-tag" @@ -526,7 +526,7 @@ disable_unsolicited_events_ready (MMIfaceModem3gppUssd *self, MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->disable_unsolicited_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Couldn't disable unsolicited USSD events: '%s'", error->message); + mm_obj_dbg (self, "couldn't disable unsolicited USSD events: %s", error->message); g_error_free (error); } @@ -547,7 +547,7 @@ cleanup_unsolicited_events_ready (MMIfaceModem3gppUssd *self, MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cleanup_unsolicited_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Couldn't cleanup unsolicited USSD events: '%s'", error->message); + mm_obj_dbg (self, "couldn't cleanup unsolicited USSD events: %s", error->message); g_error_free (error); } @@ -673,7 +673,7 @@ setup_unsolicited_events_ready (MMIfaceModem3gppUssd *self, MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->setup_unsolicited_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Couldn't setup unsolicited USSD events: '%s'", error->message); + mm_obj_dbg (self, "couldn't setup unsolicited USSD events: %s", error->message); g_error_free (error); } @@ -694,7 +694,7 @@ enable_unsolicited_events_ready (MMIfaceModem3gppUssd *self, MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->enable_unsolicited_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Couldn't enable unsolicited USSD events: '%s'", error->message); + mm_obj_dbg (self, "couldn't enable unsolicited USSD events: %s", error->message); g_error_free (error); } @@ -813,7 +813,7 @@ check_support_ready (MMIfaceModem3gppUssd *self, &error)) { if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("USSD support check failed: '%s'", error->message); + mm_obj_dbg (self, "USSD support check failed: %s", error->message); g_error_free (error); } } else { From 0592bcfdec25965c55236c091ab5facb29d198b0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 16:29:22 +0200 Subject: [PATCH 033/675] iface-modem-cdma: port to use object logging --- src/mm-iface-modem-cdma.c | 85 ++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/src/mm-iface-modem-cdma.c b/src/mm-iface-modem-cdma.c index c012fe0c..877afe4e 100644 --- a/src/mm-iface-modem-cdma.c +++ b/src/mm-iface-modem-cdma.c @@ -23,7 +23,7 @@ #include "mm-iface-modem-cdma.h" #include "mm-base-modem.h" #include "mm-modem-helpers.h" -#include "mm-log.h" +#include "mm-log-object.h" #define SUBSYSTEM_CDMA1X "cdma1x" #define SUBSYSTEM_EVDO "evdo" @@ -161,7 +161,7 @@ handle_activate_auth_ready (MMBaseModem *self, /* If we're already activated, nothing to do */ if (mm_gdbus_modem_cdma_get_activation_state (ctx->skeleton) == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED) { - mm_dbg ("Modem is already activated"); + mm_obj_dbg (self, "already activated"); mm_gdbus_modem_cdma_complete_activate (ctx->skeleton, ctx->invocation); handle_activate_context_free (ctx); return; @@ -348,7 +348,7 @@ handle_activate_manual_auth_ready (MMBaseModem *self, /* If we're already activated, nothing to do */ if (mm_gdbus_modem_cdma_get_activation_state (ctx->skeleton) == MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED) { - mm_dbg ("Modem is already activated"); + mm_obj_dbg (self, "already activated"); mm_gdbus_modem_cdma_complete_activate_manual (ctx->skeleton, ctx->invocation); handle_activate_manual_context_free (ctx); return; @@ -617,7 +617,7 @@ get_call_manager_state_ready (MMIfaceModemCdma *self, &ctx->call_manager_system_mode, &ctx->call_manager_operating_mode, &error)) { - mm_dbg ("Could not get call manager state: %s", error->message); + mm_obj_dbg (self, "could not get call manager state: %s", error->message); g_error_free (error); /* Fallback to AT-based check */ ctx->step = REGISTRATION_CHECK_STEP_AT_CDMA_SERVICE_STATUS; @@ -654,7 +654,7 @@ get_hdr_state_ready (MMIfaceModemCdma *self, &ctx->hdr_session_state, &ctx->hdr_almp_state, &error)) { - mm_dbg ("Could not get HDR state: %s", error->message); + mm_obj_dbg (self, "could not get HDR state: %s", error->message); g_error_free (error); /* Fallback to AT-based check */ ctx->step = REGISTRATION_CHECK_STEP_AT_CDMA_SERVICE_STATUS; @@ -670,14 +670,16 @@ get_hdr_state_ready (MMIfaceModemCdma *self, static void parse_qcdm_results (GTask *task) { + MMIfaceModemCdma *self; RunRegistrationChecksContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); - mm_dbg ("QCDM CM System Mode: %d", ctx->call_manager_system_mode); - mm_dbg ("QCDM HDR Hybrid Mode: %d", ctx->hdr_hybrid_mode); - mm_dbg ("QCDM HDR Session State: %d", ctx->hdr_session_state); - mm_dbg ("QCDM HDR ALMP State: %d", ctx->hdr_almp_state); + mm_obj_dbg (self, "QCDM CM System Mode: %d", ctx->call_manager_system_mode); + mm_obj_dbg (self, "QCDM HDR Hybrid Mode: %d", ctx->hdr_hybrid_mode); + mm_obj_dbg (self, "QCDM HDR Session State: %d", ctx->hdr_session_state); + mm_obj_dbg (self, "QCDM HDR ALMP State: %d", ctx->hdr_almp_state); /* Set QCDM-obtained registration info */ switch (ctx->call_manager_system_mode) { @@ -725,7 +727,7 @@ get_service_status_ready (MMIfaceModemCdma *self, res, &has_service, &error)) { - mm_warn ("Could not get service status: %s", error->message); + mm_obj_warn (self, "could not get service status: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -733,7 +735,7 @@ get_service_status_ready (MMIfaceModemCdma *self, if (!has_service) { /* There is no CDMA service at all, end registration checks */ - mm_dbg ("No CDMA service found"); + mm_obj_dbg (self, "no CDMA service found"); ctx->step = REGISTRATION_CHECK_STEP_LAST; } else /* If we do have service, go on to next step */ @@ -766,7 +768,7 @@ get_cdma1x_serving_system_ready (MMIfaceModemCdma *self, if (!g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_NO_NETWORK)) { - mm_warn ("Could not get serving system: %s", error->message); + mm_obj_warn (self, "could not get serving system: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -786,15 +788,17 @@ get_cdma1x_serving_system_ready (MMIfaceModemCdma *self, static void parse_at_results (GTask *task) { + MMIfaceModemCdma *self; RunRegistrationChecksContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* 99999 means unknown/no service */ if (ctx->cdma1x_sid == MM_MODEM_CDMA_SID_UNKNOWN && ctx->cdma1x_nid == MM_MODEM_CDMA_NID_UNKNOWN) { /* Not registered in CDMA network, end registration checks */ - mm_dbg ("Not registered in any CDMA network"); + mm_obj_dbg (self, "no registered in any CDMA network"); ctx->step = REGISTRATION_CHECK_STEP_LAST; } else { /* We're registered on the CDMA 1x network (at least) */ @@ -826,7 +830,7 @@ get_detailed_registration_state_ready (MMIfaceModemCdma *self, &error)) { /* This error is NOT fatal. If we get an error here, we'll just fallback * to the non-detailed values we already got. */ - mm_dbg ("Could not get more detailed registration state: %s", error->message); + mm_obj_dbg (self, "could not get more detailed registration state: %s", error->message); } else { ctx->cdma1x_state = detailed_cdma1x_state; ctx->evdo_state = detailed_evdo_state; @@ -868,7 +872,7 @@ registration_check_step (GTask *task) /* fall through */ case REGISTRATION_CHECK_STEP_QCDM_CALL_MANAGER_STATE: - mm_dbg ("Starting QCDM-based registration checks"); + mm_obj_dbg (self, "starting QCDM-based registration checks..."); if (!ctx->skip_qcdm_call_manager_step && MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_call_manager_state && MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->get_call_manager_state_finish) { @@ -880,7 +884,7 @@ registration_check_step (GTask *task) return; } /* Fallback to AT-based check */ - mm_dbg (" Skipping all QCDM-based checks and falling back to AT-based checks"); + mm_obj_dbg (self, " skipping all QCDM-based checks and falling back to AT-based checks"); ctx->step = REGISTRATION_CHECK_STEP_AT_CDMA_SERVICE_STATUS; registration_check_step (task); return; @@ -897,7 +901,7 @@ registration_check_step (GTask *task) task); return; } - mm_dbg (" Skipping HDR check"); + mm_obj_dbg (self, " skipping HDR check"); ctx->step++; /* fall through */ @@ -913,7 +917,7 @@ registration_check_step (GTask *task) task); return; } - mm_dbg (" Skipping CDMA1x Serving System check"); + mm_obj_dbg (self, " skipping CDMA1x serving system check"); ctx->step++; /* fall through */ @@ -923,8 +927,7 @@ registration_check_step (GTask *task) return; case REGISTRATION_CHECK_STEP_AT_CDMA_SERVICE_STATUS: - mm_dbg ("Starting AT-based registration checks"); - + mm_obj_dbg (self, "starting AT-based registration checks"); /* If we don't have means to get service status, just assume we do have * CDMA service and keep on */ if (!ctx->skip_at_cdma_service_status_step && @@ -936,7 +939,7 @@ registration_check_step (GTask *task) task); return; } - mm_dbg (" Skipping CDMA service status check, assuming with service"); + mm_obj_dbg (self, " skipping CDMA service status check, assuming with service"); ctx->step++; /* fall through */ @@ -960,7 +963,7 @@ registration_check_step (GTask *task) task); return; } - mm_dbg (" Skipping CDMA1x Serving System check"); + mm_obj_dbg (self, " skipping CDMA1x Serving System check"); ctx->step++; /* fall through */ @@ -970,7 +973,7 @@ registration_check_step (GTask *task) return; case REGISTRATION_CHECK_STEP_DETAILED_REGISTRATION_STATE: - mm_dbg ("Starting detailed registration state check"); + mm_obj_dbg (self, "starting detailed registration state check"); /* We let classes implementing this interface to look for more detailed * registration info. */ if (!ctx->skip_detailed_registration_state && @@ -988,13 +991,13 @@ registration_check_step (GTask *task) task); return; } - mm_dbg (" Skipping detailed registration state check"); + mm_obj_dbg (self, " skipping detailed registration state check"); ctx->step++; /* fall through */ case REGISTRATION_CHECK_STEP_LAST: /* We are done without errors! */ - mm_dbg ("All CDMA registration state checks done"); + mm_obj_dbg (self, "all CDMA registration state checks done"); mm_iface_modem_cdma_update_cdma1x_registration_state (self, ctx->cdma1x_state, ctx->cdma1x_sid, @@ -1043,9 +1046,9 @@ mm_iface_modem_cdma_run_registration_checks (MMIfaceModemCdma *self, MM_IFACE_MODEM_CDMA_CDMA1X_NETWORK_SUPPORTED, &cdma1x_supported, NULL); - mm_dbg ("Running registration checks (CDMA1x: '%s', EV-DO: '%s')", - cdma1x_supported ? "yes" : "no", - evdo_supported ? "yes" : "no"); + mm_obj_dbg (self, "running registration checks (CDMA1x: '%s', EV-DO: '%s')", + cdma1x_supported ? "yes" : "no", + evdo_supported ? "yes" : "no"); if (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->run_registration_checks && MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->run_registration_checks_finish) { @@ -1244,7 +1247,7 @@ periodic_registration_checks_ready (MMIfaceModemCdma *self, mm_iface_modem_cdma_run_registration_checks_finish (self, res, &error); if (error) { - mm_dbg ("Couldn't refresh CDMA registration status: '%s'", error->message); + mm_obj_dbg (self, "couldn't refresh CDMA registration status: %s", error->message); g_error_free (error); } @@ -1283,7 +1286,7 @@ periodic_registration_check_disable (MMIfaceModemCdma *self) registration_check_context_quark, NULL); - mm_dbg ("Periodic CDMA registration checks disabled"); + mm_obj_dbg (self, "periodic CDMA registration checks disabled"); } static void @@ -1302,7 +1305,7 @@ periodic_registration_check_enable (MMIfaceModemCdma *self) return; /* Create context and keep it as object data */ - mm_dbg ("Periodic CDMA registration checks enabled"); + mm_obj_dbg (self, "periodic CDMA registration checks enabled"); ctx = g_new0 (RegistrationCheckContext, 1); ctx->timeout_source = g_timeout_add_seconds (REGISTRATION_CHECK_TIMEOUT_SEC, (GSourceFunc)periodic_registration_check, @@ -1339,11 +1342,11 @@ mm_iface_modem_cdma_update_activation_state (MMIfaceModemCdma *self, return; if (activation_error) { - mm_dbg ("Activation failed: %s", activation_error->message); + mm_obj_dbg (self, "activation failed: %s", activation_error->message); if (activation_error->domain == MM_CDMA_ACTIVATION_ERROR) error = activation_error->code; else { - mm_warn ("Error given is not an activation error"); + mm_obj_warn (self, "error given is not an activation error"); error = MM_CDMA_ACTIVATION_ERROR_UNKNOWN; } } @@ -1406,7 +1409,7 @@ disable_unsolicited_events_ready (MMIfaceModemCdma *self, MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->disable_unsolicited_events_finish (self, res, &error); if (error) { - mm_dbg ("Couldn't disable unsolicited events: '%s'", error->message); + mm_obj_dbg (self, "couldn't disable unsolicited events: %s", error->message); g_error_free (error); } @@ -1426,7 +1429,7 @@ cleanup_unsolicited_events_ready (MMIfaceModemCdma *self, MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->cleanup_unsolicited_events_finish (self, res, &error); if (error) { - mm_dbg ("Couldn't cleanup unsolicited events: '%s'", error->message); + mm_obj_dbg (self, "couldn't cleanup unsolicited events: %s", error->message); g_error_free (error); } @@ -1567,7 +1570,7 @@ setup_unsolicited_events_ready (MMIfaceModemCdma *self, MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->setup_unsolicited_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Setting up unsolicited events failed: '%s'", error->message); + mm_obj_dbg (self, "setting up unsolicited events failed: %s", error->message); g_error_free (error); } @@ -1588,7 +1591,7 @@ enable_unsolicited_events_ready (MMIfaceModemCdma *self, MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->enable_unsolicited_events_finish (self, res, &error); if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Enabling unsolicited events failed: '%s'", error->message); + mm_obj_dbg (self, "enabling unsolicited events failed: %s", error->message); g_error_free (error); } @@ -1733,7 +1736,7 @@ initialization_context_free (InitializationContext *ctx) g_free (val); \ \ if (error) { \ - mm_warn ("couldn't load %s: '%s'", DISPLAY, error->message); \ + mm_obj_warn (self, "couldn't load %s: %s", DISPLAY, error->message); \ g_error_free (error); \ } \ \ @@ -1760,7 +1763,7 @@ load_activation_state_ready (MMIfaceModemCdma *self, mm_gdbus_modem_cdma_set_activation_state (ctx->skeleton, state); if (error) { - mm_warn ("couldn't load activation state: '%s'", error->message); + mm_obj_warn (self, "couldn't load activation state: %s", error->message); g_error_free (error); } From 6314e5f1d22d8b3a69e071f78256ebe6059712b1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 16:31:33 +0200 Subject: [PATCH 034/675] iface-modem-firmware: port to use object logging --- src/mm-iface-modem-firmware.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mm-iface-modem-firmware.c b/src/mm-iface-modem-firmware.c index 8344778a..9268c4b7 100644 --- a/src/mm-iface-modem-firmware.c +++ b/src/mm-iface-modem-firmware.c @@ -19,7 +19,7 @@ #include "mm-iface-modem.h" #include "mm-iface-modem-firmware.h" -#include "mm-log.h" +#include "mm-log-object.h" /*****************************************************************************/ @@ -70,7 +70,7 @@ load_current_ready (MMIfaceModemFirmware *self, handle_list_context_free (ctx); return; } - mm_dbg ("Couldn't load current firmware image: %s", error->message); + mm_obj_dbg (self, "couldn't load current firmware image: %s", error->message); g_clear_error (&error); } @@ -104,7 +104,7 @@ load_list_ready (MMIfaceModemFirmware *self, handle_list_context_free (ctx); return; } - mm_dbg ("Couldn't load firmware image list: %s", error->message); + mm_obj_dbg (self, "couldn't load firmware image list: %s", error->message); g_clear_error (&error); } @@ -380,7 +380,7 @@ load_update_settings_ready (MMIfaceModemFirmware *self, update_settings = MM_IFACE_MODEM_FIRMWARE_GET_INTERFACE (self)->load_update_settings_finish (self, res, &error); if (!update_settings) { - mm_dbg ("Couldn't load update settings: '%s'", error->message); + mm_obj_dbg (self, "couldn't load update settings: %s", error->message); g_error_free (error); goto out; } @@ -388,7 +388,7 @@ load_update_settings_ready (MMIfaceModemFirmware *self, /* If the plugin didn't specify custom device ids, add the default ones ourselves */ if (!mm_firmware_update_settings_get_device_ids (update_settings) && !add_generic_device_ids (MM_BASE_MODEM (self), update_settings, &error)) { - mm_warn ("Couldn't build device ids: '%s'", error->message); + mm_obj_warn (self, "couldn't build device ids: %s", error->message); g_error_free (error); g_clear_object (&update_settings); goto out; @@ -397,7 +397,7 @@ load_update_settings_ready (MMIfaceModemFirmware *self, /* If the plugin didn't specify custom version, add the default one ourselves */ if (!mm_firmware_update_settings_get_version (update_settings) && !add_generic_version (MM_BASE_MODEM (self), update_settings, &error)) { - mm_warn ("Couldn't set version: '%s'", error->message); + mm_obj_warn (self, "couldn't set version: %s", error->message); g_error_free (error); g_clear_object (&update_settings); goto out; From 7d5871c59c736b83112acd9eb23d6201486c306c Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 18:53:25 +0200 Subject: [PATCH 035/675] iface-modem-location: port to use object logging --- src/mm-iface-modem-location.c | 65 ++++++++++++++--------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/src/mm-iface-modem-location.c b/src/mm-iface-modem-location.c index 9a85c9e8..f40f48ab 100644 --- a/src/mm-iface-modem-location.c +++ b/src/mm-iface-modem-location.c @@ -21,7 +21,7 @@ #include "mm-iface-modem.h" #include "mm-iface-modem-location.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #define MM_LOCATION_GPS_REFRESH_TIME_SECS 30 @@ -235,11 +235,7 @@ notify_gps_location_update (MMIfaceModemLocation *self, MMLocationGpsNmea *location_gps_nmea, MMLocationGpsRaw *location_gps_raw) { - const gchar *dbus_path; - - dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self)); - mm_dbg ("Modem %s: GPS location updated", - dbus_path); + mm_obj_dbg (self, "GPS location updated"); /* We only update the property if we are supposed to signal * location */ @@ -322,7 +318,7 @@ mm_iface_modem_location_gps_update (MMIfaceModemLocation *self, g_autoptr(GString) str = NULL; g_autoptr(GDateTime) now = NULL; - mm_dbg ("GGA trace detected: '%s'", nmea_trace); + mm_obj_dbg (self, "GGA trace detected: %s", nmea_trace); now = g_date_time_new_now_utc (); str = g_string_new (""); @@ -349,17 +345,13 @@ notify_3gpp_location_update (MMIfaceModemLocation *self, MmGdbusModemLocation *skeleton, MMLocation3gpp *location_3gpp) { - const gchar *dbus_path; - - dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self)); - mm_dbg ("Modem %s: 3GPP location updated " - "(MCC: '%u', MNC: '%u', Location area code: '%lX', Tracking area code: '%lX', Cell ID: '%lX')", - dbus_path, - mm_location_3gpp_get_mobile_country_code (location_3gpp), - mm_location_3gpp_get_mobile_network_code (location_3gpp), - mm_location_3gpp_get_location_area_code (location_3gpp), - mm_location_3gpp_get_tracking_area_code (location_3gpp), - mm_location_3gpp_get_cell_id (location_3gpp)); + mm_obj_dbg (self, "3GPP location updated " + "(MCC: '%u', MNC: '%u', location area code: '%lX', tracking area code: '%lX', cell ID: '%lX')", + mm_location_3gpp_get_mobile_country_code (location_3gpp), + mm_location_3gpp_get_mobile_network_code (location_3gpp), + mm_location_3gpp_get_location_area_code (location_3gpp), + mm_location_3gpp_get_tracking_area_code (location_3gpp), + mm_location_3gpp_get_cell_id (location_3gpp)); /* We only update the property if we are supposed to signal * location */ @@ -461,14 +453,9 @@ notify_cdma_bs_location_update (MMIfaceModemLocation *self, MmGdbusModemLocation *skeleton, MMLocationCdmaBs *location_cdma_bs) { - const gchar *dbus_path; - - dbus_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (self)); - mm_dbg ("Modem %s: CDMA BS location updated " - "(Longitude: '%lf', Latitude: '%lf')", - dbus_path, - mm_location_cdma_bs_get_longitude (location_cdma_bs), - mm_location_cdma_bs_get_latitude (location_cdma_bs)); + mm_obj_dbg (self, "CDMA base station location updated (longitude: '%lf', latitude: '%lf')", + mm_location_cdma_bs_get_longitude (location_cdma_bs), + mm_location_cdma_bs_get_latitude (location_cdma_bs)); /* We only update the property if we are supposed to signal * location */ @@ -712,7 +699,7 @@ setup_gathering_step (GTask *task) } source_str = mm_modem_location_source_build_string_from_mask (ctx->current); - mm_dbg ("Enabled location '%s' gathering...", source_str); + mm_obj_dbg (self, "enabled location '%s' gathering...", source_str); g_free (source_str); } else if (ctx->to_disable & ctx->current) { /* Remove from mask */ @@ -732,7 +719,7 @@ setup_gathering_step (GTask *task) } source_str = mm_modem_location_source_build_string_from_mask (ctx->current); - mm_dbg ("Disabled location '%s' gathering...", source_str); + mm_obj_dbg (self, "disabled location '%s' gathering...", source_str); g_free (source_str); } @@ -797,7 +784,7 @@ setup_gathering (MMIfaceModemLocation *self, if (mask & source) { /* Source set in mask, need to enable if disabled */ if (currently_enabled & source) - mm_dbg ("Location '%s' gathering is already enabled...", str); + mm_obj_dbg (self, "location '%s' gathering is already enabled...", str); else ctx->to_enable |= source; } else { @@ -805,7 +792,7 @@ setup_gathering (MMIfaceModemLocation *self, if (currently_enabled & source) ctx->to_disable |= source; else - mm_dbg ("Location '%s' gathering is already disabled...", str); + mm_obj_dbg (self, "location '%s' gathering is already disabled...", str); } g_free (str); @@ -847,13 +834,13 @@ setup_gathering (MMIfaceModemLocation *self, if (ctx->to_enable != MM_MODEM_LOCATION_SOURCE_NONE) { str = mm_modem_location_source_build_string_from_mask (ctx->to_enable); - mm_dbg ("Need to enable the following location sources: '%s'", str); + mm_obj_dbg (self, "need to enable the following location sources: '%s'", str); g_free (str); } if (ctx->to_disable != MM_MODEM_LOCATION_SOURCE_NONE) { str = mm_modem_location_source_build_string_from_mask (ctx->to_disable); - mm_dbg ("Need to disable the following location sources: '%s'", str); + mm_obj_dbg (self, "need to disable the following location sources: '%s'", str); g_free (str); } @@ -944,8 +931,8 @@ handle_setup_auth_ready (MMBaseModem *self, /* Enable/disable location signaling */ location_ctx = get_location_context (ctx->self); if (mm_gdbus_modem_location_get_signals_location (ctx->skeleton) != ctx->signal_location) { - mm_dbg ("%s location signaling", - ctx->signal_location ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s location signaling", + ctx->signal_location ? "enabling" : "disabling"); mm_gdbus_modem_location_set_signals_location (ctx->skeleton, ctx->signal_location); if (ctx->signal_location) @@ -963,7 +950,7 @@ handle_setup_auth_ready (MMBaseModem *self, } str = mm_modem_location_source_build_string_from_mask (ctx->sources); - mm_dbg ("Setting up location sources: '%s'", str); + mm_obj_dbg (self, "setting up location sources: '%s'", str); g_free (str); /* Go on to enable or disable the requested sources */ @@ -1674,7 +1661,7 @@ load_assistance_data_servers_ready (MMIfaceModemLocation *self, servers = MM_IFACE_MODEM_LOCATION_GET_INTERFACE (self)->load_assistance_data_servers_finish (self, res, &error); if (error) { - mm_warn ("couldn't load assistance data servers: '%s'", error->message); + mm_obj_warn (self, "couldn't load assistance data servers: %s", error->message); g_error_free (error); } @@ -1699,7 +1686,7 @@ load_supported_assistance_data_ready (MMIfaceModemLocation *self, mask = MM_IFACE_MODEM_LOCATION_GET_INTERFACE (self)->load_supported_assistance_data_finish (self, res, &error); if (error) { - mm_warn ("couldn't load supported assistance data types: '%s'", error->message); + mm_obj_warn (self, "couldn't load supported assistance data types: %s", error->message); g_error_free (error); } @@ -1723,7 +1710,7 @@ load_supl_server_ready (MMIfaceModemLocation *self, supl = MM_IFACE_MODEM_LOCATION_GET_INTERFACE (self)->load_supl_server_finish (self, res, &error); if (error) { - mm_warn ("couldn't load SUPL server: '%s'", error->message); + mm_obj_warn (self, "couldn't load SUPL server: %s", error->message); g_error_free (error); } @@ -1747,7 +1734,7 @@ load_capabilities_ready (MMIfaceModemLocation *self, ctx->capabilities = MM_IFACE_MODEM_LOCATION_GET_INTERFACE (self)->load_capabilities_finish (self, res, &error); if (error) { - mm_warn ("couldn't load location capabilities: '%s'", error->message); + mm_obj_warn (self, "couldn't load location capabilities: %s", error->message); g_error_free (error); } From 135b5c8065b0679b3cf33779ae4dd9252d8d8497 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 18:58:07 +0200 Subject: [PATCH 036/675] iface-modem-messaging: port to use object logging --- src/mm-iface-modem-messaging.c | 53 +++++++++++++++------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/mm-iface-modem-messaging.c b/src/mm-iface-modem-messaging.c index 02e6a769..b5be318a 100644 --- a/src/mm-iface-modem-messaging.c +++ b/src/mm-iface-modem-messaging.c @@ -20,7 +20,7 @@ #include "mm-iface-modem.h" #include "mm-iface-modem-messaging.h" #include "mm-sms-list.h" -#include "mm-log.h" +#include "mm-log-object.h" #define SUPPORT_CHECKED_TAG "messaging-support-checked-tag" #define SUPPORTED_TAG "messaging-supported-tag" @@ -426,7 +426,7 @@ mm_iface_modem_messaging_take_part (MMIfaceModemMessaging *self, added = mm_sms_list_take_part (list, sms_part, state, storage, &error); if (!added) { - mm_dbg ("Couldn't take part in SMS list: '%s'", error->message); + mm_obj_dbg (self, "couldn't take part in SMS list: %s", error->message); g_error_free (error); /* If part wasn't taken, we need to free the part ourselves */ @@ -503,24 +503,20 @@ update_message_list (MmGdbusModemMessaging *skeleton, } static void -sms_added (MMSmsList *list, - const gchar *sms_path, - gboolean received, +sms_added (MMSmsList *list, + const gchar *sms_path, + gboolean received, MmGdbusModemMessaging *skeleton) { - mm_dbg ("Added %s SMS at '%s'", - received ? "received" : "local", - sms_path); update_message_list (skeleton, list); mm_gdbus_modem_messaging_emit_added (skeleton, sms_path, received); } static void -sms_deleted (MMSmsList *list, - const gchar *sms_path, +sms_deleted (MMSmsList *list, + const gchar *sms_path, MmGdbusModemMessaging *skeleton) { - mm_dbg ("Deleted SMS at '%s'", sms_path); update_message_list (skeleton, list); mm_gdbus_modem_messaging_emit_deleted (skeleton, sms_path); } @@ -762,11 +758,11 @@ load_initial_sms_parts_ready (MMIfaceModemMessaging *self, StorageContext *storage_ctx; storage_ctx = get_storage_context (self); - mm_dbg ("Couldn't load SMS parts from storage '%s': '%s'", - mm_sms_storage_get_string (g_array_index (storage_ctx->supported_mem1, - MMSmsStorage, - ctx->mem1_storage_index)), - error->message); + mm_obj_dbg (self, "couldn't load SMS parts from storage '%s': %s", + mm_sms_storage_get_string (g_array_index (storage_ctx->supported_mem1, + MMSmsStorage, + ctx->mem1_storage_index)), + error->message); g_error_free (error); } @@ -784,7 +780,7 @@ set_default_storage_ready (MMIfaceModemMessaging *self, GError *error = NULL; if (!MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->set_default_storage_finish (self, res, &error)) { - mm_warn ("Could not set default storage: '%s'", error->message); + mm_obj_warn (self, "could not set default storage: %s", error->message); g_error_free (error); } @@ -866,7 +862,7 @@ enable_unsolicited_events_ready (MMIfaceModemMessaging *self, /* Not critical! */ if (!MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->enable_unsolicited_events_finish (self, res, &error)) { - mm_dbg ("Couldn't enable unsolicited events: '%s'", error->message); + mm_obj_dbg (self, "couldn't enable unsolicited events: %s", error->message); g_error_free (error); } @@ -989,7 +985,7 @@ interface_enabling_step (GTask *task) NULL); if (default_storage == MM_SMS_STORAGE_UNKNOWN) - mm_info ("Cannot set default storage, none of the suggested ones supported"); + mm_obj_warn (self, "cannot set default storage, none of the suggested ones supported"); else if (MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->set_default_storage && MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->set_default_storage_finish) { MM_IFACE_MODEM_MESSAGING_GET_INTERFACE (self)->set_default_storage ( @@ -1141,7 +1137,7 @@ load_supported_storages_ready (MMIfaceModemMessaging *self, &storage_ctx->supported_mem2, &storage_ctx->supported_mem3, &error)) { - mm_dbg ("Couldn't load supported storages: '%s'", error->message); + mm_obj_dbg (self, "couldn't load supported storages: %s", error->message); g_error_free (error); } else { gchar *mem1; @@ -1162,10 +1158,10 @@ load_supported_storages_ready (MMIfaceModemMessaging *self, mem3 = mm_common_build_sms_storages_string ((MMSmsStorage *)storage_ctx->supported_mem3->data, storage_ctx->supported_mem3->len); - mm_dbg ("Supported storages loaded:"); - mm_dbg (" mem1 (list/read/delete) storages: '%s'", mem1); - mm_dbg (" mem2 (write/send) storages: '%s'", mem2); - mm_dbg (" mem3 (reception) storages: '%s'", mem3); + mm_obj_dbg (self, "supported storages loaded:"); + mm_obj_dbg (self, " mem1 (list/read/delete) storages: '%s'", mem1); + mm_obj_dbg (self, " mem2 (write/send) storages: '%s'", mem2); + mm_obj_dbg (self, " mem3 (reception) storages: '%s'", mem3); g_free (mem1); g_free (mem2); g_free (mem3); @@ -1215,7 +1211,7 @@ check_support_ready (MMIfaceModemMessaging *self, &error)) { if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Messaging support check failed: '%s'", error->message); + mm_obj_dbg (self, "messaging support check failed: %s", error->message); g_error_free (error); } } else { @@ -1243,11 +1239,10 @@ init_current_storages_ready (MMIfaceModemMessaging *self, self, res, &error)) { - mm_dbg ("Couldn't initialize current storages: '%s'", error->message); + mm_obj_dbg (self, "couldn't initialize current storages: %s", error->message); g_error_free (error); - } else { - mm_dbg ("Current storages initialized"); - } + } else + mm_obj_dbg (self, "current storages initialized"); /* Go on to next step */ ctx = g_task_get_task_data (task); From 84851cc6164df15b1364fbe53f488200f6bdbd55 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 18:59:52 +0200 Subject: [PATCH 037/675] iface-modem-oma: port to use object logging --- src/mm-iface-modem-oma.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/mm-iface-modem-oma.c b/src/mm-iface-modem-oma.c index cf3a7a30..cc796b88 100644 --- a/src/mm-iface-modem-oma.c +++ b/src/mm-iface-modem-oma.c @@ -19,7 +19,7 @@ #include "mm-iface-modem.h" #include "mm-iface-modem-oma.h" -#include "mm-log.h" +#include "mm-log-object.h" #define SUPPORT_CHECKED_TAG "oma-support-checked-tag" #define SUPPORTED_TAG "oma-supported-tag" @@ -124,10 +124,9 @@ mm_iface_modem_oma_update_session_state (MMIfaceModemOma *self, old_session_state = mm_gdbus_modem_oma_get_session_state (skeleton); if (old_session_state != new_session_state) { - mm_info ("Modem %s: OMA session state changed (%s -> %s)", - g_dbus_object_get_object_path (G_DBUS_OBJECT (self)), - mm_oma_session_state_get_string (old_session_state), - mm_oma_session_state_get_string (new_session_state)); + mm_obj_info (self, "OMA session state changed (%s -> %s)", + mm_oma_session_state_get_string (old_session_state), + mm_oma_session_state_get_string (new_session_state)); /* Flush current change before signaling the state change, * so that clients get the proper state already in the @@ -220,7 +219,7 @@ handle_setup_auth_ready (MMBaseModem *self, } str = mm_oma_feature_build_string_from_mask (ctx->features); - mm_dbg ("Setting up OMA features: '%s'", str); + mm_obj_dbg (self, "setting up OMA features: '%s'", str); g_free (str); MM_IFACE_MODEM_OMA_GET_INTERFACE (ctx->self)->setup ( @@ -342,8 +341,8 @@ handle_start_client_initiated_session_auth_ready (MMBaseModem *self, return; } - mm_dbg ("Starting client-initiated OMA session (%s)", - mm_oma_session_type_get_string (ctx->session_type)); + mm_obj_dbg (self, "starting client-initiated OMA session (%s)", + mm_oma_session_type_get_string (ctx->session_type)); MM_IFACE_MODEM_OMA_GET_INTERFACE (ctx->self)->start_client_initiated_session ( ctx->self, ctx->session_type, @@ -501,10 +500,10 @@ handle_accept_network_initiated_session_auth_ready (MMBaseModem *self, return; } - mm_dbg ("%s network-initiated OMA session (%s, %u)", - ctx->accept ? "Accepting" : "Rejecting", - mm_oma_session_type_get_string (ctx->session_type), - ctx->session_id); + mm_obj_dbg (self, "%s network-initiated OMA session (%s, %u)", + ctx->accept ? "accepting" : "rejecting", + mm_oma_session_type_get_string (ctx->session_type), + ctx->session_id); MM_IFACE_MODEM_OMA_GET_INTERFACE (ctx->self)->accept_network_initiated_session ( ctx->self, ctx->session_id, @@ -615,7 +614,7 @@ handle_cancel_session_auth_ready (MMBaseModem *self, return; } - mm_dbg ("Cancelling OMA session"); + mm_obj_dbg (self, "cancelling OMA session"); MM_IFACE_MODEM_OMA_GET_INTERFACE (ctx->self)->cancel_session ( ctx->self, (GAsyncReadyCallback)cancel_session_ready, @@ -890,7 +889,7 @@ enable_unsolicited_events_ready (MMIfaceModemOma *self, /* Not critical! */ if (!MM_IFACE_MODEM_OMA_GET_INTERFACE (self)->enable_unsolicited_events_finish (self, res, &error)) { - mm_dbg ("Couldn't enable unsolicited events: '%s'", error->message); + mm_obj_dbg (self, "couldn't enable unsolicited events: %s", error->message); g_error_free (error); } @@ -1036,7 +1035,7 @@ check_support_ready (MMIfaceModemOma *self, if (!MM_IFACE_MODEM_OMA_GET_INTERFACE (self)->check_support_finish (self, res, &error)) { if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("OMA support check failed: '%s'", error->message); + mm_obj_dbg (self, "OMA support check failed: %s", error->message); g_error_free (error); } } else { From 695a1003a1d00deb9e4171d5607d4c7dbf49f5e3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:02:12 +0200 Subject: [PATCH 038/675] iface-modem-signal: port to use object logging --- src/mm-iface-modem-signal.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/mm-iface-modem-signal.c b/src/mm-iface-modem-signal.c index 396ce688..03e4ce1f 100644 --- a/src/mm-iface-modem-signal.c +++ b/src/mm-iface-modem-signal.c @@ -19,7 +19,7 @@ #include "mm-iface-modem.h" #include "mm-iface-modem-signal.h" -#include "mm-log.h" +#include "mm-log-object.h" #define SUPPORT_CHECKED_TAG "signal-support-checked-tag" #define SUPPORTED_TAG "signal-supported-tag" @@ -93,7 +93,7 @@ load_values_ready (MMIfaceModemSignal *self, &umts, <e, &error)) { - mm_warn ("Couldn't load extended signal information: %s", error->message); + mm_obj_warn (self, "couldn't load extended signal information: %s", error->message); g_error_free (error); clear_values (self); return; @@ -103,8 +103,7 @@ load_values_ready (MMIfaceModemSignal *self, MM_IFACE_MODEM_SIGNAL_DBUS_SKELETON, &skeleton, NULL); if (!skeleton) { - mm_warn ("Cannot update extended signal information: " - "Couldn't get interface skeleton"); + mm_obj_warn (self, "cannot update extended signal information: couldn't get interface skeleton"); return; } @@ -172,7 +171,7 @@ teardown_refresh_context (MMIfaceModemSignal *self) if (G_UNLIKELY (!refresh_context_quark)) refresh_context_quark = g_quark_from_static_string (REFRESH_CONTEXT_TAG); if (g_object_get_qdata (G_OBJECT (self), refresh_context_quark)) { - mm_dbg ("Extended signal information reporting disabled"); + mm_obj_dbg (self, "extended signal information reporting disabled"); g_object_set_qdata (G_OBJECT (self), refresh_context_quark, NULL); } } @@ -210,14 +209,14 @@ setup_refresh_context (MMIfaceModemSignal *self, /* User disabling? */ if (new_rate == 0) { - mm_dbg ("Extended signal information reporting disabled (rate: 0 seconds)"); + mm_obj_dbg (self, "extended signal information reporting disabled (rate: 0 seconds)"); clear_values (self); g_object_set_qdata (G_OBJECT (self), refresh_context_quark, NULL); return TRUE; } if (modem_state < MM_MODEM_STATE_ENABLING) { - mm_dbg ("Extended signal information reporting disabled (modem not yet enabled)"); + mm_obj_dbg (self, "extended signal information reporting disabled (modem not yet enabled)"); return TRUE; } @@ -238,7 +237,7 @@ setup_refresh_context (MMIfaceModemSignal *self, } /* Update refresh context */ - mm_dbg ("Extended signal information reporting enabled (rate: %u seconds)", new_rate); + mm_obj_dbg (self, "extended signal information reporting enabled (rate: %u seconds)", new_rate); ctx->rate = new_rate; if (ctx->timeout_source) g_source_remove (ctx->timeout_source); @@ -402,7 +401,7 @@ check_support_ready (MMIfaceModemSignal *self, if (!MM_IFACE_MODEM_SIGNAL_GET_INTERFACE (self)->check_support_finish (self, res, &error)) { if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Extended signal support check failed: '%s'", error->message); + mm_obj_dbg (self, "extended signal support check failed: %s", error->message); g_error_free (error); } } else { From 91de19e3aecef099f2c3b3e0ab2a6b4cdeb6116b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:09:23 +0200 Subject: [PATCH 039/675] iface-modem-simple: port to use object logging --- src/mm-iface-modem-simple.c | 90 +++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/src/mm-iface-modem-simple.c b/src/mm-iface-modem-simple.c index ccf4ecc6..61ae662b 100644 --- a/src/mm-iface-modem-simple.c +++ b/src/mm-iface-modem-simple.c @@ -26,7 +26,7 @@ #include "mm-iface-modem-3gpp.h" #include "mm-iface-modem-cdma.h" #include "mm-iface-modem-simple.h" -#include "mm-log.h" +#include "mm-log-object.h" /*****************************************************************************/ /* Private data context */ @@ -280,7 +280,7 @@ connect_bearer_ready (MMBaseBearer *bearer, GError *error = NULL; if (!mm_base_bearer_connect_finish (bearer, res, &error)) { - mm_dbg ("Couldn't connect bearer: '%s'", error->message); + mm_obj_dbg (ctx->self, "couldn't connect bearer: %s", error->message); g_dbus_method_invocation_take_error (ctx->invocation, error); connection_context_free (ctx); return; @@ -541,8 +541,8 @@ connection_step (ConnectionContext *ctx) /* fall through */ case CONNECTION_STEP_UNLOCK_CHECK: - mm_info ("Simple connect state (%d/%d): Unlock check", - ctx->step, CONNECTION_STEP_LAST); + mm_obj_info (ctx->self, "simple connect state (%d/%d): unlock check", + ctx->step, CONNECTION_STEP_LAST); mm_iface_modem_update_lock_info (MM_IFACE_MODEM (ctx->self), MM_MODEM_LOCK_UNKNOWN, /* ask */ (GAsyncReadyCallback)update_lock_info_ready, @@ -550,8 +550,8 @@ connection_step (ConnectionContext *ctx) return; case CONNECTION_STEP_WAIT_FOR_INITIALIZED: - mm_info ("Simple connect state (%d/%d): Wait to get fully initialized", - ctx->step, CONNECTION_STEP_LAST); + mm_obj_info (ctx->self, "simple connect state (%d/%d): wait to get fully initialized", + ctx->step, CONNECTION_STEP_LAST); mm_iface_modem_wait_for_final_state (MM_IFACE_MODEM (ctx->self), MM_MODEM_STATE_DISABLED, /* disabled == initialized */ (GAsyncReadyCallback)wait_for_initialized_ready, @@ -559,16 +559,16 @@ connection_step (ConnectionContext *ctx) return; case CONNECTION_STEP_ENABLE: - mm_info ("Simple connect state (%d/%d): Enable", - ctx->step, CONNECTION_STEP_LAST); + mm_obj_info (ctx->self, "simple connect state (%d/%d): enable", + ctx->step, CONNECTION_STEP_LAST); mm_base_modem_enable (MM_BASE_MODEM (ctx->self), (GAsyncReadyCallback)enable_ready, ctx); return; case CONNECTION_STEP_WAIT_FOR_ENABLED: - mm_info ("Simple connect state (%d/%d): Wait to get fully enabled", - ctx->step, CONNECTION_STEP_LAST); + mm_obj_info (ctx->self, "simple connect state (%d/%d): wait to get fully enabled", + ctx->step, CONNECTION_STEP_LAST); mm_iface_modem_wait_for_final_state (MM_IFACE_MODEM (ctx->self), MM_MODEM_STATE_UNKNOWN, /* just a final state */ (GAsyncReadyCallback)wait_for_enabled_ready, @@ -576,9 +576,8 @@ connection_step (ConnectionContext *ctx) return; case CONNECTION_STEP_REGISTER: - mm_info ("Simple connect state (%d/%d): Register", - ctx->step, CONNECTION_STEP_LAST); - + mm_obj_info (ctx->self, "simple connect state (%d/%d): register", + ctx->step, CONNECTION_STEP_LAST); if (mm_iface_modem_is_3gpp (MM_IFACE_MODEM (ctx->self)) || mm_iface_modem_is_cdma (MM_IFACE_MODEM (ctx->self))) { /* 3GPP or CDMA registration */ @@ -599,9 +598,8 @@ connection_step (ConnectionContext *ctx) MMBearerList *list = NULL; MMBearerProperties *bearer_properties; - mm_info ("Simple connect state (%d/%d): Bearer", - ctx->step, CONNECTION_STEP_LAST); - + mm_obj_info (ctx->self, "simple connect state (%d/%d): bearer", + ctx->step, CONNECTION_STEP_LAST); g_object_get (ctx->self, MM_IFACE_MODEM_BEARER_LIST, &list, NULL); @@ -620,7 +618,7 @@ connection_step (ConnectionContext *ctx) /* Check if the bearer we want to create is already in the list */ ctx->bearer = mm_bearer_list_find_by_properties (list, bearer_properties); if (!ctx->bearer) { - mm_dbg ("Creating new bearer..."); + mm_obj_dbg (ctx->self, "creating new bearer..."); /* If we don't have enough space to create the bearer, try to remove * a disconnected bearer first. */ if (mm_bearer_list_get_max (list) == mm_bearer_list_get_count (list)) { @@ -638,13 +636,13 @@ connection_step (ConnectionContext *ctx) if (!mm_bearer_list_delete_bearer (list, mm_base_bearer_get_path (foreach_ctx.found), &error)) { - mm_dbg ("Couldn't delete disconnected bearer at '%s': '%s'", - mm_base_bearer_get_path (foreach_ctx.found), - error->message); + mm_obj_dbg (ctx->self, "couldn't delete disconnected bearer at '%s': %s", + mm_base_bearer_get_path (foreach_ctx.found), + error->message); g_error_free (error); } else - mm_dbg ("Deleted disconnected bearer at '%s'", - mm_base_bearer_get_path (foreach_ctx.found)); + mm_obj_dbg (ctx->self, "deleted disconnected bearer at '%s'", + mm_base_bearer_get_path (foreach_ctx.found)); g_object_unref (foreach_ctx.found); } @@ -672,16 +670,16 @@ connection_step (ConnectionContext *ctx) return; } - mm_dbg ("Using already existing bearer at '%s'...", - mm_base_bearer_get_path (ctx->bearer)); + mm_obj_dbg (ctx->self, "Using already existing bearer at '%s'...", + mm_base_bearer_get_path (ctx->bearer)); g_object_unref (list); g_object_unref (bearer_properties); ctx->step++; } /* fall through */ case CONNECTION_STEP_CONNECT: - mm_info ("Simple connect state (%d/%d): Connect", - ctx->step, CONNECTION_STEP_LAST); + mm_obj_info (ctx->self, "simple connect state (%d/%d): connect", + ctx->step, CONNECTION_STEP_LAST); /* At this point, we can cleanup the cancellation point in the Simple interface, * because the bearer connection has its own cancellation setup. */ @@ -696,15 +694,15 @@ connection_step (ConnectionContext *ctx) return; } - mm_dbg ("Bearer at '%s' is already connected...", - mm_base_bearer_get_path (ctx->bearer)); + mm_obj_dbg (ctx->self, "bearer at '%s' is already connected...", + mm_base_bearer_get_path (ctx->bearer)); ctx->step++; /* fall through */ case CONNECTION_STEP_LAST: - mm_info ("Simple connect state (%d/%d): All done", - ctx->step, CONNECTION_STEP_LAST); + mm_obj_info (ctx->self, "simple connect state (%d/%d): all done", + ctx->step, CONNECTION_STEP_LAST); /* All done, yey! */ mm_gdbus_modem_simple_complete_connect ( ctx->skeleton, @@ -752,7 +750,7 @@ connect_auth_ready (MMBaseModem *self, MM_IFACE_MODEM_STATE, ¤t, NULL); - mm_info ("Simple connect started..."); + mm_obj_info (self, "simple connect started..."); /* Log about all the parameters being used for the simple connect */ { @@ -762,33 +760,29 @@ connect_auth_ready (MMBaseModem *self, #define VALIDATE_UNSPECIFIED(str) (str ? str : "unspecified") - mm_dbg (" PIN: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_pin (ctx->properties))); - - mm_dbg (" Operator ID: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_operator_id (ctx->properties))); - - mm_dbg (" Allowed roaming: %s", mm_simple_connect_properties_get_allow_roaming (ctx->properties) ? "yes" : "no"); - - mm_dbg (" APN: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_apn (ctx->properties))); + mm_obj_dbg (self, " PIN: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_pin (ctx->properties))); + mm_obj_dbg (self, " operator ID: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_operator_id (ctx->properties))); + mm_obj_dbg (self, " allowed roaming: %s", mm_simple_connect_properties_get_allow_roaming (ctx->properties) ? "yes" : "no"); + mm_obj_dbg (self, " APN: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_apn (ctx->properties))); ip_family = mm_simple_connect_properties_get_ip_type (ctx->properties); if (ip_family != MM_BEARER_IP_FAMILY_NONE) { str = mm_bearer_ip_family_build_string_from_mask (ip_family); - mm_dbg (" IP family: %s", str); + mm_obj_dbg (self, " IP family: %s", str); g_free (str); } else - mm_dbg (" IP family: %s", VALIDATE_UNSPECIFIED (NULL)); + mm_obj_dbg (self, " IP family: %s", VALIDATE_UNSPECIFIED (NULL)); allowed_auth = mm_simple_connect_properties_get_allowed_auth (ctx->properties); if (allowed_auth != MM_BEARER_ALLOWED_AUTH_UNKNOWN) { str = mm_bearer_allowed_auth_build_string_from_mask (allowed_auth); - mm_dbg (" Allowed authentication: %s", str); + mm_obj_dbg (self, " allowed authentication: %s", str); g_free (str); } else - mm_dbg (" Allowed authentication: %s", VALIDATE_UNSPECIFIED (NULL)); - - mm_dbg (" User: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_user (ctx->properties))); + mm_obj_dbg (self, " allowed authentication: %s", VALIDATE_UNSPECIFIED (NULL)); - mm_dbg (" Password: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_password (ctx->properties))); + mm_obj_dbg (self, " User: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_user (ctx->properties))); + mm_obj_dbg (self, " Password: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_password (ctx->properties))); #undef VALIDATE_UNSPECIFIED } @@ -848,7 +842,7 @@ handle_connect (MmGdbusModemSimple *skeleton, ctx->self = g_object_ref (self); ctx->dictionary = g_variant_ref (dictionary); - mm_dbg ("User request to connect modem"); + mm_obj_dbg (self, "user request to connect modem"); mm_base_modem_authorize (MM_BASE_MODEM (self), invocation, @@ -1009,10 +1003,10 @@ handle_disconnect (MmGdbusModemSimple *skeleton, * We will detect the '/' string and set the bearer path as NULL in the * context if so, and otherwise use the given input string as path */ if (g_strcmp0 (bearer_path, "/") != 0) { - mm_dbg ("User request to disconnect modem (bearer '%s')", bearer_path); + mm_obj_dbg (self, "user request to disconnect modem (bearer '%s')", bearer_path); ctx->bearer_path = g_strdup (bearer_path); } else - mm_dbg ("User request to disconnect modem (all bearers)"); + mm_obj_dbg (self, "user request to disconnect modem (all bearers)"); mm_base_modem_authorize (MM_BASE_MODEM (self), invocation, From c8c31f0613725fb638613f650614ee1d60c40dac Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:10:47 +0200 Subject: [PATCH 040/675] iface-modem-time: port to use object logging --- src/mm-iface-modem-time.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mm-iface-modem-time.c b/src/mm-iface-modem-time.c index 3aa20820..f02bc34e 100644 --- a/src/mm-iface-modem-time.c +++ b/src/mm-iface-modem-time.c @@ -19,7 +19,7 @@ #include "mm-iface-modem.h" #include "mm-iface-modem-time.h" -#include "mm-log.h" +#include "mm-log-object.h" #define SUPPORT_CHECKED_TAG "time-support-checked-tag" #define SUPPORTED_TAG "time-supported-tag" @@ -202,7 +202,7 @@ load_network_timezone_ready (MMIfaceModemTime *self, if (!tz) { NetworkTimezoneContext *ctx; - mm_dbg ("Couldn't load network timezone: %s", error->message); + mm_obj_dbg (self, "couldn't load network timezone: %s", error->message); g_error_free (error); /* Note: may be NULL if the polling has been removed while processing the async operation */ @@ -216,7 +216,7 @@ load_network_timezone_ready (MMIfaceModemTime *self, /* If no more retries, we don't do anything else */ if (ctx->network_timezone_poll_retries == 0 || !g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_RETRY)) { - mm_warn ("Couldn't load network timezone from the current network"); + mm_obj_warn (self, "couldn't load network timezone from the current network"); return; } @@ -255,7 +255,7 @@ start_network_timezone_poll (MMIfaceModemTime *self) ctx = (NetworkTimezoneContext *) g_object_get_qdata (G_OBJECT (self), network_timezone_context_quark); - mm_dbg ("Network timezone polling started"); + mm_obj_dbg (self, "network timezone polling started"); ctx->network_timezone_poll_retries = NETWORK_TIMEZONE_POLL_RETRIES; ctx->network_timezone_poll_id = g_timeout_add_seconds (NETWORK_TIMEZONE_POLL_INTERVAL_SEC, (GSourceFunc)network_timezone_poll_cb, self); } @@ -268,7 +268,7 @@ stop_network_timezone_poll (MMIfaceModemTime *self) ctx = (NetworkTimezoneContext *) g_object_get_qdata (G_OBJECT (self), network_timezone_context_quark); if (ctx->network_timezone_poll_id) { - mm_dbg ("Network timezone polling stopped"); + mm_obj_dbg (self, "network timezone polling stopped"); g_source_remove (ctx->network_timezone_poll_id); ctx->network_timezone_poll_id = 0; } @@ -322,7 +322,7 @@ start_network_timezone (MMIfaceModemTime *self) /* If loading network timezone not supported, just finish here */ if (!MM_IFACE_MODEM_TIME_GET_INTERFACE (self)->load_network_timezone || !MM_IFACE_MODEM_TIME_GET_INTERFACE (self)->load_network_timezone_finish) { - mm_dbg ("Loading network timezone is not supported"); + mm_obj_dbg (self, "loading network timezone is not supported"); return; } @@ -622,7 +622,7 @@ enable_unsolicited_events_ready (MMIfaceModemTime *self, /* Not critical! */ if (!MM_IFACE_MODEM_TIME_GET_INTERFACE (self)->enable_unsolicited_events_finish (self, res, &error)) { - mm_dbg ("Couldn't enable unsolicited events: '%s'", error->message); + mm_obj_dbg (self, "couldn't enable unsolicited events: %s", error->message); g_error_free (error); } @@ -764,7 +764,7 @@ check_support_ready (MMIfaceModemTime *self, &error)) { if (error) { /* This error shouldn't be treated as critical */ - mm_dbg ("Time support check failed: '%s'", error->message); + mm_obj_dbg (self, "time support check failed: %s", error->message); g_error_free (error); } } else { From ed41f969d5b80ae28e1841657c85b12ef5a29ad3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:17:17 +0200 Subject: [PATCH 041/675] iface-modem-voice: port to use object logging --- src/mm-iface-modem-voice.c | 163 +++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 80 deletions(-) diff --git a/src/mm-iface-modem-voice.c b/src/mm-iface-modem-voice.c index 9a57aa00..ba6b52c5 100644 --- a/src/mm-iface-modem-voice.c +++ b/src/mm-iface-modem-voice.c @@ -21,7 +21,7 @@ #include "mm-iface-modem.h" #include "mm-iface-modem-voice.h" #include "mm-call-list.h" -#include "mm-log.h" +#include "mm-log-object.h" #define CALL_LIST_POLLING_CONTEXT_TAG "voice-call-list-polling-context-tag" #define IN_CALL_EVENT_CONTEXT_TAG "voice-in-call-event-context-tag" @@ -89,14 +89,14 @@ mm_iface_modem_voice_authorize_outgoing_call (MMIfaceModemVoice *self, /* If we're not in emergency mode, the call (emergency or normal) is always allowed */ if (!emergency_only) { - mm_dbg ("voice call to %s allowed", number); + mm_obj_dbg (self, "voice call to %s allowed", number); call_allowed = TRUE; goto out; } for (i = 0; i < G_N_ELEMENTS (always_valid_emergency_numbers); i++) { if (g_strcmp0 (number, always_valid_emergency_numbers[i]) == 0) { - mm_dbg ("voice call to %s allowed: emergency call number always valid", number); + mm_obj_dbg (self, "voice call to %s allowed: emergency call number always valid", number); call_allowed = TRUE; goto out; } @@ -110,22 +110,22 @@ mm_iface_modem_voice_authorize_outgoing_call (MMIfaceModemVoice *self, /* If no SIM available, some additional numbers may be valid emergency numbers */ for (i = 0; i < G_N_ELEMENTS (no_sim_valid_emergency_numbers); i++) { if (g_strcmp0 (number, no_sim_valid_emergency_numbers[i]) == 0) { - mm_dbg ("voice call to %s allowed: emergency call number valid when no SIM", number); + mm_obj_dbg (self, "voice call to %s allowed: emergency call number valid when no SIM", number); call_allowed = TRUE; goto out; } } - mm_dbg ("voice call to %s NOT allowed: not a valid emergency call number when no SIM", number); + mm_obj_dbg (self, "voice call to %s NOT allowed: not a valid emergency call number when no SIM", number); goto out; } /* Check if the number is programmed in EF_ECC */ if (mm_base_sim_is_emergency_number (sim, number)) { - mm_dbg ("voice call to %s allowed: emergency call number programmed in the SIM", number); + mm_obj_dbg (self, "voice call to %s allowed: emergency call number programmed in the SIM", number); call_allowed = TRUE; } else - mm_dbg ("voice call to %s NOT allowed: not a valid emergency call number programmed in the SIM", number); + mm_obj_dbg (self, "voice call to %s NOT allowed: not a valid emergency call number programmed in the SIM", number); out: @@ -188,8 +188,9 @@ create_outgoing_call_from_properties (MMIfaceModemVoice *self, /* Common helper to match call info against a known call object */ static gboolean -match_single_call_info (const MMCallInfo *call_info, - MMBaseCall *call) +match_single_call_info (MMIfaceModemVoice *self, + const MMCallInfo *call_info, + MMBaseCall *call) { MMCallState state; MMCallDirection direction; @@ -242,20 +243,20 @@ match_single_call_info (const MMCallInfo *call_info, !match_terminated) return FALSE; - mm_dbg ("call info matched (matched direction/state %s, matched number %s" - ", matched index %s, matched terminated %s) with call at '%s'", - match_direction_and_state ? "yes" : "no", - match_number ? "yes" : "no", - match_index ? "yes" : "no", - match_terminated ? "yes" : "no", - mm_base_call_get_path (call)); + mm_obj_dbg (self, "call info matched (matched direction/state %s, matched number %s" + ", matched index %s, matched terminated %s) with call at '%s'", + match_direction_and_state ? "yes" : "no", + match_number ? "yes" : "no", + match_index ? "yes" : "no", + match_terminated ? "yes" : "no", + mm_base_call_get_path (call)); /* Early detect if a known incoming call that was created * from a plain CRING URC (i.e. without caller number) * needs to have the number provided. */ if (call_info->number && !number) { - mm_dbg (" number set: %s", call_info->number); + mm_obj_dbg (self, " number set: %s", call_info->number); mm_base_call_set_number (call, call_info->number); } @@ -263,20 +264,20 @@ match_single_call_info (const MMCallInfo *call_info, * not have a known call index yet. */ if (call_info->index && !idx) { - mm_dbg (" index set: %u", call_info->index); + mm_obj_dbg (self, " index set: %u", call_info->index); mm_base_call_set_index (call, call_info->index); } /* Update state if it changed */ if (call_info->state != state) { - mm_dbg (" state updated: %s", mm_call_state_get_string (call_info->state)); + mm_obj_dbg (self, " state updated: %s", mm_call_state_get_string (call_info->state)); mm_base_call_change_state (call, call_info->state, MM_CALL_STATE_REASON_UNKNOWN); } /* refresh if incoming and new state is not terminated */ if ((call_info->state != MM_CALL_STATE_TERMINATED) && (direction == MM_CALL_DIRECTION_INCOMING)) { - mm_dbg (" incoming refreshed"); + mm_obj_dbg (self, " incoming refreshed"); mm_base_call_incoming_refresh (call); } @@ -286,7 +287,8 @@ match_single_call_info (const MMCallInfo *call_info, /*****************************************************************************/ typedef struct { - const MMCallInfo *call_info; + MMIfaceModemVoice *self; + const MMCallInfo *call_info; } ReportCallForeachContext; static void @@ -302,7 +304,7 @@ report_call_foreach (MMBaseCall *call, return; /* Reset call info in context if the call info matches an existing call */ - if (match_single_call_info (ctx->call_info, call)) + if (match_single_call_info (ctx->self, ctx->call_info, call)) ctx->call_info = NULL; } @@ -322,22 +324,23 @@ mm_iface_modem_voice_report_call (MMIfaceModemVoice *self, g_assert (call_info->state != MM_CALL_STATE_UNKNOWN); /* Early debugging of the call state update */ - mm_dbg ("call at index %u: direction %s, state %s, number %s", - call_info->index, - mm_call_direction_get_string (call_info->direction), - mm_call_state_get_string (call_info->state), - call_info->number ? call_info->number : "n/a"); + mm_obj_dbg (self, "call at index %u: direction %s, state %s, number %s", + call_info->index, + mm_call_direction_get_string (call_info->direction), + mm_call_state_get_string (call_info->state), + call_info->number ? call_info->number : "n/a"); g_object_get (MM_BASE_MODEM (self), MM_IFACE_MODEM_VOICE_CALL_LIST, &list, NULL); if (!list) { - mm_warn ("Cannot process call state update: missing call list"); + mm_obj_warn (self, "cannot process call state update: missing call list"); return; } /* Iterate over all known calls and try to match a known one */ + ctx.self = self; ctx.call_info = call_info; mm_call_list_foreach (list, (MMCallListForeachFunc)report_call_foreach, &ctx); @@ -349,13 +352,13 @@ mm_iface_modem_voice_report_call (MMIfaceModemVoice *self, * reported a NEW incoming call. If that's not the case, we'll ignore the report. */ if ((call_info->direction != MM_CALL_DIRECTION_INCOMING) || ((call_info->state != MM_CALL_STATE_WAITING) && (call_info->state != MM_CALL_STATE_RINGING_IN))) { - mm_dbg ("unhandled call state update reported: direction: %s, state %s", - mm_call_direction_get_string (call_info->direction), - mm_call_state_get_string (call_info->state)); + mm_obj_dbg (self, "unhandled call state update reported: direction: %s, state %s", + mm_call_direction_get_string (call_info->direction), + mm_call_state_get_string (call_info->state)); goto out; } - mm_dbg ("Creating new incoming call..."); + mm_obj_dbg (self, "creating new incoming call..."); call = create_incoming_call (self, call_info->number); /* Set the state */ @@ -393,7 +396,8 @@ mm_iface_modem_voice_report_call (MMIfaceModemVoice *self, */ typedef struct { - GList *call_info_list; + MMIfaceModemVoice *self; + GList *call_info_list; } ReportAllCallsForeachContext; static void @@ -413,20 +417,20 @@ report_all_calls_foreach (MMBaseCall *call, MMCallInfo *call_info = (MMCallInfo *)(l->data); /* if match found, delete item from list and halt iteration right away */ - if (match_single_call_info (call_info, call)) { + if (match_single_call_info (ctx->self, call_info, call)) { ctx->call_info_list = g_list_delete_link (ctx->call_info_list, l); return; } } /* not found in list! this call is now terminated */ - mm_dbg ("Call '%s' with direction %s, state %s, number '%s', index %u" - " not found in list, terminating", - mm_base_call_get_path (call), - mm_call_direction_get_string (mm_base_call_get_direction (call)), - mm_call_state_get_string (state), - mm_base_call_get_number (call), - mm_base_call_get_index (call)); + mm_obj_dbg (ctx->self, "call '%s' with direction %s, state %s, number '%s', index %u" + " not found in list, terminating", + mm_base_call_get_path (call), + mm_call_direction_get_string (mm_base_call_get_direction (call)), + mm_call_state_get_string (state), + mm_base_call_get_number (call), + mm_base_call_get_index (call)); mm_base_call_change_state (call, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_UNKNOWN); } @@ -439,7 +443,7 @@ mm_iface_modem_voice_report_all_calls (MMIfaceModemVoice *self, GList *l; /* Early debugging of the full list of calls */ - mm_dbg ("Reported %u ongoing calls", g_list_length (call_info_list)); + mm_obj_dbg (self, "reported %u ongoing calls", g_list_length (call_info_list)); for (l = call_info_list; l; l = g_list_next (l)) { MMCallInfo *call_info = (MMCallInfo *)(l->data); @@ -447,11 +451,11 @@ mm_iface_modem_voice_report_all_calls (MMIfaceModemVoice *self, g_assert (call_info->index != 0); g_assert (call_info->state != MM_CALL_STATE_UNKNOWN); - mm_dbg ("call at index %u: direction %s, state %s, number %s", - call_info->index, - mm_call_direction_get_string (call_info->direction), - mm_call_state_get_string (call_info->state), - call_info->number ? call_info->number : "n/a"); + mm_obj_dbg (self, "call at index %u: direction %s, state %s, number %s", + call_info->index, + mm_call_direction_get_string (call_info->direction), + mm_call_state_get_string (call_info->state), + call_info->number ? call_info->number : "n/a"); } /* Retrieve list of known calls */ @@ -459,12 +463,13 @@ mm_iface_modem_voice_report_all_calls (MMIfaceModemVoice *self, MM_IFACE_MODEM_VOICE_CALL_LIST, &list, NULL); if (!list) { - mm_warn ("Cannot report all calls: missing call list"); + mm_obj_warn (self, "cannot report all calls: missing call list"); return; } /* Iterate over all the calls already known to us. * Whenever a known call is updated, it will be removed from the call info list */ + ctx.self = self; ctx.call_info_list = g_list_copy (call_info_list); mm_call_list_foreach (list, (MMCallListForeachFunc)report_all_calls_foreach, &ctx); @@ -480,9 +485,9 @@ mm_iface_modem_voice_report_all_calls (MMIfaceModemVoice *self, continue; if (call_info->direction == MM_CALL_DIRECTION_OUTGOING) { - mm_warn ("unexpected outgoing call to number '%s' reported in call list: state %s", - call_info->number ? call_info->number : "n/a", - mm_call_state_get_string (call_info->state)); + mm_obj_warn (self, "unexpected outgoing call to number '%s' reported in call list: state %s", + call_info->number ? call_info->number : "n/a", + mm_call_state_get_string (call_info->state)); continue; } @@ -492,13 +497,13 @@ mm_iface_modem_voice_report_all_calls (MMIfaceModemVoice *self, /* We only expect either RINGING-IN or WAITING states */ if ((call_info->state != MM_CALL_STATE_RINGING_IN) && (call_info->state != MM_CALL_STATE_WAITING)) { - mm_warn ("unexpected incoming call to number '%s' reported in call list: state %s", - call_info->number ? call_info->number : "n/a", - mm_call_state_get_string (call_info->state)); + mm_obj_warn (self, "unexpected incoming call to number '%s' reported in call list: state %s", + call_info->number ? call_info->number : "n/a", + mm_call_state_get_string (call_info->state)); continue; } - mm_dbg ("Creating new incoming call..."); + mm_obj_dbg (self, "creating new incoming call..."); call = create_incoming_call (self, call_info->number); /* Set the state and the index */ @@ -515,9 +520,9 @@ mm_iface_modem_voice_report_all_calls (MMIfaceModemVoice *self, continue; } - mm_warn ("unexpected call to number '%s' reported in call list: state %s, direction unknown", - call_info->number ? call_info->number : "n/a", - mm_call_state_get_string (call_info->state)); + mm_obj_warn (self, "unexpected call to number '%s' reported in call list: state %s, direction unknown", + call_info->number ? call_info->number : "n/a", + mm_call_state_get_string (call_info->state)); } g_list_free (ctx.call_info_list); g_object_unref (list); @@ -556,7 +561,7 @@ mm_iface_modem_voice_received_dtmf (MMIfaceModemVoice *self, MM_IFACE_MODEM_VOICE_CALL_LIST, &list, NULL); if (!list) { - mm_warn ("Cannot report received DTMF: missing call list"); + mm_obj_warn (self, "cannot report received DTMF: missing call list"); return; } @@ -1839,7 +1844,7 @@ setup_in_call_audio_channel_ready (MMIfaceModemVoice *self, &ctx->audio_port, &ctx->audio_format, &error)) { - mm_warn ("Couldn't setup in-call audio channel: %s", error->message); + mm_obj_warn (self, "couldn't setup in-call audio channel: %s", error->message); g_clear_error (&error); } @@ -1858,7 +1863,7 @@ setup_in_call_unsolicited_events_ready (MMIfaceModemVoice *self, ctx = g_task_get_task_data (task); if (!MM_IFACE_MODEM_VOICE_GET_INTERFACE (self)->setup_in_call_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't setup in-call unsolicited events: %s", error->message); + mm_obj_warn (self, "couldn't setup in-call unsolicited events: %s", error->message); g_clear_error (&error); } @@ -1974,7 +1979,7 @@ cleanup_in_call_unsolicited_events_ready (MMIfaceModemVoice *self, ctx = g_task_get_task_data (task); if (!MM_IFACE_MODEM_VOICE_GET_INTERFACE (self)->cleanup_in_call_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't cleanup in-call unsolicited events: %s", error->message); + mm_obj_warn (self, "couldn't cleanup in-call unsolicited events: %s", error->message); g_clear_error (&error); } @@ -1993,7 +1998,7 @@ cleanup_in_call_audio_channel_ready (MMIfaceModemVoice *self, ctx = g_task_get_task_data (task); if (!MM_IFACE_MODEM_VOICE_GET_INTERFACE (self)->cleanup_in_call_audio_channel_finish (self, res, &error)) { - mm_warn ("Couldn't cleanup in-call audio channel: %s", error->message); + mm_obj_warn (self, "couldn't cleanup in-call audio channel: %s", error->message); g_clear_error (&error); } @@ -2154,7 +2159,7 @@ update_audio_settings_in_ongoing_calls (MMIfaceModemVoice *self) MM_IFACE_MODEM_VOICE_CALL_LIST, &list, NULL); if (!list) { - mm_warn ("Cannot update audio settings in active calls: missing internal call list"); + mm_obj_warn (self, "cannot update audio settings in active calls: missing internal call list"); return; } @@ -2209,10 +2214,10 @@ in_call_cleanup_ready (MMIfaceModemVoice *self, if (!in_call_cleanup_finish (self, res, &error)) { /* ignore cancelled operations */ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - mm_warn ("Cannot cleanup in-call modem state: %s", error->message); + mm_obj_warn (self, "cannot cleanup in-call modem state: %s", error->message); g_clear_error (&error); } else { - mm_dbg ("modem is no longer in-call state"); + mm_obj_dbg (self, "modem is no longer in-call state"); ctx->in_call_state = FALSE; g_clear_object (&ctx->audio_port); g_clear_object (&ctx->audio_format); @@ -2233,10 +2238,10 @@ in_call_setup_ready (MMIfaceModemVoice *self, if (!in_call_setup_finish (self, res, &ctx->audio_port, &ctx->audio_format, &error)) { /* ignore cancelled operations */ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - mm_warn ("Cannot setup in-call modem state: %s", error->message); + mm_obj_warn (self, "cannot setup in-call modem state: %s", error->message); g_clear_error (&error); } else { - mm_dbg ("modem is now in-call state"); + mm_obj_dbg (self, "modem is now in-call state"); ctx->in_call_state = TRUE; update_audio_settings_in_ongoing_calls (self); } @@ -2258,7 +2263,7 @@ call_list_check_in_call_events (MMIfaceModemVoice *self) MM_IFACE_MODEM_VOICE_CALL_LIST, &list, NULL); if (!list) { - mm_warn ("Cannot update in-call state: missing internal call list"); + mm_obj_warn (self, "cannot update in-call state: missing internal call list"); goto out; } @@ -2277,7 +2282,7 @@ call_list_check_in_call_events (MMIfaceModemVoice *self) } /* run setup */ - mm_dbg ("Setting up in-call state..."); + mm_obj_dbg (self, "setting up in-call state..."); ctx->setup_cancellable = g_cancellable_new (); in_call_setup (self, ctx->setup_cancellable, (GAsyncReadyCallback) in_call_setup_ready, NULL); goto out; @@ -2296,7 +2301,7 @@ call_list_check_in_call_events (MMIfaceModemVoice *self) } /* run cleanup */ - mm_dbg ("Cleaning up in-call state..."); + mm_obj_dbg (self, "cleaning up in-call state..."); ctx->cleanup_cancellable = g_cancellable_new (); in_call_cleanup (self, ctx->cleanup_cancellable, (GAsyncReadyCallback) in_call_cleanup_ready, NULL); goto out; @@ -2406,7 +2411,7 @@ load_call_list_ready (MMIfaceModemVoice *self, g_assert (MM_IFACE_MODEM_VOICE_GET_INTERFACE (self)->load_call_list_finish); if (!MM_IFACE_MODEM_VOICE_GET_INTERFACE (self)->load_call_list_finish (self, res, &call_info_list, &error)) { - mm_warn ("couldn't load call list: %s", error->message); + mm_obj_warn (self, "couldn't load call list: %s", error->message); g_error_free (error); } else { /* Always report the list even if NULL (it would mean no ongoing calls) */ @@ -2458,7 +2463,7 @@ call_list_poll (MMIfaceModemVoice *self) NULL); if (!list) { - mm_warn ("Cannot poll call list: missing internal call list"); + mm_obj_warn (self, "Cannot poll call list: missing internal call list"); goto out; } @@ -2466,14 +2471,14 @@ call_list_poll (MMIfaceModemVoice *self) /* If there is at least ONE call being established, we need the call list */ if (n_calls_establishing > 0) { - mm_dbg ("%u calls being established: call list polling required", n_calls_establishing); + mm_obj_dbg (self, "%u calls being established: call list polling required", n_calls_establishing); ctx->polling_ongoing = TRUE; g_assert (MM_IFACE_MODEM_VOICE_GET_INTERFACE (self)->load_call_list); MM_IFACE_MODEM_VOICE_GET_INTERFACE (self)->load_call_list (self, (GAsyncReadyCallback)load_call_list_ready, NULL); } else - mm_dbg ("no calls being established: call list polling stopped"); + mm_obj_dbg (self, "no calls being established: call list polling stopped"); out: g_clear_object (&list); @@ -2515,7 +2520,6 @@ call_added (MMCallList *list, const gchar *call_path, MmGdbusModemVoice *skeleton) { - mm_dbg ("Added call at '%s'", call_path); update_call_list (skeleton, list); mm_gdbus_modem_voice_emit_call_added (skeleton, call_path); } @@ -2525,7 +2529,6 @@ call_deleted (MMCallList *list, const gchar *call_path, MmGdbusModemVoice *skeleton) { - mm_dbg ("Deleted call at '%s'", call_path); update_call_list (skeleton, list); mm_gdbus_modem_voice_emit_call_deleted (skeleton, call_path); } @@ -2752,7 +2755,7 @@ enable_unsolicited_events_ready (MMIfaceModemVoice *self, /* Not critical! */ if (!MM_IFACE_MODEM_VOICE_GET_INTERFACE (self)->enable_unsolicited_events_finish (self, res, &error)) { - mm_dbg ("Couldn't enable unsolicited events: '%s'", error->message); + mm_obj_dbg (self, "couldn't enable unsolicited events: %s", error->message); g_error_free (error); } @@ -2885,7 +2888,7 @@ check_support_ready (MMIfaceModemVoice *self, if (!MM_IFACE_MODEM_VOICE_GET_INTERFACE (self)->check_support_finish (self, res, &error)) { if (error) { - mm_dbg ("Voice support check failed: '%s'", error->message); + mm_obj_dbg (self, "voice support check failed: %s", error->message); g_error_free (error); } g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Voice not supported"); @@ -2981,7 +2984,7 @@ interface_initialization_step (GTask *task) MM_IFACE_MODEM_VOICE_PERIODIC_CALL_LIST_CHECK_DISABLED, &periodic_call_list_check_disabled, NULL); if (!periodic_call_list_check_disabled) { - mm_dbg ("periodic call list polling will be used if supported"); + mm_obj_dbg (self, "periodic call list polling will be used if supported"); g_signal_connect (list, MM_CALL_ADDED, G_CALLBACK (setup_call_list_polling), From c0fb9b42c02e2f3a5697ca9e5f1d814be933066d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 16:07:11 +0200 Subject: [PATCH 042/675] base-bearer: set dbus id as soon as object is created --- src/mm-base-bearer.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c index 81c281b0..d4e60c2b 100644 --- a/src/mm-base-bearer.c +++ b/src/mm-base-bearer.c @@ -76,6 +76,8 @@ static GParamSpec *properties[PROP_LAST]; struct _MMBaseBearerPrivate { /* The connection to the system bus */ GDBusConnection *connection; + guint dbus_id; + /* The modem which owns this BEARER */ MMBaseModem *modem; /* The path where the BEARER object is exported */ @@ -139,10 +141,9 @@ static const gchar *connection_forbidden_reason_str [CONNECTION_FORBIDDEN_REASON void mm_base_bearer_export (MMBaseBearer *self) { - static guint id = 0; gchar *path; - path = g_strdup_printf (MM_DBUS_BEARER_PREFIX "/%d", id++); + path = g_strdup_printf (MM_DBUS_BEARER_PREFIX "/%d", self->priv->dbus_id); g_object_set (self, MM_BASE_BEARER_PATH, path, NULL); @@ -1429,10 +1430,16 @@ get_property (GObject *object, static void mm_base_bearer_init (MMBaseBearer *self) { + static guint id = 0; + /* Initialize private data */ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_BASE_BEARER, MMBaseBearerPrivate); + + /* Each bearer is given a unique id to build its own DBus path */ + self->priv->dbus_id = id++; + self->priv->status = MM_BEARER_STATUS_DISCONNECTED; self->priv->reason_3gpp = CONNECTION_FORBIDDEN_REASON_NONE; self->priv->reason_cdma = CONNECTION_FORBIDDEN_REASON_NONE; From fce081bbb05f8c62926e5184263e3a33f17e7d83 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 16:15:00 +0200 Subject: [PATCH 043/675] base-bearer: port to use object logging --- src/mm-base-bearer.c | 103 ++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 46 deletions(-) diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c index d4e60c2b..c74eccff 100644 --- a/src/mm-base-bearer.c +++ b/src/mm-base-bearer.c @@ -35,7 +35,7 @@ #include "mm-base-bearer.h" #include "mm-base-modem-at.h" #include "mm-base-modem.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-bearer-stats.h" @@ -50,7 +50,10 @@ #define BEARER_CONNECTION_MONITOR_INITIAL_TIMEOUT 30 #define BEARER_CONNECTION_MONITOR_TIMEOUT 5 -G_DEFINE_TYPE (MMBaseBearer, mm_base_bearer, MM_GDBUS_TYPE_BEARER_SKELETON) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMBaseBearer, mm_base_bearer, MM_GDBUS_TYPE_BEARER_SKELETON, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) typedef enum { CONNECTION_FORBIDDEN_REASON_NONE, @@ -172,14 +175,14 @@ load_connection_status_ready (MMBaseBearer *self, if (status == MM_BEARER_CONNECTION_STATUS_UNKNOWN) { /* Only warn if not reporting an "unsupported" error */ if (!g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED)) { - mm_warn ("checking if connected failed: %s", error->message); + mm_obj_warn (self, "checking if connected failed: %s", error->message); g_error_free (error); return; } /* If we're being told that connection monitoring is unsupported, just * ignore the error and remove the timeout. */ - mm_dbg ("Connection monitoring is unsupported by the device"); + mm_obj_dbg (self, "connection monitoring is unsupported by the device"); self->priv->load_connection_status_unsupported = TRUE; connection_monitor_stop (self); g_error_free (error); @@ -188,7 +191,7 @@ load_connection_status_ready (MMBaseBearer *self, /* Report connection or disconnection */ g_assert (status == MM_BEARER_CONNECTION_STATUS_CONNECTED || status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED); - mm_dbg ("connection status loaded: %s", mm_bearer_connection_status_get_string (status)); + mm_obj_dbg (self, "connection status loaded: %s", mm_bearer_connection_status_get_string (status)); mm_base_bearer_report_connection_status (self, status); } @@ -284,14 +287,14 @@ reload_stats_ready (MMBaseBearer *self, if (!MM_BASE_BEARER_GET_CLASS (self)->reload_stats_finish (self, &rx_bytes, &tx_bytes, res, &error)) { /* If reloading stats fails, warn about it and don't update anything */ if (!g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED)) { - mm_warn ("Reloading stats failed: %s", error->message); + mm_obj_warn (self, "reloading stats failed: %s", error->message); g_error_free (error); return; } /* If we're being told that reloading stats is unsupported, just ignore * the error and update oly the duration timer. */ - mm_dbg ("Reloading stats is unsupported by the device"); + mm_obj_dbg (self, "reloading stats is unsupported by the device"); self->priv->reload_stats_unsupported = TRUE; rx_bytes = 0; tx_bytes = 0; @@ -414,7 +417,7 @@ bearer_update_status_connected (MMBaseBearer *self, * the bearer when ownership of the TTY is given back to MM. */ if ((ipv4_config && mm_bearer_ip_config_get_method (ipv4_config) == MM_BEARER_IP_METHOD_PPP) || (ipv6_config && mm_bearer_ip_config_get_method (ipv6_config) == MM_BEARER_IP_METHOD_PPP)) { - mm_dbg ("PPP is required for connection, will ignore disconnection reports"); + mm_obj_dbg (self, "PPP is required for connection, will ignore disconnection reports"); self->priv->ignore_disconnection_reports = TRUE; } @@ -451,7 +454,7 @@ deferred_3gpp_unregistration_cb (MMBaseBearer *self) g_warn_if_fail (self->priv->reason_3gpp == CONNECTION_FORBIDDEN_REASON_UNREGISTERED); self->priv->deferred_3gpp_unregistration_id = 0; - mm_dbg ("Forcing bearer disconnection, not registered in 3GPP network"); + mm_obj_dbg (self, "forcing bearer disconnection, not registered in 3GPP network"); mm_base_bearer_disconnect_force (self); return G_SOURCE_REMOVE; } @@ -505,7 +508,7 @@ modem_3gpp_registration_state_changed (MMIfaceModem3gpp *modem, /* Modem is roaming and roaming not allowed, report right away */ if (self->priv->reason_3gpp == CONNECTION_FORBIDDEN_REASON_ROAMING) { - mm_dbg ("Bearer not allowed to connect, registered in roaming 3GPP network"); + mm_obj_dbg (self, "bearer not allowed to connect, registered in roaming 3GPP network"); reset_deferred_unregistration (self); mm_base_bearer_disconnect_force (self); return; @@ -513,7 +516,7 @@ modem_3gpp_registration_state_changed (MMIfaceModem3gpp *modem, /* Modem is registered under emergency services only? */ if (self->priv->reason_3gpp == CONNECTION_FORBIDDEN_REASON_EMERGENCY_ONLY) { - mm_dbg ("Bearer not allowed to connect, emergency services only"); + mm_obj_dbg (self, "bearer not allowed to connect, emergency services only"); reset_deferred_unregistration (self); mm_base_bearer_disconnect_force (self); return; @@ -527,13 +530,13 @@ modem_3gpp_registration_state_changed (MMIfaceModem3gpp *modem, /* If the bearer is not connected, report right away */ if (self->priv->status != MM_BEARER_STATUS_CONNECTED) { - mm_dbg ("Bearer not allowed to connect, not registered in 3GPP network"); + mm_obj_dbg (self, "bearer not allowed to connect, not registered in 3GPP network"); mm_base_bearer_disconnect_force (self); return; } /* Otherwise, setup the new timeout */ - mm_dbg ("Connected bearer not registered in 3GPP network"); + mm_obj_dbg (self, "connected bearer not registered in 3GPP network"); self->priv->deferred_3gpp_unregistration_id = g_timeout_add_seconds (BEARER_DEFERRED_UNREGISTRATION_TIMEOUT, (GSourceFunc) deferred_3gpp_unregistration_cb, @@ -550,7 +553,7 @@ deferred_cdma_unregistration_cb (MMBaseBearer *self) g_warn_if_fail (self->priv->reason_cdma == CONNECTION_FORBIDDEN_REASON_UNREGISTERED); self->priv->deferred_cdma_unregistration_id = 0; - mm_dbg ("Forcing bearer disconnection, not registered in CDMA network"); + mm_obj_dbg (self, "forcing bearer disconnection, not registered in CDMA network"); mm_base_bearer_disconnect_force (self); return G_SOURCE_REMOVE; } @@ -592,7 +595,7 @@ modem_cdma_registration_state_changed (MMIfaceModemCdma *modem, /* Modem is roaming and roaming not allowed, report right away */ if (self->priv->reason_cdma == CONNECTION_FORBIDDEN_REASON_ROAMING) { - mm_dbg ("Bearer not allowed to connect, registered in roaming CDMA network"); + mm_obj_dbg (self, "bearer not allowed to connect, registered in roaming CDMA network"); reset_deferred_unregistration (self); mm_base_bearer_disconnect_force (self); return; @@ -606,13 +609,13 @@ modem_cdma_registration_state_changed (MMIfaceModemCdma *modem, /* If the bearer is not connected, report right away */ if (self->priv->status != MM_BEARER_STATUS_CONNECTED) { - mm_dbg ("Bearer not allowed to connect, not registered in CDMA network"); + mm_obj_dbg (self, "bearer not allowed to connect, not registered in CDMA network"); mm_base_bearer_disconnect_force (self); return; } /* Otherwise, setup the new timeout */ - mm_dbg ("Connected bearer not registered in CDMA network"); + mm_obj_dbg (self, "connected bearer not registered in CDMA network"); self->priv->deferred_cdma_unregistration_id = g_timeout_add_seconds (BEARER_DEFERRED_UNREGISTRATION_TIMEOUT, (GSourceFunc) deferred_cdma_unregistration_cb, @@ -701,14 +704,11 @@ disconnect_after_cancel_ready (MMBaseBearer *self, GError *error = NULL; if (!MM_BASE_BEARER_GET_CLASS (self)->disconnect_finish (self, res, &error)) { - mm_warn ("Error disconnecting bearer '%s': '%s'. " - "Will assume disconnected anyway.", - self->priv->path, - error->message); + mm_obj_warn (self, "error disconnecting: %s; will assume disconnected anyway", error->message); g_error_free (error); } else - mm_dbg ("Disconnected bearer '%s'", self->priv->path); + mm_obj_dbg (self, "disconnected bearer '%s'", self->priv->path); /* Report disconnection to the bearer object using class method * mm_bearer_report_connection_status. This gives subclass implementations a @@ -730,9 +730,7 @@ connect_ready (MMBaseBearer *self, /* NOTE: connect() implementations *MUST* handle cancellations themselves */ result = MM_BASE_BEARER_GET_CLASS (self)->connect_finish (self, res, &error); if (!result) { - mm_dbg ("Couldn't connect bearer '%s': '%s'", - self->priv->path, - error->message); + mm_obj_dbg (self, "couldn't connect: '%s'", error->message); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { /* Will launch disconnection */ launch_disconnect = TRUE; @@ -741,14 +739,14 @@ connect_ready (MMBaseBearer *self, } /* Handle cancellations detected after successful connection */ else if (g_cancellable_is_cancelled (self->priv->connect_cancellable)) { - mm_dbg ("Connected bearer '%s', but need to disconnect", self->priv->path); + mm_obj_dbg (self, "connected, but need to disconnect"); mm_bearer_connect_result_unref (result); error = g_error_new (G_IO_ERROR, G_IO_ERROR_CANCELLED, "Bearer got connected, but had to disconnect after cancellation request"); launch_disconnect = TRUE; } else { - mm_dbg ("Connected bearer '%s'", self->priv->path); + mm_obj_dbg (self, "connected"); /* Update bearer and interface status */ bearer_update_status_connected ( @@ -864,7 +862,7 @@ mm_base_bearer_connect (MMBaseBearer *self, } /* Connecting! */ - mm_dbg ("Connecting bearer '%s'", self->priv->path); + mm_obj_dbg (self, "connecting..."); self->priv->connect_cancellable = g_cancellable_new (); bearer_update_status (self, MM_BEARER_STATUS_CONNECTING); bearer_reset_interface_stats (self); @@ -936,7 +934,7 @@ handle_connect (MMBaseBearer *self, MM_BASE_BEARER_MODEM, &ctx->modem, NULL); - mm_dbg ("User request to connect bearer '%s'", self->priv->path); + mm_obj_dbg (self, "user request to connect"); mm_base_modem_authorize (ctx->modem, invocation, @@ -965,12 +963,12 @@ disconnect_ready (MMBaseBearer *self, GError *error = NULL; if (!MM_BASE_BEARER_GET_CLASS (self)->disconnect_finish (self, res, &error)) { - mm_dbg ("Couldn't disconnect bearer '%s': %s", self->priv->path, error->message); + mm_obj_dbg (self, "couldn't disconnect: %s", error->message); bearer_update_status (self, MM_BEARER_STATUS_CONNECTED); g_task_return_error (task, error); } else { - mm_dbg ("Disconnected bearer '%s'", self->priv->path); + mm_obj_dbg (self, "disconnected"); bearer_update_status (self, MM_BEARER_STATUS_DISCONNECTED); g_task_return_boolean (task, TRUE); } @@ -988,8 +986,7 @@ status_changed_complete_disconnect (MMBaseBearer *self, if (self->priv->status != MM_BEARER_STATUS_DISCONNECTED) return; - mm_dbg ("Disconnected bearer '%s' after cancelling previous connect request", - self->priv->path); + mm_obj_dbg (self, "disconnected after cancelling previous connect request"); g_signal_handler_disconnect (self, self->priv->disconnect_signal_handler); self->priv->disconnect_signal_handler = 0; @@ -1038,7 +1035,7 @@ mm_base_bearer_disconnect (MMBaseBearer *self, return; } - mm_dbg ("Disconnecting bearer '%s'", self->priv->path); + mm_obj_dbg (self, "disconnecting..."); /* If currently connecting, try to cancel that operation, and wait to get * disconnected. */ @@ -1129,7 +1126,7 @@ handle_disconnect (MMBaseBearer *self, MM_BASE_BEARER_MODEM, &ctx->modem, NULL); - mm_dbg ("User request to disconnect bearer '%s'", self->priv->path); + mm_obj_dbg (self, "user request to disconnect"); mm_base_modem_authorize (ctx->modem, invocation, @@ -1160,9 +1157,7 @@ base_bearer_dbus_export (MMBaseBearer *self) self->priv->connection, self->priv->path, &error)) { - mm_warn ("couldn't export BEARER at '%s': '%s'", - self->priv->path, - error->message); + mm_obj_warn (self, "couldn't export to bus: %s", error->message); g_error_free (error); } } @@ -1175,7 +1170,7 @@ base_bearer_dbus_unexport (MMBaseBearer *self) path = g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (self)); /* Only unexport if currently exported */ if (path) { - mm_dbg ("Removing from DBus bearer at '%s'", path); + mm_obj_dbg (self, "removing from bus"); g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self)); } } @@ -1223,14 +1218,11 @@ disconnect_force_ready (MMBaseBearer *self, GError *error = NULL; if (!MM_BASE_BEARER_GET_CLASS (self)->disconnect_finish (self, res, &error)) { - mm_warn ("Error disconnecting bearer '%s': '%s'. " - "Will assume disconnected anyway.", - self->priv->path, - error->message); + mm_obj_warn (self, "error disconnecting: %s; will assume disconnected anyway", error->message); g_error_free (error); } else - mm_dbg ("Disconnected bearer '%s'", self->priv->path); + mm_obj_dbg (self, "disconnected"); /* Report disconnection to the bearer object using class method * mm_bearer_report_connection_status. This gives subclass implementations a @@ -1247,7 +1239,7 @@ mm_base_bearer_disconnect_force (MMBaseBearer *self) self->priv->status == MM_BEARER_STATUS_DISCONNECTED) return; - mm_dbg ("Forcing disconnection of bearer '%s'", self->priv->path); + mm_obj_dbg (self, "forcing disconnection"); /* If currently connecting, try to cancel that operation. */ if (self->priv->status == MM_BEARER_STATUS_CONNECTING) { @@ -1311,7 +1303,7 @@ mm_base_bearer_report_connection_status (MMBaseBearer *self, MMBearerConnectionStatus status) { if ((status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED) && self->priv->ignore_disconnection_reports) { - mm_dbg ("ignoring disconnection report for bearer '%s'", self->priv->path); + mm_obj_dbg (self, "ignoring disconnection report"); return; } @@ -1320,6 +1312,17 @@ mm_base_bearer_report_connection_status (MMBaseBearer *self, /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMBaseBearer *self; + + self = MM_BASE_BEARER (_self); + return g_strdup_printf ("bearer%u", self->priv->dbus_id); +} + +/*****************************************************************************/ + static void set_property (GObject *object, guint prop_id, @@ -1352,6 +1355,8 @@ set_property (GObject *object, g_clear_object (&self->priv->modem); self->priv->modem = g_value_dup_object (value); if (self->priv->modem) { + /* Set owner ID */ + mm_log_object_set_owner_id (MM_LOG_OBJECT (self), mm_log_object_get_id (MM_LOG_OBJECT (self->priv->modem))); /* Bind the modem's connection (which is set when it is exported, * and unset when unexported) to the BEARER's connection */ g_object_bind_property (self->priv->modem, MM_BASE_MODEM_CONNECTION, @@ -1491,6 +1496,12 @@ dispose (GObject *object) G_OBJECT_CLASS (mm_base_bearer_parent_class)->dispose (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_base_bearer_class_init (MMBaseBearerClass *klass) { From b2d3ff0b3d77e2c859a37dcb0e3d67350c81c4c1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 17:30:25 +0200 Subject: [PATCH 044/675] broadband-bearer: port to use object logging --- src/mm-broadband-bearer.c | 195 +++++++++++++++++++++----------------- 1 file changed, 109 insertions(+), 86 deletions(-) diff --git a/src/mm-broadband-bearer.c b/src/mm-broadband-bearer.c index 29c1d2dd..1b1892fc 100644 --- a/src/mm-broadband-bearer.c +++ b/src/mm-broadband-bearer.c @@ -32,7 +32,7 @@ #include "mm-iface-modem-3gpp.h" #include "mm-iface-modem-cdma.h" #include "mm-base-modem-at.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-port-enums-types.h" #include "mm-helper-enums-types.h" @@ -93,7 +93,7 @@ select_bearer_ip_family (MMBroadbandBearer *self) ip_family = mm_base_bearer_get_default_ip_family (MM_BASE_BEARER (self)); default_family = mm_bearer_ip_family_build_string_from_mask (ip_family); - mm_dbg ("No specific IP family requested, defaulting to %s", default_family); + mm_obj_dbg (self, "no specific IP family requested, defaulting to %s", default_family); g_free (default_family); } @@ -159,8 +159,9 @@ detailed_connect_context_new (MMBroadbandBearer *self, /* Generic implementations (both 3GPP and CDMA) are always AT-port based */ static MMPortSerialAt * -common_get_at_data_port (MMBaseModem *modem, - GError **error) +common_get_at_data_port (MMBroadbandBearer *self, + MMBaseModem *modem, + GError **error) { MMPort *data; @@ -181,7 +182,7 @@ common_get_at_data_port (MMBaseModem *modem, return NULL; } - mm_dbg ("Connection through a plain serial AT port (%s)", mm_port_get_device (data)); + mm_obj_dbg (self, "connection through a plain serial AT port: %s", mm_port_get_device (data)); return MM_PORT_SERIAL_AT (g_object_ref (data)); } @@ -198,39 +199,39 @@ common_get_at_data_port (MMBaseModem *modem, */ static void -dial_cdma_ready (MMBaseModem *modem, +dial_cdma_ready (MMBaseModem *modem, GAsyncResult *res, - GTask *task) + GTask *task) { - MMBroadbandBearer *self; + MMBroadbandBearer *self; DetailedConnectContext *ctx; - GError *error = NULL; - MMBearerIpConfig *config; + GError *error = NULL; + MMBearerIpConfig *config; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* DO NOT check for cancellable here. If we got here without errors, the * bearer is really connected and therefore we need to reflect that in * the state machine. */ mm_base_modem_at_command_full_finish (modem, res, &error); if (error) { - mm_warn ("Couldn't connect: '%s'", error->message); + mm_obj_warn (self, "couldn't connect: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; } - self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); - /* Configure flow control to use while connected */ if (self->priv->flow_control != MM_FLOW_CONTROL_NONE) { gchar *flow_control_str; flow_control_str = mm_flow_control_build_string_from_mask (self->priv->flow_control); - mm_dbg ("[%s] Setting flow control: %s", mm_port_get_device (ctx->data), flow_control_str); + mm_obj_dbg (self, "setting flow control in %s: %s", mm_port_get_device (ctx->data), flow_control_str); g_free (flow_control_str); if (!mm_port_serial_set_flow_control (MM_PORT_SERIAL (ctx->data), self->priv->flow_control, &error)) { - mm_warn ("Couldn't set flow control settings: %s", error->message); + mm_obj_warn (self, "couldn't set flow control settings in %s: %s", mm_port_get_device (ctx->data), error->message); g_clear_error (&error); } } @@ -291,7 +292,7 @@ set_rm_protocol_ready (MMBaseModem *self, mm_base_modem_at_command_full_finish (self, res, &error); if (error) { - mm_warn ("Couldn't set RM protocol: '%s'", error->message); + mm_obj_warn (self, "couldn't set RM protocol: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -319,7 +320,7 @@ current_rm_protocol_ready (MMBaseModem *self, result = mm_base_modem_at_command_full_finish (self, res, &error); if (error) { - mm_warn ("Couldn't query current RM protocol: '%s'", error->message); + mm_obj_warn (self, "couldn't query current RM protocol: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -329,9 +330,7 @@ current_rm_protocol_ready (MMBaseModem *self, current_index = (guint) atoi (result); current_rm = mm_cdma_get_rm_protocol_from_index (current_index, &error); if (error) { - mm_warn ("Couldn't parse RM protocol reply (%s): '%s'", - result, - error->message); + mm_obj_warn (self, "couldn't parse RM protocol reply (%s): %s", result, error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -342,14 +341,13 @@ current_rm_protocol_ready (MMBaseModem *self, guint new_index; gchar *command; - mm_dbg ("Setting requested RM protocol..."); + mm_obj_dbg (self, "setting requested RM protocol..."); new_index = (mm_cdma_get_index_from_rm_protocol ( mm_bearer_properties_get_rm_protocol (mm_base_bearer_peek_config (MM_BASE_BEARER (self))), &error)); if (error) { - mm_warn ("Cannot set RM protocol: '%s'", - error->message); + mm_obj_warn (self, "cannot set RM protocol: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -396,7 +394,7 @@ connect_cdma (MMBroadbandBearer *self, /* Grab dial port. This gets a reference to the dial port and OPENs it. * If we fail, we'll need to close it ourselves. */ - ctx->data = (MMPort *)common_get_at_data_port (ctx->modem, &error); + ctx->data = (MMPort *)common_get_at_data_port (self, ctx->modem, &error); if (!ctx->data) { g_task_return_error (task, error); g_object_unref (task); @@ -408,7 +406,7 @@ connect_cdma (MMBroadbandBearer *self, mm_base_bearer_peek_config (MM_BASE_BEARER (self))) != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) { /* Need to query current RM protocol */ - mm_dbg ("Querying current RM protocol set..."); + mm_obj_dbg (self, "querying current RM protocol set..."); mm_base_modem_at_command_full (ctx->modem, ctx->primary, "+CRM?", @@ -531,11 +529,11 @@ atd_ready (MMBaseModem *modem, GError *error = NULL; flow_control_str = mm_flow_control_build_string_from_mask (self->priv->flow_control); - mm_dbg ("[%s] Setting flow control: %s", mm_port_get_device (MM_PORT (ctx->dial_port)), flow_control_str); + mm_obj_dbg (self, "setting flow control in %s: %s", mm_port_get_device (MM_PORT (ctx->dial_port)), flow_control_str); g_free (flow_control_str); if (!mm_port_serial_set_flow_control (MM_PORT_SERIAL (ctx->dial_port), self->priv->flow_control, &error)) { - mm_warn ("Couldn't set flow control settings: %s", error->message); + mm_obj_warn (self, "couldn't set flow control settings in %s: %s", mm_port_get_device (MM_PORT (ctx->dial_port)), error->message); g_clear_error (&error); } } @@ -576,7 +574,7 @@ dial_3gpp (MMBroadbandBearer *self, /* Grab dial port. This gets a reference to the dial port and OPENs it. * If we fail, we'll need to close it ourselves. */ - ctx->dial_port = common_get_at_data_port (ctx->modem, &error); + ctx->dial_port = common_get_at_data_port (self, ctx->modem, &error); if (!ctx->dial_port) { g_task_return_error (task, error); g_object_unref (task); @@ -653,14 +651,16 @@ cgdcont_set_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { + MMBroadbandBearer *self; CidSelection3gppContext *ctx; GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); mm_base_modem_at_command_full_finish (modem, res, &error); if (error) { - mm_warn ("Couldn't initialize context: '%s'", error->message); + mm_obj_warn (self, "couldn't initialize context: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -686,9 +686,9 @@ cid_selection_3gpp_initialize_context (GTask *task) /* Initialize a PDP context with our APN and PDP type */ apn = mm_bearer_properties_get_apn (mm_base_bearer_peek_config (MM_BASE_BEARER (self))); - mm_dbg ("%s context with APN '%s' and PDP type '%s'", - ctx->cid_overwritten ? "Overwriting" : "Initializing", - apn, ctx->pdp_type); + mm_obj_dbg (self, "%s context with APN '%s' and PDP type '%s'", + ctx->cid_overwritten ? "overwriting" : "initializing", + apn, ctx->pdp_type); quoted_apn = mm_port_serial_at_quote_string (apn); cmd = g_strdup_printf ("+CGDCONT=%u,\"%s\",%s", ctx->cid, ctx->pdp_type, quoted_apn); g_free (quoted_apn); @@ -738,17 +738,19 @@ cgdcont_query_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { + MMBroadbandBearer *self; CidSelection3gppContext *ctx; GError *error = NULL; const gchar *response; GList *l; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mm_base_modem_at_command_full_finish (modem, res, &error); if (!response) { /* Ignore errors */ - mm_dbg ("Failed checking currently defined contexts: %s", error->message); + mm_obj_dbg (self, "failed checking currently defined contexts: %s", error->message); g_clear_error (&error); goto out; } @@ -757,24 +759,24 @@ cgdcont_query_ready (MMBaseModem *modem, ctx->context_list = mm_3gpp_parse_cgdcont_read_response (response, &error); if (!ctx->context_list) { if (error) { - mm_dbg ("Failed parsing currently defined contexts: %s", error->message); + mm_obj_dbg (self, "failed parsing currently defined contexts: %s", error->message); g_clear_error (&error); } else - mm_dbg ("No contexts currently defined"); + mm_obj_dbg (self, "no contexts currently defined"); goto out; } /* Show all found PDP contexts in debug log */ - mm_dbg ("Found '%u' PDP contexts", g_list_length (ctx->context_list)); + mm_obj_dbg (self, "found %u PDP contexts", g_list_length (ctx->context_list)); for (l = ctx->context_list; l; l = g_list_next (l)) { MM3gppPdpContext *pdp = l->data; gchar *ip_family_str; ip_family_str = mm_bearer_ip_family_build_string_from_mask (pdp->pdp_type); - mm_dbg (" PDP context [cid=%u] [type='%s'] [apn='%s']", - pdp->cid, - ip_family_str, - pdp->apn ? pdp->apn : ""); + mm_obj_dbg (self, " PDP context [cid=%u] [type='%s'] [apn='%s']", + pdp->cid, + ip_family_str, + pdp->apn ? pdp->apn : ""); g_free (ip_family_str); } @@ -786,11 +788,13 @@ cgdcont_query_ready (MMBaseModem *modem, static void cid_selection_3gpp_query_current (GTask *task) { + MMBroadbandBearer *self; CidSelection3gppContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); - mm_dbg ("Checking currently defined contexts..."); + mm_obj_dbg (self, "checking currently defined contexts..."); mm_base_modem_at_command_full (ctx->modem, ctx->primary, "+CGDCONT?", @@ -807,23 +811,25 @@ cgdcont_test_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { + MMBroadbandBearer *self; CidSelection3gppContext *ctx; GError *error = NULL; const gchar *response; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mm_base_modem_at_command_full_finish (modem, res, &error); if (!response) { /* Ignore errors */ - mm_dbg ("Failed checking context definition format: %s", error->message); + mm_obj_dbg (self, "failed checking context definition format: %s", error->message); g_clear_error (&error); goto out; } ctx->context_format_list = mm_3gpp_parse_cgdcont_test_response (response, &error); if (error) { - mm_dbg ("Error parsing +CGDCONT test response: '%s'", error->message); + mm_obj_dbg (self, "error parsing +CGDCONT test response: %s", error->message); g_clear_error (&error); goto out; } @@ -836,11 +842,13 @@ cgdcont_test_ready (MMBaseModem *modem, static void cid_selection_3gpp_query_format (GTask *task) { + MMBroadbandBearer *self; CidSelection3gppContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); - mm_dbg ("Checking context definition format..."); + mm_obj_dbg (self, "checking context definition format..."); mm_base_modem_at_command_full (ctx->modem, ctx->primary, "+CGDCONT=?", @@ -1309,7 +1317,7 @@ connect (MMBaseBearer *self, /* If the modem has 3GPP capabilities and an APN, launch 3GPP-based connection */ if (mm_iface_modem_is_3gpp (MM_IFACE_MODEM (modem)) && apn) { - mm_dbg ("Launching 3GPP connection attempt with APN '%s'", apn); + mm_obj_dbg (self, "launching 3GPP connection attempt with APN '%s'", apn); MM_BROADBAND_BEARER_GET_CLASS (self)->connect_3gpp ( MM_BROADBAND_BEARER (self), MM_BROADBAND_MODEM (modem), @@ -1324,7 +1332,7 @@ connect (MMBaseBearer *self, /* Otherwise, launch CDMA-specific connection. */ if (mm_iface_modem_is_cdma (MM_IFACE_MODEM (modem)) && !apn) { - mm_dbg ("Launching 3GPP2 connection attempt"); + mm_obj_dbg (self, "launching 3GPP2 connection attempt"); MM_BROADBAND_BEARER_GET_CLASS (self)->connect_cdma ( MM_BROADBAND_BEARER (self), MM_BROADBAND_MODEM (modem), @@ -1397,9 +1405,12 @@ detailed_disconnect_context_new (MMBroadbandModem *modem, static void data_flash_cdma_ready (MMPortSerial *data, GAsyncResult *res, - GTask *task) + GTask *task) { - GError *error = NULL; + MMBroadbandBearer *self; + GError *error = NULL; + + self = g_task_get_source_object (task); mm_port_serial_flash_finish (data, res, &error); @@ -1426,7 +1437,7 @@ data_flash_cdma_ready (MMPortSerial *data, return; } - mm_dbg ("Port flashing failed (not fatal): %s", error->message); + mm_obj_dbg (self, "port flashing failed (not fatal): %s", error->message); g_error_free (error); } @@ -1442,8 +1453,12 @@ data_reopen_cdma_ready (MMPortSerial *data, GAsyncResult *res, GTask *task) { + MMBroadbandBearer *self; DetailedDisconnectContext *ctx; - GError *error = NULL; + GError *error = NULL; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); g_object_set (data, MM_PORT_SERIAL_AT_INIT_SEQUENCE_ENABLED, TRUE, NULL); @@ -1454,10 +1469,8 @@ data_reopen_cdma_ready (MMPortSerial *data, return; } - ctx = g_task_get_task_data (task); - /* Just flash the data port */ - mm_dbg ("Flashing data port (%s)...", mm_port_get_device (MM_PORT (ctx->data))); + mm_obj_dbg (self, "flashing data port %s...", mm_port_get_device (MM_PORT (ctx->data))); mm_port_serial_flash (MM_PORT_SERIAL (ctx->data), 1000, TRUE, @@ -1492,7 +1505,7 @@ disconnect_cdma (MMBroadbandBearer *self, g_object_set (data, MM_PORT_SERIAL_AT_INIT_SEQUENCE_ENABLED, FALSE, NULL); /* Fully reopen the port before flashing */ - mm_dbg ("Reopening data port (%s)...", mm_port_get_device (MM_PORT (ctx->data))); + mm_obj_dbg (self, "reopening data port %s...", mm_port_get_device (MM_PORT (ctx->data))); mm_port_serial_reopen (MM_PORT_SERIAL (ctx->data), 1000, (GAsyncReadyCallback)data_reopen_cdma_ready, @@ -1503,17 +1516,19 @@ disconnect_cdma (MMBroadbandBearer *self, /* 3GPP disconnect */ static void -cgact_data_ready (MMBaseModem *modem, +cgact_data_ready (MMBaseModem *modem, GAsyncResult *res, - GTask *task) + GTask *task) { + MMBroadbandBearer *self; + GError *error = NULL; - GError *error = NULL; + self = g_task_get_source_object (task); /* Ignore errors for now */ mm_base_modem_at_command_full_finish (modem, res, &error); if (error) { - mm_dbg ("PDP context deactivation failed (not fatal): %s", error->message); + mm_obj_dbg (self, "PDP context deactivation failed (not fatal): %s", error->message); g_error_free (error); } @@ -1524,12 +1539,14 @@ cgact_data_ready (MMBaseModem *modem, static void data_flash_3gpp_ready (MMPortSerial *data, GAsyncResult *res, - GTask *task) + GTask *task) { + MMBroadbandBearer *self; DetailedDisconnectContext *ctx; - GError *error = NULL; + GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); mm_port_serial_flash_finish (data, res, &error); @@ -1556,7 +1573,7 @@ data_flash_3gpp_ready (MMPortSerial *data, return; } - mm_dbg ("Port flashing failed (not fatal): %s", error->message); + mm_obj_dbg (self, "port flashing failed (not fatal): %s", error->message); g_error_free (error); } @@ -1566,7 +1583,7 @@ data_flash_3gpp_ready (MMPortSerial *data, /* Don't bother doing the CGACT again if it was already done on the * primary or secondary port */ if (ctx->cgact_sent) { - mm_dbg ("PDP disconnection already sent"); + mm_obj_dbg (self, "PDP disconnection already sent"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -1578,9 +1595,9 @@ data_flash_3gpp_ready (MMPortSerial *data, * port when the CGACT is sent on the separte data port. */ if (MM_PORT_SERIAL (ctx->primary) == data) - mm_dbg ("Sending PDP context deactivation in primary/data port..."); + mm_obj_dbg (self, "sending PDP context deactivation in primary/data port..."); else - mm_dbg ("Sending PDP context deactivation in primary port again..."); + mm_obj_dbg (self, "sending PDP context deactivation in primary port again..."); mm_base_modem_at_command_full (ctx->modem, ctx->primary, @@ -1596,10 +1613,14 @@ data_flash_3gpp_ready (MMPortSerial *data, static void data_reopen_3gpp_ready (MMPortSerial *data, GAsyncResult *res, - GTask *task) + GTask *task) { + MMBroadbandBearer *self; DetailedDisconnectContext *ctx; - GError *error = NULL; + GError *error = NULL; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); g_object_set (data, MM_PORT_SERIAL_AT_INIT_SEQUENCE_ENABLED, TRUE, NULL); @@ -1610,10 +1631,8 @@ data_reopen_3gpp_ready (MMPortSerial *data, return; } - ctx = g_task_get_task_data (task); - /* Just flash the data port */ - mm_dbg ("Flashing data port (%s)...", mm_port_get_device (MM_PORT (ctx->data))); + mm_obj_dbg (self, "flashing data port %s...", mm_port_get_device (MM_PORT (ctx->data))); mm_port_serial_flash (MM_PORT_SERIAL (ctx->data), 1000, TRUE, @@ -1624,16 +1643,18 @@ data_reopen_3gpp_ready (MMPortSerial *data, static void data_reopen_3gpp (GTask *task) { + MMBroadbandBearer *self; DetailedDisconnectContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* We don't want to run init sequence right away during the reopen, as we're * going to flash afterwards. */ g_object_set (ctx->data, MM_PORT_SERIAL_AT_INIT_SEQUENCE_ENABLED, FALSE, NULL); /* Fully reopen the port before flashing */ - mm_dbg ("Reopening data port (%s)...", mm_port_get_device (MM_PORT (ctx->data))); + mm_obj_dbg (self, "reopening data port %s...", mm_port_get_device (MM_PORT (ctx->data))); mm_port_serial_reopen (MM_PORT_SERIAL (ctx->data), 1000, (GAsyncReadyCallback)data_reopen_3gpp_ready, @@ -1641,20 +1662,22 @@ data_reopen_3gpp (GTask *task) } static void -cgact_ready (MMBaseModem *modem, +cgact_ready (MMBaseModem *modem, GAsyncResult *res, - GTask *task) + GTask *task) { + MMBroadbandBearer *self; DetailedDisconnectContext *ctx; - GError *error = NULL; + GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); mm_base_modem_at_command_full_finish (modem, res, &error); if (!error) ctx->cgact_sent = TRUE; else { - mm_dbg ("PDP context deactivation failed (not fatal): %s", error->message); + mm_obj_dbg (self, "PDP context deactivation failed (not fatal): %s", error->message); g_error_free (error); } @@ -1692,7 +1715,7 @@ disconnect_3gpp (MMBroadbandBearer *self, /* If the primary port is NOT connected (doesn't have to be the data port), * we'll send CGACT there */ if (!mm_port_get_connected (MM_PORT (ctx->primary))) { - mm_dbg ("Sending PDP context deactivation in primary port..."); + mm_obj_dbg (self, "sending PDP context deactivation in primary port..."); mm_base_modem_at_command_full (ctx->modem, ctx->primary, ctx->cgact_command, @@ -1711,7 +1734,7 @@ disconnect_3gpp (MMBroadbandBearer *self, * driver doesn't support it). */ if (ctx->secondary) { - mm_dbg ("Sending PDP context deactivation in secondary port..."); + mm_obj_dbg (self, "sending PDP context deactivation in secondary port..."); mm_base_modem_at_command_full (ctx->modem, ctx->secondary, ctx->cgact_command, @@ -1811,7 +1834,7 @@ disconnect (MMBaseBearer *self, task = g_task_new (self, NULL, callback, user_data); if (!MM_BROADBAND_BEARER (self)->priv->port) { - mm_dbg ("No need to disconnect: bearer is already disconnected"); + mm_obj_dbg (self, "no need to disconnect: bearer is already disconnected"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; From ba89d59471a92ac0b5caabdd03d3b199b1cf8ab5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:25:25 +0200 Subject: [PATCH 045/675] bearer-qmi: port to use object logging --- src/mm-bearer-qmi.c | 139 ++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 69 deletions(-) diff --git a/src/mm-bearer-qmi.c b/src/mm-bearer-qmi.c index ece92275..4ec93d7f 100644 --- a/src/mm-bearer-qmi.c +++ b/src/mm-bearer-qmi.c @@ -31,7 +31,7 @@ #include "mm-bearer-qmi.h" #include "mm-modem-helpers-qmi.h" #include "mm-port-enums-types.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" G_DEFINE_TYPE (MMBearerQmi, mm_bearer_qmi, MM_TYPE_BASE_BEARER) @@ -537,11 +537,14 @@ start_network_ready (QmiClientWds *client, GAsyncResult *res, GTask *task) { + MMBearerQmi *self; ConnectContext *ctx; GError *error = NULL; QmiMessageWdsStartNetworkOutput *output; - ctx = g_task_get_task_data (task); + self = g_task_get_task_data (task); + ctx = g_task_get_task_data (task); + g_assert (ctx->running_ipv4 || ctx->running_ipv6); g_assert (!(ctx->running_ipv4 && ctx->running_ipv6)); @@ -565,7 +568,7 @@ start_network_ready (QmiClientWds *client, /* Fall down to a successful connection */ } else { - mm_info ("error: couldn't start network: %s", error->message); + mm_obj_info (self, "couldn't start network: %s", error->message); if (g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_CALL_FAILED)) { @@ -577,20 +580,18 @@ start_network_ready (QmiClientWds *client, output, &cer, NULL)) - mm_info ("call end reason (%u): '%s'", - cer, - qmi_wds_call_end_reason_get_string (cer)); + mm_obj_info (self, "call end reason (%u): %s", cer, qmi_wds_call_end_reason_get_string (cer)); if (qmi_message_wds_start_network_output_get_verbose_call_end_reason ( output, &verbose_cer_type, &verbose_cer_reason, NULL)) - mm_info ("verbose call end reason (%u,%d): [%s] %s", - verbose_cer_type, - verbose_cer_reason, - qmi_wds_verbose_call_end_reason_type_get_string (verbose_cer_type), - qmi_wds_verbose_call_end_reason_get_string (verbose_cer_type, verbose_cer_reason)); + mm_obj_info (self, "verbose call end reason (%u,%d): [%s] %s", + verbose_cer_type, + verbose_cer_reason, + qmi_wds_verbose_call_end_reason_type_get_string (verbose_cer_type), + qmi_wds_verbose_call_end_reason_get_string (verbose_cer_type, verbose_cer_reason)); } } } @@ -693,7 +694,7 @@ get_ipv4_config (MMBearerQmi *self, /* IPv4 subnet mask */ if (!qmi_message_wds_get_current_settings_output_get_ipv4_gateway_subnet_mask (output, &addr, &error)) { - mm_warn ("Failed to read IPv4 netmask (%s)", error->message); + mm_obj_warn (self, "failed to read IPv4 netmask: %s", error->message); g_clear_error (&error); return NULL; } @@ -702,12 +703,12 @@ get_ipv4_config (MMBearerQmi *self, /* IPv4 address */ if (!qmi_message_wds_get_current_settings_output_get_ipv4_address (output, &addr, &error)) { - mm_warn ("IPv4 family but no IPv4 address (%s)", error->message); + mm_obj_warn (self, "IPv4 family but no IPv4 address: %s", error->message); g_clear_error (&error); return NULL; } - mm_info ("QMI IPv4 Settings:"); + mm_obj_info (self, "QMI IPv4 Settings:"); config = mm_bearer_ip_config_new (); mm_bearer_ip_config_set_method (config, ip_method); @@ -716,15 +717,15 @@ get_ipv4_config (MMBearerQmi *self, qmi_inet4_ntop (addr, buf, sizeof (buf)); mm_bearer_ip_config_set_address (config, buf); mm_bearer_ip_config_set_prefix (config, prefix); - mm_info (" Address: %s/%d", buf, prefix); + mm_obj_info (self, " address: %s/%d", buf, prefix); /* IPv4 gateway address */ if (qmi_message_wds_get_current_settings_output_get_ipv4_gateway_address (output, &addr, &error)) { qmi_inet4_ntop (addr, buf, sizeof (buf)); mm_bearer_ip_config_set_gateway (config, buf); - mm_info (" Gateway: %s", buf); + mm_obj_info (self, " gateway: %s", buf); } else { - mm_info (" Gateway: failed (%s)", error->message); + mm_obj_info (self, " gateway: failed (%s)", error->message); g_clear_error (&error); } @@ -732,9 +733,9 @@ get_ipv4_config (MMBearerQmi *self, if (qmi_message_wds_get_current_settings_output_get_primary_ipv4_dns_address (output, &addr, &error)) { qmi_inet4_ntop (addr, buf, sizeof (buf)); dns[dns_idx++] = buf; - mm_info (" DNS #1: %s", buf); + mm_obj_info (self, " DNS #1: %s", buf); } else { - mm_info (" DNS #1: failed (%s)", error->message); + mm_obj_info (self, " DNS #1: failed (%s)", error->message); g_clear_error (&error); } @@ -742,9 +743,9 @@ get_ipv4_config (MMBearerQmi *self, if (qmi_message_wds_get_current_settings_output_get_secondary_ipv4_dns_address (output, &addr, &error)) { qmi_inet4_ntop (addr, buf2, sizeof (buf2)); dns[dns_idx++] = buf2; - mm_info (" DNS #2: %s", buf2); + mm_obj_info (self, " DNS #2: %s", buf2); } else { - mm_info (" DNS #2: failed (%s)", error->message); + mm_obj_info (self, " DNS #2: failed (%s)", error->message); g_clear_error (&error); } @@ -753,7 +754,7 @@ get_ipv4_config (MMBearerQmi *self, if (mtu) { mm_bearer_ip_config_set_mtu (config, mtu); - mm_info (" MTU: %d", mtu); + mm_obj_info (self, " MTU: %d", mtu); } return config; @@ -795,12 +796,12 @@ get_ipv6_config (MMBearerQmi *self, /* If the message has an IPv6 address, create an IPv6 bearer config */ if (!qmi_message_wds_get_current_settings_output_get_ipv6_address (output, &array, &prefix, &error)) { - mm_warn ("IPv6 family but no IPv6 address (%s)", error->message); + mm_obj_warn (self, "IPv6 family but no IPv6 address: %s", error->message); g_clear_error (&error); return NULL; } - mm_info ("QMI IPv6 Settings:"); + mm_obj_info (self, "QMI IPv6 Settings:"); config = mm_bearer_ip_config_new (); mm_bearer_ip_config_set_method (config, ip_method); @@ -810,15 +811,15 @@ get_ipv6_config (MMBearerQmi *self, mm_bearer_ip_config_set_address (config, buf); mm_bearer_ip_config_set_prefix (config, prefix); - mm_info (" Address: %s/%d", buf, prefix); + mm_obj_info (self, " address: %s/%d", buf, prefix); /* IPv6 gateway address */ if (qmi_message_wds_get_current_settings_output_get_ipv6_gateway_address (output, &array, &prefix, &error)) { qmi_inet6_ntop (array, buf, sizeof (buf)); mm_bearer_ip_config_set_gateway (config, buf); - mm_info (" Gateway: %s/%d", buf, prefix); + mm_obj_info (self, " gateway: %s/%d", buf, prefix); } else { - mm_info (" Gateway: failed (%s)", error->message); + mm_obj_info (self, " gateway: failed (%s)", error->message); g_clear_error (&error); } @@ -826,9 +827,9 @@ get_ipv6_config (MMBearerQmi *self, if (qmi_message_wds_get_current_settings_output_get_ipv6_primary_dns_address (output, &array, &error)) { qmi_inet6_ntop (array, buf, sizeof (buf)); dns[dns_idx++] = buf; - mm_info (" DNS #1: %s", buf); + mm_obj_info (self, " DNS #1: %s", buf); } else { - mm_info (" DNS #1: failed (%s)", error->message); + mm_obj_info (self, " DNS #1: failed (%s)", error->message); g_clear_error (&error); } @@ -836,9 +837,9 @@ get_ipv6_config (MMBearerQmi *self, if (qmi_message_wds_get_current_settings_output_get_ipv6_secondary_dns_address (output, &array, &error)) { qmi_inet6_ntop (array, buf2, sizeof (buf2)); dns[dns_idx++] = buf2; - mm_info (" DNS #2: %s", buf2); + mm_obj_info (self, " DNS #2: %s", buf2); } else { - mm_info (" DNS #2: failed (%s)", error->message); + mm_obj_info (self, " DNS #2: failed (%s)", error->message); g_clear_error (&error); } @@ -847,7 +848,7 @@ get_ipv6_config (MMBearerQmi *self, if (mtu) { mm_bearer_ip_config_set_mtu (config, mtu); - mm_info (" MTU: %d", mtu); + mm_obj_info (self, " MTU: %d", mtu); } return config; @@ -858,11 +859,13 @@ get_current_settings_ready (QmiClientWds *client, GAsyncResult *res, GTask *task) { + MMBearerQmi *self; ConnectContext *ctx; GError *error = NULL; QmiMessageWdsGetCurrentSettingsOutput *output; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); g_assert (ctx->running_ipv4 || ctx->running_ipv6); output = qmi_client_wds_get_current_settings_finish (client, res, &error); @@ -871,7 +874,7 @@ get_current_settings_ready (QmiClientWds *client, /* When we're using static IP address, the current settings are mandatory */ if (ctx->ip_method == MM_BEARER_IP_METHOD_STATIC) { - mm_warn ("Failed to retrieve mandatory IP settings: %s", error->message); + mm_obj_warn (self, "failed to retrieve mandatory IP settings: %s", error->message); if (output) qmi_message_wds_get_current_settings_output_unref (output); complete_connect (task, NULL, error); @@ -879,7 +882,7 @@ get_current_settings_ready (QmiClientWds *client, } /* Otherwise, just go on as we're asking for DHCP */ - mm_dbg ("Couldn't get current settings: %s", error->message); + mm_obj_dbg (self, "couldn't get current settings: %s", error->message); g_error_free (error); config = mm_bearer_ip_config_new (); @@ -897,16 +900,16 @@ get_current_settings_ready (QmiClientWds *client, GArray *array; if (!qmi_message_wds_get_current_settings_output_get_ip_family (output, &ip_family, &error)) { - mm_dbg (" IP Family: failed (%s); assuming IPv4", error->message); + mm_obj_dbg (self, " IP Family: failed (%s); assuming IPv4", error->message); g_clear_error (&error); ip_family = QMI_WDS_IP_FAMILY_IPV4; } - mm_dbg (" IP Family: %s", + mm_obj_dbg (self, " IP Family: %s", (ip_family == QMI_WDS_IP_FAMILY_IPV4) ? "IPv4" : (ip_family == QMI_WDS_IP_FAMILY_IPV6) ? "IPv6" : "unknown"); if (!qmi_message_wds_get_current_settings_output_get_mtu (output, &mtu, &error)) { - mm_dbg (" MTU: failed (%s)", error->message); + mm_obj_dbg (self, " MTU: failed (%s)", error->message); g_clear_error (&error); } @@ -925,10 +928,10 @@ get_current_settings_ready (QmiClientWds *client, g_string_append (s, ", "); g_string_append (s, g_array_index (array, const char *, i)); } - mm_dbg (" Domains: %s", s->str); + mm_obj_dbg (self, " domains: %s", s->str); g_string_free (s, TRUE); } else { - mm_dbg (" Domains: failed (%s)", error ? error->message : "unknown"); + mm_obj_dbg (self, " domains: failed (%s)", error ? error->message : "unknown"); g_clear_error (&error); } } @@ -975,11 +978,14 @@ set_ip_family_ready (QmiClientWds *client, GAsyncResult *res, GTask *task) { + MMBearerQmi *self; ConnectContext *ctx; GError *error = NULL; QmiMessageWdsSetIpFamilyOutput *output; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); + g_assert (ctx->running_ipv4 || ctx->running_ipv6); g_assert (!(ctx->running_ipv4 && ctx->running_ipv6)); @@ -991,7 +997,7 @@ set_ip_family_ready (QmiClientWds *client, if (error) { /* Ensure we add the IP family preference TLV */ - mm_dbg ("Couldn't set IP family preference: '%s'", error->message); + mm_obj_dbg (self, "couldn't set IP family preference: %s", error->message); g_error_free (error); ctx->default_ip_family_set = FALSE; } else { @@ -1029,20 +1035,18 @@ packet_service_status_indication_cb (QmiClientWds *client, output, &cer, NULL)) - mm_info ("bearer call end reason (%u): '%s'", - cer, - qmi_wds_call_end_reason_get_string (cer)); + mm_obj_info (self, "bearer call end reason (%u): '%s'", cer, qmi_wds_call_end_reason_get_string (cer)); if (qmi_indication_wds_packet_service_status_output_get_verbose_call_end_reason ( output, &verbose_cer_type, &verbose_cer_reason, NULL)) - mm_info ("bearer verbose call end reason (%u,%d): [%s] %s", - verbose_cer_type, - verbose_cer_reason, - qmi_wds_verbose_call_end_reason_type_get_string (verbose_cer_type), - qmi_wds_verbose_call_end_reason_get_string (verbose_cer_type, verbose_cer_reason)); + mm_obj_info (self, "bearer verbose call end reason (%u,%d): [%s] %s", + verbose_cer_type, + verbose_cer_reason, + qmi_wds_verbose_call_end_reason_type_get_string (verbose_cer_type), + qmi_wds_verbose_call_end_reason_get_string (verbose_cer_type, verbose_cer_reason)); mm_base_bearer_report_connection_status (MM_BASE_BEARER (self), MM_BEARER_CONNECTION_STATUS_DISCONNECTED); } @@ -1077,7 +1081,7 @@ event_report_indication_cb (QmiClientWds *client, QmiIndicationWdsEventReportOutput *output, MMBearerQmi *self) { - mm_dbg ("Got QMI WDS event report"); + mm_obj_dbg (self, "got QMI WDS event report"); } static guint @@ -1326,7 +1330,7 @@ connect_context_step (GTask *task) else ctx->ip_method = MM_BEARER_IP_METHOD_DHCP; - mm_dbg ("Defaulting to use %s IP method", mm_bearer_ip_method_get_string (ctx->ip_method)); + mm_obj_dbg (self, "defaulting to use %s IP method", mm_bearer_ip_method_get_string (ctx->ip_method)); ctx->step++; /* fall through */ @@ -1339,7 +1343,7 @@ connect_context_step (GTask *task) } /* Start IPv4 setup */ - mm_dbg ("Running IPv4 connection setup"); + mm_obj_dbg (self, "running IPv4 connection setup"); ctx->running_ipv4 = TRUE; ctx->running_ipv6 = FALSE; ctx->step++; @@ -1352,7 +1356,7 @@ connect_context_step (GTask *task) QMI_SERVICE_WDS, MM_PORT_QMI_FLAG_WDS_IPV4); if (!client) { - mm_dbg ("Allocating IPv4-specific WDS client"); + mm_obj_dbg (self, "allocating IPv4-specific WDS client"); mm_port_qmi_allocate_client (ctx->qmi, QMI_SERVICE_WDS, MM_PORT_QMI_FLAG_WDS_IPV4, @@ -1372,7 +1376,7 @@ connect_context_step (GTask *task) qmi_client_check_version (QMI_CLIENT (ctx->client_ipv4), 1, 9)) { QmiMessageWdsSetIpFamilyInput *input; - mm_dbg ("Setting default IP family to: IPv4"); + mm_obj_dbg (self, "setting default IP family to: IPv4"); input = qmi_message_wds_set_ip_family_input_new (); qmi_message_wds_set_ip_family_input_set_preference (input, QMI_WDS_IP_FAMILY_IPV4, NULL); qmi_client_wds_set_ip_family (ctx->client_ipv4, @@ -1405,7 +1409,7 @@ connect_context_step (GTask *task) case CONNECT_STEP_START_NETWORK_IPV4: { QmiMessageWdsStartNetworkInput *input; - mm_dbg ("Starting IPv4 connection..."); + mm_obj_dbg (self, "starting IPv4 connection..."); input = build_start_network_input (ctx); qmi_client_wds_start_network (ctx->client_ipv4, input, @@ -1420,7 +1424,7 @@ connect_context_step (GTask *task) case CONNECT_STEP_GET_CURRENT_SETTINGS_IPV4: /* Retrieve and print IP configuration */ if (ctx->packet_data_handle_ipv4) { - mm_dbg ("Getting IPv4 configuration..."); + mm_obj_dbg (self, "getting IPv4 configuration..."); get_current_settings (task, ctx->client_ipv4); return; } @@ -1436,7 +1440,7 @@ connect_context_step (GTask *task) } /* Start IPv6 setup */ - mm_dbg ("Running IPv6 connection setup"); + mm_obj_dbg (self, "running IPv6 connection setup"); ctx->running_ipv4 = FALSE; ctx->running_ipv6 = TRUE; ctx->step++; @@ -1449,7 +1453,7 @@ connect_context_step (GTask *task) QMI_SERVICE_WDS, MM_PORT_QMI_FLAG_WDS_IPV6); if (!client) { - mm_dbg ("Allocating IPv6-specific WDS client"); + mm_obj_dbg (self, "allocating IPv6-specific WDS client"); mm_port_qmi_allocate_client (ctx->qmi, QMI_SERVICE_WDS, MM_PORT_QMI_FLAG_WDS_IPV6, @@ -1471,7 +1475,7 @@ connect_context_step (GTask *task) if (qmi_client_check_version (QMI_CLIENT (ctx->client_ipv6), 1, 9)) { QmiMessageWdsSetIpFamilyInput *input; - mm_dbg ("Setting default IP family to: IPv6"); + mm_obj_dbg (self, "setting default IP family to: IPv6"); input = qmi_message_wds_set_ip_family_input_new (); qmi_message_wds_set_ip_family_input_set_preference (input, QMI_WDS_IP_FAMILY_IPV6, NULL); qmi_client_wds_set_ip_family (ctx->client_ipv6, @@ -1504,7 +1508,7 @@ connect_context_step (GTask *task) case CONNECT_STEP_START_NETWORK_IPV6: { QmiMessageWdsStartNetworkInput *input; - mm_dbg ("Starting IPv6 connection..."); + mm_obj_dbg (self, "starting IPv6 connection..."); input = build_start_network_input (ctx); qmi_client_wds_start_network (ctx->client_ipv6, input, @@ -1519,7 +1523,7 @@ connect_context_step (GTask *task) case CONNECT_STEP_GET_CURRENT_SETTINGS_IPV6: /* Retrieve and print IP configuration */ if (ctx->packet_data_handle_ipv6) { - mm_dbg ("Getting IPv6 configuration..."); + mm_obj_dbg (self, "getting IPv6 configuration..."); get_current_settings (task, ctx->client_ipv6); return; } @@ -1677,11 +1681,9 @@ _connect (MMBaseBearer *_self, goto out; } - mm_dbg ("Launching connection with QMI port (%s/%s) and data port (%s/%s)", - mm_port_subsys_get_string (mm_port_get_subsys (MM_PORT (qmi))), - mm_port_get_device (MM_PORT (qmi)), - mm_port_subsys_get_string (mm_port_get_subsys (data)), - mm_port_get_device (data)); + mm_obj_dbg (self, "launching connection with QMI port (%s) and data port (%s)", + mm_port_get_device (MM_PORT (qmi)), + mm_port_get_device (data)); ctx = g_slice_new0 (ConnectContext); ctx->self = g_object_ref (self); @@ -1714,8 +1716,7 @@ _connect (MMBaseBearer *_self, ip_family = mm_base_bearer_get_default_ip_family (_self); ip_family_str = mm_bearer_ip_family_build_string_from_mask (ip_family); - mm_dbg ("No specific IP family requested, defaulting to %s", - ip_family_str); + mm_obj_dbg (self, "no specific IP family requested, defaulting to %s", ip_family_str); ctx->no_ip_family_preference = TRUE; g_free (ip_family_str); } @@ -2061,7 +2062,7 @@ disconnect (MMBaseBearer *_self, (!self->priv->client_ipv4 && !self->priv->client_ipv6) || !self->priv->data || !self->priv->qmi) { - mm_dbg ("No need to disconnect: QMI bearer is already disconnected"); + mm_obj_dbg (self, "no need to disconnect: QMI bearer is already disconnected"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; From 6c0d9e5a1be72d70036bca2adbd0955f31d5612b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:30:24 +0200 Subject: [PATCH 046/675] bearer-mbim: port to use object logging --- src/mm-bearer-mbim.c | 118 ++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 53 deletions(-) diff --git a/src/mm-bearer-mbim.c b/src/mm-bearer-mbim.c index 392ddde3..ce413a71 100644 --- a/src/mm-bearer-mbim.c +++ b/src/mm-bearer-mbim.c @@ -30,7 +30,7 @@ #include "mm-modem-helpers-mbim.h" #include "mm-port-enums-types.h" #include "mm-bearer-mbim.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMBearerMbim, mm_bearer_mbim, MM_TYPE_BASE_BEARER) @@ -253,6 +253,7 @@ ip_configuration_query_ready (MbimDevice *device, GAsyncResult *res, GTask *task) { + MMBearerMbim *self; ConnectContext *ctx; GError *error = NULL; MbimMessage *response; @@ -271,7 +272,8 @@ ip_configuration_query_ready (MbimDevice *device, guint32 ipv4mtu; guint32 ipv6mtu; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mbim_device_command_finish (device, res, &error); if (response && @@ -302,17 +304,17 @@ ip_configuration_query_ready (MbimDevice *device, /* IPv4 info */ str = mbim_ip_configuration_available_flag_build_string_from_mask (ipv4configurationavailable); - mm_dbg ("IPv4 configuration available: '%s'", str); + mm_obj_dbg (self, "IPv4 configuration available: '%s'", str); g_free (str); if ((ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) && ipv4addresscount) { guint i; - mm_dbg (" IP addresses (%u)", ipv4addresscount); + mm_obj_dbg (self, " IP addresses (%u)", ipv4addresscount); for (i = 0; i < ipv4addresscount; i++) { addr = g_inet_address_new_from_bytes ((guint8 *)&ipv4address[i]->ipv4_address, G_SOCKET_FAMILY_IPV4); str = g_inet_address_to_string (addr); - mm_dbg (" IP [%u]: '%s/%u'", i, str, ipv4address[i]->on_link_prefix_length); + mm_obj_dbg (self, " IP [%u]: '%s/%u'", i, str, ipv4address[i]->on_link_prefix_length); g_free (str); g_object_unref (addr); } @@ -321,7 +323,7 @@ ip_configuration_query_ready (MbimDevice *device, if ((ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) && ipv4gateway) { addr = g_inet_address_new_from_bytes ((guint8 *)ipv4gateway, G_SOCKET_FAMILY_IPV4); str = g_inet_address_to_string (addr); - mm_dbg (" Gateway: '%s'", str); + mm_obj_dbg (self, " gateway: '%s'", str); g_free (str); g_object_unref (addr); } @@ -329,12 +331,12 @@ ip_configuration_query_ready (MbimDevice *device, if ((ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) && ipv4dnsservercount) { guint i; - mm_dbg (" DNS addresses (%u)", ipv4dnsservercount); + mm_obj_dbg (self, " DNS addresses (%u)", ipv4dnsservercount); for (i = 0; i < ipv4dnsservercount; i++) { addr = g_inet_address_new_from_bytes ((guint8 *)&ipv4dnsserver[i], G_SOCKET_FAMILY_IPV4); if (!g_inet_address_get_is_any (addr)) { str = g_inet_address_to_string (addr); - mm_dbg (" DNS [%u]: '%s'", i, str); + mm_obj_dbg (self, " DNS [%u]: '%s'", i, str); g_free (str); } g_object_unref (addr); @@ -342,23 +344,23 @@ ip_configuration_query_ready (MbimDevice *device, } if ((ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU) && ipv4mtu) { - mm_dbg (" MTU: '%u'", ipv4mtu); + mm_obj_dbg (self, " MTU: '%u'", ipv4mtu); } /* IPv6 info */ str = mbim_ip_configuration_available_flag_build_string_from_mask (ipv6configurationavailable); - mm_dbg ("IPv6 configuration available: '%s'", str); + mm_obj_dbg (self, "IPv6 configuration available: '%s'", str); g_free (str); if ((ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) && ipv6addresscount) { guint i; - mm_dbg (" IP addresses (%u)", ipv6addresscount); + mm_obj_dbg (self, " IP addresses (%u)", ipv6addresscount); for (i = 0; i < ipv6addresscount; i++) { addr = g_inet_address_new_from_bytes ((guint8 *)&ipv6address[i]->ipv6_address, G_SOCKET_FAMILY_IPV6); str = g_inet_address_to_string (addr); - mm_dbg (" IP [%u]: '%s/%u'", i, str, ipv6address[i]->on_link_prefix_length); + mm_obj_dbg (self, " IP [%u]: '%s/%u'", i, str, ipv6address[i]->on_link_prefix_length); g_free (str); g_object_unref (addr); } @@ -367,7 +369,7 @@ ip_configuration_query_ready (MbimDevice *device, if ((ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) && ipv6gateway) { addr = g_inet_address_new_from_bytes ((guint8 *)ipv6gateway, G_SOCKET_FAMILY_IPV6); str = g_inet_address_to_string (addr); - mm_dbg (" Gateway: '%s'", str); + mm_obj_dbg (self, " gateway: '%s'", str); g_free (str); g_object_unref (addr); } @@ -375,12 +377,12 @@ ip_configuration_query_ready (MbimDevice *device, if ((ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) && ipv6dnsservercount) { guint i; - mm_dbg (" DNS addresses (%u)", ipv6dnsservercount); + mm_obj_dbg (self, " DNS addresses (%u)", ipv6dnsservercount); for (i = 0; i < ipv6dnsservercount; i++) { addr = g_inet_address_new_from_bytes ((guint8 *)&ipv6dnsserver[i], G_SOCKET_FAMILY_IPV6); if (!g_inet_address_get_is_any (addr)) { str = g_inet_address_to_string (addr); - mm_dbg (" DNS [%u]: '%s'", i, str); + mm_obj_dbg (self, " DNS [%u]: '%s'", i, str); g_free (str); } g_object_unref (addr); @@ -388,7 +390,7 @@ ip_configuration_query_ready (MbimDevice *device, } if ((ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU) && ipv6mtu) { - mm_dbg (" MTU: '%u'", ipv6mtu); + mm_obj_dbg (self, " MTU: '%u'", ipv6mtu); } /* Build connection results */ @@ -563,6 +565,7 @@ connect_set_ready (MbimDevice *device, GAsyncResult *res, GTask *task) { + MMBearerMbim *self; ConnectContext *ctx; GError *error = NULL; MbimMessage *response; @@ -570,7 +573,8 @@ connect_set_ready (MbimDevice *device, MbimActivationState activation_state; guint32 nw_error; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mbim_device_command_finish (device, res, &error); if (response && @@ -597,10 +601,10 @@ connect_set_ready (MbimDevice *device, * MBIM_CONTEXT_IP_TYPE_DEFAULT, which MM never does. Some * devices (K5160) report the wrong type in the response. */ - mm_dbg ("Session ID '%u': %s (IP type: %s)", - session_id, - mbim_activation_state_get_string (activation_state), - mbim_context_ip_type_get_string (ctx->ip_type)); + mm_obj_dbg (self, "session ID '%u': %s (IP type: %s)", + session_id, + mbim_activation_state_get_string (activation_state), + mbim_context_ip_type_get_string (ctx->ip_type)); } } else { /* Prefer the error from the result to the parsing error */ @@ -650,13 +654,15 @@ check_disconnected_ready (MbimDevice *device, GAsyncResult *res, GTask *task) { + MMBearerMbim *self; ConnectContext *ctx; GError *error = NULL; MbimMessage *response; guint32 session_id; MbimActivationState activation_state; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mbim_device_command_finish (device, res, &error); if (response && @@ -670,7 +676,7 @@ check_disconnected_ready (MbimDevice *device, NULL, /* context_type */ NULL, /* nw_error */ &error)) { - mm_dbg ("Session ID '%u': %s", session_id, mbim_activation_state_get_string (activation_state)); + mm_obj_dbg (self, "session ID '%u': %s", session_id, mbim_activation_state_get_string (activation_state)); } else activation_state = MBIM_ACTIVATION_STATE_UNKNOWN; @@ -697,13 +703,15 @@ provisioned_contexts_query_ready (MbimDevice *device, GAsyncResult *res, GTask *task) { + MMBearerMbim *self; ConnectContext *ctx; GError *error = NULL; MbimMessage *response; guint32 provisioned_contexts_count; MbimProvisionedContextElement **provisioned_contexts; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mbim_device_command_finish (device, res, &error); if (response && @@ -715,25 +723,25 @@ provisioned_contexts_query_ready (MbimDevice *device, &error)) { guint32 i; - mm_dbg ("Provisioned contexts found (%u):", provisioned_contexts_count); + mm_obj_dbg (self, "provisioned contexts found (%u):", provisioned_contexts_count); for (i = 0; i < provisioned_contexts_count; i++) { MbimProvisionedContextElement *el = provisioned_contexts[i]; gchar *uuid_str; uuid_str = mbim_uuid_get_printable (&el->context_type); - mm_dbg ("[%u] context type: %s", el->context_id, mbim_context_type_get_string (mbim_uuid_to_context_type (&el->context_type))); - mm_dbg (" uuid: %s", uuid_str); - mm_dbg (" access string: %s", el->access_string ? el->access_string : ""); - mm_dbg (" username: %s", el->user_name ? el->user_name : ""); - mm_dbg (" password: %s", el->password ? el->password : ""); - mm_dbg (" compression: %s", mbim_compression_get_string (el->compression)); - mm_dbg (" auth: %s", mbim_auth_protocol_get_string (el->auth_protocol)); + mm_obj_dbg (self, "[%u] context type: %s", el->context_id, mbim_context_type_get_string (mbim_uuid_to_context_type (&el->context_type))); + mm_obj_dbg (self, " uuid: %s", uuid_str); + mm_obj_dbg (self, " access string: %s", el->access_string ? el->access_string : ""); + mm_obj_dbg (self, " username: %s", el->user_name ? el->user_name : ""); + mm_obj_dbg (self, " password: %s", el->password ? el->password : ""); + mm_obj_dbg (self, " compression: %s", mbim_compression_get_string (el->compression)); + mm_obj_dbg (self, " auth: %s", mbim_auth_protocol_get_string (el->auth_protocol)); g_free (uuid_str); } mbim_provisioned_context_element_array_free (provisioned_contexts); } else { - mm_dbg ("Error listing provisioned contexts: %s", error->message); + mm_obj_dbg (self, "error listing provisioned contexts: %s", error->message); g_error_free (error); } @@ -750,6 +758,7 @@ packet_service_set_ready (MbimDevice *device, GAsyncResult *res, GTask *task) { + MMBearerMbim *self; ConnectContext *ctx; GError *error = NULL; MbimMessage *response; @@ -759,6 +768,7 @@ packet_service_set_ready (MbimDevice *device, guint64 uplink_speed; guint64 downlink_speed; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); response = mbim_device_command_finish (device, res, &error); @@ -783,11 +793,11 @@ packet_service_set_ready (MbimDevice *device, gchar *str; str = mbim_data_class_build_string_from_mask (highest_available_data_class); - mm_dbg ("Packet service update:"); - mm_dbg (" state: '%s'", mbim_packet_service_state_get_string (packet_service_state)); - mm_dbg (" data class: '%s'", str); - mm_dbg (" uplink: '%" G_GUINT64_FORMAT "' bps", uplink_speed); - mm_dbg (" downlink: '%" G_GUINT64_FORMAT "' bps", downlink_speed); + mm_obj_dbg (self, "packet service update:"); + mm_obj_dbg (self, " state: '%s'", mbim_packet_service_state_get_string (packet_service_state)); + mm_obj_dbg (self, " data class: '%s'", str); + mm_obj_dbg (self, " uplink: '%" G_GUINT64_FORMAT "' bps", uplink_speed); + mm_obj_dbg (self, " downlink: '%" G_GUINT64_FORMAT "' bps", downlink_speed); g_free (str); } } else { @@ -806,7 +816,7 @@ packet_service_set_ready (MbimDevice *device, /* Don't make NoDeviceSupport errors fatal; just try to keep on the * connection sequence even with this error. */ if (g_error_matches (error, MBIM_STATUS_ERROR, MBIM_STATUS_ERROR_NO_DEVICE_SUPPORT)) { - mm_dbg ("Device doesn't support packet service attach"); + mm_obj_dbg (self, "device doesn't support packet service attach"); g_error_free (error); } else { /* All other errors are fatal */ @@ -845,7 +855,7 @@ connect_context_step (GTask *task) case CONNECT_STEP_PACKET_SERVICE: { GError *error = NULL; - mm_dbg ("Activating packet service..."); + mm_obj_dbg (self, "activating packet service..."); message = (mbim_message_packet_service_set_new ( MBIM_PACKET_SERVICE_ACTION_ATTACH, &error)); @@ -866,7 +876,7 @@ connect_context_step (GTask *task) } case CONNECT_STEP_PROVISIONED_CONTEXTS: - mm_dbg ("Listing provisioned contexts..."); + mm_obj_dbg (self, "listing provisioned contexts..."); message = mbim_message_provisioned_contexts_query_new (NULL); mbim_device_command (ctx->device, message, @@ -969,7 +979,7 @@ connect_context_step (GTask *task) ip_family = mm_base_bearer_get_default_ip_family (MM_BASE_BEARER (self)); str = mm_bearer_ip_family_build_string_from_mask (ip_family); - mm_dbg ("No specific IP family requested, defaulting to %s", str); + mm_obj_dbg (self, "no specific IP family requested, defaulting to %s", str); g_free (str); } @@ -980,7 +990,7 @@ connect_context_step (GTask *task) return; } - mm_dbg ("Launching %s connection with APN '%s'...", mbim_context_ip_type_get_string (ctx->ip_type), apn); + mm_obj_dbg (self, "launching %s connection with APN '%s'...", mbim_context_ip_type_get_string (ctx->ip_type), apn); message = (mbim_message_connect_set_new ( self->priv->session_id, MBIM_ACTIVATION_COMMAND_ACTIVATE, @@ -1011,7 +1021,7 @@ connect_context_step (GTask *task) case CONNECT_STEP_IP_CONFIGURATION: { GError *error = NULL; - mm_dbg ("Querying IP configuration..."); + mm_obj_dbg (self, "querying IP configuration..."); message = (mbim_message_ip_configuration_query_new ( self->priv->session_id, MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_NONE, /* ipv4configurationavailable */ @@ -1108,7 +1118,7 @@ _connect (MMBaseBearer *self, g_object_unref (modem); - mm_dbg ("Launching connection with data port (%s/%s)", + mm_obj_dbg (self, "launching connection with data port (%s/%s)", mm_port_subsys_get_string (mm_port_get_subsys (data)), mm_port_get_device (data)); @@ -1174,6 +1184,7 @@ disconnect_set_ready (MbimDevice *device, GAsyncResult *res, GTask *task) { + MMBearerMbim *self; DisconnectContext *ctx; GError *error = NULL; MbimMessage *response; @@ -1183,7 +1194,8 @@ disconnect_set_ready (MbimDevice *device, GError *inner_error = NULL; gboolean result = FALSE, parsed_result = FALSE; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mbim_device_command_finish (device, res, &error); if (!response) @@ -1211,16 +1223,16 @@ disconnect_set_ready (MbimDevice *device, if (result && parsed_result) { g_assert (!error); g_assert (!inner_error); - mm_dbg ("Session ID '%u': %s", session_id, mbim_activation_state_get_string (activation_state)); + mm_obj_dbg (self, "session ID '%u': %s", session_id, mbim_activation_state_get_string (activation_state)); /* success */ goto out; } if (g_error_matches (error, MBIM_STATUS_ERROR, MBIM_STATUS_ERROR_CONTEXT_NOT_ACTIVATED)) { if (parsed_result) - mm_dbg ("Context not activated: session ID '%u' already disconnected", session_id); + mm_obj_dbg (self, "context not activated: session ID '%u' already disconnected", session_id); else - mm_dbg ("Context not activated: already disconnected"); + mm_obj_dbg (self, "context not activated: already disconnected"); g_clear_error (&error); g_clear_error (&inner_error); @@ -1331,15 +1343,15 @@ disconnect (MMBaseBearer *_self, task = g_task_new (self, NULL, callback, user_data); if (!self->priv->data) { - mm_dbg ("No need to disconnect: MBIM bearer is already disconnected"); + mm_obj_dbg (self, "no need to disconnect: MBIM bearer is already disconnected"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } - mm_dbg ("Launching disconnection on data port (%s/%s)", - mm_port_subsys_get_string (mm_port_get_subsys (self->priv->data)), - mm_port_get_device (self->priv->data)); + mm_obj_dbg (self, "launching disconnection on data port (%s/%s)", + mm_port_subsys_get_string (mm_port_get_subsys (self->priv->data)), + mm_port_get_device (self->priv->data)); ctx = g_slice_new0 (DisconnectContext); ctx->device = g_object_ref (device); From 7e5af3b38d2afe8902f9ea194848a89a329fe83d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:34:18 +0200 Subject: [PATCH 047/675] base-sim: set dbus id as soon as object is created --- src/mm-base-sim.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 7eca8e4a..41540c94 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -57,6 +57,8 @@ static GParamSpec *properties[PROP_LAST]; struct _MMBaseSimPrivate { /* The connection to the system bus */ GDBusConnection *connection; + guint dbus_id; + /* The modem which owns this SIM */ MMBaseModem *modem; /* The path where the SIM object is exported */ @@ -70,10 +72,9 @@ static guint signals[SIGNAL_LAST] = { 0 }; void mm_base_sim_export (MMBaseSim *self) { - static guint id = 0; gchar *path; - path = g_strdup_printf (MM_DBUS_SIM_PREFIX "/%d", id++); + path = g_strdup_printf (MM_DBUS_SIM_PREFIX "/%d", self->priv->dbus_id); g_object_set (self, MM_BASE_SIM_PATH, path, NULL); @@ -1811,8 +1812,13 @@ get_property (GObject *object, static void mm_base_sim_init (MMBaseSim *self) { + static guint id = 0; + /* Initialize private data */ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_BASE_SIM, MMBaseSimPrivate); + + /* Each SIM is given a unique id to build its own DBus path */ + self->priv->dbus_id = id++; } static void From ae38106ad21741d6668ccf9ca649518e9cd62d94 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:37:09 +0200 Subject: [PATCH 048/675] base-sim: port to use object logging --- src/mm-base-sim.c | 59 +++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 41540c94..27759532 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -30,14 +30,15 @@ #include "mm-base-sim.h" #include "mm-base-modem-at.h" #include "mm-base-modem.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" static void async_initable_iface_init (GAsyncInitableIface *iface); +static void log_object_iface_init (MMLogObjectInterface *iface); G_DEFINE_TYPE_EXTENDED (MMBaseSim, mm_base_sim, MM_GDBUS_TYPE_SIM_SKELETON, 0, - G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, - async_initable_iface_init)) + G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -913,9 +914,7 @@ sim_dbus_export (MMBaseSim *self) self->priv->connection, self->priv->path, &error)) { - mm_warn ("couldn't export SIM at '%s': '%s'", - self->priv->path, - error->message); + mm_obj_warn (self, "couldn't export SIM: %s", error->message); g_error_free (error); } } @@ -1032,7 +1031,7 @@ load_emergency_numbers_finish (MMBaseSim *self, return NULL; for (i = 0; emergency_numbers[i]; i++) - mm_dbg ("loaded emergency number: %s", emergency_numbers[i]); + mm_obj_dbg (self, "loaded emergency number: %s", emergency_numbers[i]); return emergency_numbers; } @@ -1044,7 +1043,7 @@ load_emergency_numbers (MMBaseSim *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading emergency numbers..."); + mm_obj_dbg (self, "loading emergency numbers..."); /* READ BINARY of EF_ECC (Emergency Call Codes) ETSI TS 51.011 section 10.3.27 */ mm_base_modem_at_command ( @@ -1110,7 +1109,7 @@ load_sim_identifier_finish (MMBaseSim *self, if (!sim_identifier) return NULL; - mm_dbg ("loaded SIM identifier: %s", sim_identifier); + mm_obj_dbg (self, "loaded SIM identifier: %s", sim_identifier); return sim_identifier; } @@ -1121,7 +1120,7 @@ load_sim_identifier (MMBaseSim *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading SIM identifier..."); + mm_obj_dbg (self, "loading SIM identifier..."); /* READ BINARY of EFiccid (ICC Identification) ETSI TS 102.221 section 13.2 */ mm_base_modem_at_command ( @@ -1178,7 +1177,7 @@ load_imsi_finish (MMBaseSim *self, if (!imsi) return NULL; - mm_dbg ("loaded IMSI: %s", imsi); + mm_obj_dbg (self, "loaded IMSI: %s", imsi); return imsi; } @@ -1189,7 +1188,7 @@ load_imsi (MMBaseSim *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading IMSI..."); + mm_obj_dbg (self, "loading IMSI..."); mm_base_modem_at_command ( self->priv->modem, @@ -1307,7 +1306,7 @@ load_operator_identifier (MMBaseSim *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading Operator ID..."); + mm_obj_dbg (self, "loading operator ID..."); /* READ BINARY of EFad (Administrative Data) ETSI 51.011 section 10.3.18 */ mm_base_modem_at_command ( @@ -1402,7 +1401,7 @@ load_operator_name (MMBaseSim *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading Operator Name..."); + mm_obj_dbg (self, "loading operator name..."); /* READ BINARY of EFspn (Service Provider Name) ETSI 51.011 section 10.3.11 */ mm_base_modem_at_command ( @@ -1486,8 +1485,7 @@ init_load_sim_identifier_ready (MMBaseSim *self, return; } - mm_warn ("couldn't load SIM identifier: '%s'", - error ? error->message : "unknown error"); + mm_obj_warn (self, "couldn't load SIM identifier: %s", error ? error->message : "unknown error"); g_clear_error (&error); } @@ -1510,7 +1508,7 @@ init_load_emergency_numbers_ready (MMBaseSim *self, str_list = MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers_finish (self, res, &error); if (error) { - mm_warn ("couldn't load list of Emergency Numbers: '%s'", error->message); + mm_obj_warn (self, "couldn't load list of emergency numbers: %s", error->message); g_error_free (error); } @@ -1541,7 +1539,7 @@ init_load_emergency_numbers_ready (MMBaseSim *self, g_free (val); \ \ if (error) { \ - mm_warn ("couldn't load %s: '%s'", DISPLAY, error->message); \ + mm_obj_warn (self, "couldn't load %s: %s", DISPLAY, error->message); \ g_error_free (error); \ } \ \ @@ -1552,8 +1550,8 @@ init_load_emergency_numbers_ready (MMBaseSim *self, } STR_REPLY_READY_FN (imsi, "IMSI") -STR_REPLY_READY_FN (operator_identifier, "Operator identifier") -STR_REPLY_READY_FN (operator_name, "Operator name") +STR_REPLY_READY_FN (operator_identifier, "operator identifier") +STR_REPLY_READY_FN (operator_name, "operator name") static void interface_initialization_step (GTask *task) @@ -1740,6 +1738,19 @@ mm_base_sim_initialize (MMBaseSim *self, user_data); } +/*****************************************************************************/ + +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMBaseSim *self; + + self = MM_BASE_SIM (_self); + return g_strdup_printf ("sim%u", self->priv->dbus_id); +} + +/*****************************************************************************/ + static void set_property (GObject *object, guint prop_id, @@ -1772,6 +1783,8 @@ set_property (GObject *object, g_clear_object (&self->priv->modem); self->priv->modem = g_value_dup_object (value); if (self->priv->modem) { + /* Set owner ID */ + mm_log_object_set_owner_id (MM_LOG_OBJECT (self), mm_log_object_get_id (MM_LOG_OBJECT (self->priv->modem))); /* Bind the modem's connection (which is set when it is exported, * and unset when unexported) to the SIM's connection */ g_object_bind_property (self->priv->modem, MM_BASE_MODEM_CONNECTION, @@ -1855,6 +1868,12 @@ async_initable_iface_init (GAsyncInitableIface *iface) iface->init_finish = initable_init_finish; } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_base_sim_class_init (MMBaseSimClass *klass) { From e8c9001f6e8867f95017378b96f34df91660fd5f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:40:49 +0200 Subject: [PATCH 049/675] sim-mbim: port to use object logging --- src/mm-sim-mbim.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mm-sim-mbim.c b/src/mm-sim-mbim.c index a2aa1eaf..d1fc145f 100644 --- a/src/mm-sim-mbim.c +++ b/src/mm-sim-mbim.c @@ -26,7 +26,7 @@ #include "mm-error-helpers.h" #include "mm-iface-modem.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers-mbim.h" #include "mm-sim-mbim.h" @@ -416,7 +416,7 @@ send_pin (MMBaseSim *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("Sending PIN..."); + mm_obj_dbg (self, "sending PIN..."); message = (mbim_message_pin_set_new ( MBIM_PIN_TYPE_PIN1, MBIM_PIN_OPERATION_ENTER, @@ -514,7 +514,7 @@ send_puk (MMBaseSim *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("Sending PUK..."); + mm_obj_dbg (self, "sending PUK..."); message = (mbim_message_pin_set_new ( MBIM_PIN_TYPE_PUK1, MBIM_PIN_OPERATION_ENTER, @@ -605,7 +605,7 @@ enable_pin (MMBaseSim *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("%s PIN ...", enabled ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s PIN ...", enabled ? "enabling" : "disabling"); message = (mbim_message_pin_set_new ( MBIM_PIN_TYPE_PIN1, enabled ? MBIM_PIN_OPERATION_ENABLE : MBIM_PIN_OPERATION_DISABLE, @@ -696,7 +696,7 @@ change_pin (MMBaseSim *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("Changing PIN"); + mm_obj_dbg (self, "changing PIN..."); message = (mbim_message_pin_set_new ( MBIM_PIN_TYPE_PIN1, MBIM_PIN_OPERATION_CHANGE, From e2d15e9bf43e507fe973cf40bfd5f248faf09643 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:42:08 +0200 Subject: [PATCH 050/675] sim-qmi: port to use object logging --- src/mm-sim-qmi.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mm-sim-qmi.c b/src/mm-sim-qmi.c index 9294a1fc..6eb5854d 100644 --- a/src/mm-sim-qmi.c +++ b/src/mm-sim-qmi.c @@ -25,7 +25,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-sim-qmi.h" G_DEFINE_TYPE (MMSimQmi, mm_sim_qmi, MM_TYPE_BASE_SIM) @@ -298,7 +298,7 @@ load_sim_identifier (MMBaseSim *_self, self = MM_SIM_QMI (_self); task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("loading SIM identifier..."); + mm_obj_dbg (self, "loading SIM identifier..."); if (!self->priv->dms_uim_deprecated) dms_uim_get_iccid (self, task); else @@ -423,7 +423,7 @@ load_imsi (MMBaseSim *_self, self = MM_SIM_QMI (_self); task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("loading IMSI..."); + mm_obj_dbg (self, "loading IMSI..."); if (!self->priv->dms_uim_deprecated) dms_uim_get_imsi (self, task); else @@ -540,7 +540,7 @@ load_operator_identifier (MMBaseSim *self, QMI_SERVICE_NAS, &client)) return; - mm_dbg ("loading SIM operator identifier..."); + mm_obj_dbg (self, "loading SIM operator identifier..."); qmi_client_nas_get_home_network (QMI_CLIENT_NAS (client), NULL, 5, @@ -589,7 +589,7 @@ load_operator_name (MMBaseSim *self, QMI_SERVICE_NAS, &client)) return; - mm_dbg ("loading SIM operator name..."); + mm_obj_dbg (self, "loading SIM operator name..."); qmi_client_nas_get_home_network (QMI_CLIENT_NAS (client), NULL, 5, @@ -733,7 +733,7 @@ dms_uim_verify_pin (MMSimQmi *self, return; } - mm_dbg ("Sending PIN..."); + mm_obj_dbg (self, "sending PIN..."); input = qmi_message_dms_uim_verify_pin_input_new (); qmi_message_dms_uim_verify_pin_input_set_info ( input, @@ -763,7 +763,7 @@ send_pin (MMBaseSim *_self, g_task_set_task_data (task, g_strdup (pin), g_free); - mm_dbg ("Verifying PIN..."); + mm_obj_dbg (self, "verifying PIN..."); if (!self->priv->dms_uim_deprecated) dms_uim_verify_pin (self, task); else @@ -933,7 +933,7 @@ send_puk (MMBaseSim *_self, ctx->new_pin = g_strdup (new_pin); g_task_set_task_data (task, ctx, (GDestroyNotify) unblock_pin_context_free); - mm_dbg ("Unblocking PIN..."); + mm_obj_dbg (self, "unblocking PIN..."); if (!self->priv->dms_uim_deprecated) dms_uim_unblock_pin (self, task); else @@ -1103,7 +1103,7 @@ change_pin (MMBaseSim *_self, ctx->new_pin = g_strdup (new_pin); g_task_set_task_data (task, ctx, (GDestroyNotify) change_pin_context_free); - mm_dbg ("Changing PIN..."); + mm_obj_dbg (self, "changing PIN..."); if (!self->priv->dms_uim_deprecated) dms_uim_change_pin (self, task); else @@ -1272,7 +1272,7 @@ enable_pin (MMBaseSim *_self, ctx->enabled = enabled; g_task_set_task_data (task, ctx, (GDestroyNotify) enable_pin_context_free); - mm_dbg ("%s PIN...", enabled ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s PIN...", enabled ? "enabling" : "disabling"); if (!self->priv->dms_uim_deprecated) dms_uim_enable_pin (self, task); else From 6c5a2e24aeaa6030ee7fc9d370acf502be5f4625 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Mar 2020 19:47:30 +0200 Subject: [PATCH 051/675] base-sms: set dbus id as soon as object is created --- src/mm-base-sms.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mm-base-sms.c b/src/mm-base-sms.c index 4d306e7a..be0f2045 100644 --- a/src/mm-base-sms.c +++ b/src/mm-base-sms.c @@ -55,6 +55,8 @@ static GParamSpec *properties[PROP_LAST]; struct _MMBaseSmsPrivate { /* The connection to the system bus */ GDBusConnection *connection; + guint dbus_id; + /* The modem which owns this SMS */ MMBaseModem *modem; /* The path where the SMS object is exported */ @@ -651,10 +653,9 @@ handle_send (MMBaseSms *self, void mm_base_sms_export (MMBaseSms *self) { - static guint id = 0; gchar *path; - path = g_strdup_printf (MM_DBUS_SMS_PREFIX "/%d", id++); + path = g_strdup_printf (MM_DBUS_SMS_PREFIX "/%d", self->priv->dbus_id); g_object_set (self, MM_BASE_SMS_PATH, path, NULL); @@ -1989,10 +1990,15 @@ get_property (GObject *object, static void mm_base_sms_init (MMBaseSms *self) { + static guint id = 0; + /* Initialize private data */ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_BASE_SMS, MMBaseSmsPrivate); /* Defaults */ self->priv->max_parts = 1; + + /* Each SMS is given a unique id to build its own DBus path */ + self->priv->dbus_id = id++; } static void From 0e05d0dcf0548c93f441cc395ce6a64b13e74381 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 07:18:00 +0200 Subject: [PATCH 052/675] base-sms: port to use object logging --- src/mm-base-sms.c | 73 +++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/src/mm-base-sms.c b/src/mm-base-sms.c index be0f2045..e907637a 100644 --- a/src/mm-base-sms.c +++ b/src/mm-base-sms.c @@ -1,4 +1,3 @@ - /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This program is free software; you can redistribute it and/or modify @@ -34,10 +33,13 @@ #include "mm-sms-part-3gpp.h" #include "mm-base-modem-at.h" #include "mm-base-modem.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" -G_DEFINE_TYPE (MMBaseSms, mm_base_sms, MM_GDBUS_TYPE_SMS_SKELETON) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMBaseSms, mm_base_sms, MM_GDBUS_TYPE_SMS_SKELETON, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -176,14 +178,14 @@ generate_3gpp_submit_pdus (MMBaseSms *self, if (!split_text[i]) break; part_text = split_text[i]; - mm_dbg (" Processing chunk '%u' of text with '%u' bytes", - i, (guint) strlen (part_text)); + mm_obj_dbg (self, " processing chunk '%u' of text with '%u' bytes", + i, (guint) strlen (part_text)); } else if (split_data) { if (!split_data[i]) break; part_data = split_data[i]; - mm_dbg (" Processing chunk '%u' of data with '%u' bytes", - i, part_data->len); + mm_obj_dbg (self, " processing chunk '%u' of data with '%u' bytes", + i, part_data->len); } else g_assert_not_reached (); @@ -203,11 +205,9 @@ generate_3gpp_submit_pdus (MMBaseSms *self, mm_sms_part_set_concat_reference (part, 0); /* We don't set a concat reference here */ mm_sms_part_set_concat_sequence (part, i + 1); mm_sms_part_set_concat_max (part, n_parts); - - mm_dbg ("Created SMS part '%u' for multipart SMS ('%u' parts expected)", - i + 1, n_parts); + mm_obj_dbg (self, "created SMS part '%u' for multipart SMS ('%u' parts expected)", i + 1, n_parts); } else { - mm_dbg ("Created SMS part for singlepart SMS"); + mm_obj_dbg (self, "created SMS part for singlepart SMS"); } /* Add to the list of parts */ @@ -273,14 +273,14 @@ generate_cdma_submit_pdus (MMBaseSms *self, /* If creating a CDMA SMS part but we don't have a Teleservice ID, we default to WMT */ if (mm_gdbus_sms_get_teleservice_id (MM_GDBUS_SMS (self)) == MM_SMS_CDMA_TELESERVICE_ID_UNKNOWN) { - mm_dbg ("Defaulting to WMT teleservice ID when creating SMS part"); + mm_obj_dbg (self, "defaulting to WMT teleservice ID when creating SMS part"); mm_sms_part_set_cdma_teleservice_id (part, MM_SMS_CDMA_TELESERVICE_ID_WMT); } else mm_sms_part_set_cdma_teleservice_id (part, mm_gdbus_sms_get_teleservice_id (MM_GDBUS_SMS (self))); mm_sms_part_set_cdma_service_category (part, mm_gdbus_sms_get_service_category (MM_GDBUS_SMS (self))); - mm_dbg ("Created SMS part for CDMA SMS"); + mm_obj_dbg (self, "created SMS part for CDMA SMS"); /* Add to the list of parts */ self->priv->parts = g_list_append (self->priv->parts, part); @@ -691,9 +691,7 @@ sms_dbus_export (MMBaseSms *self) self->priv->connection, self->priv->path, &error)) { - mm_warn ("couldn't export SMS at '%s': '%s'", - self->priv->path, - error->message); + mm_obj_warn (self, "couldn't export SMS: %s", error->message); g_error_free (error); } } @@ -1154,12 +1152,14 @@ send_from_storage_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { + MMBaseSms *self; SmsSendContext *ctx; GError *error = NULL; const gchar *response; gint message_reference; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mm_base_modem_at_command_finish (modem, res, &error); if (error) { @@ -1169,8 +1169,7 @@ send_from_storage_ready (MMBaseModem *modem, return; } - mm_dbg ("Couldn't send SMS from storage: '%s'; trying generic send...", - error->message); + mm_obj_dbg (self, "couldn't send SMS from storage: %s; trying generic send...", error->message); g_error_free (error); ctx->from_storage = FALSE; @@ -1346,17 +1345,19 @@ delete_part_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { + MMBaseSms *self; SmsDeletePartsContext *ctx; GError *error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); mm_base_modem_at_command_finish (modem, res, &error); if (error) { ctx->n_failed++; - mm_dbg ("Couldn't delete SMS part with index %u: '%s'", - mm_sms_part_get_index ((MMSmsPart *)ctx->current->data), - error->message); + mm_obj_dbg (self, "couldn't delete SMS part with index %u: %s", + mm_sms_part_get_index ((MMSmsPart *)ctx->current->data), + error->message); g_error_free (error); } @@ -1448,7 +1449,7 @@ sms_delete (MMBaseSms *self, g_task_set_task_data (task, ctx, (GDestroyNotify)sms_delete_parts_context_free); if (mm_base_sms_get_storage (self) == MM_SMS_STORAGE_UNKNOWN) { - mm_dbg ("Not removing parts from non-stored SMS"); + mm_obj_dbg (self, "not removing parts from non-stored SMS"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -1570,12 +1571,12 @@ assemble_sms (MMBaseSms *self, idx = mm_sms_part_get_concat_sequence ((MMSmsPart *)l->data); if (idx < 1 || idx > self->priv->max_parts) { - mm_warn ("Invalid part index (%u) found, ignoring", idx); + mm_obj_warn (self, "invalid part index (%u) found, ignoring", idx); continue; } if (sorted_parts[idx - 1]) { - mm_warn ("Duplicate part index (%u) found, ignoring", idx); + mm_obj_warn (self, "duplicate part index (%u) found, ignoring", idx); continue; } @@ -1724,8 +1725,7 @@ mm_base_sms_multipart_take_part (MMBaseSms *self, if (!assemble_sms (self, &inner_error)) { /* We DO NOT propagate the error. The part was properly taken * so ownership passed to the MMBaseSms object. */ - mm_warn ("Couldn't assemble SMS: '%s'", - inner_error->message); + mm_obj_warn (self, "couldn't assemble SMS: %s", inner_error->message); g_error_free (inner_error); } else { /* Completed AND assembled @@ -1899,6 +1899,17 @@ mm_base_sms_new_from_properties (MMBaseModem *modem, /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMBaseSms *self; + + self = MM_BASE_SMS (_self); + return g_strdup_printf ("sms%u", self->priv->dbus_id); +} + +/*****************************************************************************/ + static void set_property (GObject *object, guint prop_id, @@ -1932,6 +1943,8 @@ set_property (GObject *object, g_clear_object (&self->priv->modem); self->priv->modem = g_value_dup_object (value); if (self->priv->modem) { + /* Set owner ID */ + mm_log_object_set_owner_id (MM_LOG_OBJECT (self), mm_log_object_get_id (MM_LOG_OBJECT (self->priv->modem))); /* Bind the modem's connection (which is set when it is exported, * and unset when unexported) to the SMS's connection */ g_object_bind_property (self->priv->modem, MM_BASE_MODEM_CONNECTION, @@ -2029,6 +2042,12 @@ dispose (GObject *object) G_OBJECT_CLASS (mm_base_sms_parent_class)->dispose (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_base_sms_class_init (MMBaseSmsClass *klass) { From cc1bb544ee46d69b7ab6b1026bc1dd66eafc24f4 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 07:32:00 +0200 Subject: [PATCH 053/675] sms-qmi: port to use object logging --- src/mm-sms-qmi.c | 59 ++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/mm-sms-qmi.c b/src/mm-sms-qmi.c index fabd417a..7124be32 100644 --- a/src/mm-sms-qmi.c +++ b/src/mm-sms-qmi.c @@ -31,7 +31,7 @@ #include "mm-base-modem.h" #include "mm-sms-part-3gpp.h" #include "mm-sms-part-cdma.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMSmsQmi, mm_sms_qmi, MM_TYPE_BASE_SMS) @@ -329,11 +329,14 @@ send_generic_ready (QmiClientWms *client, GAsyncResult *res, GTask *task) { + MMSmsQmi *self; SmsSendContext *ctx; QmiMessageWmsRawSendOutput *output = NULL; GError *error = NULL; guint16 message_id; + self = g_task_get_source_object (task); + output = qmi_client_wms_raw_send_finish (client, res, &error); if (!output) { g_prefix_error (&error, "QMI operation failed: "); @@ -351,11 +354,11 @@ send_generic_ready (QmiClientWms *client, &rp_cause, &tp_cause, NULL)) { - mm_warn ("Couldn't send SMS; RP cause (%u): '%s'; TP cause (%u): '%s'", - rp_cause, - qmi_wms_gsm_umts_rp_cause_get_string (rp_cause), - tp_cause, - qmi_wms_gsm_umts_tp_cause_get_string (tp_cause)); + mm_obj_warn (self, "couldn't send SMS; RP cause (%u): %s; TP cause (%u): %s", + rp_cause, + qmi_wms_gsm_umts_rp_cause_get_string (rp_cause), + tp_cause, + qmi_wms_gsm_umts_tp_cause_get_string (tp_cause)); } qmi_message_wms_raw_send_output_unref (output); @@ -442,11 +445,13 @@ send_from_storage_ready (QmiClientWms *client, GAsyncResult *res, GTask *task) { + MMSmsQmi *self; SmsSendContext *ctx; QmiMessageWmsSendFromMemoryStorageOutput *output = NULL; GError *error = NULL; guint16 message_id; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); output = qmi_client_wms_send_from_memory_storage_finish (client, res, &error); @@ -454,8 +459,7 @@ send_from_storage_ready (QmiClientWms *client, if (g_error_matches (error, QMI_CORE_ERROR, QMI_CORE_ERROR_UNSUPPORTED)) { - mm_dbg ("Couldn't send SMS from storage: '%s'; trying generic send...", - error->message); + mm_obj_dbg (self, "couldn't send SMS from storage: %s; trying generic send...", error->message); g_error_free (error); ctx->from_storage = FALSE; sms_send_next_part (task); @@ -473,8 +477,7 @@ send_from_storage_ready (QmiClientWms *client, if (g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_INVALID_QMI_COMMAND)) { - mm_dbg ("Couldn't send SMS from storage: '%s'; trying generic send...", - error->message); + mm_obj_dbg (self, "couldn't send SMS from storage: %s; trying generic send...", error->message); g_error_free (error); ctx->from_storage = FALSE; sms_send_next_part (task); @@ -489,29 +492,29 @@ send_from_storage_ready (QmiClientWms *client, &rp_cause, &tp_cause, NULL)) { - mm_warn ("Couldn't send SMS; RP cause (%u): '%s'; TP cause (%u): '%s'", - rp_cause, - qmi_wms_gsm_umts_rp_cause_get_string (rp_cause), - tp_cause, - qmi_wms_gsm_umts_tp_cause_get_string (tp_cause)); + mm_obj_warn (self, "couldn't send SMS; RP cause (%u): %s; TP cause (%u): %s", + rp_cause, + qmi_wms_gsm_umts_rp_cause_get_string (rp_cause), + tp_cause, + qmi_wms_gsm_umts_tp_cause_get_string (tp_cause)); } if (qmi_message_wms_send_from_memory_storage_output_get_cdma_cause_code ( output, &cdma_cause_code, NULL)) { - mm_warn ("Couldn't send SMS; cause code (%u): '%s'", - cdma_cause_code, - qmi_wms_cdma_cause_code_get_string (cdma_cause_code)); + mm_obj_warn (self, "couldn't send SMS; cause code (%u): %s", + cdma_cause_code, + qmi_wms_cdma_cause_code_get_string (cdma_cause_code)); } if (qmi_message_wms_send_from_memory_storage_output_get_cdma_error_class ( output, &cdma_error_class, NULL)) { - mm_warn ("Couldn't send SMS; error class (%u): '%s'", - cdma_error_class, - qmi_wms_cdma_error_class_get_string (cdma_error_class)); + mm_obj_warn (self, "couldn't send SMS; error class (%u): %s", + cdma_error_class, + qmi_wms_cdma_error_class_get_string (cdma_error_class)); } g_prefix_error (&error, "Couldn't write SMS part: "); @@ -658,24 +661,26 @@ delete_part_ready (QmiClientWms *client, GAsyncResult *res, GTask *task) { + MMSmsQmi *self; SmsDeletePartsContext *ctx; QmiMessageWmsDeleteOutput *output = NULL; GError *error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); output = qmi_client_wms_delete_finish (client, res, &error); if (!output) { ctx->n_failed++; - mm_dbg ("QMI operation failed: Couldn't delete SMS part with index %u: '%s'", - mm_sms_part_get_index ((MMSmsPart *)ctx->current->data), - error->message); + mm_obj_dbg (self, "QMI operation failed: couldn't delete SMS part with index %u: %s", + mm_sms_part_get_index ((MMSmsPart *)ctx->current->data), + error->message); g_error_free (error); } else if (!qmi_message_wms_delete_output_get_result (output, &error)) { ctx->n_failed++; - mm_dbg ("Couldn't delete SMS part with index %u: '%s'", - mm_sms_part_get_index ((MMSmsPart *)ctx->current->data), - error->message); + mm_obj_dbg (self, "couldn't delete SMS part with index %u: %s", + mm_sms_part_get_index ((MMSmsPart *)ctx->current->data), + error->message); g_error_free (error); } From d0545f60ad76e5288a51c27d8063399c6a074955 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 07:33:06 +0200 Subject: [PATCH 054/675] sms-mbim: port to use object logging --- src/mm-sms-mbim.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mm-sms-mbim.c b/src/mm-sms-mbim.c index e20a83d2..5c48c0c0 100644 --- a/src/mm-sms-mbim.c +++ b/src/mm-sms-mbim.c @@ -28,7 +28,7 @@ #include "mm-iface-modem-messaging.h" #include "mm-sms-mbim.h" #include "mm-base-modem.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-sms-part-3gpp.h" G_DEFINE_TYPE (MMSmsMbim, mm_sms_mbim, MM_TYPE_BASE_SMS) @@ -237,11 +237,14 @@ sms_delete_set_ready (MbimDevice *device, GAsyncResult *res, GTask *task) { + MMSmsMbim *self; SmsDeletePartsContext *ctx; MbimMessage *response; GError *error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); + response = mbim_device_command_finish (device, res, &error); if (response && mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) @@ -252,9 +255,9 @@ sms_delete_set_ready (MbimDevice *device, if (error) { ctx->n_failed++; - mm_dbg ("Couldn't delete SMS part with index %u: '%s'", - mm_sms_part_get_index ((MMSmsPart *)ctx->current->data), - error->message); + mm_obj_dbg (self, "couldn't delete SMS part with index %u: %s", + mm_sms_part_get_index ((MMSmsPart *)ctx->current->data), + error->message); g_error_free (error); } From 3186a498c188a8686d6766a4c23bc051f3d00abe Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 11:06:32 +0200 Subject: [PATCH 055/675] sms-part-3gpp: port to use object logging --- src/mm-base-sms.c | 27 ++++--- src/mm-broadband-modem-mbim.c | 1 + src/mm-broadband-modem-qmi.c | 1 + src/mm-broadband-modem.c | 6 +- src/mm-sms-mbim.c | 5 +- src/mm-sms-part-3gpp.c | 124 ++++++++++++++++++--------------- src/mm-sms-part-3gpp.h | 46 ++++++------ src/mm-sms-qmi.c | 8 ++- src/tests/test-sms-part-3gpp.c | 9 +-- test/mmsmspdu.c | 2 +- 10 files changed, 128 insertions(+), 101 deletions(-) diff --git a/src/mm-base-sms.c b/src/mm-base-sms.c index e907637a..ad6bba26 100644 --- a/src/mm-base-sms.c +++ b/src/mm-base-sms.c @@ -129,7 +129,7 @@ generate_3gpp_submit_pdus (MMBaseSms *self, g_assert (!(text != NULL && data != NULL)); if (text) { - split_text = mm_sms_part_3gpp_util_split_text (text, &encoding); + split_text = mm_sms_part_3gpp_util_split_text (text, &encoding, self); if (!split_text) { g_set_error (error, MM_CORE_ERROR, @@ -771,12 +771,13 @@ mm_base_sms_get_parts (MMBaseSms *self) /*****************************************************************************/ static gboolean -sms_get_store_or_send_command (MMSmsPart *part, - gboolean text_or_pdu, /* TRUE for PDU */ - gboolean store_or_send, /* TRUE for send */ - gchar **out_cmd, - gchar **out_msg_data, - GError **error) +sms_get_store_or_send_command (MMBaseSms *self, + MMSmsPart *part, + gboolean text_or_pdu, /* TRUE for PDU */ + gboolean store_or_send, /* TRUE for send */ + gchar **out_cmd, + gchar **out_msg_data, + GError **error) { g_assert (out_cmd != NULL); g_assert (out_msg_data != NULL); @@ -795,7 +796,7 @@ sms_get_store_or_send_command (MMSmsPart *part, /* AT+CMGW=[, ] PDU can be entered. / */ - pdu = mm_sms_part_3gpp_get_submit_pdu (part, &pdulen, &msgstart, error); + pdu = mm_sms_part_3gpp_get_submit_pdu (part, &pdulen, &msgstart, self, error); if (!pdu) /* 'error' should already be set */ return FALSE; @@ -929,10 +930,12 @@ store_ready (MMBaseModem *modem, static void sms_store_next_part (GTask *task) { + MMBaseSms *self; SmsStoreContext *ctx; gchar *cmd; GError *error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); if (!ctx->current) { @@ -944,7 +947,8 @@ sms_store_next_part (GTask *task) g_clear_pointer (&ctx->msg_data, g_free); - if (!sms_get_store_or_send_command ((MMSmsPart *)ctx->current->data, + if (!sms_get_store_or_send_command (self, + (MMSmsPart *)ctx->current->data, ctx->use_pdu_mode, FALSE, &cmd, @@ -1194,10 +1198,12 @@ send_from_storage_ready (MMBaseModem *modem, static void sms_send_next_part (GTask *task) { + MMBaseSms *self; SmsSendContext *ctx; GError *error = NULL; gchar *cmd; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); if (!ctx->current) { @@ -1225,7 +1231,8 @@ sms_send_next_part (GTask *task) g_clear_pointer (&ctx->msg_data, g_free); - if (!sms_get_store_or_send_command ((MMSmsPart *)ctx->current->data, + if (!sms_get_store_or_send_command (self, + (MMSmsPart *)ctx->current->data, ctx->use_pdu_mode, TRUE, &cmd, diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index fac54504..c524b7ff 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -5161,6 +5161,7 @@ add_sms_part (MMBroadbandModemMbim *self, part = mm_sms_part_3gpp_new_from_binary_pdu (pdu->message_index, pdu->pdu_data, pdu->pdu_data_size, + self, &error); if (part) { mm_obj_dbg (self, "correctly parsed PDU (%d)", pdu->message_index); diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 17630579..388edd00 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -5535,6 +5535,7 @@ add_new_read_sms_part (MMIfaceModemMessaging *self, part = mm_sms_part_3gpp_new_from_binary_pdu (index, (guint8 *)data->data, data->len, + self, &error); break; case QMI_WMS_MESSAGE_FORMAT_MWI: diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 05da641a..011662d1 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -6810,7 +6810,7 @@ sms_part_ready (MMBroadbandModem *self, return; } - part = mm_sms_part_3gpp_new_from_pdu (info->index, info->pdu, &error); + part = mm_sms_part_3gpp_new_from_pdu (info->index, info->pdu, self, &error); if (part) { mm_obj_dbg (self, "correctly parsed PDU (%d)", ctx->idx); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), @@ -6925,7 +6925,7 @@ cds_received (MMPortSerialAt *port, if (!pdu) return; - part = mm_sms_part_3gpp_new_from_pdu (SMS_PART_INVALID_INDEX, pdu, &error); + part = mm_sms_part_3gpp_new_from_pdu (SMS_PART_INVALID_INDEX, pdu, self, &error); if (part) { mm_obj_dbg (self, "correctly parsed non-stored PDU"); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), @@ -7355,7 +7355,7 @@ sms_pdu_part_list_ready (MMBroadbandModem *self, MM3gppPduInfo *info = l->data; MMSmsPart *part; - part = mm_sms_part_3gpp_new_from_pdu (info->index, info->pdu, &error); + part = mm_sms_part_3gpp_new_from_pdu (info->index, info->pdu, self, &error); if (part) { mm_obj_dbg (self, "correctly parsed PDU (%d)", info->index); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), diff --git a/src/mm-sms-mbim.c b/src/mm-sms-mbim.c index 5c48c0c0..5ad3e519 100644 --- a/src/mm-sms-mbim.c +++ b/src/mm-sms-mbim.c @@ -138,6 +138,7 @@ sms_send_set_ready (MbimDevice *device, static void sms_send_next_part (GTask *task) { + MMSmsMbim *self; SmsSendContext *ctx; MbimMessage *message; guint8 *pdu; @@ -146,7 +147,9 @@ sms_send_next_part (GTask *task) GError *error = NULL; MbimSmsPduSendRecord send_record; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); + if (!ctx->current) { /* Done we are */ g_task_return_boolean (task, TRUE); @@ -155,7 +158,7 @@ sms_send_next_part (GTask *task) } /* Get PDU */ - pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error); + pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, self, &error); if (!pdu) { g_task_return_error (task, error); g_object_unref (task); diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index 3a59cdca..7b8689ed 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -240,17 +240,21 @@ sms_encoding_type (int dcs) } static char * -sms_decode_text (const guint8 *text, int len, MMSmsEncoding encoding, int bit_offset) +sms_decode_text (const guint8 *text, + int len, + MMSmsEncoding encoding, + int bit_offset, + gpointer log_object) { char *utf8; guint8 *unpacked; guint32 unpacked_len; if (encoding == MM_SMS_ENCODING_GSM7) { - mm_dbg ("Converting SMS part text from GSM-7 to UTF-8..."); + mm_obj_dbg (log_object, "converting SMS part text from GSM-7 to UTF-8..."); unpacked = mm_charset_gsm_unpack ((const guint8 *) text, len, bit_offset, &unpacked_len); utf8 = (char *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len); - mm_dbg (" Got UTF-8 text: '%s'", utf8); + mm_obj_dbg (log_object, " got UTF-8 text: '%s'", utf8); g_free (unpacked); } else if (encoding == MM_SMS_ENCODING_UCS2) { /* Despite 3GPP TS 23.038 specifies that Unicode SMS messages are @@ -266,19 +270,19 @@ sms_decode_text (const guint8 *text, int len, MMSmsEncoding encoding, int bit_of * the SMS message in UTF-16BE, and if that fails, fall back to decode * in UCS-2BE. */ - mm_dbg ("Converting SMS part text from UTF-16BE to UTF-8..."); + mm_obj_dbg (log_object, "converting SMS part text from UTF-16BE to UTF-8..."); utf8 = g_convert ((const gchar *) text, len, "UTF8", "UTF16BE", NULL, NULL, NULL); if (!utf8) { - mm_dbg ("Converting SMS part text from UCS-2BE to UTF8..."); + mm_obj_dbg (log_object, "converting SMS part text from UCS-2BE to UTF8..."); utf8 = g_convert ((const gchar *) text, len, "UTF8", "UCS-2BE", NULL, NULL, NULL); } if (!utf8) { - mm_warn ("Couldn't convert SMS part contents from UTF-16BE/UCS-2BE to UTF-8: not decoding any text"); + mm_obj_warn (log_object, "couldn't convert SMS part contents from UTF-16BE/UCS-2BE to UTF-8: not decoding any text"); utf8 = g_strdup (""); } else - mm_dbg (" Got UTF-8 text: '%s'", utf8); + mm_obj_dbg (log_object, " got UTF-8 text: '%s'", utf8); } else { - mm_warn ("Unexpected encoding '%s': not decoding any text", mm_sms_encoding_get_string (encoding)); + mm_obj_warn (log_object, "unexpected encoding: %s; not decoding any text", mm_sms_encoding_get_string (encoding)); utf8 = g_strdup (""); } @@ -343,9 +347,10 @@ validity_to_relative (guint validity) } MMSmsPart * -mm_sms_part_3gpp_new_from_pdu (guint index, - const gchar *hexpdu, - GError **error) +mm_sms_part_3gpp_new_from_pdu (guint index, + const gchar *hexpdu, + gpointer log_object, + GError **error) { gsize pdu_len; guint8 *pdu; @@ -361,17 +366,18 @@ mm_sms_part_3gpp_new_from_pdu (guint index, return NULL; } - part = mm_sms_part_3gpp_new_from_binary_pdu (index, pdu, pdu_len, error); + part = mm_sms_part_3gpp_new_from_binary_pdu (index, pdu, pdu_len, log_object, error); g_free (pdu); return part; } MMSmsPart * -mm_sms_part_3gpp_new_from_binary_pdu (guint index, - const guint8 *pdu, - gsize pdu_len, - GError **error) +mm_sms_part_3gpp_new_from_binary_pdu (guint index, + const guint8 *pdu, + gsize pdu_len, + gpointer log_object, + GError **error) { MMSmsPart *sms_part; guint8 pdu_type; @@ -392,9 +398,9 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, sms_part = mm_sms_part_new (index, MM_SMS_PDU_TYPE_UNKNOWN); if (index != SMS_PART_INVALID_INDEX) - mm_dbg ("Parsing PDU (%u)...", index); + mm_obj_dbg (log_object, "parsing PDU (%u)...", index); else - mm_dbg ("Parsing PDU..."); + mm_obj_dbg (log_object, "parsing PDU..."); #define PDU_SIZE_CHECK(required_size, check_descr_str) \ if (pdu_len < required_size) { \ @@ -421,10 +427,10 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, /* SMSC may not be given in DELIVER PDUs */ mm_sms_part_take_smsc (sms_part, sms_decode_address (&pdu[1], 2 * (smsc_addr_size_bytes - 1))); - mm_dbg (" SMSC address parsed: '%s'", mm_sms_part_get_smsc (sms_part)); + mm_obj_dbg (log_object, " SMSC address parsed: '%s'", mm_sms_part_get_smsc (sms_part)); offset += smsc_addr_size_bytes; } else - mm_dbg (" No SMSC address given"); + mm_obj_dbg (log_object, " no SMSC address given"); /* ---------------------------------------------------------------------- */ @@ -434,15 +440,15 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, pdu_type = (pdu[offset] & SMS_TP_MTI_MASK); switch (pdu_type) { case SMS_TP_MTI_SMS_DELIVER: - mm_dbg (" Deliver type PDU detected"); + mm_obj_dbg (log_object, " deliver type PDU detected"); mm_sms_part_set_pdu_type (sms_part, MM_SMS_PDU_TYPE_DELIVER); break; case SMS_TP_MTI_SMS_SUBMIT: - mm_dbg (" Submit type PDU detected"); + mm_obj_dbg (log_object, " submit type PDU detected"); mm_sms_part_set_pdu_type (sms_part, MM_SMS_PDU_TYPE_SUBMIT); break; case SMS_TP_MTI_SMS_STATUS_REPORT: - mm_dbg (" Status report type PDU detected"); + mm_obj_dbg (log_object, " status report type PDU detected"); mm_sms_part_set_pdu_type (sms_part, MM_SMS_PDU_TYPE_STATUS_REPORT); break; default: @@ -475,7 +481,7 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, pdu_type == SMS_TP_MTI_SMS_SUBMIT) { PDU_SIZE_CHECK (offset + 1, "cannot read message reference"); - mm_dbg (" message reference: %u", (guint)pdu[offset]); + mm_obj_dbg (log_object, " message reference: %u", (guint)pdu[offset]); mm_sms_part_set_message_reference (sms_part, pdu[offset]); offset++; } @@ -495,7 +501,7 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, mm_sms_part_take_number (sms_part, sms_decode_address (&pdu[offset], tp_addr_size_digits)); - mm_dbg (" Number parsed: '%s'", mm_sms_part_get_number (sms_part)); + mm_obj_dbg (log_object, " number parsed: %s", mm_sms_part_get_number (sms_part)); offset += (1 + tp_addr_size_bytes); /* +1 due to the Type of Address byte */ /* ---------------------------------------------------------------------- */ @@ -531,20 +537,20 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, if (validity_format) { switch (validity_format) { case 0x10: - mm_dbg (" validity available, format relative"); + mm_obj_dbg (log_object, " validity available, format relative"); mm_sms_part_set_validity_relative (sms_part, relative_to_validity (pdu[offset])); offset++; break; case 0x08: /* TODO: support enhanced format; GSM 03.40 */ - mm_dbg (" validity available, format enhanced (not implemented)"); + mm_obj_dbg (log_object, " validity available, format enhanced (not implemented)"); /* 7 bytes for enhanced validity */ offset += 7; break; case 0x18: /* TODO: support absolute format; GSM 03.40 */ - mm_dbg (" validity available, format absolute (not implemented)"); + mm_obj_dbg (log_object, " validity available, format absolute (not implemented)"); /* 7 bytes for absolute validity */ offset += 7; break; @@ -574,7 +580,7 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, offset += 7; /* ----- TP-STATUS (1 byte) ------ */ - mm_dbg (" delivery state: %u", (guint)pdu[offset]); + mm_obj_dbg (log_object, " delivery state: %u", (guint)pdu[offset]); mm_sms_part_set_delivery_state (sms_part, pdu[offset]); offset++; @@ -599,7 +605,7 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, if (tp_pid_offset > 0) { PDU_SIZE_CHECK (tp_pid_offset + 1, "cannot read TP-PID"); - mm_dbg (" PID: %u", (guint)pdu[tp_pid_offset]); + mm_obj_dbg (log_object, " PID: %u", (guint)pdu[tp_pid_offset]); } /* Grab user data encoding and message class */ @@ -610,17 +616,17 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, user_data_encoding = sms_encoding_type (pdu[tp_dcs_offset]); switch (user_data_encoding) { case MM_SMS_ENCODING_GSM7: - mm_dbg (" user data encoding is GSM7"); + mm_obj_dbg (log_object, " user data encoding is GSM7"); break; case MM_SMS_ENCODING_UCS2: - mm_dbg (" user data encoding is UCS2"); + mm_obj_dbg (log_object, " user data encoding is UCS2"); break; case MM_SMS_ENCODING_8BIT: - mm_dbg (" user data encoding is 8bit"); + mm_obj_dbg (log_object, " user data encoding is 8bit"); break; case MM_SMS_ENCODING_UNKNOWN: default: - mm_dbg (" user data encoding is unknown"); + mm_obj_dbg (log_object, " user data encoding is unknown"); break; } mm_sms_part_set_encoding (sms_part, user_data_encoding); @@ -639,13 +645,13 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, PDU_SIZE_CHECK (tp_user_data_len_offset + 1, "cannot read TP-UDL"); tp_user_data_size_elements = pdu[tp_user_data_len_offset]; - mm_dbg (" user data length: %u elements", tp_user_data_size_elements); + mm_obj_dbg (log_object, " user data length: %u elements", tp_user_data_size_elements); if (user_data_encoding == MM_SMS_ENCODING_GSM7) tp_user_data_size_bytes = (7 * (tp_user_data_size_elements + 1 )) / 8; else tp_user_data_size_bytes = tp_user_data_size_elements; - mm_dbg (" user data length: %u bytes", tp_user_data_size_bytes); + mm_obj_dbg (log_object, " user data length: %u bytes", tp_user_data_size_bytes); tp_user_data_offset = tp_user_data_len_offset + 1; PDU_SIZE_CHECK (tp_user_data_offset + tp_user_data_size_bytes, "cannot read TP-UD"); @@ -722,12 +728,13 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, case MM_SMS_ENCODING_GSM7: case MM_SMS_ENCODING_UCS2: /* Otherwise if it's 7-bit or UCS2 we can decode it */ - mm_dbg ("Decoding SMS text with '%u' elements", tp_user_data_size_elements); + mm_obj_dbg (log_object, "decoding SMS text with %u elements", tp_user_data_size_elements); mm_sms_part_take_text (sms_part, sms_decode_text (&pdu[tp_user_data_offset], tp_user_data_size_elements, user_data_encoding, - bit_offset)); + bit_offset, + log_object)); g_warn_if_fail (mm_sms_part_get_text (sms_part) != NULL); break; @@ -737,7 +744,7 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, { GByteArray *raw; - mm_dbg ("Skipping SMS text: Unknown encoding (0x%02X)", user_data_encoding); + mm_obj_dbg (log_object, "skipping SMS text: unknown encoding (0x%02X)", user_data_encoding); PDU_SIZE_CHECK (tp_user_data_offset + tp_user_data_size_bytes, "cannot read user data"); @@ -815,6 +822,7 @@ guint8 * mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, guint *out_pdulen, guint *out_msgstart, + gpointer log_object, GError **error) { guint8 *pdu; @@ -834,13 +842,13 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, return NULL; } - mm_dbg ("Creating PDU for part..."); + mm_obj_dbg (log_object, "creating PDU for part..."); /* Build up the PDU */ pdu = g_malloc0 (PDU_SIZE); if (mm_sms_part_get_smsc (part)) { - mm_dbg (" adding SMSC to PDU..."); + mm_obj_dbg (log_object, " adding SMSC to PDU..."); len = mm_sms_part_3gpp_encode_address (mm_sms_part_get_smsc (part), pdu, PDU_SIZE, TRUE); if (len == 0) { g_set_error (error, @@ -863,13 +871,13 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, /* TP-VP present; format RELATIVE */ if (mm_sms_part_get_validity_relative (part) > 0) { - mm_dbg (" adding validity to PDU..."); + mm_obj_dbg (log_object, " adding validity to PDU..."); pdu[offset] |= 0x10; } /* Concatenation sequence only found in multipart SMS */ if (mm_sms_part_get_concat_sequence (part)) { - mm_dbg (" adding UDHI to PDU..."); + mm_obj_dbg (log_object, " adding UDHI to PDU..."); pdu[offset] |= 0x40; /* UDHI */ } @@ -878,7 +886,7 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, if (mm_sms_part_get_delivery_report_request (part) && (!mm_sms_part_get_concat_sequence (part) || mm_sms_part_get_concat_max (part) == mm_sms_part_get_concat_sequence (part))) { - mm_dbg (" requesting delivery report..."); + mm_obj_dbg (log_object, " requesting delivery report..."); pdu[offset] |= 0x20; } @@ -910,24 +918,24 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, pdu[offset] = 0x00; if (mm_sms_part_get_class (part) >= 0 && mm_sms_part_get_class (part) <= 3) { - mm_dbg (" using class %d...", mm_sms_part_get_class (part)); + mm_obj_dbg (log_object, " using class %d...", mm_sms_part_get_class (part)); pdu[offset] |= SMS_DCS_CLASS_VALID; pdu[offset] |= mm_sms_part_get_class (part); } switch (mm_sms_part_get_encoding (part)) { case MM_SMS_ENCODING_UCS2: - mm_dbg (" using UCS2 encoding..."); + mm_obj_dbg (log_object, " using UCS2 encoding..."); pdu[offset] |= SMS_DCS_CODING_UCS2; break; case MM_SMS_ENCODING_GSM7: - mm_dbg (" using GSM7 encoding..."); + mm_obj_dbg (log_object, " using GSM7 encoding..."); pdu[offset] |= SMS_DCS_CODING_DEFAULT; /* GSM */ break; case MM_SMS_ENCODING_8BIT: case MM_SMS_ENCODING_UNKNOWN: default: - mm_dbg (" using 8bit encoding..."); + mm_obj_dbg (log_object, " using 8bit encoding..."); pdu[offset] |= SMS_DCS_CODING_8BIT; break; } @@ -946,7 +954,7 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, /* Build UDH */ if (mm_sms_part_get_concat_sequence (part)) { - mm_dbg (" adding UDH header in PDU... (reference: %u, max: %u, sequence: %u)", + mm_obj_dbg (log_object, " adding UDH header in PDU... (reference: %u, max: %u, sequence: %u)", mm_sms_part_get_concat_reference (part), mm_sms_part_get_concat_max (part), mm_sms_part_get_concat_sequence (part)); @@ -986,9 +994,9 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, * If we had UDH, add 7 septets */ *udl_ptr = mm_sms_part_get_concat_sequence (part) ? (7 + unlen) : unlen; - mm_dbg (" user data length is '%u' septets (%s UDH)", - *udl_ptr, - mm_sms_part_get_concat_sequence (part) ? "with" : "without"); + mm_obj_dbg (log_object, " user data length is %u septets (%s UDH)", + *udl_ptr, + mm_sms_part_get_concat_sequence (part) ? "with" : "without"); packed = mm_charset_gsm_pack (unpacked, unlen, shift, &packlen); g_free (unpacked); @@ -1022,7 +1030,7 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, * If we had UDH, add 6 octets */ *udl_ptr = mm_sms_part_get_concat_sequence (part) ? (6 + array->len) : array->len; - mm_dbg (" user data length is '%u' octets (%s UDH)", + mm_obj_dbg (log_object, " user data length is %u octets (%s UDH)", *udl_ptr, mm_sms_part_get_concat_sequence (part) ? "with" : "without"); @@ -1038,7 +1046,7 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, * If we had UDH, add 6 octets */ *udl_ptr = mm_sms_part_get_concat_sequence (part) ? (6 + data->len) : data->len; - mm_dbg (" binary user data length is '%u' octets (%s UDH)", + mm_obj_dbg (log_object, " binary user data length is %u octets (%s UDH)", *udl_ptr, mm_sms_part_get_concat_sequence (part) ? "with" : "without"); @@ -1057,8 +1065,9 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, } gchar ** -mm_sms_part_3gpp_util_split_text (const gchar *text, - MMSmsEncoding *encoding) +mm_sms_part_3gpp_util_split_text (const gchar *text, + MMSmsEncoding *encoding, + gpointer log_object) { gchar **out; guint n_chunks; @@ -1132,7 +1141,8 @@ mm_sms_part_3gpp_util_split_text (const gchar *text, out[i] = sms_decode_text (&array->data[j], MIN (array->len - j, 134), MM_SMS_ENCODING_UCS2, - 0); + 0, + log_object); } } g_byte_array_unref (array); diff --git a/src/mm-sms-part-3gpp.h b/src/mm-sms-part-3gpp.h index bd6a242a..bef416fa 100644 --- a/src/mm-sms-part-3gpp.h +++ b/src/mm-sms-part-3gpp.h @@ -22,31 +22,31 @@ #include "mm-sms-part.h" -MMSmsPart *mm_sms_part_3gpp_new_from_pdu (guint index, - const gchar *hexpdu, - GError **error); - -MMSmsPart *mm_sms_part_3gpp_new_from_binary_pdu (guint index, - const guint8 *pdu, - gsize pdu_len, - GError **error); - -guint8 *mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, - guint *out_pdulen, - guint *out_msgstart, - GError **error); +MMSmsPart *mm_sms_part_3gpp_new_from_pdu (guint index, + const gchar *hexpdu, + gpointer log_object, + GError **error); +MMSmsPart *mm_sms_part_3gpp_new_from_binary_pdu (guint index, + const guint8 *pdu, + gsize pdu_len, + gpointer log_object, + GError **error); +guint8 *mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, + guint *out_pdulen, + guint *out_msgstart, + gpointer log_object, + GError **error); /* For testcases only */ -guint mm_sms_part_3gpp_encode_address (const gchar *address, - guint8 *buf, - gsize buflen, - gboolean is_smsc); - -gchar **mm_sms_part_3gpp_util_split_text (const gchar *text, - MMSmsEncoding *encoding); - -GByteArray **mm_sms_part_3gpp_util_split_data (const guint8 *data, - gsize data_len); +guint mm_sms_part_3gpp_encode_address (const gchar *address, + guint8 *buf, + gsize buflen, + gboolean is_smsc); +gchar **mm_sms_part_3gpp_util_split_text (const gchar *text, + MMSmsEncoding *encoding, + gpointer log_object); +GByteArray **mm_sms_part_3gpp_util_split_data (const guint8 *data, + gsize data_len); #endif /* MM_SMS_PART_3GPP_H */ diff --git a/src/mm-sms-qmi.c b/src/mm-sms-qmi.c index 7124be32..02c0fd59 100644 --- a/src/mm-sms-qmi.c +++ b/src/mm-sms-qmi.c @@ -190,6 +190,7 @@ store_ready (QmiClientWms *client, static void sms_store_next_part (GTask *task) { + MMSmsQmi *self; SmsStoreContext *ctx; QmiMessageWmsRawWriteInput *input; guint8 *pdu = NULL; @@ -198,6 +199,7 @@ sms_store_next_part (GTask *task) GArray *array; GError *error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); if (!ctx->current) { @@ -209,7 +211,7 @@ sms_store_next_part (GTask *task) /* Get PDU */ if (MM_SMS_PART_IS_3GPP ((MMSmsPart *)ctx->current->data)) - pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error); + pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, self, &error); else if (MM_SMS_PART_IS_CDMA ((MMSmsPart *)ctx->current->data)) pdu = mm_sms_part_cdma_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &error); @@ -384,6 +386,7 @@ send_generic_ready (QmiClientWms *client, static void sms_send_generic (GTask *task) { + MMSmsQmi *self; SmsSendContext *ctx; QmiMessageWmsRawSendInput *input; guint8 *pdu = NULL; @@ -392,11 +395,12 @@ sms_send_generic (GTask *task) GArray *array; GError *error = NULL; + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); /* Get PDU */ if (MM_SMS_PART_IS_3GPP ((MMSmsPart *)ctx->current->data)) - pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, &error); + pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, self, &error); else if (MM_SMS_PART_IS_CDMA ((MMSmsPart *)ctx->current->data)) pdu = mm_sms_part_cdma_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &error); diff --git a/src/tests/test-sms-part-3gpp.c b/src/tests/test-sms-part-3gpp.c index a2ad304e..9889a4e9 100644 --- a/src/tests/test-sms-part-3gpp.c +++ b/src/tests/test-sms-part-3gpp.c @@ -41,7 +41,7 @@ common_test_part_from_hexpdu (const gchar *hexpdu, MMSmsPart *part; GError *error = NULL; - part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, &error); + part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, NULL, &error); g_assert_no_error (error); g_assert (part != NULL); @@ -339,7 +339,7 @@ test_pdu_insufficient_data (void) }; hexpdu = mm_utils_bin2hexstr (pdu, sizeof (pdu)); - part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, &error); + part = mm_sms_part_3gpp_new_from_pdu (0, hexpdu, NULL, &error); g_assert (part == NULL); /* We don't care for the specific error type */ g_assert (error != NULL); @@ -531,7 +531,7 @@ common_test_create_pdu (const gchar *smsc, MMSmsEncoding encoding = MM_SMS_ENCODING_UNKNOWN; /* Detect best encoding */ - out = mm_sms_part_3gpp_util_split_text (text, &encoding); + out = mm_sms_part_3gpp_util_split_text (text, &encoding, NULL); g_strfreev (out); mm_sms_part_set_text (part, text); mm_sms_part_set_encoding (part, encoding); @@ -544,6 +544,7 @@ common_test_create_pdu (const gchar *smsc, pdu = mm_sms_part_3gpp_get_submit_pdu (part, &len, &msgstart, + NULL, &error); mm_sms_part_free (part); @@ -719,7 +720,7 @@ common_test_text_split (const gchar *text, MMSmsEncoding out_encoding = MM_SMS_ENCODING_UNKNOWN; guint i; - out = mm_sms_part_3gpp_util_split_text (text, &out_encoding); + out = mm_sms_part_3gpp_util_split_text (text, &out_encoding, NULL); g_assert (out != NULL); g_assert (out_encoding != MM_SMS_ENCODING_UNKNOWN); diff --git a/test/mmsmspdu.c b/test/mmsmspdu.c index 787f98f5..ef27074c 100644 --- a/test/mmsmspdu.c +++ b/test/mmsmspdu.c @@ -220,7 +220,7 @@ int main (int argc, char **argv) exit (EXIT_FAILURE); } - part = mm_sms_part_3gpp_new_from_pdu (0, pdu, &error); + part = mm_sms_part_3gpp_new_from_pdu (0, pdu, NULL, &error); if (!part) { g_printerr ("error: couldn't parse PDU: %s\n", error->message); exit (EXIT_FAILURE); From 72efb1b28da7daba1448def917d28b30014fde27 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 17:00:14 +0200 Subject: [PATCH 056/675] sms-part-cdma: port to use object logging --- src/mm-broadband-modem-qmi.c | 1 + src/mm-sms-part-cdma.c | 420 +++++++++++++++++---------------- src/mm-sms-part-cdma.h | 25 +- src/mm-sms-qmi.c | 4 +- src/tests/test-sms-part-cdma.c | 6 +- 5 files changed, 238 insertions(+), 218 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 388edd00..ec85c1c7 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -5527,6 +5527,7 @@ add_new_read_sms_part (MMIfaceModemMessaging *self, part = mm_sms_part_cdma_new_from_binary_pdu (index, (guint8 *)data->data, data->len, + self, &error); break; diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index 0f40f653..96302261 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -24,7 +24,7 @@ #include "mm-charsets.h" #include "mm-sms-part-cdma.h" -#include "mm-log.h" +#include "mm-log-object.h" /* * Documentation that you may want to have around: @@ -312,9 +312,10 @@ cause_code_to_delivery_state (guint8 error_class, /*****************************************************************************/ MMSmsPart * -mm_sms_part_cdma_new_from_pdu (guint index, - const gchar *hexpdu, - GError **error) +mm_sms_part_cdma_new_from_pdu (guint index, + const gchar *hexpdu, + gpointer log_object, + GError **error) { gsize pdu_len; guint8 *pdu; @@ -330,7 +331,7 @@ mm_sms_part_cdma_new_from_pdu (guint index, return NULL; } - part = mm_sms_part_cdma_new_from_binary_pdu (index, pdu, pdu_len, error); + part = mm_sms_part_cdma_new_from_binary_pdu (index, pdu, pdu_len, log_object, error); g_free (pdu); return part; @@ -343,16 +344,17 @@ struct Parameter { } __attribute__((packed)); static void -read_teleservice_id (MMSmsPart *sms_part, - const struct Parameter *parameter) +read_teleservice_id (MMSmsPart *sms_part, + const struct Parameter *parameter, + gpointer log_object) { guint16 teleservice_id; g_assert (parameter->parameter_id == PARAMETER_ID_TELESERVICE_ID); if (parameter->parameter_len != 2) { - mm_dbg (" invalid teleservice ID length found (%u != 2): ignoring", - parameter->parameter_len); + mm_obj_dbg (log_object, " invalid teleservice ID length found (%u != 2): ignoring", + parameter->parameter_len); return; } @@ -370,29 +372,30 @@ read_teleservice_id (MMSmsPart *sms_part, case MM_SMS_CDMA_TELESERVICE_ID_CATPT: break; default: - mm_dbg (" invalid teleservice ID found (%u): ignoring", teleservice_id); + mm_obj_dbg (log_object, " invalid teleservice ID found (%u): ignoring", teleservice_id); return; } - mm_dbg (" teleservice ID: %s (%u)", - mm_sms_cdma_teleservice_id_get_string (teleservice_id), - teleservice_id); + mm_obj_dbg (log_object, " teleservice ID: %s (%u)", + mm_sms_cdma_teleservice_id_get_string (teleservice_id), + teleservice_id); mm_sms_part_set_cdma_teleservice_id (sms_part, (MMSmsCdmaTeleserviceId)teleservice_id); } static void -read_service_category (MMSmsPart *sms_part, - const struct Parameter *parameter) +read_service_category (MMSmsPart *sms_part, + const struct Parameter *parameter, + gpointer log_object) { guint16 service_category; g_assert (parameter->parameter_id == PARAMETER_ID_SERVICE_CATEGORY); if (parameter->parameter_len != 2) { - mm_dbg (" invalid service category length found (%u != 2): ignoring", - parameter->parameter_len); + mm_obj_dbg (log_object, " invalid service category length found (%u != 2): ignoring", + parameter->parameter_len); return; } @@ -438,20 +441,21 @@ read_service_category (MMSmsPart *sms_part, case MM_SMS_CDMA_SERVICE_CATEGORY_CMAS_TEST: break; default: - mm_dbg (" invalid service category found (%u): ignoring", service_category); + mm_obj_dbg (log_object, " invalid service category found (%u): ignoring", service_category); return; } - mm_dbg (" service category: %s (%u)", - mm_sms_cdma_service_category_get_string (service_category), - service_category); + mm_obj_dbg (log_object, " service category: %s (%u)", + mm_sms_cdma_service_category_get_string (service_category), + service_category); mm_sms_part_set_cdma_service_category (sms_part, - (MMSmsCdmaServiceCategory)service_category); + (MMSmsCdmaServiceCategory)service_category); } static guint8 -dtmf_to_ascii (guint8 dtmf) +dtmf_to_ascii (guint8 dtmf, + gpointer log_object) { static const gchar dtmf_to_ascii_digits[13] = { '\0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '*', '#' }; @@ -459,13 +463,14 @@ dtmf_to_ascii (guint8 dtmf) if (dtmf > 0 && dtmf < 13) return dtmf_to_ascii_digits[dtmf]; - mm_dbg (" invalid dtmf digit: %u", dtmf); + mm_obj_dbg (log_object, " invalid dtmf digit: %u", dtmf); return '\0'; } static void -read_address (MMSmsPart *sms_part, - const struct Parameter *parameter) +read_address (MMSmsPart *sms_part, + const struct Parameter *parameter, + gpointer log_object) { guint8 digit_mode; guint8 number_mode; @@ -487,9 +492,9 @@ read_address (MMSmsPart *sms_part, #define PARAMETER_SIZE_CHECK(required_size) \ if (parameter->parameter_len < required_size) { \ - mm_dbg (" cannot read address, need at least %u bytes (got %u)", \ - required_size, \ - parameter->parameter_len); \ + mm_obj_dbg (log_object, " cannot read address, need at least %u bytes (got %u)", \ + required_size, \ + parameter->parameter_len); \ return; \ } @@ -502,10 +507,10 @@ read_address (MMSmsPart *sms_part, g_assert (digit_mode <= 1); switch (digit_mode) { case DIGIT_MODE_DTMF: - mm_dbg (" digit mode: dtmf"); + mm_obj_dbg (log_object, " digit mode: dtmf"); break; case DIGIT_MODE_ASCII: - mm_dbg (" digit mode: ascii"); + mm_obj_dbg (log_object, " digit mode: ascii"); break; default: g_assert_not_reached (); @@ -516,10 +521,10 @@ read_address (MMSmsPart *sms_part, OFFSETS_UPDATE (1); switch (number_mode) { case NUMBER_MODE_DIGIT: - mm_dbg (" number mode: digit"); + mm_obj_dbg (log_object, " number mode: digit"); break; case NUMBER_MODE_DATA_NETWORK_ADDRESS: - mm_dbg (" number mode: data network address"); + mm_obj_dbg (log_object, " number mode: data network address"); break; default: g_assert_not_reached (); @@ -532,25 +537,25 @@ read_address (MMSmsPart *sms_part, OFFSETS_UPDATE (3); switch (number_type) { case NUMBER_TYPE_UNKNOWN: - mm_dbg (" number type: unknown"); + mm_obj_dbg (log_object, " number type: unknown"); break; case NUMBER_TYPE_INTERNATIONAL: - mm_dbg (" number type: international"); + mm_obj_dbg (log_object, " number type: international"); break; case NUMBER_TYPE_NATIONAL: - mm_dbg (" number type: national"); + mm_obj_dbg (log_object, " number type: national"); break; case NUMBER_TYPE_NETWORK_SPECIFIC: - mm_dbg (" number type: specific"); + mm_obj_dbg (log_object, " number type: specific"); break; case NUMBER_TYPE_SUBSCRIBER: - mm_dbg (" number type: subscriber"); + mm_obj_dbg (log_object, " number type: subscriber"); break; case NUMBER_TYPE_ABBREVIATED: - mm_dbg (" number type: abbreviated"); + mm_obj_dbg (log_object, " number type: abbreviated"); break; default: - mm_dbg (" number type unknown (%u)", number_type); + mm_obj_dbg (log_object, " number type unknown (%u)", number_type); break; } } else @@ -564,22 +569,22 @@ read_address (MMSmsPart *sms_part, OFFSETS_UPDATE (4); switch (numbering_plan) { case NUMBERING_PLAN_UNKNOWN: - mm_dbg (" numbering plan: unknown"); + mm_obj_dbg (log_object, " numbering plan: unknown"); break; case NUMBERING_PLAN_ISDN: - mm_dbg (" numbering plan: isdn"); + mm_obj_dbg (log_object, " numbering plan: isdn"); break; case NUMBERING_PLAN_DATA: - mm_dbg (" numbering plan: data"); + mm_obj_dbg (log_object, " numbering plan: data"); break; case NUMBERING_PLAN_TELEX: - mm_dbg (" numbering plan: telex"); + mm_obj_dbg (log_object, " numbering plan: telex"); break; case NUMBERING_PLAN_PRIVATE: - mm_dbg (" numbering plan: private"); + mm_obj_dbg (log_object, " numbering plan: private"); break; default: - mm_dbg (" numbering plan unknown (%u)", numbering_plan); + mm_obj_dbg (log_object, " numbering plan unknown (%u)", numbering_plan); break; } } else @@ -589,7 +594,7 @@ read_address (MMSmsPart *sms_part, PARAMETER_SIZE_CHECK (byte_offset + 2); num_fields = read_bits (¶meter->parameter_value[byte_offset], bit_offset, 8); OFFSETS_UPDATE (8); - mm_dbg (" num fields: %u", num_fields); + mm_obj_dbg (log_object, " num fields: %u", num_fields); /* Address string */ @@ -598,7 +603,7 @@ read_address (MMSmsPart *sms_part, PARAMETER_SIZE_CHECK (byte_offset + 1 + ((bit_offset + (num_fields * 4)) / 8)); number = g_malloc (num_fields + 1); for (i = 0; i < num_fields; i++) { - number[i] = dtmf_to_ascii (read_bits (¶meter->parameter_value[byte_offset], bit_offset, 4)); + number[i] = dtmf_to_ascii (read_bits (¶meter->parameter_value[byte_offset], bit_offset, 4), log_object); OFFSETS_UPDATE (4); } number[i] = '\0'; @@ -634,9 +639,9 @@ read_address (MMSmsPart *sms_part, } number = g_string_free (str, FALSE); } else - mm_dbg (" data network address number type unknown (%u)", number_type); + mm_obj_dbg (log_object, " data network address number type unknown (%u)", number_type); - mm_dbg (" address: %s", number); + mm_obj_dbg (log_object, " address: %s", number); mm_sms_part_set_number (sms_part, number); g_free (number); @@ -646,28 +651,30 @@ read_address (MMSmsPart *sms_part, } static void -read_bearer_reply_option (MMSmsPart *sms_part, - const struct Parameter *parameter) +read_bearer_reply_option (MMSmsPart *sms_part, + const struct Parameter *parameter, + gpointer log_object) { guint8 sequence; g_assert (parameter->parameter_id == PARAMETER_ID_BEARER_REPLY_OPTION); if (parameter->parameter_len != 1) { - mm_dbg (" invalid bearer reply option length found (%u != 1): ignoring", + mm_obj_dbg (log_object, " invalid bearer reply option length found (%u != 1): ignoring", parameter->parameter_len); return; } sequence = read_bits (¶meter->parameter_value[0], 0, 6); - mm_dbg (" sequence: %u", sequence); + mm_obj_dbg (log_object, " sequence: %u", sequence); mm_sms_part_set_message_reference (sms_part, sequence); } static void -read_cause_codes (MMSmsPart *sms_part, - const struct Parameter *parameter) +read_cause_codes (MMSmsPart *sms_part, + const struct Parameter *parameter, + gpointer log_object) { guint8 sequence; guint8 error_class; @@ -677,38 +684,39 @@ read_cause_codes (MMSmsPart *sms_part, g_assert (parameter->parameter_id == PARAMETER_ID_BEARER_REPLY_OPTION); if (parameter->parameter_len != 1 && parameter->parameter_len != 2) { - mm_dbg (" invalid cause codes length found (%u): ignoring", + mm_obj_dbg (log_object, " invalid cause codes length found (%u): ignoring", parameter->parameter_len); return; } sequence = read_bits (¶meter->parameter_value[0], 0, 6); - mm_dbg (" sequence: %u", sequence); + mm_obj_dbg (log_object, " sequence: %u", sequence); error_class = read_bits (¶meter->parameter_value[0], 6, 2); - mm_dbg (" error class: %u", error_class); + mm_obj_dbg (log_object, " error class: %u", error_class); if (error_class != ERROR_CLASS_NO_ERROR) { if (parameter->parameter_len != 2) { - mm_dbg (" invalid cause codes length found (%u != 2): ignoring", + mm_obj_dbg (log_object, " invalid cause codes length found (%u != 2): ignoring", parameter->parameter_len); return; } cause_code = parameter->parameter_value[1]; - mm_dbg (" cause code: %u", cause_code); + mm_obj_dbg (log_object, " cause code: %u", cause_code); } else cause_code = 0; delivery_state = cause_code_to_delivery_state (error_class, cause_code); - mm_dbg (" delivery state: %s", mm_sms_delivery_state_get_string (delivery_state)); + mm_obj_dbg (log_object, " delivery state: %s", mm_sms_delivery_state_get_string (delivery_state)); mm_sms_part_set_message_reference (sms_part, sequence); mm_sms_part_set_delivery_state (sms_part, delivery_state); } static void -read_bearer_data_message_identifier (MMSmsPart *sms_part, - const struct Parameter *subparameter) +read_bearer_data_message_identifier (MMSmsPart *sms_part, + const struct Parameter *subparameter, + gpointer log_object) { guint8 message_type; guint16 message_id; @@ -717,7 +725,7 @@ read_bearer_data_message_identifier (MMSmsPart *sms_part, g_assert (subparameter->parameter_id == SUBPARAMETER_ID_MESSAGE_ID); if (subparameter->parameter_len != 3) { - mm_dbg (" invalid message identifier length found (%u): ignoring", + mm_obj_dbg (log_object, " invalid message identifier length found (%u): ignoring", subparameter->parameter_len); return; } @@ -725,49 +733,50 @@ read_bearer_data_message_identifier (MMSmsPart *sms_part, message_type = read_bits (&subparameter->parameter_value[0], 0, 4); switch (message_type) { case TELESERVICE_MESSAGE_TYPE_UNKNOWN: - mm_dbg (" message type: unknown"); + mm_obj_dbg (log_object, " message type: unknown"); break; case TELESERVICE_MESSAGE_TYPE_DELIVER: - mm_dbg (" message type: deliver"); + mm_obj_dbg (log_object, " message type: deliver"); mm_sms_part_set_pdu_type (sms_part, MM_SMS_PDU_TYPE_CDMA_DELIVER); break; case TELESERVICE_MESSAGE_TYPE_SUBMIT: - mm_dbg (" message type: submit"); + mm_obj_dbg (log_object, " message type: submit"); mm_sms_part_set_pdu_type (sms_part, MM_SMS_PDU_TYPE_CDMA_SUBMIT); break; case TELESERVICE_MESSAGE_TYPE_CANCELLATION: - mm_dbg (" message type: cancellation"); + mm_obj_dbg (log_object, " message type: cancellation"); mm_sms_part_set_pdu_type (sms_part, MM_SMS_PDU_TYPE_CDMA_CANCELLATION); break; case TELESERVICE_MESSAGE_TYPE_DELIVERY_ACKNOWLEDGEMENT: - mm_dbg (" message type: delivery acknowledgement"); + mm_obj_dbg (log_object, " message type: delivery acknowledgement"); mm_sms_part_set_pdu_type (sms_part, MM_SMS_PDU_TYPE_CDMA_DELIVERY_ACKNOWLEDGEMENT); break; case TELESERVICE_MESSAGE_TYPE_USER_ACKNOWLEDGEMENT: - mm_dbg (" message type: user acknowledgement"); + mm_obj_dbg (log_object, " message type: user acknowledgement"); mm_sms_part_set_pdu_type (sms_part, MM_SMS_PDU_TYPE_CDMA_USER_ACKNOWLEDGEMENT); break; case TELESERVICE_MESSAGE_TYPE_READ_ACKNOWLEDGEMENT: - mm_dbg (" message type: read acknowledgement"); + mm_obj_dbg (log_object, " message type: read acknowledgement"); mm_sms_part_set_pdu_type (sms_part, MM_SMS_PDU_TYPE_CDMA_READ_ACKNOWLEDGEMENT); break; default: - mm_dbg (" message type unknown (%u)", message_type); + mm_obj_dbg (log_object, " message type unknown (%u)", message_type); break; } message_id = ((read_bits (&subparameter->parameter_value[0], 4, 8) << 8) | (read_bits (&subparameter->parameter_value[1], 4, 8))); message_id = GUINT16_FROM_BE (message_id); - mm_dbg (" message id: %u", (guint) message_id); + mm_obj_dbg (log_object, " message id: %u", (guint) message_id); header_ind = read_bits (&subparameter->parameter_value[2], 4, 1); - mm_dbg (" header indicator: %u", header_ind); + mm_obj_dbg (log_object, " header indicator: %u", header_ind); } static void -read_bearer_data_user_data (MMSmsPart *sms_part, - const struct Parameter *subparameter) +read_bearer_data_user_data (MMSmsPart *sms_part, + const struct Parameter *subparameter, + gpointer log_object) { guint8 message_encoding; guint8 message_type = 0; @@ -785,7 +794,7 @@ read_bearer_data_user_data (MMSmsPart *sms_part, #define SUBPARAMETER_SIZE_CHECK(required_size) \ if (subparameter->parameter_len < required_size) { \ - mm_dbg (" cannot read user data, need at least %u bytes (got %u)", \ + mm_obj_dbg (log_object, " cannot read user data, need at least %u bytes (got %u)", \ required_size, \ subparameter->parameter_len); \ return; \ @@ -797,21 +806,21 @@ read_bearer_data_user_data (MMSmsPart *sms_part, SUBPARAMETER_SIZE_CHECK (1); message_encoding = read_bits (&subparameter->parameter_value[byte_offset], bit_offset, 5); OFFSETS_UPDATE (5); - mm_dbg (" message encoding: %s", encoding_to_string (message_encoding)); + mm_obj_dbg (log_object, " message encoding: %s", encoding_to_string (message_encoding)); /* Message type, only if extended protocol message */ if (message_encoding == ENCODING_EXTENDED_PROTOCOL_MESSAGE) { SUBPARAMETER_SIZE_CHECK (2); message_type = read_bits (&subparameter->parameter_value[byte_offset], bit_offset, 8); OFFSETS_UPDATE (8); - mm_dbg (" message type: %u", message_type); + mm_obj_dbg (log_object, " message type: %u", message_type); } /* Number of fields */ SUBPARAMETER_SIZE_CHECK (byte_offset + 1 + ((bit_offset + 8) / 8)); num_fields = read_bits (&subparameter->parameter_value[byte_offset], bit_offset, 8); OFFSETS_UPDATE (8); - mm_dbg (" num fields: %u", num_fields); + mm_obj_dbg (log_object, " num fields: %u", num_fields); /* Now, process actual text or data */ switch (message_encoding) { @@ -828,7 +837,7 @@ read_bearer_data_user_data (MMSmsPart *sms_part, OFFSETS_UPDATE (8); } - mm_dbg (" data: (%u bytes)", num_fields); + mm_obj_dbg (log_object, " data: (%u bytes)", num_fields); mm_sms_part_take_data (sms_part, data); break; } @@ -846,7 +855,7 @@ read_bearer_data_user_data (MMSmsPart *sms_part, } text[i] = '\0'; - mm_dbg (" text: '%s'", text); + mm_obj_dbg (log_object, " text: '%s'", text); mm_sms_part_take_text (sms_part, text); break; } @@ -867,9 +876,9 @@ read_bearer_data_user_data (MMSmsPart *sms_part, text = g_convert (latin, -1, "UTF-8", "ISO−8859−1", NULL, NULL, NULL); if (!text) { - mm_dbg (" text/data: ignored (latin to UTF-8 conversion error)"); + mm_obj_dbg (log_object, " text/data: ignored (latin to UTF-8 conversion error)"); } else { - mm_dbg (" text: '%s'", text); + mm_obj_dbg (log_object, " text: '%s'", text); mm_sms_part_take_text (sms_part, text); } @@ -896,9 +905,9 @@ read_bearer_data_user_data (MMSmsPart *sms_part, text = g_convert (utf16, num_bytes, "UTF-8", "UCS-2BE", NULL, NULL, NULL); if (!text) { - mm_dbg (" text/data: ignored (UTF-16 to UTF-8 conversion error)"); + mm_obj_dbg (log_object, " text/data: ignored (UTF-16 to UTF-8 conversion error)"); } else { - mm_dbg (" text: '%s'", text); + mm_obj_dbg (log_object, " text: '%s'", text); mm_sms_part_take_text (sms_part, text); } @@ -907,7 +916,7 @@ read_bearer_data_user_data (MMSmsPart *sms_part, } default: - mm_dbg (" text/data: ignored (unsupported encoding)"); + mm_obj_dbg (log_object, " text/data: ignored (unsupported encoding)"); } #undef OFFSETS_UPDATE @@ -915,16 +924,17 @@ read_bearer_data_user_data (MMSmsPart *sms_part, } static void -read_bearer_data (MMSmsPart *sms_part, - const struct Parameter *parameter) +read_bearer_data (MMSmsPart *sms_part, + const struct Parameter *parameter, + gpointer log_object) { guint offset; #define PARAMETER_SIZE_CHECK(required_size) \ if (parameter->parameter_len < required_size) { \ - mm_dbg (" cannot read bearer data, need at least %u bytes (got %u)", \ - required_size, \ - parameter->parameter_len); \ + mm_obj_dbg (log_object, " cannot read bearer data, need at least %u bytes (got %u)", \ + required_size, \ + parameter->parameter_len); \ return; \ } @@ -941,81 +951,81 @@ read_bearer_data (MMSmsPart *sms_part, switch (subparameter->parameter_id) { case SUBPARAMETER_ID_MESSAGE_ID: - mm_dbg (" reading message ID..."); - read_bearer_data_message_identifier (sms_part, subparameter); + mm_obj_dbg (log_object, " reading message ID..."); + read_bearer_data_message_identifier (sms_part, subparameter, log_object); break; case SUBPARAMETER_ID_USER_DATA: - mm_dbg (" reading user data..."); - read_bearer_data_user_data (sms_part, subparameter); + mm_obj_dbg (log_object, " reading user data..."); + read_bearer_data_user_data (sms_part, subparameter, log_object); break; case SUBPARAMETER_ID_USER_RESPONSE_CODE: - mm_dbg (" skipping user response code..."); + mm_obj_dbg (log_object, " skipping user response code..."); break; case SUBPARAMETER_ID_MESSAGE_CENTER_TIME_STAMP: - mm_dbg (" skipping message center timestamp..."); + mm_obj_dbg (log_object, " skipping message center timestamp..."); break; case SUBPARAMETER_ID_VALIDITY_PERIOD_ABSOLUTE: - mm_dbg (" skipping absolute validity period..."); + mm_obj_dbg (log_object, " skipping absolute validity period..."); break; case SUBPARAMETER_ID_VALIDITY_PERIOD_RELATIVE: - mm_dbg (" skipping relative validity period..."); + mm_obj_dbg (log_object, " skipping relative validity period..."); break; case SUBPARAMETER_ID_DEFERRED_DELIVERY_TIME_ABSOLUTE: - mm_dbg (" skipping absolute deferred delivery time..."); + mm_obj_dbg (log_object, " skipping absolute deferred delivery time..."); break; case SUBPARAMETER_ID_DEFERRED_DELIVERY_TIME_RELATIVE: - mm_dbg (" skipping relative deferred delivery time..."); + mm_obj_dbg (log_object, " skipping relative deferred delivery time..."); break; case SUBPARAMETER_ID_PRIORITY_INDICATOR: - mm_dbg (" skipping priority indicator..."); + mm_obj_dbg (log_object, " skipping priority indicator..."); break; case SUBPARAMETER_ID_PRIVACY_INDICATOR: - mm_dbg (" skipping privacy indicator..."); + mm_obj_dbg (log_object, " skipping privacy indicator..."); break; case SUBPARAMETER_ID_REPLY_OPTION: - mm_dbg (" skipping reply option..."); + mm_obj_dbg (log_object, " skipping reply option..."); break; case SUBPARAMETER_ID_NUMBER_OF_MESSAGES: - mm_dbg (" skipping number of messages..."); + mm_obj_dbg (log_object, " skipping number of messages..."); break; case SUBPARAMETER_ID_ALERT_ON_MESSAGE_DELIVERY: - mm_dbg (" skipping alert on message delivery..."); + mm_obj_dbg (log_object, " skipping alert on message delivery..."); break; case SUBPARAMETER_ID_LANGUAGE_INDICATOR: - mm_dbg (" skipping language indicator..."); + mm_obj_dbg (log_object, " skipping language indicator..."); break; case SUBPARAMETER_ID_CALL_BACK_NUMBER: - mm_dbg (" skipping call back number..."); + mm_obj_dbg (log_object, " skipping call back number..."); break; case SUBPARAMETER_ID_MESSAGE_DISPLAY_MODE: - mm_dbg (" skipping message display mode..."); + mm_obj_dbg (log_object, " skipping message display mode..."); break; case SUBPARAMETER_ID_MULTIPLE_ENCODING_USER_DATA: - mm_dbg (" skipping multiple encoding user data..."); + mm_obj_dbg (log_object, " skipping multiple encoding user data..."); break; case SUBPARAMETER_ID_MESSAGE_DEPOSIT_INDEX: - mm_dbg (" skipping message deposit index..."); + mm_obj_dbg (log_object, " skipping message deposit index..."); break; case SUBPARAMETER_ID_SERVICE_CATEGORY_PROGRAM_DATA: - mm_dbg (" skipping service category program data..."); + mm_obj_dbg (log_object, " skipping service category program data..."); break; case SUBPARAMETER_ID_SERVICE_CATEGORY_PROGRAM_RESULT: - mm_dbg (" skipping service category program result..."); + mm_obj_dbg (log_object, " skipping service category program result..."); break; case SUBPARAMETER_ID_MESSAGE_STATUS: - mm_dbg (" skipping message status..."); + mm_obj_dbg (log_object, " skipping message status..."); break; case SUBPARAMETER_ID_TP_FAILURE_CAUSE: - mm_dbg (" skipping TP failure case..."); + mm_obj_dbg (log_object, " skipping TP failure case..."); break; case SUBPARAMETER_ID_ENHANCED_VMN: - mm_dbg (" skipping enhanced vmn..."); + mm_obj_dbg (log_object, " skipping enhanced vmn..."); break; case SUBPARAMETER_ID_ENHANCED_VMN_ACK: - mm_dbg (" skipping enhanced vmn ack..."); + mm_obj_dbg (log_object, " skipping enhanced vmn ack..."); break; default: - mm_dbg (" unknown subparameter found: '%u' (ignoring)", + mm_obj_dbg (log_object, " unknown subparameter found: '%u' (ignoring)", subparameter->parameter_id); break; } @@ -1025,10 +1035,11 @@ read_bearer_data (MMSmsPart *sms_part, } MMSmsPart * -mm_sms_part_cdma_new_from_binary_pdu (guint index, - const guint8 *pdu, - gsize pdu_len, - GError **error) +mm_sms_part_cdma_new_from_binary_pdu (guint index, + const guint8 *pdu, + gsize pdu_len, + gpointer log_object, + GError **error) { MMSmsPart *sms_part; guint offset; @@ -1038,9 +1049,9 @@ mm_sms_part_cdma_new_from_binary_pdu (guint index, sms_part = mm_sms_part_new (index, MM_SMS_PDU_TYPE_UNKNOWN); if (index != SMS_PART_INVALID_INDEX) - mm_dbg ("Parsing CDMA PDU (%u)...", index); + mm_obj_dbg (log_object, "parsing CDMA PDU (%u)...", index); else - mm_dbg ("Parsing CDMA PDU..."); + mm_obj_dbg (log_object, "parsing CDMA PDU..."); #define PDU_SIZE_CHECK(required_size, check_descr_str) \ if (pdu_len < required_size) { \ @@ -1088,47 +1099,47 @@ mm_sms_part_cdma_new_from_binary_pdu (guint index, switch (parameter->parameter_id) { case PARAMETER_ID_TELESERVICE_ID: - mm_dbg (" reading teleservice ID..."); - read_teleservice_id (sms_part, parameter); + mm_obj_dbg (log_object, " reading teleservice ID..."); + read_teleservice_id (sms_part, parameter, log_object); break; case PARAMETER_ID_SERVICE_CATEGORY: - mm_dbg (" reading service category..."); - read_service_category (sms_part, parameter); + mm_obj_dbg (log_object, " reading service category..."); + read_service_category (sms_part, parameter, log_object); break; case PARAMETER_ID_ORIGINATING_ADDRESS: - mm_dbg (" reading originating address..."); + mm_obj_dbg (log_object, " reading originating address..."); if (mm_sms_part_get_number (sms_part)) - mm_dbg (" cannot read originating address; an address field was already read"); + mm_obj_dbg (log_object, " cannot read originating address; an address field was already read"); else - read_address (sms_part, parameter); + read_address (sms_part, parameter, log_object); break; case PARAMETER_ID_ORIGINATING_SUBADDRESS: - mm_dbg (" skipping originating subaddress..."); + mm_obj_dbg (log_object, " skipping originating subaddress..."); break; case PARAMETER_ID_DESTINATION_ADDRESS: - mm_dbg (" reading destination address..."); + mm_obj_dbg (log_object, " reading destination address..."); if (mm_sms_part_get_number (sms_part)) - mm_dbg (" cannot read destination address; an address field was already read"); + mm_obj_dbg (log_object, " cannot read destination address; an address field was already read"); else - read_address (sms_part, parameter); + read_address (sms_part, parameter, log_object); break; case PARAMETER_ID_DESTINATION_SUBADDRESS: - mm_dbg (" skipping destination subaddress..."); + mm_obj_dbg (log_object, " skipping destination subaddress..."); break; case PARAMETER_ID_BEARER_REPLY_OPTION: - mm_dbg (" reading bearer reply option..."); - read_bearer_reply_option (sms_part, parameter); + mm_obj_dbg (log_object, " reading bearer reply option..."); + read_bearer_reply_option (sms_part, parameter, log_object); break; case PARAMETER_ID_CAUSE_CODES: - mm_dbg (" reading cause codes..."); - read_cause_codes (sms_part, parameter); + mm_obj_dbg (log_object, " reading cause codes..."); + read_cause_codes (sms_part, parameter, log_object); break; case PARAMETER_ID_BEARER_DATA: - mm_dbg (" reading bearer data..."); - read_bearer_data (sms_part, parameter); + mm_obj_dbg (log_object, " reading bearer data..."); + read_bearer_data (sms_part, parameter, log_object); break; default: - mm_dbg (" unknown parameter found: '%u' (ignoring)", + mm_obj_dbg (log_object, " unknown parameter found: '%u' (ignoring)", parameter->parameter_id); break; } @@ -1138,15 +1149,15 @@ mm_sms_part_cdma_new_from_binary_pdu (guint index, switch (message_type) { case MESSAGE_TYPE_POINT_TO_POINT: if (mm_sms_part_get_cdma_teleservice_id (sms_part) == MM_SMS_CDMA_TELESERVICE_ID_UNKNOWN) - mm_dbg (" mandatory parameter missing: teleservice ID not found or invalid in point-to-point message"); + mm_obj_dbg (log_object, " mandatory parameter missing: teleservice ID not found or invalid in point-to-point message"); break; case MESSAGE_TYPE_BROADCAST: if (mm_sms_part_get_cdma_service_category (sms_part) == MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN) - mm_dbg (" mandatory parameter missing: service category not found or invalid in broadcast message"); + mm_obj_dbg (log_object, " mandatory parameter missing: service category not found or invalid in broadcast message"); break; case MESSAGE_TYPE_ACKNOWLEDGE: if (mm_sms_part_get_message_reference (sms_part) == 0) - mm_dbg (" mandatory parameter missing: cause codes not found or invalid in acknowledge message"); + mm_obj_dbg (log_object, " mandatory parameter missing: cause codes not found or invalid in acknowledge message"); break; default: break; @@ -1197,7 +1208,8 @@ write_bits (guint8 *bytes, /*****************************************************************************/ static guint8 -dtmf_from_ascii (guint8 ascii) +dtmf_from_ascii (guint8 ascii, + gpointer log_object) { if (ascii >= '1' && ascii <= '9') return ascii - '0'; @@ -1208,19 +1220,20 @@ dtmf_from_ascii (guint8 ascii) if (ascii == '#') return 12; - mm_dbg (" invalid ascii digit in dtmf conversion: %c", ascii); + mm_obj_dbg (log_object, " invalid ascii digit in dtmf conversion: %c", ascii); return 0; } static gboolean -write_teleservice_id (MMSmsPart *part, - guint8 *pdu, - guint *absolute_offset, - GError **error) +write_teleservice_id (MMSmsPart *part, + guint8 *pdu, + guint *absolute_offset, + gpointer log_object, + GError **error) { guint16 aux16; - mm_dbg (" writing teleservice ID..."); + mm_obj_dbg (log_object, " writing teleservice ID..."); if (mm_sms_part_get_cdma_teleservice_id (part) != MM_SMS_CDMA_TELESERVICE_ID_WMT) { g_set_error (error, @@ -1232,9 +1245,9 @@ write_teleservice_id (MMSmsPart *part, return FALSE; } - mm_dbg (" teleservice ID: %s (%u)", - mm_sms_cdma_teleservice_id_get_string (MM_SMS_CDMA_TELESERVICE_ID_WMT), - MM_SMS_CDMA_TELESERVICE_ID_WMT); + mm_obj_dbg (log_object, " teleservice ID: %s (%u)", + mm_sms_cdma_teleservice_id_get_string (MM_SMS_CDMA_TELESERVICE_ID_WMT), + MM_SMS_CDMA_TELESERVICE_ID_WMT); /* Teleservice ID: WMT always */ pdu[0] = PARAMETER_ID_TELESERVICE_ID; @@ -1247,10 +1260,11 @@ write_teleservice_id (MMSmsPart *part, } static gboolean -write_destination_address (MMSmsPart *part, - guint8 *pdu, - guint *absolute_offset, - GError **error) +write_destination_address (MMSmsPart *part, + guint8 *pdu, + guint *absolute_offset, + gpointer log_object, + GError **error) { const gchar *number; guint bit_offset; @@ -1258,7 +1272,7 @@ write_destination_address (MMSmsPart *part, guint n_digits; guint i; - mm_dbg (" writing destination address..."); + mm_obj_dbg (log_object, " writing destination address..."); #define OFFSETS_UPDATE(n_bits) do { \ bit_offset += n_bits; \ @@ -1278,12 +1292,12 @@ write_destination_address (MMSmsPart *part, bit_offset = 0; /* Digit mode: DTMF always */ - mm_dbg (" digit mode: dtmf"); + mm_obj_dbg (log_object, " digit mode: dtmf"); write_bits (&pdu[byte_offset], bit_offset, 1, DIGIT_MODE_DTMF); OFFSETS_UPDATE (1); /* Number mode: DIGIT always */ - mm_dbg (" number mode: digit"); + mm_obj_dbg (log_object, " number mode: digit"); write_bits (&pdu[byte_offset], bit_offset, 1, NUMBER_MODE_DIGIT); OFFSETS_UPDATE (1); @@ -1298,16 +1312,16 @@ write_destination_address (MMSmsPart *part, n_digits); return FALSE; } - mm_dbg (" num fields: %u", n_digits); + mm_obj_dbg (log_object, " num fields: %u", n_digits); write_bits (&pdu[byte_offset], bit_offset, 8, n_digits); OFFSETS_UPDATE (8); /* Actual DTMF encoded number */ - mm_dbg (" address: %s", number); + mm_obj_dbg (log_object, " address: %s", number); for (i = 0; i < n_digits; i++) { guint8 dtmf; - dtmf = dtmf_from_ascii (number[i]); + dtmf = dtmf_from_ascii (number[i], log_object); if (!dtmf) { g_set_error (error, MM_CORE_ERROR, @@ -1339,15 +1353,16 @@ write_destination_address (MMSmsPart *part, } static gboolean -write_bearer_data_message_identifier (MMSmsPart *part, - guint8 *pdu, - guint *parameter_offset, - GError **error) +write_bearer_data_message_identifier (MMSmsPart *part, + guint8 *pdu, + guint *parameter_offset, + gpointer log_object, + GError **error) { pdu[0] = SUBPARAMETER_ID_MESSAGE_ID; pdu[1] = 3; /* subparameter_len, always 3 */ - mm_dbg (" writing message identifier: submit"); + mm_obj_dbg (log_object, " writing message identifier: submit"); /* Message type */ write_bits (&pdu[2], 0, 4, TELESERVICE_MESSAGE_TYPE_SUBMIT); @@ -1416,10 +1431,11 @@ decide_best_encoding (const gchar *text, } static gboolean -write_bearer_data_user_data (MMSmsPart *part, - guint8 *pdu, - guint *parameter_offset, - GError **error) +write_bearer_data_user_data (MMSmsPart *part, + guint8 *pdu, + guint *parameter_offset, + gpointer log_object, + GError **error) { const gchar *text; const GByteArray *data; @@ -1433,7 +1449,7 @@ write_bearer_data_user_data (MMSmsPart *part, const GByteArray *aux; guint num_bits_per_iter; - mm_dbg (" writing user data..."); + mm_obj_dbg (log_object, " writing user data..."); #define OFFSETS_UPDATE(n_bits) do { \ bit_offset += n_bits; \ @@ -1469,7 +1485,7 @@ write_bearer_data_user_data (MMSmsPart *part, } /* Message encoding*/ - mm_dbg (" message encoding: %s", encoding_to_string (encoding)); + mm_obj_dbg (log_object, " message encoding: %s", encoding_to_string (encoding)); write_bits (&pdu[byte_offset], bit_offset, 5, encoding); OFFSETS_UPDATE (5); @@ -1484,16 +1500,16 @@ write_bearer_data_user_data (MMSmsPart *part, num_fields); return FALSE; } - mm_dbg (" num fields: %u", num_fields); + mm_obj_dbg (log_object, " num fields: %u", num_fields); write_bits (&pdu[byte_offset], bit_offset, 8, num_fields); OFFSETS_UPDATE (8); /* For ASCII-7, write 7 bits in each iteration; for the remaining ones * go byte per byte */ if (text) - mm_dbg (" text: '%s'", text); + mm_obj_dbg (log_object, " text: '%s'", text); else - mm_dbg (" data: (%u bytes)", num_fields); + mm_obj_dbg (log_object, " data: (%u bytes)", num_fields); num_bits_per_iter = num_bits_per_field < 8 ? num_bits_per_field : 8; for (i = 0; i < aux->len; i++) { write_bits (&pdu[byte_offset], bit_offset, num_bits_per_iter, aux->data[i]); @@ -1522,24 +1538,25 @@ write_bearer_data_user_data (MMSmsPart *part, } static gboolean -write_bearer_data (MMSmsPart *part, - guint8 *pdu, - guint *absolute_offset, - GError **error) +write_bearer_data (MMSmsPart *part, + guint8 *pdu, + guint *absolute_offset, + gpointer log_object, + GError **error) { GError *inner_error = NULL; guint offset = 0; - mm_dbg (" writing bearer data..."); + mm_obj_dbg (log_object, " writing bearer data..."); pdu[0] = PARAMETER_ID_BEARER_DATA; /* Write parameter length at the end */ offset = 2; - if (!write_bearer_data_message_identifier (part, &pdu[offset], &offset, &inner_error)) - mm_dbg ("Error writing message identifier: %s", inner_error->message); - else if (!write_bearer_data_user_data (part, &pdu[offset], &offset, &inner_error)) - mm_dbg ("Error writing user data: %s", inner_error->message); + if (!write_bearer_data_message_identifier (part, &pdu[offset], &offset, log_object, &inner_error)) + mm_obj_dbg (log_object, "error writing message identifier: %s", inner_error->message); + else if (!write_bearer_data_user_data (part, &pdu[offset], &offset, log_object, &inner_error)) + mm_obj_dbg (log_object, "error writing user data: %s", inner_error->message); if (inner_error) { g_propagate_error (error, inner_error); @@ -1564,9 +1581,10 @@ write_bearer_data (MMSmsPart *part, } guint8 * -mm_sms_part_cdma_get_submit_pdu (MMSmsPart *part, - guint *out_pdulen, - GError **error) +mm_sms_part_cdma_get_submit_pdu (MMSmsPart *part, + guint *out_pdulen, + gpointer log_object, + GError **error) { GError *inner_error = NULL; guint offset = 0; @@ -1584,7 +1602,7 @@ mm_sms_part_cdma_get_submit_pdu (MMSmsPart *part, return NULL; } - mm_dbg ("Creating PDU for part..."); + mm_obj_dbg (log_object, "creating PDU for part..."); /* Current max size estimations: * Message type: 1 byte @@ -1597,12 +1615,12 @@ mm_sms_part_cdma_get_submit_pdu (MMSmsPart *part, /* First byte: SMS message type */ pdu[offset++] = MESSAGE_TYPE_POINT_TO_POINT; - if (!write_teleservice_id (part, &pdu[offset], &offset, &inner_error)) - mm_dbg ("Error writing Teleservice ID: %s", inner_error->message); - else if (!write_destination_address (part, &pdu[offset], &offset, &inner_error)) - mm_dbg ("Error writing destination address: %s", inner_error->message); - else if (!write_bearer_data (part, &pdu[offset], &offset, &inner_error)) - mm_dbg ("Error writing bearer data: %s", inner_error->message); + if (!write_teleservice_id (part, &pdu[offset], &offset, log_object, &inner_error)) + mm_obj_dbg (log_object, "error writing teleservice ID: %s", inner_error->message); + else if (!write_destination_address (part, &pdu[offset], &offset, log_object, &inner_error)) + mm_obj_dbg (log_object, "error writing destination address: %s", inner_error->message); + else if (!write_bearer_data (part, &pdu[offset], &offset, log_object, &inner_error)) + mm_obj_dbg (log_object, "error writing bearer data: %s", inner_error->message); if (inner_error) { g_propagate_error (error, inner_error); diff --git a/src/mm-sms-part-cdma.h b/src/mm-sms-part-cdma.h index 7331c892..804f67b1 100644 --- a/src/mm-sms-part-cdma.h +++ b/src/mm-sms-part-cdma.h @@ -21,17 +21,18 @@ #include "mm-sms-part.h" -MMSmsPart *mm_sms_part_cdma_new_from_pdu (guint index, - const gchar *hexpdu, - GError **error); - -MMSmsPart *mm_sms_part_cdma_new_from_binary_pdu (guint index, - const guint8 *pdu, - gsize pdu_len, - GError **error); - -guint8 *mm_sms_part_cdma_get_submit_pdu (MMSmsPart *part, - guint *out_pdulen, - GError **error); +MMSmsPart *mm_sms_part_cdma_new_from_pdu (guint index, + const gchar *hexpdu, + gpointer log_object, + GError **error); +MMSmsPart *mm_sms_part_cdma_new_from_binary_pdu (guint index, + const guint8 *pdu, + gsize pdu_len, + gpointer log_object, + GError **error); +guint8 *mm_sms_part_cdma_get_submit_pdu (MMSmsPart *part, + guint *out_pdulen, + gpointer log_object, + GError **error); #endif /* MM_SMS_PART_CDMA_H */ diff --git a/src/mm-sms-qmi.c b/src/mm-sms-qmi.c index 02c0fd59..6f3fe0d2 100644 --- a/src/mm-sms-qmi.c +++ b/src/mm-sms-qmi.c @@ -213,7 +213,7 @@ sms_store_next_part (GTask *task) if (MM_SMS_PART_IS_3GPP ((MMSmsPart *)ctx->current->data)) pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, self, &error); else if (MM_SMS_PART_IS_CDMA ((MMSmsPart *)ctx->current->data)) - pdu = mm_sms_part_cdma_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &error); + pdu = mm_sms_part_cdma_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, self, &error); if (!pdu) { if (error) @@ -402,7 +402,7 @@ sms_send_generic (GTask *task) if (MM_SMS_PART_IS_3GPP ((MMSmsPart *)ctx->current->data)) pdu = mm_sms_part_3gpp_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &msgstart, self, &error); else if (MM_SMS_PART_IS_CDMA ((MMSmsPart *)ctx->current->data)) - pdu = mm_sms_part_cdma_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, &error); + pdu = mm_sms_part_cdma_get_submit_pdu ((MMSmsPart *)ctx->current->data, &pdulen, self, &error); if (!pdu) { if (error) diff --git a/src/tests/test-sms-part-cdma.c b/src/tests/test-sms-part-cdma.c index b1900fa8..0f36fe36 100644 --- a/src/tests/test-sms-part-cdma.c +++ b/src/tests/test-sms-part-cdma.c @@ -39,7 +39,7 @@ common_test_part_from_hexpdu (const gchar *hexpdu, GError *error = NULL; mm_dbg (" "); - part = mm_sms_part_cdma_new_from_pdu (0, hexpdu, &error); + part = mm_sms_part_cdma_new_from_pdu (0, hexpdu, NULL, &error); g_assert_no_error (error); g_assert (part != NULL); @@ -89,7 +89,7 @@ common_test_invalid_part_from_hexpdu (const gchar *hexpdu) GError *error = NULL; mm_dbg (" "); - part = mm_sms_part_cdma_new_from_pdu (0, hexpdu, &error); + part = mm_sms_part_cdma_new_from_pdu (0, hexpdu, NULL, &error); g_assert (part == NULL); /* We don't care for the specific error type */ g_assert (error != NULL); @@ -396,7 +396,7 @@ common_test_create_pdu (MMSmsCdmaTeleserviceId teleservice_id, mm_sms_part_take_data (part, data_bytearray); } - pdu = mm_sms_part_cdma_get_submit_pdu (part, &len, &error); + pdu = mm_sms_part_cdma_get_submit_pdu (part, &len, NULL, &error); mm_sms_part_free (part); if (g_test_verbose ()) From 2e0d23ce7218baab6d08aede3a1269ac475e420d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 17:09:53 +0200 Subject: [PATCH 057/675] serial-parsers: port to use object logging --- src/mm-port-serial-at.c | 2 +- src/mm-port-serial-at.h | 7 ++++--- src/mm-serial-parsers.c | 13 +++++++------ src/mm-serial-parsers.h | 1 + 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/mm-port-serial-at.c b/src/mm-port-serial-at.c index 680c9297..c8e4782f 100644 --- a/src/mm-port-serial-at.c +++ b/src/mm-port-serial-at.c @@ -148,7 +148,7 @@ parse_response (MMPortSerial *port, /* Parse it; returns FALSE if there is nothing we can do with this * response yet. */ - if (!self->priv->response_parser_fn (self->priv->response_parser_user_data, string, &inner_error)) { + if (!self->priv->response_parser_fn (self->priv->response_parser_user_data, string, self, &inner_error)) { /* Copy what we got back in the response buffer. */ g_byte_array_append (response, (const guint8 *) string->str, string->len); g_string_free (string, TRUE); diff --git a/src/mm-port-serial-at.h b/src/mm-port-serial-at.h index 8e19409e..f447d144 100644 --- a/src/mm-port-serial-at.h +++ b/src/mm-port-serial-at.h @@ -53,9 +53,10 @@ typedef enum { /*< underscore_name=mm_port_serial_at_flag >*/ MM_PORT_SERIAL_AT_FLAG_GPS_CONTROL = 1 << 3, } MMPortSerialAtFlag; -typedef gboolean (*MMPortSerialAtResponseParserFn) (gpointer user_data, - GString *response, - GError **error); +typedef gboolean (*MMPortSerialAtResponseParserFn) (gpointer user_data, + GString *response, + gpointer log_object, + GError **error); typedef void (*MMPortSerialAtUnsolicitedMsgFn) (MMPortSerialAt *port, GMatchInfo *match_info, diff --git a/src/mm-serial-parsers.c b/src/mm-serial-parsers.c index b7bb3087..62592455 100644 --- a/src/mm-serial-parsers.c +++ b/src/mm-serial-parsers.c @@ -19,7 +19,7 @@ #include "mm-error-helpers.h" #include "mm-serial-parsers.h" -#include "mm-log.h" +#include "mm-log-object.h" /* Clean up the response by removing control characters like etc */ static void @@ -161,9 +161,10 @@ mm_serial_parser_v1_add_filter (gpointer data, } gboolean -mm_serial_parser_v1_parse (gpointer data, - GString *response, - GError **error) +mm_serial_parser_v1_parse (gpointer data, + GString *response, + gpointer log_object, + GError **error) { MMSerialParserV1 *parser = (MMSerialParserV1 *) data; GMatchInfo *match_info; @@ -188,7 +189,7 @@ mm_serial_parser_v1_parse (gpointer data, response, &local_error)) { g_assert (local_error != NULL); - mm_dbg ("Got response filtered in serial port: %s", local_error->message); + mm_obj_dbg (log_object, "response filtered in serial port: %s", local_error->message); g_propagate_error (error, local_error); response_clean (response); return TRUE; @@ -361,7 +362,7 @@ mm_serial_parser_v1_parse (gpointer data, response_clean (response); if (local_error) { - mm_dbg ("Got failure code %d: %s", local_error->code, local_error->message); + mm_obj_dbg (log_object, "operation failure: %d (%s)", local_error->code, local_error->message); g_propagate_error (error, local_error); } diff --git a/src/mm-serial-parsers.h b/src/mm-serial-parsers.h index 641c5e0f..523597b9 100644 --- a/src/mm-serial-parsers.h +++ b/src/mm-serial-parsers.h @@ -24,6 +24,7 @@ void mm_serial_parser_v1_set_custom_regex (gpointer data, GRegex *error); gboolean mm_serial_parser_v1_parse (gpointer parser, GString *response, + gpointer log_object, GError **error); void mm_serial_parser_v1_destroy (gpointer parser); gboolean mm_serial_parser_v1_is_known_error (const GError *error); From 4d761330e1a1edecd460465c38ec66dad3176d93 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 17:17:35 +0200 Subject: [PATCH 058/675] filter: port to use object logging --- src/mm-filter.c | 93 +++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/src/mm-filter.c b/src/mm-filter.c index 73c6bde1..cfa620b4 100644 --- a/src/mm-filter.c +++ b/src/mm-filter.c @@ -21,11 +21,14 @@ #include "mm-daemon-enums-types.h" #include "mm-filter.h" -#include "mm-log.h" +#include "mm-log-object.h" #define FILTER_PORT_MAYBE_FORBIDDEN "maybe-forbidden" -G_DEFINE_TYPE (MMFilter, mm_filter, G_TYPE_OBJECT) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMFilter, mm_filter, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -46,7 +49,7 @@ mm_filter_register_plugin_whitelist_tag (MMFilter *self, const gchar *tag) { if (!g_list_find_custom (self->priv->plugin_whitelist_tags, tag, (GCompareFunc) g_strcmp0)) { - mm_dbg ("[filter] registered plugin whitelist tag: %s", tag); + mm_obj_dbg (self, "registered plugin whitelist tag: %s", tag); self->priv->plugin_whitelist_tags = g_list_prepend (self->priv->plugin_whitelist_tags, g_strdup (tag)); } } @@ -73,7 +76,7 @@ mm_filter_register_plugin_whitelist_product_id (MMFilter *self, new_item.l = vid; new_item.r = pid; g_array_append_val (self->priv->plugin_whitelist_product_ids, new_item); - mm_dbg ("[filter] registered plugin whitelist product id: %04x:%04x", vid, pid); + mm_obj_dbg (self, "registered plugin whitelist product id: %04x:%04x", vid, pid); } /*****************************************************************************/ @@ -95,14 +98,14 @@ mm_filter_port (MMFilter *self, if ((self->priv->enabled_rules & MM_FILTER_RULE_EXPLICIT_WHITELIST) && (mm_kernel_device_get_global_property_as_boolean (port, ID_MM_DEVICE_PROCESS) || mm_kernel_device_get_property_as_boolean (port, ID_MM_DEVICE_PROCESS))) { - mm_dbg ("[filter] (%s/%s) port allowed: device is whitelisted", subsystem, name); + mm_obj_dbg (self, "(%s/%s) port allowed: device is whitelisted", subsystem, name); return TRUE; } /* If the device is explicitly blacklisted, we ignore every port. */ if ((self->priv->enabled_rules & MM_FILTER_RULE_EXPLICIT_BLACKLIST) && (mm_kernel_device_get_global_property_as_boolean (port, ID_MM_DEVICE_IGNORE))) { - mm_dbg ("[filter] (%s/%s): port filtered: device is blacklisted", subsystem, name); + mm_obj_dbg (self, "(%s/%s): port filtered: device is blacklisted", subsystem, name); return FALSE; } @@ -115,7 +118,7 @@ mm_filter_port (MMFilter *self, for (l = self->priv->plugin_whitelist_tags; l; l = g_list_next (l)) { if (mm_kernel_device_get_global_property_as_boolean (port, (const gchar *)(l->data)) || mm_kernel_device_get_property_as_boolean (port, (const gchar *)(l->data))) { - mm_dbg ("[filter] (%s/%s) port allowed: device is whitelisted by plugin (tag)", subsystem, name); + mm_obj_dbg (self, "(%s/%s) port allowed: device is whitelisted by plugin (tag)", subsystem, name); return TRUE; } } @@ -132,7 +135,7 @@ mm_filter_port (MMFilter *self, item = &g_array_index (self->priv->plugin_whitelist_product_ids, mm_uint16_pair, i); if (item->l == vid && item->r == pid) { - mm_dbg ("[filter] (%s/%s) port allowed: device is whitelisted by plugin (vid/pid)", subsystem, name); + mm_obj_dbg (self, "(%s/%s) port allowed: device is whitelisted by plugin (vid/pid)", subsystem, name); return TRUE; } } @@ -142,14 +145,14 @@ mm_filter_port (MMFilter *self, /* If this is a virtual device, don't allow it */ if ((self->priv->enabled_rules & MM_FILTER_RULE_VIRTUAL) && (!mm_kernel_device_get_physdev_sysfs_path (port))) { - mm_dbg ("[filter] (%s/%s) port filtered: virtual device", subsystem, name); + mm_obj_dbg (self, "(%s/%s) port filtered: virtual device", subsystem, name); return FALSE; } /* If this is a net device, we always allow it */ if ((self->priv->enabled_rules & MM_FILTER_RULE_NET) && (g_strcmp0 (subsystem, "net") == 0)) { - mm_dbg ("[filter] (%s/%s) port allowed: net device", subsystem, name); + mm_obj_dbg (self, "(%s/%s) port allowed: net device", subsystem, name); return TRUE; } @@ -157,7 +160,7 @@ mm_filter_port (MMFilter *self, if ((self->priv->enabled_rules & MM_FILTER_RULE_CDC_WDM) && (g_strcmp0 (subsystem, "usb") == 0 || g_strcmp0 (subsystem, "usbmisc") == 0) && (name && g_str_has_prefix (name, "cdc-wdm"))) { - mm_dbg ("[filter] (%s/%s) port allowed: cdc-wdm device", subsystem, name); + mm_obj_dbg (self, "(%s/%s) port allowed: cdc-wdm device", subsystem, name); return TRUE; } @@ -172,7 +175,7 @@ mm_filter_port (MMFilter *self, /* Ignore blacklisted tty devices. */ if ((self->priv->enabled_rules & MM_FILTER_RULE_TTY_BLACKLIST) && (mm_kernel_device_get_global_property_as_boolean (port, ID_MM_TTY_BLACKLIST))) { - mm_dbg ("[filter] (%s/%s): port filtered: tty is blacklisted", subsystem, name); + mm_obj_dbg (self, "(%s/%s): port filtered: tty is blacklisted", subsystem, name); return FALSE; } @@ -180,7 +183,7 @@ mm_filter_port (MMFilter *self, * automatic scan. */ if ((self->priv->enabled_rules & MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY) && (!manual_scan && mm_kernel_device_get_global_property_as_boolean (port, ID_MM_TTY_MANUAL_SCAN_ONLY))) { - mm_dbg ("[filter] (%s/%s): port filtered: tty probed only in manual scan", subsystem, name); + mm_obj_dbg (self, "(%s/%s): port filtered: tty probed only in manual scan", subsystem, name); return FALSE; } @@ -193,13 +196,13 @@ mm_filter_port (MMFilter *self, !g_strcmp0 (physdev_subsystem, "pci") || !g_strcmp0 (physdev_subsystem, "pnp") || !g_strcmp0 (physdev_subsystem, "sdio"))) { - mm_dbg ("[filter] (%s/%s): port filtered: tty platform driver", subsystem, name); + mm_obj_dbg (self, "(%s/%s): port filtered: tty platform driver", subsystem, name); return FALSE; } /* Default allowed? */ if (self->priv->enabled_rules & MM_FILTER_RULE_TTY_DEFAULT_ALLOWED) { - mm_dbg ("[filter] (%s/%s) port allowed", subsystem, name); + mm_obj_dbg (self, "(%s/%s) port allowed", subsystem, name); return TRUE; } @@ -213,7 +216,7 @@ mm_filter_port (MMFilter *self, !g_strcmp0 (driver, "qcaux") || !g_strcmp0 (driver, "nozomi") || !g_strcmp0 (driver, "sierra"))) { - mm_dbg ("[filter] (%s/%s): port allowed: modem-specific kernel driver detected", subsystem, name); + mm_obj_dbg (self, "(%s/%s): port allowed: modem-specific kernel driver detected", subsystem, name); return TRUE; } @@ -246,7 +249,7 @@ mm_filter_port (MMFilter *self, (mm_kernel_device_get_interface_subclass (port) != 2) || (mm_kernel_device_get_interface_protocol (port) < 1) || (mm_kernel_device_get_interface_protocol (port) > 6))) { - mm_dbg ("[filter] (%s/%s): port filtered: cdc-acm interface is not AT-capable", subsystem, name); + mm_obj_dbg (self, "(%s/%s): port filtered: cdc-acm interface is not AT-capable", subsystem, name); return FALSE; } @@ -260,7 +263,7 @@ mm_filter_port (MMFilter *self, } /* Otherwise forbidden */ - mm_dbg ("[filter] (%s/%s) port filtered: forbidden port type", subsystem, name); + mm_obj_dbg (self, "(%s/%s) port filtered: forbidden port type", subsystem, name); return FALSE; } @@ -303,7 +306,7 @@ mm_filter_device_and_port (MMFilter *self, /* Check whether this device holds a NET port in addition to this TTY */ if ((self->priv->enabled_rules & MM_FILTER_RULE_TTY_WITH_NET) && device_has_net_port (device)) { - mm_dbg ("[filter] (%s/%s): port allowed: device also exports a net interface", subsystem, name); + mm_obj_dbg (self, "(%s/%s): port allowed: device also exports a net interface", subsystem, name); return TRUE; } @@ -312,11 +315,11 @@ mm_filter_device_and_port (MMFilter *self, if ((self->priv->enabled_rules & MM_FILTER_RULE_TTY_ACM_INTERFACE) && (!g_strcmp0 (driver, "cdc_acm")) && device_has_multiple_ports (device)) { - mm_dbg ("[filter] (%s/%s): port allowed: device exports multiple interfaces", subsystem, name); + mm_obj_dbg (self, "(%s/%s): port allowed: device exports multiple interfaces", subsystem, name); return TRUE; } - mm_dbg ("[filter] (%s/%s) port filtered: forbidden", subsystem, name); + mm_obj_dbg (self, "(%s/%s) port filtered: forbidden", subsystem, name); return FALSE; } @@ -368,6 +371,14 @@ mm_filter_check_rule_enabled (MMFilter *self, /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + return g_strdup ("filter"); +} + +/*****************************************************************************/ + /* If TTY rule enabled, either DEFAULT_ALLOWED or DEFAULT_FORBIDDEN must be set. */ #define VALIDATE_RULE_TTY(rules) (!(rules & MM_FILTER_RULE_TTY) || \ ((rules & (MM_FILTER_RULE_TTY_DEFAULT_ALLOWED | MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN)) && \ @@ -396,29 +407,29 @@ mm_filter_new (MMFilterRule enabled_rules, #define RULE_ENABLED_STR(flag) ((self->priv->enabled_rules & flag) ? "yes" : "no") - mm_dbg ("[filter] created"); - mm_dbg ("[filter] explicit whitelist: %s", RULE_ENABLED_STR (MM_FILTER_RULE_EXPLICIT_WHITELIST)); - mm_dbg ("[filter] explicit blacklist: %s", RULE_ENABLED_STR (MM_FILTER_RULE_EXPLICIT_BLACKLIST)); - mm_dbg ("[filter] plugin whitelist: %s", RULE_ENABLED_STR (MM_FILTER_RULE_PLUGIN_WHITELIST)); - mm_dbg ("[filter] virtual devices forbidden: %s", RULE_ENABLED_STR (MM_FILTER_RULE_VIRTUAL)); - mm_dbg ("[filter] net devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_NET)); - mm_dbg ("[filter] cdc-wdm devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_CDC_WDM)); + mm_obj_dbg (self, "created"); + mm_obj_dbg (self, " explicit whitelist: %s", RULE_ENABLED_STR (MM_FILTER_RULE_EXPLICIT_WHITELIST)); + mm_obj_dbg (self, " explicit blacklist: %s", RULE_ENABLED_STR (MM_FILTER_RULE_EXPLICIT_BLACKLIST)); + mm_obj_dbg (self, " plugin whitelist: %s", RULE_ENABLED_STR (MM_FILTER_RULE_PLUGIN_WHITELIST)); + mm_obj_dbg (self, " virtual devices forbidden: %s", RULE_ENABLED_STR (MM_FILTER_RULE_VIRTUAL)); + mm_obj_dbg (self, " net devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_NET)); + mm_obj_dbg (self, " cdc-wdm devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_CDC_WDM)); if (self->priv->enabled_rules & MM_FILTER_RULE_TTY) { - mm_dbg ("[filter] tty devices:"); - mm_dbg ("[filter] blacklist applied: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_BLACKLIST)); - mm_dbg ("[filter] manual scan only applied: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY)); - mm_dbg ("[filter] platform driver check: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_PLATFORM_DRIVER)); - mm_dbg ("[filter] driver check: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_DRIVER)); - mm_dbg ("[filter] cdc-acm interface check: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_ACM_INTERFACE)); - mm_dbg ("[filter] with net check: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_WITH_NET)); + mm_obj_dbg (self, " tty devices:"); + mm_obj_dbg (self, " blacklist applied: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_BLACKLIST)); + mm_obj_dbg (self, " manual scan only applied: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY)); + mm_obj_dbg (self, " platform driver check: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_PLATFORM_DRIVER)); + mm_obj_dbg (self, " driver check: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_DRIVER)); + mm_obj_dbg (self, " cdc-acm interface check: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_ACM_INTERFACE)); + mm_obj_dbg (self, " with net check: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_WITH_NET)); if (self->priv->enabled_rules & MM_FILTER_RULE_TTY_DEFAULT_ALLOWED) - mm_dbg ("[filter] default: allowed"); + mm_obj_dbg (self, " default: allowed"); else if (self->priv->enabled_rules & MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN) - mm_dbg ("[filter] default: forbidden"); + mm_obj_dbg (self, " default: forbidden"); else g_assert_not_reached (); } else - mm_dbg ("[filter] tty devices: no"); + mm_obj_dbg (self, " tty devices: no"); #undef RULE_ENABLED_STR @@ -478,6 +489,12 @@ finalize (GObject *object) G_OBJECT_CLASS (mm_filter_parent_class)->finalize (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_filter_class_init (MMFilterClass *klass) { From 28cb2b73682976df0abe6fa2fca95c2935064f22 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 17:35:05 +0200 Subject: [PATCH 059/675] sleep-monitor: port to use object logging --- src/mm-sleep-monitor.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/mm-sleep-monitor.c b/src/mm-sleep-monitor.c index c5aae5aa..d3d181c1 100644 --- a/src/mm-sleep-monitor.c +++ b/src/mm-sleep-monitor.c @@ -26,7 +26,7 @@ #include #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-utils.h" #include "mm-sleep-monitor.h" @@ -57,7 +57,18 @@ enum { }; static guint signals[LAST_SIGNAL] = {0}; -G_DEFINE_TYPE (MMSleepMonitor, mm_sleep_monitor, G_TYPE_OBJECT); +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMSleepMonitor, mm_sleep_monitor, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) + +/*****************************************************************************/ + +static gchar * +log_object_build_id (MMLogObject *_self) +{ + return g_strdup ("sleep-monitor"); +} /********************************************************************/ @@ -65,7 +76,7 @@ static gboolean drop_inhibitor (MMSleepMonitor *self) { if (self->inhibit_fd >= 0) { - mm_dbg ("[sleep-monitor] dropping systemd sleep inhibitor"); + mm_obj_dbg (self, "dropping systemd sleep inhibitor"); close (self->inhibit_fd); self->inhibit_fd = -1; return TRUE; @@ -86,15 +97,15 @@ inhibit_done (GObject *source, res = g_dbus_proxy_call_with_unix_fd_list_finish (sd_proxy, &fd_list, result, &error); if (!res) { - mm_warn ("[sleep-monitor] inhibit failed: %s", error->message); + mm_obj_warn (self, "inhibit failed: %s", error->message); g_error_free (error); } else { if (!fd_list || g_unix_fd_list_get_length (fd_list) != 1) - mm_warn ("[sleep-monitor] didn't get a single fd back"); + mm_obj_warn (self, "didn't get a single fd back"); self->inhibit_fd = g_unix_fd_list_get (fd_list, 0, NULL); - mm_dbg ("[sleep-monitor] inhibitor fd is %d", self->inhibit_fd); + mm_obj_dbg (self, "inhibitor fd is %d", self->inhibit_fd); g_object_unref (fd_list); g_variant_unref (res); } @@ -105,7 +116,7 @@ take_inhibitor (MMSleepMonitor *self) { g_assert (self->inhibit_fd == -1); - mm_dbg ("[sleep-monitor] taking systemd sleep inhibitor"); + mm_obj_dbg (self, "taking systemd sleep inhibitor"); g_dbus_proxy_call_with_unix_fd_list (self->sd_proxy, "Inhibit", g_variant_new ("(ssss)", @@ -135,12 +146,13 @@ signal_cb (GDBusProxy *proxy, return; g_variant_get (args, "(b)", &is_about_to_suspend); - mm_dbg ("[sleep-monitor] received PrepareForSleep signal: %d", is_about_to_suspend); if (is_about_to_suspend) { + mm_obj_info (self, "system is about to suspend"); g_signal_emit (self, signals[SLEEPING], 0); drop_inhibitor (self); } else { + mm_obj_info (self, "system is resuming"); take_inhibitor (self); g_signal_emit (self, signals[RESUMING], 0); } @@ -175,7 +187,7 @@ on_proxy_acquired (GObject *object, self->sd_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); if (!self->sd_proxy) { - mm_warn ("[sleep-monitor] failed to acquire logind proxy: %s", error->message); + mm_obj_warn (self, "failed to acquire logind proxy: %s", error->message); g_clear_error (&error); return; } @@ -215,6 +227,12 @@ finalize (GObject *object) G_OBJECT_CLASS (mm_sleep_monitor_parent_class)->finalize (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_sleep_monitor_class_init (MMSleepMonitorClass *klass) { From a6a4037da756498054d96408a8311932b9c9b5cc Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 17:41:51 +0200 Subject: [PATCH 060/675] auth-provider: port to use object logging --- src/mm-auth-provider.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/mm-auth-provider.c b/src/mm-auth-provider.c index bea27d01..5b4b13f3 100644 --- a/src/mm-auth-provider.c +++ b/src/mm-auth-provider.c @@ -19,7 +19,7 @@ #include #include "mm-errors-types.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-utils.h" #include "mm-auth-provider.h" @@ -38,7 +38,10 @@ struct _MMAuthProviderClass { GObjectClass parent; }; -G_DEFINE_TYPE (MMAuthProvider, mm_auth_provider, G_TYPE_OBJECT) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMAuthProvider, mm_auth_provider, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) /*****************************************************************************/ @@ -163,6 +166,14 @@ mm_auth_provider_authorize (MMAuthProvider *self, /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + return g_strdup ("auth-provider"); +} + +/*****************************************************************************/ + static void mm_auth_provider_init (MMAuthProvider *self) { @@ -174,8 +185,8 @@ mm_auth_provider_init (MMAuthProvider *self) if (!self->authority) { /* NOTE: we failed to create the polkit authority, but we still create * our AuthProvider. Every request will fail, though. */ - mm_warn ("failed to create PolicyKit authority: '%s'", - error ? error->message : "unknown"); + mm_obj_warn (self, "failed to create PolicyKit authority: '%s'", + error ? error->message : "unknown"); g_clear_error (&error); } } @@ -192,6 +203,12 @@ dispose (GObject *object) G_OBJECT_CLASS (mm_auth_provider_parent_class)->dispose (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_auth_provider_class_init (MMAuthProviderClass *class) { From 4b0c83b9ed4c427bf848340fbccdb4853ce0d3f3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 17:42:00 +0200 Subject: [PATCH 061/675] utils: port to use object logging --- src/mm-utils.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mm-utils.h b/src/mm-utils.h index 395c39e1..cdb123cd 100644 --- a/src/mm-utils.h +++ b/src/mm-utils.h @@ -20,7 +20,7 @@ #include #include -#include "mm-log.h" +#include "mm-log-object.h" /*****************************************************************************/ @@ -32,7 +32,7 @@ _singleton_instance_weak_ref_cb (gpointer data, \ GObject *where_the_object_was) \ { \ - mm_dbg ("disposing %s singleton (%p)", G_STRINGIFY (TYPE), singleton_instance); \ + mm_obj_dbg (singleton_instance, "singleton disposed"); \ singleton_instance = NULL; \ } \ static inline void \ @@ -47,7 +47,7 @@ { \ if (singleton_instance) { \ if (G_OBJECT (singleton_instance)->ref_count > 1) \ - mm_dbg ("disown %s singleton (%p)", G_STRINGIFY (TYPE), singleton_instance); \ + mm_obj_dbg (singleton_instance, "singleton disowned"); \ g_object_unref (singleton_instance); \ } \ } @@ -70,9 +70,9 @@ g_assert (!_already_created || (MM_DEFINE_SINGLETON_ALLOW_MULTIPLE)); \ _already_created = TRUE; \ singleton_instance = (g_object_new (GTYPE, ##__VA_ARGS__, NULL)); \ - g_assert (singleton_instance); \ - mm_singleton_instance_weak_ref_register (); \ - mm_dbg ("create %s singleton (%p)", G_STRINGIFY (TYPE), singleton_instance); \ + g_assert (singleton_instance); \ + mm_singleton_instance_weak_ref_register (); \ + mm_obj_dbg (singleton_instance, "singleton created"); \ } \ return singleton_instance; \ } \ From 6987d1bea680b24110f79a66de7cac6b365fa418 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 17:58:09 +0200 Subject: [PATCH 062/675] plugin: port to use object logging --- src/mm-plugin.c | 141 +++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 79 deletions(-) diff --git a/src/mm-plugin.c b/src/mm-plugin.c index 4407ecec..6849218d 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -34,7 +34,7 @@ #include "mm-port-serial-qcdm.h" #include "mm-serial-parsers.h" #include "mm-private-boxed-types.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-daemon-enums-types.h" #if defined WITH_QMI @@ -44,7 +44,10 @@ # include "mm-broadband-modem-mbim.h" #endif -G_DEFINE_TYPE (MMPlugin, mm_plugin, G_TYPE_OBJECT) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMPlugin, mm_plugin, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) /* Virtual port corresponding to the embedded modem */ static const gchar *virtual_port[] = {"smd0", NULL}; @@ -234,9 +237,7 @@ apply_pre_probing_filters (MMPlugin *self, /* The plugin may specify that only some subsystems are supported. If that * is the case, filter by subsystem */ if (apply_subsystem_filter (self, port)) { - mm_dbg ("(%s) [%s] filtered by subsystem", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "port %s filtered by subsystem", mm_kernel_device_get_name (port)); return TRUE; } @@ -265,9 +266,7 @@ apply_pre_probing_filters (MMPlugin *self, /* If error retrieving driver: unsupported */ if (!drivers) { - mm_dbg ("(%s) [%s] filtered as couldn't retrieve drivers", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "port %s filtered as couldn't retrieve drivers", mm_kernel_device_get_name (port)); return TRUE; } @@ -286,9 +285,7 @@ apply_pre_probing_filters (MMPlugin *self, /* If we didn't match any driver: unsupported */ if (!found) { - mm_dbg ("(%s) [%s] filtered by drivers", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "port %s filtered by drivers", mm_kernel_device_get_name (port)); return TRUE; } } @@ -301,9 +298,7 @@ apply_pre_probing_filters (MMPlugin *self, for (j = 0; drivers[j]; j++) { /* If we match a forbidden driver: unsupported */ if (g_str_equal (drivers[j], self->priv->forbidden_drivers[i])) { - mm_dbg ("(%s) [%s] filtered by forbidden drivers", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "port %s filtered by forbidden drivers", mm_kernel_device_get_name (port)); return TRUE; } } @@ -317,9 +312,7 @@ apply_pre_probing_filters (MMPlugin *self, for (j = 0; drivers[j]; j++) { /* If we match the QMI driver: unsupported */ if (g_str_equal (drivers[j], "qmi_wwan")) { - mm_dbg ("(%s) [%s] filtered by implicit QMI driver", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "port %s filtered by implicit QMI driver", mm_kernel_device_get_name (port)); return TRUE; } } @@ -332,9 +325,7 @@ apply_pre_probing_filters (MMPlugin *self, for (j = 0; drivers[j]; j++) { /* If we match the MBIM driver: unsupported */ if (g_str_equal (drivers[j], "cdc_mbim")) { - mm_dbg ("(%s) [%s] filtered by implicit MBIM driver", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "port %s filtered by implicit MBIM driver", mm_kernel_device_get_name (port)); return TRUE; } } @@ -398,9 +389,7 @@ apply_pre_probing_filters (MMPlugin *self, !self->priv->forbidden_product_strings) || g_str_equal (mm_kernel_device_get_subsystem (port), "net") || g_str_has_prefix (mm_kernel_device_get_name (port), "cdc-wdm"))) { - mm_dbg ("(%s) [%s] filtered by vendor/product IDs", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "port %s filtered by vendor/product IDs", mm_kernel_device_get_name (port)); return TRUE; } @@ -410,9 +399,7 @@ apply_pre_probing_filters (MMPlugin *self, for (i = 0; self->priv->forbidden_product_ids[i].l; i++) { if (vendor == self->priv->forbidden_product_ids[i].l && product == self->priv->forbidden_product_ids[i].r) { - mm_dbg ("(%s) [%s] filtered by forbidden vendor/product IDs", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "port %s filtered by forbidden vendor/product IDs", mm_kernel_device_get_name (port)); return TRUE; } } @@ -451,9 +438,7 @@ apply_pre_probing_filters (MMPlugin *self, /* If we didn't match any udev tag: unsupported */ if (!self->priv->udev_tags[i]) { - mm_dbg ("(%s) [%s] filtered by udev tags", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "port %s filtered by udev tags", mm_kernel_device_get_name (port)); return TRUE; } } @@ -500,9 +485,7 @@ apply_post_probing_filters (MMPlugin *self, if (vendor_filtered) { if (!self->priv->product_strings) { - mm_dbg ("(%s) [%s] filtered by vendor strings", - self->priv->name, - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port %s filtered by vendor strings", mm_port_probe_get_port_name (probe)); return TRUE; } } else @@ -525,9 +508,7 @@ apply_post_probing_filters (MMPlugin *self, if (self->priv->product_strings) { /* If we didn't get any vendor or product: filtered */ if (!vendor || !product) { - mm_dbg ("(%s) [%s] filtered as no vendor/product strings given", - self->priv->name, - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port %s filtered as no vendor/product strings given", mm_port_probe_get_port_name (probe)); return TRUE; } else { @@ -548,9 +529,7 @@ apply_post_probing_filters (MMPlugin *self, /* If we didn't match any product: unsupported */ if (!self->priv->product_strings[i].l) { - mm_dbg ("(%s) [%s] filtered by vendor/product strings", - self->priv->name, - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port %s filtered by vendor/product strings", mm_port_probe_get_port_name (probe)); return TRUE; } } @@ -570,9 +549,7 @@ apply_post_probing_filters (MMPlugin *self, g_free (casefolded_product); if (found) { /* If we match a forbidden product: unsupported */ - mm_dbg ("(%s) [%s] filtered by forbidden vendor/product strings", - self->priv->name, - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port %s filtered by forbidden vendor/product strings", mm_port_probe_get_port_name (probe)); return TRUE; } } @@ -586,9 +563,7 @@ apply_post_probing_filters (MMPlugin *self, if (self->priv->allowed_icera && !mm_port_probe_is_icera (probe)) { /* Unsupported! */ - mm_dbg ("(%s) [%s] filtered as modem is not icera", - self->priv->name, - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port %s filtered as modem is not icera", mm_port_probe_get_port_name (probe)); return TRUE; } @@ -597,9 +572,7 @@ apply_post_probing_filters (MMPlugin *self, if (self->priv->forbidden_icera && mm_port_probe_is_icera (probe)) { /* Unsupported! */ - mm_dbg ("(%s) [%s] filtered as modem is icera", - self->priv->name, - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port %s filtered as modem is icera", mm_port_probe_get_port_name (probe)); return TRUE; } @@ -608,9 +581,7 @@ apply_post_probing_filters (MMPlugin *self, if (self->priv->allowed_xmm && !mm_port_probe_is_xmm (probe)) { /* Unsupported! */ - mm_dbg ("(%s) [%s] filtered as modem is not XMM", - self->priv->name, - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port %s filtered as modem is not XMM", mm_port_probe_get_port_name (probe)); return TRUE; } @@ -619,9 +590,7 @@ apply_post_probing_filters (MMPlugin *self, if (self->priv->forbidden_xmm && mm_port_probe_is_xmm (probe)) { /* Unsupported! */ - mm_dbg ("(%s) [%s] filtered as modem is XMM", - self->priv->name, - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port %s filtered as modem is XMM", mm_port_probe_get_port_name (probe)); return TRUE; } @@ -782,8 +751,7 @@ mm_plugin_supports_port (MMPlugin *self, /* Before launching any probing, check if the port is a net device. */ if (g_str_equal (mm_kernel_device_get_subsystem (port), "net")) { - mm_dbg ("(%s) [%s] probing deferred until result suggested", - self->priv->name, mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "probing of port %s deferred until result suggested", mm_kernel_device_get_name (port)); g_task_return_int (task, MM_PLUGIN_SUPPORTS_PORT_DEFER_UNTIL_SUGGESTED); g_object_unref (task); return; @@ -835,10 +803,9 @@ mm_plugin_supports_port (MMPlugin *self, if (self->priv->single_at && mm_port_probe_list_has_at_port (mm_device_peek_port_probe_list (device)) && !mm_port_probe_is_at (probe)) { - mm_dbg ("(%s) [%s] not setting up AT probing tasks: " - "modem already has the expected single AT port", - self->priv->name, - mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "not setting up AT probing tasks in port %s: " + "modem already has the expected single AT port", + mm_kernel_device_get_name (port)); /* Assuming it won't be an AT port. We still run the probe anyway, in * case we need to check for other port types (e.g. QCDM) */ @@ -856,10 +823,9 @@ mm_plugin_supports_port (MMPlugin *self, /* Launch the probe */ probe_list_str = mm_port_probe_flag_build_string_from_mask (ctx->flags); - mm_dbg ("(%s) [%s] probe required: '%s'", - self->priv->name, - mm_kernel_device_get_name (port), - probe_list_str); + mm_obj_dbg (self, "probes required for port %s: '%s'", + mm_kernel_device_get_name (port), + probe_list_str); g_free (probe_list_str); mm_port_probe_run (probe, @@ -972,7 +938,7 @@ mm_plugin_create_modem (MMPlugin *self, /* Ports that are explicitly blacklisted will be grabbed as ignored */ if (mm_port_probe_is_ignored (probe)) { - mm_dbg ("(%s/%s): port is blacklisted", subsys, name); + mm_obj_dbg (self, "port %s is blacklisted", name); force_ignored = TRUE; goto grab_port; } @@ -982,7 +948,7 @@ mm_plugin_create_modem (MMPlugin *self, port_type == MM_PORT_TYPE_NET && g_strcmp0 (driver, "qmi_wwan") != 0) { /* Non-QMI net ports are ignored in QMI modems */ - mm_dbg ("(%s/%s): ignoring non-QMI net port in QMI modem", subsys, name); + mm_obj_dbg (self, "ignoring non-QMI net port %s in QMI modem", name); force_ignored = TRUE; goto grab_port; } @@ -991,7 +957,7 @@ mm_plugin_create_modem (MMPlugin *self, port_type == MM_PORT_TYPE_NET && g_strcmp0 (driver, "qmi_wwan") == 0) { /* QMI net ports are ignored in non-QMI modems */ - mm_dbg ("(%s/%s): ignoring QMI net port in non-QMI modem", subsys, name); + mm_obj_dbg (self, "ignoring QMI net port %s in non-QMI modem", name); force_ignored = TRUE; goto grab_port; } @@ -999,7 +965,7 @@ mm_plugin_create_modem (MMPlugin *self, if (port_type == MM_PORT_TYPE_NET && g_strcmp0 (driver, "qmi_wwan") == 0) { /* QMI net ports are ignored if QMI support not built */ - mm_dbg ("(%s/%s): ignoring QMI net port as QMI support isn't available", subsys, name); + mm_obj_dbg (self, "ignoring QMI net port %s as QMI support isn't available", name); force_ignored = TRUE; goto grab_port; } @@ -1010,7 +976,7 @@ mm_plugin_create_modem (MMPlugin *self, port_type == MM_PORT_TYPE_NET && g_strcmp0 (driver, "cdc_mbim") != 0) { /* Non-MBIM net ports are ignored in MBIM modems */ - mm_dbg ("(%s/%s): ignoring non-MBIM net port in MBIM modem", subsys, name); + mm_obj_dbg (self, "ignoring non-MBIM net port %s in MBIM modem", name); force_ignored = TRUE; goto grab_port; } @@ -1019,14 +985,14 @@ mm_plugin_create_modem (MMPlugin *self, port_type == MM_PORT_TYPE_NET && g_strcmp0 (driver, "cdc_mbim") == 0) { /* MBIM net ports are ignored in non-MBIM modems */ - mm_dbg ("(%s/%s): ignoring MBIM net port in non-MBIM modem", subsys, name); + mm_obj_dbg (self, "ignoring MBIM net port %s in non-MBIM modem", name); force_ignored = TRUE; goto grab_port; } #else if (port_type == MM_PORT_TYPE_NET && g_strcmp0 (driver, "cdc_mbim") == 0) { - mm_dbg ("(%s/%s): ignoring MBIM net port as MBIM support isn't available", subsys, name); + mm_obj_dbg (self, "ignoring MBIM net port %s as MBIM support isn't available", name); force_ignored = TRUE; goto grab_port; } @@ -1053,9 +1019,7 @@ mm_plugin_create_modem (MMPlugin *self, next: if (!grabbed) { - mm_warn ("Could not grab port (%s/%s): '%s'", - subsys, name, - inner_error ? inner_error->message : "unknown error"); + mm_obj_warn (self, "could not grab port %s: %s", name, inner_error ? inner_error->message : "unknown error"); g_clear_error (&inner_error); } } @@ -1077,18 +1041,18 @@ mm_plugin_create_modem (MMPlugin *self, * installed yet). */ kernel_device = mm_kernel_device_generic_new_with_rules (properties, NULL, &inner_error); if (!kernel_device) { - mm_warn ("Could not grab port (virtual/%s): '%s'", - virtual_ports[i], - inner_error ? inner_error->message : "unknown error"); + mm_obj_warn (self, "could not create generic device for virtual port %s: %s", + virtual_ports[i], + inner_error ? inner_error->message : "unknown error"); g_clear_error (&inner_error); } else if (!mm_base_modem_grab_port (modem, kernel_device, MM_PORT_TYPE_AT, MM_PORT_SERIAL_AT_FLAG_NONE, &inner_error)) { - mm_warn ("Could not grab port (virtual/%s): '%s'", - virtual_ports[i], - inner_error ? inner_error->message : "unknown error"); + mm_obj_warn (self, "could not grab virtual port %s: %s", + virtual_ports[i], + inner_error ? inner_error->message : "unknown error"); g_clear_error (&inner_error); } @@ -1107,6 +1071,19 @@ mm_plugin_create_modem (MMPlugin *self, /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMPlugin *self; + g_autofree gchar *plugin_name_lowercase; + + self = MM_PLUGIN (_self); + plugin_name_lowercase = g_ascii_strdown (self->priv->name, -1); + return g_strdup_printf ("plugin/%s", plugin_name_lowercase); +} + +/*****************************************************************************/ + static void mm_plugin_init (MMPlugin *self) { @@ -1366,6 +1343,12 @@ finalize (GObject *object) G_OBJECT_CLASS (mm_plugin_parent_class)->finalize (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_plugin_class_init (MMPluginClass *klass) { From b2a06fa99554cda2ddd5094d7ba05d7eb66d94b5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 18:18:40 +0200 Subject: [PATCH 063/675] plugin-manager: port to use object logging --- src/mm-plugin-manager.c | 317 ++++++++++++++++++++++++---------------- 1 file changed, 190 insertions(+), 127 deletions(-) diff --git a/src/mm-plugin-manager.c b/src/mm-plugin-manager.c index 950af441..d00b65e3 100644 --- a/src/mm-plugin-manager.c +++ b/src/mm-plugin-manager.c @@ -28,16 +28,17 @@ #include "mm-plugin-manager.h" #include "mm-plugin.h" #include "mm-shared.h" -#include "mm-log.h" +#include "mm-log-object.h" #define SHARED_PREFIX "libmm-shared" #define PLUGIN_PREFIX "libmm-plugin" -static void initable_iface_init (GInitableIface *iface); +static void initable_iface_init (GInitableIface *iface); +static void log_object_iface_init (MMLogObjectInterface *iface); G_DEFINE_TYPE_EXTENDED (MMPluginManager, mm_plugin_manager, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, - initable_iface_init)) + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -260,7 +261,8 @@ port_context_run_finish (MMPluginManager *self, static void port_context_complete (PortContext *port_context) { - GTask *task; + MMPluginManager *self; + GTask *task; /* If already completed, do nothing */ if (!port_context->task) @@ -271,8 +273,9 @@ port_context_complete (PortContext *port_context) port_context->task = NULL; /* Log about the time required to complete the checks */ - mm_dbg ("[plugin manager] task %s: finished in '%lf' seconds", - port_context->name, g_timer_elapsed (port_context->timer, NULL)); + self = g_task_get_source_object (task); + mm_obj_dbg (self, "task %s: finished in '%lf' seconds", + port_context->name, g_timer_elapsed (port_context->timer, NULL)); if (!port_context->best_plugin) g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Unsupported"); @@ -287,10 +290,13 @@ static void port_context_supported (PortContext *port_context, MMPlugin *plugin) { + MMPluginManager *self; + g_assert (plugin); + self = g_task_get_source_object (port_context->task); - mm_dbg ("[plugin manager] task %s: found best plugin for port (%s)", - port_context->name, mm_plugin_get_name (plugin)); + mm_obj_dbg (self, "task %s: found best plugin for port (%s)", + port_context->name, mm_plugin_get_name (plugin)); /* Found a best plugin, store it to return it */ port_context->best_plugin = g_object_ref (plugin); @@ -309,7 +315,8 @@ static void port_context_set_suggestion (PortContext *port_context, MMPlugin *suggested_plugin) { - gboolean forbidden_icera; + MMPluginManager *self; + gboolean forbidden_icera; /* Plugin suggestions serve two different purposes here: * 1) Finish all the probes which were deferred until suggested. @@ -325,6 +332,9 @@ port_context_set_suggestion (PortContext *port_context, if (port_context->best_plugin || port_context->suggested_plugin) return; + /* There may not be a task at this point, so be gentle */ + self = port_context->task ? g_task_get_source_object (port_context->task) : NULL; + /* Complete tasks which were deferred until suggested */ if (port_context->defer_until_suggested) { /* Reset the defer until suggested flag; we consider this @@ -332,8 +342,8 @@ port_context_set_suggestion (PortContext *port_context, port_context->defer_until_suggested = FALSE; if (suggested_plugin) { - mm_dbg ("[plugin manager] task %s: deferred task completed, got suggested plugin (%s)", - port_context->name, mm_plugin_get_name (suggested_plugin)); + mm_obj_dbg (self, "task %s: deferred task completed, got suggested plugin (%s)", + port_context->name, mm_plugin_get_name (suggested_plugin)); /* Advance to the suggested plugin and re-check support there */ port_context->suggested_plugin = g_object_ref (suggested_plugin); port_context->current = g_list_find (port_context->current, port_context->suggested_plugin); @@ -343,8 +353,7 @@ port_context_set_suggestion (PortContext *port_context, return; } - mm_dbg ("[plugin manager] task %s: deferred task completed, no suggested plugin", - port_context->name); + mm_obj_dbg (self, "task %s: deferred task completed, no suggested plugin", port_context->name); port_context_complete (port_context); return; } @@ -372,8 +381,8 @@ port_context_set_suggestion (PortContext *port_context, * should run its probing independently, and we'll later decide * which result applies to the whole device. */ - mm_dbg ("[plugin manager] task %s: got suggested plugin (%s)", - port_context->name, mm_plugin_get_name (suggested_plugin)); + mm_obj_dbg (self, "task %s: got suggested plugin (%s)", + port_context->name, mm_plugin_get_name (suggested_plugin)); port_context->suggested_plugin = g_object_ref (suggested_plugin); } @@ -381,7 +390,10 @@ static void port_context_unsupported (PortContext *port_context, MMPlugin *plugin) { + MMPluginManager *self; + g_assert (plugin); + self = g_task_get_source_object (port_context->task); /* If there is no suggested plugin, go on to the next one */ if (!port_context->suggested_plugin) { @@ -396,8 +408,8 @@ port_context_unsupported (PortContext *port_context, * just cancel the port probing and avoid more tests. */ if (port_context->suggested_plugin == plugin) { - mm_dbg ("[plugin manager] task %s: ignoring port unsupported by physical modem's plugin", - port_context->name); + mm_obj_dbg (self, "task %s: ignoring port unsupported by physical modem's plugin", + port_context->name); port_context_complete (port_context); return; } @@ -412,14 +424,17 @@ port_context_unsupported (PortContext *port_context, static void port_context_defer (PortContext *port_context) { + MMPluginManager *self; + + self = g_task_get_source_object (port_context->task); + /* Try with the suggested one after being deferred */ if (port_context->suggested_plugin) { - mm_dbg ("[plugin manager] task %s: deferring support check (%s suggested)", - port_context->name, mm_plugin_get_name (MM_PLUGIN (port_context->suggested_plugin))); + mm_obj_dbg (self, "task %s: deferring support check (%s suggested)", + port_context->name, mm_plugin_get_name (MM_PLUGIN (port_context->suggested_plugin))); port_context->current = g_list_find (port_context->current, port_context->suggested_plugin); } else - mm_dbg ("[plugin manager] task %s: deferring support check", - port_context->name); + mm_obj_dbg (self, "task %s: deferring support check", port_context->name); /* Schedule checking support. * @@ -434,14 +449,17 @@ static void port_context_defer_until_suggested (PortContext *port_context, MMPlugin *plugin) { + MMPluginManager *self; + g_assert (plugin); + self = g_task_get_source_object (port_context->task); /* If we arrived here and we already have a plugin suggested, use it */ if (port_context->suggested_plugin) { /* We can finish this context */ if (port_context->suggested_plugin == plugin) { - mm_dbg ("[plugin manager] task %s: completed, got suggested plugin (%s)", - port_context->name, mm_plugin_get_name (port_context->suggested_plugin)); + mm_obj_dbg (self, "task %s: completed, got suggested plugin (%s)", + port_context->name, mm_plugin_get_name (port_context->suggested_plugin)); /* Store best plugin and end operation */ port_context->best_plugin = g_object_ref (port_context->suggested_plugin); port_context_complete (port_context); @@ -449,8 +467,8 @@ port_context_defer_until_suggested (PortContext *port_context, } /* Recheck support in deferred task */ - mm_dbg ("[plugin manager] task %s: re-checking support on deferred task, got suggested plugin (%s)", - port_context->name, mm_plugin_get_name (port_context->suggested_plugin)); + mm_obj_dbg (self, "task %s: re-checking support on deferred task, got suggested plugin (%s)", + port_context->name, mm_plugin_get_name (port_context->suggested_plugin)); port_context->current = g_list_find (port_context->current, port_context->suggested_plugin); port_context_next (port_context); return; @@ -459,8 +477,7 @@ port_context_defer_until_suggested (PortContext *port_context, /* We are deferred until a suggested plugin is given. If last supports task * of a given device is finished without finding a best plugin, this task * will get finished reporting unsupported. */ - mm_dbg ("[plugin manager] task %s: deferring support check until result suggested", - port_context->name); + mm_obj_dbg (self, "task %s: deferring support check until result suggested", port_context->name); port_context->defer_until_suggested = TRUE; } @@ -469,15 +486,18 @@ plugin_supports_port_ready (MMPlugin *plugin, GAsyncResult *res, PortContext *port_context) { + MMPluginManager *self; MMPluginSupportsResult support_result; GError *error = NULL; + self = g_task_get_source_object (port_context->task); + /* Get supports check results */ support_result = mm_plugin_supports_port_finish (plugin, res, &error); if (error) { g_assert_cmpuint (support_result, ==, MM_PLUGIN_SUPPORTS_PORT_UNKNOWN); - mm_warn ("[plugin manager] task %s: error when checking support with plugin '%s': '%s'", - port_context->name, mm_plugin_get_name (plugin), error->message); + mm_obj_warn (self, "task %s: error when checking support with plugin '%s': %s", + port_context->name, mm_plugin_get_name (plugin), error->message); g_error_free (error); } @@ -507,7 +527,10 @@ plugin_supports_port_ready (MMPlugin *plugin, static void port_context_next (PortContext *port_context) { - MMPlugin *plugin; + MMPluginManager *self; + MMPlugin *plugin; + + self = g_task_get_source_object (port_context->task); /* If we're cancelled, done */ if (g_cancellable_is_cancelled (port_context->cancellable)) { @@ -527,8 +550,8 @@ port_context_next (PortContext *port_context) * async method because we want to make sure the context is still valid * once the method finishes. */ plugin = MM_PLUGIN (port_context->current->data); - mm_dbg ("[plugin manager] task %s: checking with plugin '%s'", - port_context->name, mm_plugin_get_name (plugin)); + mm_obj_dbg (self, "task %s: checking with plugin '%s'", + port_context->name, mm_plugin_get_name (plugin)); mm_plugin_supports_port (plugin, port_context->device, port_context->port, @@ -540,6 +563,8 @@ port_context_next (PortContext *port_context) static gboolean port_context_cancel (PortContext *port_context) { + MMPluginManager *self; + /* Port context cancellation, which only makes sense if the context is * actually being run, so just exit if it isn't. */ if (!port_context->task) @@ -549,8 +574,8 @@ port_context_cancel (PortContext *port_context) if (g_cancellable_is_cancelled (port_context->cancellable)) return FALSE; - mm_dbg ("[plugin manager) task %s: cancellation requested", - port_context->name); + self = g_task_get_source_object (port_context->task); + mm_obj_dbg (self, "task %s: cancellation requested", port_context->name); /* Make sure we hold a port context reference while cancelling, as the * cancellable signal handlers may end up unref-ing our last reference @@ -600,8 +625,8 @@ port_context_run (MMPluginManager *self, port_context->suggested_plugin = g_object_ref (suggested); port_context->current = g_list_find (port_context->current, port_context->suggested_plugin); if (!port_context->current) - mm_warn ("[plugin manager] task %s: suggested plugin (%s) not among the ones to test", - port_context->name, mm_plugin_get_name (suggested)); + mm_obj_warn (self, "task %s: suggested plugin (%s) not among the ones to test", + port_context->name, mm_plugin_get_name (suggested)); } /* Log the list of plugins found and specify which are the ones that are going @@ -610,31 +635,31 @@ port_context_run (MMPluginManager *self, gboolean suggested_found = FALSE; GList *l; - mm_dbg ("[plugin manager] task %s: found '%u' plugins to try", - port_context->name, g_list_length (port_context->plugins)); + mm_obj_dbg (self, "task %s: found '%u' plugins to try", + port_context->name, g_list_length (port_context->plugins)); for (l = port_context->plugins; l; l = g_list_next (l)) { MMPlugin *plugin; plugin = MM_PLUGIN (l->data); if (suggested_found) { - mm_dbg ("[plugin manager] task %s: may try with plugin '%s'", - port_context->name, mm_plugin_get_name (plugin)); + mm_obj_dbg (self, "task %s: may try with plugin '%s'", + port_context->name, mm_plugin_get_name (plugin)); continue; } if (suggested && l == port_context->current) { suggested_found = TRUE; - mm_dbg ("[plugin manager] task %s: will try with plugin '%s' (suggested)", - port_context->name, mm_plugin_get_name (plugin)); + mm_obj_dbg (self, "task %s: will try with plugin '%s' (suggested)", + port_context->name, mm_plugin_get_name (plugin)); continue; } if (suggested && !suggested_found) { - mm_dbg ("[plugin manager] task %s: won't try with plugin '%s' (skipped)", - port_context->name, mm_plugin_get_name (plugin)); + mm_obj_dbg (self, "task %s: won't try with plugin '%s' (skipped)", + port_context->name, mm_plugin_get_name (plugin)); continue; } - mm_dbg ("[plugin manager] task %s: will try with plugin '%s'", - port_context->name, mm_plugin_get_name (plugin)); + mm_obj_dbg (self, "task %s: will try with plugin '%s'", + port_context->name, mm_plugin_get_name (plugin)); } } @@ -647,7 +672,7 @@ port_context_run (MMPluginManager *self, * best plugin found for the port. */ port_context->task = g_task_new (self, port_context->cancellable, callback, user_data); - mm_dbg ("[plugin manager) task %s: started", port_context->name); + mm_obj_dbg (self, "task %s: started", port_context->name); /* Go probe with the first plugin */ port_context_next (port_context); @@ -828,22 +853,25 @@ device_context_run_finish (MMPluginManager *self, static void device_context_complete (DeviceContext *device_context) { - GTask *task; + MMPluginManager *self; + GTask *task; + + self = g_task_get_source_object (device_context->task); /* If the context is completed before the 2500ms minimum probing time, we need to wait * until that happens, so that we give enough time to udev/hotplug to report the * new port additions. */ if (device_context->min_probing_time_id) { - mm_dbg ("[plugin manager] task %s: all port probings completed, but not reached min probing time yet", - device_context->name); + mm_obj_dbg (self, "task %s: all port probings completed, but not reached min probing time yet", + device_context->name); return; } /* If the context is completed less than 1500ms before the last port was exposed, * wait some more. */ if (device_context->extra_probing_time_id) { - mm_dbg ("[plugin manager] task %s: all port probings completed, but not reached extra probing time yet", - device_context->name); + mm_obj_dbg (self, "task %s: all port probings completed, but not reached extra probing time yet", + device_context->name); return; } @@ -853,8 +881,8 @@ device_context_complete (DeviceContext *device_context) device_context->task = NULL; /* Log about the time required to complete the checks */ - mm_dbg ("[plugin manager] task %s: finished in '%lf' seconds", - device_context->name, g_timer_elapsed (device_context->timer, NULL)); + mm_obj_dbg (self, "task %s: finished in '%lf' seconds", + device_context->name, g_timer_elapsed (device_context->timer, NULL)); /* Remove signal handlers */ if (device_context->grabbed_id) { @@ -913,20 +941,24 @@ device_context_set_best_plugin (DeviceContext *device_context, PortContext *port_context, MMPlugin *best_plugin) { + MMPluginManager *self; + + self = g_task_get_source_object (device_context->task); + if (!best_plugin) { /* If the port appeared after an already probed port, which decided that * the Generic plugin was the best one (which is by default not initially * suggested), we'll end up arriving here. Don't ignore it, it may well * be a wwan port that we do need to grab. */ if (device_context->best_plugin) { - mm_dbg ("[plugin manager] task %s: assuming port can be handled by the '%s' plugin", - port_context->name, mm_plugin_get_name (device_context->best_plugin)); + mm_obj_dbg (self, "task %s: assuming port can be handled by the '%s' plugin", + port_context->name, mm_plugin_get_name (device_context->best_plugin)); return; } /* Unsupported error, this is generic when we cannot find a plugin */ - mm_dbg ("[plugin manager] task %s: not supported by any plugin" , - port_context->name); + mm_obj_dbg (self, "task %s: not supported by any plugin" , + port_context->name); /* Tell the device to ignore this port */ mm_device_ignore_port (device_context->device, port_context->port); @@ -946,8 +978,8 @@ device_context_set_best_plugin (DeviceContext *device_context, device_context->best_plugin != best_plugin)) { /* Only log best plugin if it's not the generic one */ if (!g_str_equal (mm_plugin_get_name (best_plugin), MM_PLUGIN_GENERIC_NAME)) - mm_dbg ("[plugin manager] task %s: found best plugin: %s", - port_context->name, mm_plugin_get_name (best_plugin)); + mm_obj_dbg (self, "task %s: found best plugin: %s", + port_context->name, mm_plugin_get_name (best_plugin)); /* Store and suggest this plugin also to other port probes */ device_context->best_plugin = g_object_ref (best_plugin); device_context_suggest_plugin (device_context, port_context, best_plugin); @@ -979,19 +1011,19 @@ device_context_set_best_plugin (DeviceContext *device_context, g_assert (new_allowed_icera == FALSE || new_forbidden_icera == FALSE); if (previous_allowed_icera && new_forbidden_icera) - mm_warn ("[plugin manager] task %s: will use plugin '%s' instead of '%s', modem is icera-capable", + mm_obj_warn (self, "task %s: will use plugin '%s' instead of '%s', modem is icera-capable", port_context->name, mm_plugin_get_name (device_context->best_plugin), mm_plugin_get_name (best_plugin)); else if (new_allowed_icera && previous_forbidden_icera) { - mm_warn ("[plugin manager] task %s: overriding previously selected device plugin '%s' with '%s', modem is icera-capable", + mm_obj_warn (self, "task %s: overriding previously selected device plugin '%s' with '%s', modem is icera-capable", port_context->name, mm_plugin_get_name (device_context->best_plugin), mm_plugin_get_name (best_plugin)); g_object_unref (device_context->best_plugin); device_context->best_plugin = g_object_ref (best_plugin); } else - mm_warn ("[plugin manager] task %s: plugin mismatch error (device reports '%s', port reports '%s')", + mm_obj_warn (self, "task %s: plugin mismatch error (device reports '%s', port reports '%s')", port_context->name, mm_plugin_get_name (device_context->best_plugin), mm_plugin_get_name (best_plugin)); @@ -999,21 +1031,24 @@ device_context_set_best_plugin (DeviceContext *device_context, } /* Device plugin equal to best plugin */ - mm_dbg ("[plugin manager] task %s: best plugin matches device reported one: %s", - port_context->name, mm_plugin_get_name (best_plugin)); + mm_obj_dbg (self, "task %s: best plugin matches device reported one: %s", + port_context->name, mm_plugin_get_name (best_plugin)); } static void device_context_continue (DeviceContext *device_context) { - GList *l; - GString *s = NULL; - guint n = 0; - guint n_active = 0; + MMPluginManager *self; + GList *l; + GString *s = NULL; + guint n = 0; + guint n_active = 0; + + self = g_task_get_source_object (device_context->task); /* If there are no running port contexts around, we're free to finish */ if (!device_context->port_contexts) { - mm_dbg ("[plugin manager] task %s: no more ports to probe", device_context->name); + mm_obj_dbg (self, "task %s: no more ports to probe", device_context->name); device_context_complete (device_context); return; } @@ -1038,12 +1073,12 @@ device_context_continue (DeviceContext *device_context) } g_assert (n > 0 && s); - mm_dbg ("[plugin Manager] task %s: still %u running probes (%u active): %s", - device_context->name, n, n_active, s->str); + mm_obj_dbg (self, "task %s: still %u running probes (%u active): %s", + device_context->name, n, n_active, s->str); g_string_free (s, TRUE); if (n_active == 0) { - mm_dbg ("[plugin manager] task %s: no active tasks to probe", device_context->name); + mm_obj_dbg (self, "task %s: no active tasks to probe", device_context->name); device_context_suggest_plugin (device_context, NULL, NULL); } } @@ -1064,7 +1099,7 @@ port_context_run_ready (MMPluginManager *self, /* This error is not critical */ device_context_set_best_plugin (common->device_context, common->port_context, NULL); } else - mm_warn ("[plugin manager] task %s: failed: %s", common->port_context->name, error->message); + mm_obj_warn (self, "task %s: failed: %s", common->port_context->name, error->message); g_error_free (error); } else { /* Set the plugin as the best one in the device context */ @@ -1090,9 +1125,12 @@ port_context_run_ready (MMPluginManager *self, static gboolean device_context_min_probing_time_elapsed (DeviceContext *device_context) { + MMPluginManager *self; + device_context->min_probing_time_id = 0; - mm_dbg ("[plugin manager] task %s: min probing time elapsed", device_context->name); + self = g_task_get_source_object (device_context->task); + mm_obj_dbg (self, "task %s: min probing time elapsed", device_context->name); /* Wakeup the device context logic */ device_context_continue (device_context); @@ -1102,9 +1140,12 @@ device_context_min_probing_time_elapsed (DeviceContext *device_context) static gboolean device_context_extra_probing_time_elapsed (DeviceContext *device_context) { + MMPluginManager *self; + device_context->extra_probing_time_id = 0; - mm_dbg ("[plugin manager] task %s: extra probing time elapsed", device_context->name); + self = g_task_get_source_object (device_context->task); + mm_obj_dbg (self, "task %s: extra probing time elapsed", device_context->name); /* Wakeup the device context logic */ device_context_continue (device_context); @@ -1156,7 +1197,7 @@ device_context_min_wait_time_elapsed (DeviceContext *device_context) self = device_context->self; device_context->min_wait_time_id = 0; - mm_dbg ("[plugin manager] task %s: min wait time elapsed", device_context->name); + mm_obj_dbg (self, "task %s: min wait time elapsed", device_context->name); /* Move list of port contexts out of the wait list */ g_assert (!device_context->port_contexts); @@ -1185,10 +1226,12 @@ static void device_context_port_released (DeviceContext *device_context, MMKernelDevice *port) { - PortContext *port_context; + MMPluginManager *self; + PortContext *port_context; - mm_dbg ("[plugin manager] task %s: port released: %s", - device_context->name, mm_kernel_device_get_name (port)); + self = g_task_get_source_object (device_context->task); + mm_obj_dbg (self, "task %s: port released: %s", + device_context->name, mm_kernel_device_get_name (port)); /* Check if there's a waiting port context */ port_context = device_context_peek_waiting_port_context (device_context, port); @@ -1209,8 +1252,8 @@ device_context_port_released (DeviceContext *device_context, /* This is not something worth warning. If the probing task has already * been finished, it will already be removed from the list */ - mm_dbg ("[plugin manager] task %s: port wasn't found: %s", - device_context->name, mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "task %s: port wasn't found: %s", + device_context->name, mm_kernel_device_get_name (port)); } static void @@ -1223,13 +1266,13 @@ device_context_port_grabbed (DeviceContext *device_context, /* Recover plugin manager */ self = MM_PLUGIN_MANAGER (device_context->self); - mm_dbg ("[plugin manager] task %s: port grabbed: %s", - device_context->name, mm_kernel_device_get_name (port)); + mm_obj_dbg (self, "task %s: port grabbed: %s", + device_context->name, mm_kernel_device_get_name (port)); /* Ignore if for any reason we still have it in the running list */ port_context = device_context_peek_running_port_context (device_context, port); if (port_context) { - mm_warn ("[plugin manager] task %s: port context already being processed", + mm_obj_warn (self, "task %s: port context already being processed", device_context->name); return; } @@ -1237,7 +1280,7 @@ device_context_port_grabbed (DeviceContext *device_context, /* Ignore if for any reason we still have it in the waiting list */ port_context = device_context_peek_waiting_port_context (device_context, port); if (port_context) { - mm_warn ("[plugin manager] task %s: port context already scheduled", + mm_obj_warn (self, "task %s: port context already scheduled", device_context->name); return; } @@ -1255,13 +1298,13 @@ device_context_port_grabbed (DeviceContext *device_context, device_context->device, port); - mm_dbg ("[plugin manager] task %s: new support task for port", - port_context->name); + mm_obj_dbg (self, "task %s: new support task for port", + port_context->name); /* Îf still waiting the min wait time, store it in the waiting list */ if (device_context->min_wait_time_id) { - mm_dbg ("[plugin manager) task %s: deferred until min wait time elapsed", - port_context->name); + mm_obj_dbg (self, "task %s: deferred until min wait time elapsed", + port_context->name); /* Store the port reference in the list within the device */ device_context->wait_port_contexts = g_list_prepend (device_context->wait_port_contexts, port_context); return; @@ -1278,12 +1321,14 @@ device_context_port_grabbed (DeviceContext *device_context, static gboolean device_context_cancel (DeviceContext *device_context) { + MMPluginManager *self; + /* If cancelled already, do nothing */ if (g_cancellable_is_cancelled (device_context->cancellable)) return FALSE; - mm_dbg ("[plugin manager) task %s: cancellation requested", - device_context->name); + self = g_task_get_source_object (device_context->task); + mm_obj_dbg (self, "task %s: cancellation requested", device_context->name); /* The device context is cancelled now */ g_cancellable_cancel (device_context->cancellable); @@ -1502,7 +1547,7 @@ mm_plugin_manager_device_support_check (MMPluginManager *self, * Note that we handle cancellations ourselves, as we don't want the caller * to be required to keep track of a GCancellable for each of these tasks. */ - task = g_task_new (G_OBJECT (self), NULL, callback, user_data); + task = g_task_new (self, NULL, callback, user_data); /* Fail if there is already a task for the same device */ device_context = plugin_manager_peek_device_context (self, device); @@ -1520,8 +1565,8 @@ mm_plugin_manager_device_support_check (MMPluginManager *self, /* Track the device context in the list within the plugin manager. */ self->priv->device_contexts = g_list_prepend (self->priv->device_contexts, device_context); - mm_dbg ("[plugin manager] task %s: new support task for device: %s", - device_context->name, mm_device_get_uid (device_context->device)); + mm_obj_dbg (self, "task %s: new support task for device: %s", + device_context->name, mm_device_get_uid (device_context->device)); /* Run device context */ device_context_run (self, @@ -1589,57 +1634,58 @@ register_plugin_whitelist_product_ids (MMPluginManager *self, } static MMPlugin * -load_plugin (const gchar *path) +load_plugin (MMPluginManager *self, + const gchar *path) { - MMPlugin *plugin = NULL; - GModule *module; - MMPluginCreateFunc plugin_create_func; - gint *major_plugin_version; - gint *minor_plugin_version; - gchar *path_display; + MMPlugin *plugin = NULL; + GModule *module; + MMPluginCreateFunc plugin_create_func; + gint *major_plugin_version; + gint *minor_plugin_version; + gchar *path_display; /* Get printable UTF-8 string of the path */ path_display = g_filename_display_name (path); module = g_module_open (path, 0); if (!module) { - mm_warn ("[plugin manager] could not load plugin '%s': %s", path_display, g_module_error ()); + mm_obj_warn (self, "could not load plugin '%s': %s", path_display, g_module_error ()); goto out; } if (!g_module_symbol (module, "mm_plugin_major_version", (gpointer *) &major_plugin_version)) { - mm_warn ("[plugin manager] could not load plugin '%s': Missing major version info", path_display); + mm_obj_warn (self, "could not load plugin '%s': Missing major version info", path_display); goto out; } if (*major_plugin_version != MM_PLUGIN_MAJOR_VERSION) { - mm_warn ("[plugin manager] could not load plugin '%s': Plugin major version %d, %d is required", + mm_obj_warn (self, "could not load plugin '%s': Plugin major version %d, %d is required", path_display, *major_plugin_version, MM_PLUGIN_MAJOR_VERSION); goto out; } if (!g_module_symbol (module, "mm_plugin_minor_version", (gpointer *) &minor_plugin_version)) { - mm_warn ("[plugin manager] could not load plugin '%s': Missing minor version info", path_display); + mm_obj_warn (self, "could not load plugin '%s': Missing minor version info", path_display); goto out; } if (*minor_plugin_version != MM_PLUGIN_MINOR_VERSION) { - mm_warn ("[plugin manager] could not load plugin '%s': Plugin minor version %d, %d is required", + mm_obj_warn (self, "could not load plugin '%s': Plugin minor version %d, %d is required", path_display, *minor_plugin_version, MM_PLUGIN_MINOR_VERSION); goto out; } if (!g_module_symbol (module, "mm_plugin_create", (gpointer *) &plugin_create_func)) { - mm_warn ("[plugin manager] could not load plugin '%s': %s", path_display, g_module_error ()); + mm_obj_warn (self, "could not load plugin '%s': %s", path_display, g_module_error ()); goto out; } plugin = (*plugin_create_func) (); if (plugin) { - mm_dbg ("[plugin manager] loaded plugin '%s' from '%s'", mm_plugin_get_name (plugin), path_display); + mm_obj_dbg (self, "loaded plugin '%s' from '%s'", mm_plugin_get_name (plugin), path_display); g_object_weak_ref (G_OBJECT (plugin), (GWeakNotify) g_module_close, module); } else - mm_warn ("[plugin manager] could not load plugin '%s': initialization failed", path_display); + mm_obj_warn (self, "could not load plugin '%s': initialization failed", path_display); out: if (module && !plugin) @@ -1651,7 +1697,8 @@ load_plugin (const gchar *path) } static void -load_shared (const gchar *path) +load_shared (MMPluginManager *self, + const gchar *path) { GModule *module; gchar *path_display; @@ -1664,38 +1711,38 @@ load_shared (const gchar *path) module = g_module_open (path, 0); if (!module) { - mm_warn ("[plugin manager] could not load shared '%s': %s", path_display, g_module_error ()); + mm_obj_warn (self, "could not load shared '%s': %s", path_display, g_module_error ()); goto out; } if (!g_module_symbol (module, "mm_shared_major_version", (gpointer *) &major_shared_version)) { - mm_warn ("[plugin manager] could not load shared '%s': Missing major version info", path_display); + mm_obj_warn (self, "could not load shared '%s': Missing major version info", path_display); goto out; } if (*major_shared_version != MM_SHARED_MAJOR_VERSION) { - mm_warn ("[plugin manager] could not load shared '%s': Shared major version %d, %d is required", - path_display, *major_shared_version, MM_SHARED_MAJOR_VERSION); + mm_obj_warn (self, "could not load shared '%s': Shared major version %d, %d is required", + path_display, *major_shared_version, MM_SHARED_MAJOR_VERSION); goto out; } if (!g_module_symbol (module, "mm_shared_minor_version", (gpointer *) &minor_shared_version)) { - mm_warn ("[plugin manager] could not load shared '%s': Missing minor version info", path_display); + mm_obj_warn (self, "could not load shared '%s': Missing minor version info", path_display); goto out; } if (*minor_shared_version != MM_SHARED_MINOR_VERSION) { - mm_warn ("[plugin manager] could not load shared '%s': Shared minor version %d, %d is required", - path_display, *minor_shared_version, MM_SHARED_MINOR_VERSION); + mm_obj_warn (self, "could not load shared '%s': Shared minor version %d, %d is required", + path_display, *minor_shared_version, MM_SHARED_MINOR_VERSION); goto out; } if (!g_module_symbol (module, "mm_shared_name", (gpointer *) &shared_name)) { - mm_warn ("[plugin manager] could not load shared '%s': Missing name", path_display); + mm_obj_warn (self, "could not load shared '%s': Missing name", path_display); goto out; } - mm_dbg ("[plugin manager] loaded shared '%s' utils from '%s'", *shared_name, path_display); + mm_obj_dbg (self, "loaded shared '%s' utils from '%s'", *shared_name, path_display); out: if (module && !(*shared_name)) @@ -1726,7 +1773,7 @@ load_plugins (MMPluginManager *self, /* Get printable UTF-8 string of the path */ plugindir_display = g_filename_display_name (self->priv->plugin_dir); - mm_dbg ("[plugin manager] looking for plugins in '%s'", plugindir_display); + mm_obj_dbg (self, "looking for plugins in '%s'", plugindir_display); dir = g_dir_open (self->priv->plugin_dir, 0, NULL); if (!dir) { g_set_error (error, @@ -1748,13 +1795,13 @@ load_plugins (MMPluginManager *self, /* Load all shared utils */ for (l = shared_paths; l; l = g_list_next (l)) - load_shared ((const gchar *)(l->data)); + load_shared (self, (const gchar *)(l->data)); /* Load all plugins */ for (l = plugin_paths; l; l = g_list_next (l)) { MMPlugin *plugin; - plugin = load_plugin ((const gchar *)(l->data)); + plugin = load_plugin (self, (const gchar *)(l->data)); if (!plugin) continue; @@ -1772,7 +1819,7 @@ load_plugins (MMPluginManager *self, /* Check the generic plugin once all looped */ if (!self->priv->generic) - mm_warn ("[plugin manager] generic plugin not loaded"); + mm_obj_dbg (self, "generic plugin not loaded"); /* Treat as error if we don't find any plugin */ if (!self->priv->plugins && !self->priv->generic) { @@ -1784,8 +1831,8 @@ load_plugins (MMPluginManager *self, goto out; } - mm_dbg ("[plugin manager] successfully loaded %u plugins", - g_list_length (self->priv->plugins) + !!self->priv->generic); + mm_obj_dbg (self, "successfully loaded %u plugins", + g_list_length (self->priv->plugins) + !!self->priv->generic); out: g_list_free_full (shared_paths, g_free); @@ -1798,6 +1845,16 @@ load_plugins (MMPluginManager *self, return (self->priv->plugins || self->priv->generic); } +/*****************************************************************************/ + +static gchar * +log_object_build_id (MMLogObject *_self) +{ + return g_strdup ("plugin-manager"); +} + +/*****************************************************************************/ + MMPluginManager * mm_plugin_manager_new (const gchar *plugin_dir, MMFilter *filter, @@ -1898,6 +1955,12 @@ initable_iface_init (GInitableIface *iface) iface->init = initable_init; } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_plugin_manager_class_init (MMPluginManagerClass *manager_class) { From aab6a46515f28c9459b08a7db30a5dc7984ffc71 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 18:40:34 +0200 Subject: [PATCH 064/675] base-manager: port to use object logging --- src/mm-base-manager.c | 314 +++++++++++++++++++++--------------------- 1 file changed, 159 insertions(+), 155 deletions(-) diff --git a/src/mm-base-manager.c b/src/mm-base-manager.c index 5ff0c059..653adb5c 100644 --- a/src/mm-base-manager.c +++ b/src/mm-base-manager.c @@ -44,13 +44,14 @@ #include "mm-auth-provider.h" #include "mm-plugin.h" #include "mm-filter.h" -#include "mm-log.h" +#include "mm-log-object.h" -static void initable_iface_init (GInitableIface *iface); +static void initable_iface_init (GInitableIface *iface); +static void log_object_iface_init (MMLogObjectInterface *iface); G_DEFINE_TYPE_EXTENDED (MMBaseManager, mm_base_manager, MM_GDBUS_TYPE_ORG_FREEDESKTOP_MODEM_MANAGER1_SKELETON, 0, - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, - initable_iface_init)); + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -180,8 +181,8 @@ device_support_check_ready (MMPluginManager *plugin_manager, /* Receive plugin result from the plugin manager */ plugin = mm_plugin_manager_device_support_check_finish (plugin_manager, res, &error); if (!plugin) { - mm_info ("Couldn't check support for device '%s': %s", - mm_device_get_uid (ctx->device), error->message); + mm_obj_info (ctx->self, "couldn't check support for device '%s': %s", + mm_device_get_uid (ctx->device), error->message); g_error_free (error); g_hash_table_remove (ctx->self->priv->devices, mm_device_get_uid (ctx->device)); find_device_support_context_free (ctx); @@ -193,8 +194,8 @@ device_support_check_ready (MMPluginManager *plugin_manager, g_object_unref (plugin); if (!mm_device_create_modem (ctx->device, &error)) { - mm_warn ("Couldn't create modem for device '%s': %s", - mm_device_get_uid (ctx->device), error->message); + mm_obj_warn (ctx->self, "couldn't create modem for device '%s': %s", + mm_device_get_uid (ctx->device), error->message); g_error_free (error); g_hash_table_remove (ctx->self->priv->devices, mm_device_get_uid (ctx->device)); find_device_support_context_free (ctx); @@ -202,8 +203,8 @@ device_support_check_ready (MMPluginManager *plugin_manager, } /* Modem now created */ - mm_info ("Modem for device '%s' successfully created", - mm_device_get_uid (ctx->device)); + mm_obj_info (ctx->self, "modem for device '%s' successfully created", + mm_device_get_uid (ctx->device)); find_device_support_context_free (ctx); } @@ -220,7 +221,7 @@ static void device_removed (MMBaseManager *self, MMKernelDevice *kernel_device) { - MMDevice *device; + MMDevice *device; const gchar *subsys; const gchar *name; @@ -241,14 +242,14 @@ device_removed (MMBaseManager *self, * ourselves. */ g_object_ref (device); { - mm_info ("(%s/%s): released by device '%s'", subsys, name, mm_device_get_uid (device)); + mm_obj_info (self, "port %s released by device '%s'", name, mm_device_get_uid (device)); mm_device_release_port (device, kernel_device); /* If port probe list gets empty, remove the device object iself */ if (!mm_device_peek_port_probe_list (device)) { - mm_dbg ("Removing empty device '%s'", mm_device_get_uid (device)); + mm_obj_dbg (self, "removing empty device '%s'", mm_device_get_uid (device)); if (mm_plugin_manager_device_support_check_cancel (self->priv->plugin_manager, device)) - mm_dbg ("Device support check has been cancelled"); + mm_obj_dbg (self, "device support check has been cancelled"); /* The device may have already been removed from the tracking HT, we * just try to remove it and if it fails, we ignore it */ @@ -291,7 +292,7 @@ device_removed (MMBaseManager *self, */ device = find_device_by_kernel_device (self, kernel_device); if (device) { - mm_dbg ("Removing device '%s'", mm_device_get_uid (device)); + mm_obj_dbg (self, "removing device '%s'", mm_device_get_uid (device)); mm_device_remove_modem (device); g_hash_table_remove (self->priv->devices, mm_device_get_uid (device)); return; @@ -299,23 +300,21 @@ device_removed (MMBaseManager *self, } static void -device_added (MMBaseManager *manager, +device_added (MMBaseManager *self, MMKernelDevice *port, gboolean hotplugged, gboolean manual_scan) { MMDevice *device; const gchar *physdev_uid; - const gchar *subsys; const gchar *name; g_return_if_fail (port != NULL); - subsys = mm_kernel_device_get_subsystem (port); name = mm_kernel_device_get_name (port); - mm_dbg ("(%s/%s): adding device at sysfs path: %s", - subsys, name, mm_kernel_device_get_sysfs_path (port)); + mm_obj_dbg (self, "adding port %s at sysfs path: %s", + name, mm_kernel_device_get_sysfs_path (port)); /* Ignore devices that aren't completely configured by udev yet. If * ModemManager is started in parallel with udev, explicitly requesting @@ -330,8 +329,8 @@ device_added (MMBaseManager *manager, /* This could mean that device changed, losing its candidate * flags (such as Bluetooth RFCOMM devices upon disconnect. * Try to forget it. */ - device_removed (manager, port); - mm_dbg ("(%s/%s): port not candidate", subsys, name); + device_removed (self, port); + mm_obj_dbg (self, "port %s not candidate", name); return; } @@ -341,50 +340,48 @@ device_added (MMBaseManager *manager, g_assert (physdev_uid); /* If the device is inhibited, do nothing else */ - if (is_device_inhibited (manager, physdev_uid)) { + if (is_device_inhibited (self, physdev_uid)) { /* Note: we will not report as hotplugged an inhibited device port * because we don't know what was done with the port out of our * context. */ - device_inhibited_track_port (manager, physdev_uid, port, manual_scan); + device_inhibited_track_port (self, physdev_uid, port, manual_scan); return; } /* Run port filter */ - if (!mm_filter_port (manager->priv->filter, port, manual_scan)) + if (!mm_filter_port (self->priv->filter, port, manual_scan)) return; /* If already added, ignore new event */ - if (find_device_by_port (manager, port)) { - mm_dbg ("(%s/%s): port already added", subsys, name); + if (find_device_by_port (self, port)) { + mm_obj_dbg (self, "port %s already added", name); return; } /* See if we already created an object to handle ports in this device */ - device = find_device_by_physdev_uid (manager, physdev_uid); + device = find_device_by_physdev_uid (self, physdev_uid); if (!device) { FindDeviceSupportContext *ctx; - mm_dbg ("(%s/%s): first port in device %s", - subsys, name, physdev_uid); + mm_obj_dbg (self, "port %s is first in device %s", name, physdev_uid); /* Keep the device listed in the Manager */ - device = mm_device_new (physdev_uid, hotplugged, FALSE, manager->priv->object_manager); - g_hash_table_insert (manager->priv->devices, + device = mm_device_new (physdev_uid, hotplugged, FALSE, self->priv->object_manager); + g_hash_table_insert (self->priv->devices, g_strdup (physdev_uid), device); /* Launch device support check */ ctx = g_slice_new (FindDeviceSupportContext); - ctx->self = g_object_ref (manager); + ctx->self = g_object_ref (self); ctx->device = g_object_ref (device); mm_plugin_manager_device_support_check ( - manager->priv->plugin_manager, + self->priv->plugin_manager, device, (GAsyncReadyCallback) device_support_check_ready, ctx); } else - mm_dbg ("(%s/%s): additional port in device %s", - subsys, name, physdev_uid); + mm_obj_dbg (self, "additional port %s in device %s", name, physdev_uid); /* Grab the port in the existing device. */ mm_device_grab_port (device, port); @@ -425,11 +422,11 @@ handle_kernel_event (MMBaseManager *self, uid = mm_kernel_event_properties_get_uid (properties); - mm_dbg ("Kernel event reported:"); - mm_dbg (" action: %s", action); - mm_dbg (" subsystem: %s", subsystem); - mm_dbg (" name: %s", name); - mm_dbg (" uid: %s", uid ? uid : "n/a"); + mm_obj_dbg (self, "kernel event reported:"); + mm_obj_dbg (self, " action: %s", action); + mm_obj_dbg (self, " subsystem: %s", subsystem); + mm_obj_dbg (self, " name: %s", name); + mm_obj_dbg (self, " uid: %s", uid ? uid : "n/a"); #if defined WITH_UDEV kernel_device = mm_kernel_device_udev_new_from_properties (properties, error); @@ -455,15 +452,16 @@ handle_kernel_event (MMBaseManager *self, static void handle_uevent (GUdevClient *client, - const char *action, + const gchar *action, GUdevDevice *device, - gpointer user_data) + gpointer user_data) { - MMBaseManager *self = MM_BASE_MANAGER (user_data); - const gchar *subsys; - const gchar *name; + MMBaseManager *self; + const gchar *subsys; + const gchar *name; MMKernelDevice *kernel_device; + self = MM_BASE_MANAGER (user_data); g_return_if_fail (action != NULL); /* A bit paranoid */ @@ -629,11 +627,11 @@ mm_base_manager_start (MMBaseManager *self, } #if defined WITH_UDEV - mm_dbg ("Starting %s device scan...", manual_scan ? "manual" : "automatic"); + mm_obj_dbg (self, "starting %s device scan...", manual_scan ? "manual" : "automatic"); process_scan (self, manual_scan); - mm_dbg ("Finished device scan..."); + mm_obj_dbg (self, "finished device scan..."); #else - mm_dbg ("Unsupported %s device scan...", manual_scan ? "manual" : "automatic"); + mm_obj_dbg (self, "unsupported %s device scan...", manual_scan ? "manual" : "automatic"); #endif } @@ -745,8 +743,8 @@ set_logging_context_free (SetLoggingContext *ctx) } static void -set_logging_auth_ready (MMAuthProvider *authp, - GAsyncResult *res, +set_logging_auth_ready (MMAuthProvider *authp, + GAsyncResult *res, SetLoggingContext *ctx) { GError *error = NULL; @@ -756,7 +754,7 @@ set_logging_auth_ready (MMAuthProvider *authp, else if (!mm_log_set_level (ctx->level, &error)) g_dbus_method_invocation_take_error (ctx->invocation, error); else { - mm_info ("logging: level '%s'", ctx->level); + mm_obj_info (ctx->self, "logging: level '%s'", ctx->level); mm_gdbus_org_freedesktop_modem_manager1_complete_set_logging ( MM_GDBUS_ORG_FREEDESKTOP_MODEM_MANAGER1 (ctx->self), ctx->invocation); @@ -985,9 +983,7 @@ device_inhibited_untrack_port (MMBaseManager *self, port_info = (InhibitedDevicePortInfo *)(l->data); if (mm_kernel_device_cmp (port_info->kernel_port, kernel_port)) { - mm_dbg ("(%s/%s): released while inhibited", - mm_kernel_device_get_subsystem (kernel_port), - mm_kernel_device_get_name (kernel_port)); + mm_obj_dbg (self, "released port %s while inhibited", mm_kernel_device_get_name (kernel_port)); inhibited_device_port_info_free (port_info); info->port_infos = g_list_delete_link (info->port_infos, l); return; @@ -1018,9 +1014,7 @@ device_inhibited_track_port (MMBaseManager *self, } } - mm_dbg ("(%s/%s): added while inhibited", - mm_kernel_device_get_subsystem (kernel_port), - mm_kernel_device_get_name (kernel_port)); + mm_obj_dbg (self, "added port %s while inhibited", mm_kernel_device_get_name (kernel_port)); port_info = g_slice_new0 (InhibitedDevicePortInfo); port_info->kernel_port = g_object_ref (kernel_port); @@ -1085,7 +1079,7 @@ remove_device_inhibition (MMBaseManager *self, /* Uninhibit device, which will create and expose the modem object */ if (!mm_device_uninhibit (device, &error)) { - mm_warn ("Couldn't uninhibit device: %s", error->message); + mm_obj_warn (self, "couldn't uninhibit device: %s", error->message); g_error_free (error); } } @@ -1096,7 +1090,7 @@ inhibit_sender_lost (GDBusConnection *connection, const gchar *sender_name, InhibitSenderLostContext *lost_ctx) { - mm_info ("Device inhibition teardown for uid '%s' (owner disappeared from bus)", lost_ctx->uid); + mm_obj_info (lost_ctx->self, "device inhibition teardown for uid '%s' (owner disappeared from bus)", lost_ctx->uid); remove_device_inhibition (lost_ctx->self, lost_ctx->uid); } @@ -1151,7 +1145,7 @@ device_inhibit_ready (MMDevice *device, g_hash_table_insert (ctx->self->priv->inhibited_devices, g_strdup (ctx->uid), info); - mm_info ("Device inhibition setup for uid '%s'", ctx->uid); + mm_obj_info (ctx->self, "device inhibition setup for uid '%s'", ctx->uid); mm_gdbus_org_freedesktop_modem_manager1_complete_inhibit_device ( MM_GDBUS_ORG_FREEDESKTOP_MODEM_MANAGER1 (ctx->self), @@ -1200,7 +1194,7 @@ base_manager_uninhibit_device (InhibitDeviceContext *ctx) return; } - mm_info ("Device inhibition teardown for uid '%s'", ctx->uid); + mm_obj_info (ctx->self, "device inhibition teardown for uid '%s'", ctx->uid); remove_device_inhibition (ctx->self, ctx->uid); mm_gdbus_org_freedesktop_modem_manager1_complete_inhibit_device ( @@ -1267,7 +1261,7 @@ handle_set_profile (MmGdbusTest *skeleton, gchar *physdev_uid; GError *error = NULL; - mm_info ("Test profile set to: '%s'", id); + mm_obj_info (self, "test profile set to: '%s'", id); /* Create device and keep it listed in the Manager */ physdev_uid = g_strdup_printf ("/virtual/%s", id); @@ -1284,23 +1278,23 @@ handle_set_profile (MmGdbusTest *skeleton, MM_CORE_ERROR_NOT_FOUND, "Requested plugin '%s' not found", plugin_name); - mm_warn ("Couldn't set plugin for virtual device '%s': %s", - mm_device_get_uid (device), - error->message); + mm_obj_warn (self, "couldn't set plugin for virtual device '%s': %s", + mm_device_get_uid (device), + error->message); goto out; } mm_device_set_plugin (device, G_OBJECT (plugin)); /* Create modem */ if (!mm_device_create_modem (device, &error)) { - mm_warn ("Couldn't create modem for virtual device '%s': %s", - mm_device_get_uid (device), - error->message); + mm_obj_warn (self, "couldn't create modem for virtual device '%s': %s", + mm_device_get_uid (device), + error->message); goto out; } - mm_info ("Modem for virtual device '%s' successfully created", - mm_device_get_uid (device)); + mm_obj_info (self, "modem for virtual device '%s' successfully created", + mm_device_get_uid (device)); out: @@ -1317,6 +1311,14 @@ handle_set_profile (MmGdbusTest *skeleton, /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + return g_strdup ("base-manager"); +} + +/*****************************************************************************/ + MMBaseManager * mm_base_manager_new (GDBusConnection *connection, const gchar *plugin_dir, @@ -1342,52 +1344,52 @@ mm_base_manager_new (GDBusConnection *connection, } static void -set_property (GObject *object, - guint prop_id, +set_property (GObject *object, + guint prop_id, const GValue *value, - GParamSpec *pspec) + GParamSpec *pspec) { - MMBaseManagerPrivate *priv = MM_BASE_MANAGER (object)->priv; + MMBaseManager *self = MM_BASE_MANAGER (object); switch (prop_id) { case PROP_CONNECTION: { gboolean had_connection = FALSE; - if (priv->connection) { + if (self->priv->connection) { had_connection = TRUE; - g_object_unref (priv->connection); + g_object_unref (self->priv->connection); } - priv->connection = g_value_dup_object (value); + self->priv->connection = g_value_dup_object (value); /* Propagate connection loss to subobjects */ - if (had_connection && !priv->connection) { - if (priv->object_manager) { - mm_dbg ("Stopping connection in object manager server"); - g_dbus_object_manager_server_set_connection (priv->object_manager, NULL); + if (had_connection && !self->priv->connection) { + if (self->priv->object_manager) { + mm_obj_dbg (self, "stopping connection in object manager server"); + g_dbus_object_manager_server_set_connection (self->priv->object_manager, NULL); } - if (priv->test_skeleton && - g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (priv->test_skeleton))) { - mm_dbg ("Stopping connection in test skeleton"); - g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (priv->test_skeleton)); + if (self->priv->test_skeleton && + g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (self->priv->test_skeleton))) { + mm_obj_dbg (self, "stopping connection in test skeleton"); + g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->priv->test_skeleton)); } } break; } case PROP_AUTO_SCAN: - priv->auto_scan = g_value_get_boolean (value); + self->priv->auto_scan = g_value_get_boolean (value); break; case PROP_FILTER_POLICY: - priv->filter_policy = g_value_get_flags (value); + self->priv->filter_policy = g_value_get_flags (value); break; case PROP_ENABLE_TEST: - priv->enable_test = g_value_get_boolean (value); + self->priv->enable_test = g_value_get_boolean (value); break; case PROP_PLUGIN_DIR: - g_free (priv->plugin_dir); - priv->plugin_dir = g_value_dup_string (value); + g_free (self->priv->plugin_dir); + self->priv->plugin_dir = g_value_dup_string (value); break; case PROP_INITIAL_KERNEL_EVENTS: - g_free (priv->initial_kernel_events); - priv->initial_kernel_events = g_value_dup_string (value); + g_free (self->priv->initial_kernel_events); + self->priv->initial_kernel_events = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1396,31 +1398,31 @@ set_property (GObject *object, } static void -get_property (GObject *object, - guint prop_id, - GValue *value, +get_property (GObject *object, + guint prop_id, + GValue *value, GParamSpec *pspec) { - MMBaseManagerPrivate *priv = MM_BASE_MANAGER (object)->priv; + MMBaseManager *self = MM_BASE_MANAGER (object); switch (prop_id) { case PROP_CONNECTION: - g_value_set_object (value, priv->connection); + g_value_set_object (value, self->priv->connection); break; case PROP_AUTO_SCAN: - g_value_set_boolean (value, priv->auto_scan); + g_value_set_boolean (value, self->priv->auto_scan); break; case PROP_FILTER_POLICY: - g_value_set_flags (value, priv->filter_policy); + g_value_set_flags (value, self->priv->filter_policy); break; case PROP_ENABLE_TEST: - g_value_set_boolean (value, priv->enable_test); + g_value_set_boolean (value, self->priv->enable_test); break; case PROP_PLUGIN_DIR: - g_value_set_string (value, priv->plugin_dir); + g_value_set_string (value, self->priv->plugin_dir); break; case PROP_INITIAL_KERNEL_EVENTS: - g_value_set_string (value, priv->initial_kernel_events); + g_value_set_string (value, self->priv->initial_kernel_events); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1429,45 +1431,41 @@ get_property (GObject *object, } static void -mm_base_manager_init (MMBaseManager *manager) +mm_base_manager_init (MMBaseManager *self) { - MMBaseManagerPrivate *priv; - /* Setup private data */ - manager->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, - MM_TYPE_BASE_MANAGER, - MMBaseManagerPrivate); + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_BASE_MANAGER, MMBaseManagerPrivate); /* Setup authorization provider */ - priv->authp = mm_auth_provider_get (); - priv->authp_cancellable = g_cancellable_new (); + self->priv->authp = mm_auth_provider_get (); + self->priv->authp_cancellable = g_cancellable_new (); /* Setup internal lists of device objects */ - priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); + self->priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); /* Setup internal list of inhibited devices */ - priv->inhibited_devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)inhibited_device_info_free); + self->priv->inhibited_devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)inhibited_device_info_free); #if defined WITH_UDEV { const gchar *subsys[5] = { "tty", "net", "usb", "usbmisc", NULL }; /* Setup UDev client */ - priv->udev = g_udev_client_new (subsys); + self->priv->udev = g_udev_client_new (subsys); } #endif /* By default, enable autoscan */ - priv->auto_scan = TRUE; + self->priv->auto_scan = TRUE; /* By default, no test interface */ - priv->enable_test = FALSE; + self->priv->enable_test = FALSE; /* Setup Object Manager Server */ - priv->object_manager = g_dbus_object_manager_server_new (MM_DBUS_PATH); + self->priv->object_manager = g_dbus_object_manager_server_new (MM_DBUS_PATH); /* Enable processing of input DBus messages */ - g_object_connect (manager, + g_object_connect (self, "signal::handle-set-logging", G_CALLBACK (handle_set_logging), NULL, "signal::handle-scan-devices", G_CALLBACK (handle_scan_devices), NULL, "signal::handle-report-kernel-event", G_CALLBACK (handle_report_kernel_event), NULL, @@ -1476,48 +1474,48 @@ mm_base_manager_init (MMBaseManager *manager) } static gboolean -initable_init (GInitable *initable, - GCancellable *cancellable, - GError **error) +initable_init (GInitable *initable, + GCancellable *cancellable, + GError **error) { - MMBaseManagerPrivate *priv = MM_BASE_MANAGER (initable)->priv; + MMBaseManager *self = MM_BASE_MANAGER (initable); #if defined WITH_UDEV /* If autoscan enabled, list for udev events */ - if (priv->auto_scan) - g_signal_connect (priv->udev, "uevent", G_CALLBACK (handle_uevent), initable); + if (self->priv->auto_scan) + g_signal_connect (self->priv->udev, "uevent", G_CALLBACK (handle_uevent), initable); #endif /* Create filter */ - priv->filter = mm_filter_new (priv->filter_policy, error); - if (!priv->filter) + self->priv->filter = mm_filter_new (self->priv->filter_policy, error); + if (!self->priv->filter) return FALSE; /* Create plugin manager */ - priv->plugin_manager = mm_plugin_manager_new (priv->plugin_dir, priv->filter, error); - if (!priv->plugin_manager) + self->priv->plugin_manager = mm_plugin_manager_new (self->priv->plugin_dir, self->priv->filter, error); + if (!self->priv->plugin_manager) return FALSE; /* Export the manager interface */ if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (initable), - priv->connection, + self->priv->connection, MM_DBUS_PATH, error)) return FALSE; /* Export the Object Manager interface */ - g_dbus_object_manager_server_set_connection (priv->object_manager, - priv->connection); + g_dbus_object_manager_server_set_connection (self->priv->object_manager, + self->priv->connection); /* Setup the Test skeleton and export the interface */ - if (priv->enable_test) { - priv->test_skeleton = mm_gdbus_test_skeleton_new (); - g_signal_connect (priv->test_skeleton, + if (self->priv->enable_test) { + self->priv->test_skeleton = mm_gdbus_test_skeleton_new (); + g_signal_connect (self->priv->test_skeleton, "handle-set-profile", G_CALLBACK (handle_set_profile), initable); - if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->test_skeleton), - priv->connection, + if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->priv->test_skeleton), + self->priv->connection, MM_DBUS_PATH, error)) return FALSE; @@ -1530,38 +1528,38 @@ initable_init (GInitable *initable, static void finalize (GObject *object) { - MMBaseManagerPrivate *priv = MM_BASE_MANAGER (object)->priv; + MMBaseManager *self = MM_BASE_MANAGER (object); - g_free (priv->initial_kernel_events); - g_free (priv->plugin_dir); + g_free (self->priv->initial_kernel_events); + g_free (self->priv->plugin_dir); - g_hash_table_destroy (priv->inhibited_devices); - g_hash_table_destroy (priv->devices); + g_hash_table_destroy (self->priv->inhibited_devices); + g_hash_table_destroy (self->priv->devices); #if defined WITH_UDEV - if (priv->udev) - g_object_unref (priv->udev); + if (self->priv->udev) + g_object_unref (self->priv->udev); #endif - if (priv->filter) - g_object_unref (priv->filter); + if (self->priv->filter) + g_object_unref (self->priv->filter); - if (priv->plugin_manager) - g_object_unref (priv->plugin_manager); + if (self->priv->plugin_manager) + g_object_unref (self->priv->plugin_manager); - if (priv->object_manager) - g_object_unref (priv->object_manager); + if (self->priv->object_manager) + g_object_unref (self->priv->object_manager); - if (priv->test_skeleton) - g_object_unref (priv->test_skeleton); + if (self->priv->test_skeleton) + g_object_unref (self->priv->test_skeleton); - if (priv->connection) - g_object_unref (priv->connection); + if (self->priv->connection) + g_object_unref (self->priv->connection); /* note: authp is a singleton, we don't keep a full reference */ - if (priv->authp_cancellable) - g_object_unref (priv->authp_cancellable); + if (self->priv->authp_cancellable) + g_object_unref (self->priv->authp_cancellable); G_OBJECT_CLASS (mm_base_manager_parent_class)->finalize (object); } @@ -1572,6 +1570,12 @@ initable_iface_init (GInitableIface *iface) iface->init = initable_init; } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_base_manager_class_init (MMBaseManagerClass *manager_class) { From 84e3ea63b9fe3d15862ab79ad401474330c28454 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 18:44:47 +0200 Subject: [PATCH 065/675] base-call: set dbus id as soon as object is created --- src/mm-base-call.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mm-base-call.c b/src/mm-base-call.c index 6966e94a..56cd97f9 100644 --- a/src/mm-base-call.c +++ b/src/mm-base-call.c @@ -54,6 +54,8 @@ static GParamSpec *properties[PROP_LAST]; struct _MMBaseCallPrivate { /* The connection to the system bus */ GDBusConnection *connection; + guint dbus_id; + /* The modem which owns this call */ MMBaseModem *modem; /* The path where the call object is exported */ @@ -856,10 +858,9 @@ handle_send_dtmf (MMBaseCall *self, void mm_base_call_export (MMBaseCall *self) { - static guint id = 0; gchar *path; - path = g_strdup_printf (MM_DBUS_CALL_PREFIX "/%d", id++); + path = g_strdup_printf (MM_DBUS_CALL_PREFIX "/%d", self->priv->dbus_id); g_object_set (self, MM_BASE_CALL_PATH, path, NULL); @@ -1439,8 +1440,13 @@ get_property (GObject *object, static void mm_base_call_init (MMBaseCall *self) { + static guint id = 0; + /* Initialize private data */ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_BASE_CALL, MMBaseCallPrivate); + + /* Each call is given a unique id to build its own DBus path */ + self->priv->dbus_id = id++; } static void From 661e3c91ccf8834d2df250df1cc84f9818aefe67 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 18:45:56 +0200 Subject: [PATCH 066/675] base-call: port to use object logging --- src/mm-base-call.c | 71 ++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/src/mm-base-call.c b/src/mm-base-call.c index 56cd97f9..792c6adb 100644 --- a/src/mm-base-call.c +++ b/src/mm-base-call.c @@ -32,11 +32,14 @@ #include "mm-iface-modem-voice.h" #include "mm-base-modem-at.h" #include "mm-base-modem.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-error-helpers.h" -G_DEFINE_TYPE (MMBaseCall, mm_base_call, MM_GDBUS_TYPE_CALL_SKELETON) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMBaseCall, mm_base_call, MM_GDBUS_TYPE_CALL_SKELETON, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -94,7 +97,7 @@ static gboolean incoming_timeout_cb (MMBaseCall *self) { self->priv->incoming_timeout = 0; - mm_info ("incoming call timed out: no response"); + mm_obj_info (self, "incoming call timed out: no response"); mm_base_call_change_state (self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_TERMINATED); return G_SOURCE_REMOVE; } @@ -159,7 +162,7 @@ handle_start_ready (MMBaseCall *self, g_clear_object (&ctx->self->priv->start_cancellable); if (!MM_BASE_CALL_GET_CLASS (self)->start_finish (self, res, &error)) { - mm_warn ("Couldn't start call : '%s'", error->message); + mm_obj_warn (self, "couldn't start call: %s", error->message); /* When cancelled via the start cancellable, it's because we got an early in-call error * before the call attempt was reported as started. */ @@ -184,7 +187,7 @@ handle_start_ready (MMBaseCall *self, return; } - mm_info ("call is started"); + mm_obj_info (self, "call is started"); /* If dialing to ringing supported, leave it dialing */ if (!ctx->self->priv->supports_dialing_to_ringing) { @@ -226,7 +229,7 @@ handle_start_auth_ready (MMBaseModem *modem, return; } - mm_info ("user request to start call"); + mm_obj_info (ctx->self, "user request to start call"); /* Disallow non-emergency calls when in emergency-only state */ if (!mm_iface_modem_voice_authorize_outgoing_call (MM_IFACE_MODEM_VOICE (modem), ctx->self, &error)) { @@ -313,7 +316,7 @@ handle_accept_ready (MMBaseCall *self, return; } - mm_info ("call is accepted"); + mm_obj_info (self, "call is accepted"); if (ctx->self->priv->incoming_timeout) { g_source_remove (ctx->self->priv->incoming_timeout); @@ -350,7 +353,7 @@ handle_accept_auth_ready (MMBaseModem *modem, return; } - mm_info ("user request to accept call"); + mm_obj_info (ctx->self, "user request to accept call"); /* Check if we do support doing it */ if (!MM_BASE_CALL_GET_CLASS (ctx->self)->accept || @@ -423,7 +426,7 @@ handle_deflect_ready (MMBaseCall *self, return; } - mm_info ("call is deflected to '%s'", ctx->number); + mm_obj_info (self, "call is deflected to '%s'", ctx->number); mm_base_call_change_state (ctx->self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_DEFLECTED); mm_gdbus_call_complete_deflect (MM_GDBUS_CALL (ctx->self), ctx->invocation); handle_deflect_context_free (ctx); @@ -455,7 +458,7 @@ handle_deflect_auth_ready (MMBaseModem *modem, return; } - mm_info ("user request to deflect call"); + mm_obj_info (ctx->self, "user request to deflect call"); /* Check if we do support doing it */ if (!MM_BASE_CALL_GET_CLASS (ctx->self)->deflect || @@ -712,7 +715,7 @@ handle_hangup_auth_ready (MMBaseModem *modem, return; } - mm_info ("user request to hangup call"); + mm_obj_info (ctx->self, "user request to hangup call"); /* Check if we do support doing it */ if (!MM_BASE_CALL_GET_CLASS (ctx->self)->hangup || @@ -897,9 +900,7 @@ call_dbus_export (MMBaseCall *self) self->priv->connection, self->priv->path, &error)) { - mm_warn ("couldn't export call at '%s': '%s'", - self->priv->path, - error->message); + mm_obj_warn (self, "couldn't export call: %s", error->message); g_error_free (error); } } @@ -990,10 +991,10 @@ mm_base_call_change_state (MMBaseCall *self, if (old_state == new_state) return; - mm_info ("Call state changed: %s -> %s (%s)", - mm_call_state_get_string (old_state), - mm_call_state_get_string (new_state), - mm_call_state_reason_get_string (reason)); + mm_obj_info (self, "call state changed: %s -> %s (%s)", + mm_call_state_get_string (old_state), + mm_call_state_get_string (new_state), + mm_call_state_reason_get_string (reason)); /* Setup/cleanup unsolicited events based on state transitions to/from ACTIVE */ if (new_state == MM_CALL_STATE_TERMINATED) { @@ -1236,8 +1237,8 @@ chld_hangup_ready (MMBaseModem *modem, mm_base_modem_at_command_finish (modem, res, &error); if (error) { - mm_warn ("couldn't hangup single call with call id '%u': %s", - self->priv->index, error->message); + mm_obj_warn (self, "couldn't hangup single call with call id '%u': %s", + self->priv->index, error->message); g_error_free (error); chup_fallback (task); return; @@ -1287,15 +1288,18 @@ call_send_dtmf_finish (MMBaseCall *self, } static void -call_send_dtmf_ready (MMBaseModem *modem, +call_send_dtmf_ready (MMBaseModem *modem, GAsyncResult *res, - GTask *task) + GTask *task) { - GError *error = NULL; + MMBaseCall *self; + GError *error = NULL; + + self = g_task_get_source_object (task); mm_base_modem_at_command_finish (modem, res, &error); if (error) { - mm_dbg ("Couldn't send_dtmf: '%s'", error->message); + mm_obj_dbg (self, "couldn't send dtmf: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -1329,6 +1333,17 @@ call_send_dtmf (MMBaseCall *self, /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMBaseCall *self; + + self = MM_BASE_CALL (_self); + return g_strdup_printf ("call%u", self->priv->dbus_id); +} + +/*****************************************************************************/ + MMBaseCall * mm_base_call_new (MMBaseModem *modem, MMCallDirection direction, @@ -1382,6 +1397,8 @@ set_property (GObject *object, g_clear_object (&self->priv->modem); self->priv->modem = g_value_dup_object (value); if (self->priv->modem) { + /* Set owner ID */ + mm_log_object_set_owner_id (MM_LOG_OBJECT (self), mm_log_object_get_id (MM_LOG_OBJECT (self->priv->modem))); /* Bind the modem's connection (which is set when it is exported, * and unset when unexported) to the call's connection */ g_object_bind_property (self->priv->modem, MM_BASE_MODEM_CONNECTION, @@ -1484,6 +1501,12 @@ dispose (GObject *object) G_OBJECT_CLASS (mm_base_call_parent_class)->dispose (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_base_call_class_init (MMBaseCallClass *klass) { From dea6677df0eea55ac498f7c64011827035bfec25 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 18:51:37 +0200 Subject: [PATCH 067/675] bearer-list: no logging in object --- src/mm-bearer-list.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/mm-bearer-list.c b/src/mm-bearer-list.c index 4ae446b5..504b99ae 100644 --- a/src/mm-bearer-list.c +++ b/src/mm-bearer-list.c @@ -268,10 +268,6 @@ MMBearerList * mm_bearer_list_new (guint max_bearers, guint max_active_bearers) { - mm_dbg ("Creating bearer list (max: %u, max active: %u)", - max_bearers, - max_active_bearers); - /* Create the object */ return g_object_new (MM_TYPE_BEARER_LIST, MM_BEARER_LIST_MAX_BEARERS, max_bearers, From 0e00f04fd8d8b6452c6379193b2023f2ea340160 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 18:54:45 +0200 Subject: [PATCH 068/675] sms-list: port to use object logging --- src/mm-sms-list.c | 62 +++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/src/mm-sms-list.c b/src/mm-sms-list.c index ec3adca5..1a832216 100644 --- a/src/mm-sms-list.c +++ b/src/mm-sms-list.c @@ -27,9 +27,12 @@ #include "mm-iface-modem-messaging.h" #include "mm-sms-list.h" #include "mm-base-sms.h" -#include "mm-log.h" +#include "mm-log-object.h" -G_DEFINE_TYPE (MMSmsList, mm_sms_list, G_TYPE_OBJECT); +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMSmsList, mm_sms_list, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -280,8 +283,7 @@ take_multipart (MMSmsList *self, (GCompareFunc)cmp_sms_by_concat_reference); if (l) { /* Try to take the part */ - mm_dbg ("Found existing multipart SMS object with reference '%u': adding new part", - concat_reference); + mm_obj_dbg (self, "found existing multipart SMS object with reference '%u': adding new part", concat_reference); return mm_base_sms_multipart_take_part (MM_BASE_SMS (l->data), part, error); } @@ -296,9 +298,9 @@ take_multipart (MMSmsList *self, if (!sms) return FALSE; - mm_dbg ("Creating new multipart SMS object: need to receive %u parts with reference '%u'", - mm_sms_part_get_concat_max (part), - concat_reference); + mm_obj_dbg (self, "creating new multipart SMS object: need to receive %u parts with reference '%u'", + mm_sms_part_get_concat_max (part), + concat_reference); self->priv->list = g_list_prepend (self->priv->list, sms); g_signal_emit (self, signals[SIGNAL_ADDED], 0, mm_base_sms_get_path (sms), @@ -349,33 +351,41 @@ mm_sms_list_take_part (MMSmsList *self, /* Did we just get a part of a multi-part SMS? */ if (mm_sms_part_should_concat (part)) { if (mm_sms_part_get_index (part) != SMS_PART_INVALID_INDEX) - mm_dbg ("SMS part at '%s/%u' is from a multipart SMS (reference: '%u', sequence: '%u/%u')", - mm_sms_storage_get_string (storage), - mm_sms_part_get_index (part), - mm_sms_part_get_concat_reference (part), - mm_sms_part_get_concat_sequence (part), - mm_sms_part_get_concat_max (part)); + mm_obj_dbg (self, "SMS part at '%s/%u' is from a multipart SMS (reference: '%u', sequence: '%u/%u')", + mm_sms_storage_get_string (storage), + mm_sms_part_get_index (part), + mm_sms_part_get_concat_reference (part), + mm_sms_part_get_concat_sequence (part), + mm_sms_part_get_concat_max (part)); else - mm_dbg ("SMS part (not stored) is from a multipart SMS (reference: '%u', sequence: '%u/%u')", - mm_sms_part_get_concat_reference (part), - mm_sms_part_get_concat_sequence (part), - mm_sms_part_get_concat_max (part)); + mm_obj_dbg (self, "SMS part (not stored) is from a multipart SMS (reference: '%u', sequence: '%u/%u')", + mm_sms_part_get_concat_reference (part), + mm_sms_part_get_concat_sequence (part), + mm_sms_part_get_concat_max (part)); return take_multipart (self, part, state, storage, error); } /* Otherwise, we build a whole new single-part MMSms just from this part */ if (mm_sms_part_get_index (part) != SMS_PART_INVALID_INDEX) - mm_dbg ("SMS part at '%s/%u' is from a singlepart SMS", - mm_sms_storage_get_string (storage), - mm_sms_part_get_index (part)); + mm_obj_dbg (self, "SMS part at '%s/%u' is from a singlepart SMS", + mm_sms_storage_get_string (storage), + mm_sms_part_get_index (part)); else - mm_dbg ("SMS part (not stored) is from a singlepart SMS"); + mm_obj_dbg (self, "SMS part (not stored) is from a singlepart SMS"); return take_singlepart (self, part, state, storage, error); } /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + return g_strdup ("sms-list"); +} + +/*****************************************************************************/ + MMSmsList * mm_sms_list_new (MMBaseModem *modem) { @@ -397,6 +407,10 @@ set_property (GObject *object, case PROP_MODEM: g_clear_object (&self->priv->modem); self->priv->modem = g_value_dup_object (value); + if (self->priv->modem) { + /* Set owner ID */ + mm_log_object_set_owner_id (MM_LOG_OBJECT (self), mm_log_object_get_id (MM_LOG_OBJECT (self->priv->modem))); + } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -443,6 +457,12 @@ dispose (GObject *object) G_OBJECT_CLASS (mm_sms_list_parent_class)->dispose (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_sms_list_class_init (MMSmsListClass *klass) { From 2b1201af3cba7f2dc11835a6ad088eddd0e37e61 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 19:01:21 +0200 Subject: [PATCH 069/675] device: port to use object logging --- src/mm-device.c | 71 +++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/src/mm-device.c b/src/mm-device.c index f3b0726d..a128d63e 100644 --- a/src/mm-device.c +++ b/src/mm-device.c @@ -25,9 +25,12 @@ #include "mm-device.h" #include "mm-plugin.h" -#include "mm-log.h" +#include "mm-log-object.h" -G_DEFINE_TYPE (MMDevice, mm_device, G_TYPE_OBJECT) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMDevice, mm_device, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -215,10 +218,8 @@ mm_device_ignore_port (MMDevice *self, probe = device_find_probe_with_device (self, kernel_port, FALSE); if (probe) { /* Found, remove from list and add to the ignored list */ - mm_dbg ("[device %s] fully ignoring port '%s/%s' from now on", - self->priv->uid, - mm_kernel_device_get_subsystem (kernel_port), - mm_kernel_device_get_name (kernel_port)); + mm_obj_dbg (self, "fully ignoring port %s from now on", + mm_kernel_device_get_name (kernel_port)); self->priv->port_probes = g_list_remove (self->priv->port_probes, probe); self->priv->ignored_port_probes = g_list_prepend (self->priv->ignored_port_probes, probe); } @@ -240,7 +241,7 @@ unexport_modem (MMDevice *self) g_object_set (self->priv->modem, MM_BASE_MODEM_CONNECTION, NULL, NULL); - mm_dbg ("[device %s] unexported modem from path '%s'", self->priv->uid, path); + mm_obj_dbg (self, "unexported modem from path '%s'", path); g_free (path); } } @@ -258,7 +259,7 @@ export_modem (MMDevice *self) /* If modem not yet valid (not fully initialized), don't export it */ if (!mm_base_modem_get_valid (self->priv->modem)) { - mm_dbg ("[device %s] modem not yet fully initialized", self->priv->uid); + mm_obj_dbg (self, "modem not yet fully initialized"); return; } @@ -268,7 +269,7 @@ export_modem (MMDevice *self) NULL); if (path) { g_free (path); - mm_dbg ("[device %s] modem already exported", self->priv->uid); + mm_obj_dbg (self, "modem already exported"); return; } @@ -287,14 +288,13 @@ export_modem (MMDevice *self) g_dbus_object_manager_server_export (self->priv->object_manager, G_DBUS_OBJECT_SKELETON (self->priv->modem)); - mm_dbg ("[device %s] exported modem at path '%s'", self->priv->uid, path); - mm_dbg ("[device %s] plugin: %s", self->priv->uid, mm_base_modem_get_plugin (self->priv->modem)); - mm_dbg ("[device %s] vid:pid: 0x%04X:0x%04X", - self->priv->uid, - (mm_base_modem_get_vendor_id (self->priv->modem) & 0xFFFF), - (mm_base_modem_get_product_id (self->priv->modem) & 0xFFFF)); + mm_obj_dbg (self, " exported modem at path '%s'", path); + mm_obj_dbg (self, " plugin: %s", mm_base_modem_get_plugin (self->priv->modem)); + mm_obj_dbg (self, " vid:pid: 0x%04X:0x%04X", + (mm_base_modem_get_vendor_id (self->priv->modem) & 0xFFFF), + (mm_base_modem_get_product_id (self->priv->modem) & 0xFFFF)); if (self->priv->virtual) - mm_dbg ("[device %s] virtual", self->priv->uid); + mm_obj_dbg (self, " virtual"); g_free (path); } @@ -337,12 +337,10 @@ reprobe (MMDevice *self) GError *error = NULL; if (!mm_device_create_modem (self, &error)) { - mm_warn ("Could not recreate modem for device '%s': %s", - self->priv->uid, - error ? error->message : "unknown"); + mm_obj_warn (self, "could not recreate modem: %s", error->message); g_error_free (error); } else - mm_dbg ("Modem recreated for device '%s'", self->priv->uid); + mm_obj_dbg (self, "modem recreated"); return G_SOURCE_REMOVE; } @@ -365,7 +363,7 @@ modem_valid (MMBaseModem *modem, if (self->priv->modem) export_modem (self); else - mm_dbg ("[device %s] not exporting modem; no longer available", self->priv->uid); + mm_obj_dbg (self, "not exporting modem; no longer available"); } } @@ -390,10 +388,9 @@ mm_device_create_modem (MMDevice *self, return FALSE; } - mm_info ("[device %s] creating modem with plugin '%s' and '%u' ports", - self->priv->uid, - mm_plugin_get_name (self->priv->plugin), - g_list_length (self->priv->port_probes)); + mm_obj_info (self, "creating modem with plugin '%s' and '%u' ports", + mm_plugin_get_name (self->priv->plugin), + g_list_length (self->priv->port_probes)); } else { if (!self->priv->virtual_ports) { g_set_error (error, @@ -403,10 +400,9 @@ mm_device_create_modem (MMDevice *self, return FALSE; } - mm_info ("[device %s] creating virtual modem with plugin '%s' and '%u' ports", - self->priv->uid, - mm_plugin_get_name (self->priv->plugin), - g_strv_length (self->priv->virtual_ports)); + mm_obj_info (self, "creating virtual modem with plugin '%s' and '%u' ports", + mm_plugin_get_name (self->priv->plugin), + g_strv_length (self->priv->virtual_ports)); } self->priv->modem = mm_plugin_create_modem (self->priv->plugin, self, error); @@ -639,6 +635,17 @@ mm_device_is_virtual (MMDevice *self) /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMDevice *self; + + self = MM_DEVICE (_self); + return g_strdup_printf ("device %s", self->priv->uid); +} + +/*****************************************************************************/ + MMDevice * mm_device_new (const gchar *uid, gboolean hotplugged, @@ -771,6 +778,12 @@ finalize (GObject *object) G_OBJECT_CLASS (mm_device_parent_class)->finalize (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_device_class_init (MMDeviceClass *klass) { From afe7a8e2363eaa57102d3dd4b5ae865e8d3311cc Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 19:12:53 +0200 Subject: [PATCH 070/675] port-probe: port to use object logging --- src/mm-port-probe.c | 177 ++++++++++++++++---------------------------- 1 file changed, 62 insertions(+), 115 deletions(-) diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c index 1700111f..0c1edef1 100644 --- a/src/mm-port-probe.c +++ b/src/mm-port-probe.c @@ -27,7 +27,7 @@ #include #include "mm-port-probe.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-port-serial-at.h" #include "mm-port-serial.h" #include "mm-serial-parsers.h" @@ -63,7 +63,10 @@ * |----> MBIM capabilities check */ -G_DEFINE_TYPE (MMPortProbe, mm_port_probe, G_TYPE_OBJECT) +static void log_object_iface_init (MMLogObjectInterface *iface); + +G_DEFINE_TYPE_EXTENDED (MMPortProbe, mm_port_probe, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_LOG_OBJECT, log_object_iface_init)) enum { PROP_0, @@ -159,9 +162,7 @@ mm_port_probe_set_result_at (MMPortProbe *self, self->priv->flags |= MM_PORT_PROBE_AT; if (self->priv->is_at) { - mm_dbg ("(%s/%s) port is AT-capable", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port is AT-capable"); /* Also set as not a QCDM/QMI/MBIM port */ self->priv->is_qcdm = FALSE; @@ -169,9 +170,7 @@ mm_port_probe_set_result_at (MMPortProbe *self, self->priv->is_mbim = FALSE; self->priv->flags |= (MM_PORT_PROBE_QCDM | MM_PORT_PROBE_QMI | MM_PORT_PROBE_MBIM); } else { - mm_dbg ("(%s/%s) port is not AT-capable", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port is not AT-capable"); self->priv->vendor = NULL; self->priv->product = NULL; self->priv->is_icera = FALSE; @@ -188,15 +187,11 @@ mm_port_probe_set_result_at_vendor (MMPortProbe *self, const gchar *at_vendor) { if (at_vendor) { - mm_dbg ("(%s/%s) vendor probing finished", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "vendor probing finished"); self->priv->vendor = g_utf8_casefold (at_vendor, -1); self->priv->flags |= MM_PORT_PROBE_AT_VENDOR; } else { - mm_dbg ("(%s/%s) couldn't probe for vendor string", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "couldn't probe for vendor string"); self->priv->vendor = NULL; self->priv->product = NULL; self->priv->flags |= (MM_PORT_PROBE_AT_VENDOR | MM_PORT_PROBE_AT_PRODUCT); @@ -208,15 +203,11 @@ mm_port_probe_set_result_at_product (MMPortProbe *self, const gchar *at_product) { if (at_product) { - mm_dbg ("(%s/%s) product probing finished", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "product probing finished"); self->priv->product = g_utf8_casefold (at_product, -1); self->priv->flags |= MM_PORT_PROBE_AT_PRODUCT; } else { - mm_dbg ("(%s/%s) couldn't probe for product string", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "couldn't probe for product string"); self->priv->product = NULL; self->priv->flags |= MM_PORT_PROBE_AT_PRODUCT; } @@ -227,15 +218,11 @@ mm_port_probe_set_result_at_icera (MMPortProbe *self, gboolean is_icera) { if (is_icera) { - mm_dbg ("(%s/%s) Modem is Icera-based", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "modem is Icera-based"); self->priv->is_icera = TRUE; self->priv->flags |= MM_PORT_PROBE_AT_ICERA; } else { - mm_dbg ("(%s/%s) Modem is probably not Icera-based", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "modem is probably not Icera-based"); self->priv->is_icera = FALSE; self->priv->flags |= MM_PORT_PROBE_AT_ICERA; } @@ -246,15 +233,11 @@ mm_port_probe_set_result_at_xmm (MMPortProbe *self, gboolean is_xmm) { if (is_xmm) { - mm_dbg ("(%s/%s) Modem is XMM-based", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "modem is XMM-based"); self->priv->is_xmm = TRUE; self->priv->flags |= MM_PORT_PROBE_AT_XMM; } else { - mm_dbg ("(%s/%s) Modem is probably not XMM-based", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "modem is probably not XMM-based"); self->priv->is_xmm = FALSE; self->priv->flags |= MM_PORT_PROBE_AT_XMM; } @@ -268,9 +251,7 @@ mm_port_probe_set_result_qcdm (MMPortProbe *self, self->priv->flags |= MM_PORT_PROBE_QCDM; if (self->priv->is_qcdm) { - mm_dbg ("(%s/%s) port is QCDM-capable", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port is QCDM-capable"); /* Also set as not an AT/QMI/MBIM port */ self->priv->is_at = FALSE; @@ -288,9 +269,7 @@ mm_port_probe_set_result_qcdm (MMPortProbe *self, MM_PORT_PROBE_QMI | MM_PORT_PROBE_MBIM); } else - mm_dbg ("(%s/%s) port is not QCDM-capable", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port is not QCDM-capable"); } void @@ -301,9 +280,7 @@ mm_port_probe_set_result_qmi (MMPortProbe *self, self->priv->flags |= MM_PORT_PROBE_QMI; if (self->priv->is_qmi) { - mm_dbg ("(%s/%s) port is QMI-capable", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port is QMI-capable"); /* Also set as not an AT/QCDM/MBIM port */ self->priv->is_at = FALSE; @@ -319,9 +296,7 @@ mm_port_probe_set_result_qmi (MMPortProbe *self, MM_PORT_PROBE_QCDM | MM_PORT_PROBE_MBIM); } else - mm_dbg ("(%s/%s) port is not QMI-capable", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port is not QMI-capable"); } void @@ -332,9 +307,7 @@ mm_port_probe_set_result_mbim (MMPortProbe *self, self->priv->flags |= MM_PORT_PROBE_MBIM; if (self->priv->is_mbim) { - mm_dbg ("(%s/%s) port is MBIM-capable", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port is MBIM-capable"); /* Also set as not an AT/QCDM/QMI port */ self->priv->is_at = FALSE; @@ -350,9 +323,7 @@ mm_port_probe_set_result_mbim (MMPortProbe *self, MM_PORT_PROBE_QCDM | MM_PORT_PROBE_QMI); } else - mm_dbg ("(%s/%s) port is not MBIM-capable", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port is not MBIM-capable"); } /*****************************************************************************/ @@ -494,10 +465,8 @@ port_qmi_open_ready (MMPortQmi *port_qmi, is_qmi = mm_port_qmi_open_finish (port_qmi, res, &error); if (!is_qmi) { - mm_dbg ("(%s/%s) error checking QMI support: '%s'", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port), - error ? error->message : "unknown error"); + mm_obj_dbg (self, "error checking QMI support: %s", + error ? error->message : "unknown error"); g_clear_error (&error); } @@ -520,9 +489,7 @@ wdm_probe_qmi (MMPortProbe *self) ctx = g_task_get_task_data (self->priv->task); #if defined WITH_QMI - mm_dbg ("(%s/%s) probing QMI...", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "probing QMI..."); /* Create a port and try to open it */ ctx->port_qmi = mm_port_qmi_new (mm_kernel_device_get_name (self->priv->port)); @@ -570,10 +537,8 @@ mbim_port_open_ready (MMPortMbim *mbim_port, is_mbim = mm_port_mbim_open_finish (mbim_port, res, &error); if (!is_mbim) { - mm_dbg ("(%s/%s) error checking MBIM support: '%s'", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port), - error ? error->message : "unknown error"); + mm_obj_dbg (self, "error checking MBIM support: %s", + error ? error->message : "unknown error"); g_clear_error (&error); } @@ -596,9 +561,7 @@ wdm_probe_mbim (MMPortProbe *self) ctx = g_task_get_task_data (self->priv->task); #if defined WITH_MBIM - mm_dbg ("(%s/%s) probing MBIM...", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "probing MBIM..."); /* Create a port and try to open it */ ctx->mbim_port = mm_port_mbim_new (mm_kernel_device_get_name (self->priv->port)); @@ -668,10 +631,7 @@ common_serial_port_setup (MMPortProbe *self, flow_control = mm_flow_control_from_string (flow_control_tag, &error); if (flow_control == MM_FLOW_CONTROL_UNKNOWN) { - mm_warn ("(%s/%s) Unsupported flow control settings in port: %s", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port), - error->message); + mm_obj_warn (self, "unsupported flow control settings in port: %s", error->message); g_error_free (error); } else { g_object_set (serial, @@ -708,10 +668,7 @@ serial_probe_qcdm_parse_response (MMPortSerialQcdm *port, /* Parse the response */ result = qcdm_cmd_version_info_result ((const gchar *) response->data, response->len, &err); if (!result) { - mm_warn ("(%s/%s) failed to parse QCDM version info command result: %d", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port), - err); + mm_obj_warn (self, "failed to parse QCDM version info command result: %d", err); retry = TRUE; } else { /* yay, probably a QCDM port */ @@ -721,11 +678,11 @@ serial_probe_qcdm_parse_response (MMPortSerialQcdm *port, g_byte_array_unref (response); } else if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_PARSE_FAILED)) { /* Failed to unescape QCDM packet: don't retry */ - mm_dbg ("QCDM parsing error: %s", error->message); + mm_obj_dbg (self, "QCDM parsing error: %s", error->message); g_error_free (error); } else { if (!g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) - mm_dbg ("QCDM probe error: (%d) %s", error->code, error->message); + mm_obj_dbg (self, "QCDM probe error: (%d) %s", error->code, error->message); g_error_free (error); retry = TRUE; } @@ -772,9 +729,7 @@ serial_probe_qcdm (MMPortProbe *self) if (port_probe_task_return_error_if_cancelled (self)) return G_SOURCE_REMOVE; - mm_dbg ("(%s/%s) probing QCDM...", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "probing QCDM..."); /* If open, close the AT port */ if (ctx->serial) { @@ -1003,9 +958,7 @@ serial_probe_at_parse_response (MMPortSerialAt *port, /* If AT probing cancelled, end this partial probing */ if (g_cancellable_is_cancelled (ctx->at_probing_cancellable)) { - mm_dbg ("(%s/%s) no need to keep on probing the port for AT support", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "no need to keep on probing the port for AT support"); ctx->at_result_processor (self, NULL); serial_probe_schedule (self); return; @@ -1046,10 +999,8 @@ serial_probe_at_parse_response (MMPortSerialAt *port, if (ctx->at_commands_wait_secs == 0) ctx->source_id = g_idle_add ((GSourceFunc) serial_probe_at, self); else { - mm_dbg ("(%s/%s) re-scheduling next command in probing group in %u seconds...", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port), - ctx->at_commands_wait_secs); + mm_obj_dbg (self, "re-scheduling next command in probing group in %u seconds...", + ctx->at_commands_wait_secs); ctx->source_id = g_timeout_add_seconds (ctx->at_commands_wait_secs, (GSourceFunc) serial_probe_at, self); } goto out; @@ -1083,9 +1034,7 @@ serial_probe_at (MMPortProbe *self) /* If AT probing cancelled, end this partial probing */ if (g_cancellable_is_cancelled (ctx->at_probing_cancellable)) { - mm_dbg ("(%s/%s) no need to launch probing for AT support", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "no need to launch probing for AT support"); ctx->at_result_processor (self, NULL); serial_probe_schedule (self); return G_SOURCE_REMOVE; @@ -1275,9 +1224,7 @@ serial_buffer_full (MMPortSerial *serial, g_assert (self->priv->task); ctx = g_task_get_task_data (self->priv->task); - mm_dbg ("(%s/%s) serial buffer full", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "serial buffer full"); /* Don't explicitly close the AT port, just end the AT probing * (or custom init probing) */ mm_port_probe_set_result_at (self, FALSE); @@ -1420,9 +1367,7 @@ mm_port_probe_run_cancel_at_probing (MMPortProbe *self) if (g_cancellable_is_cancelled (ctx->at_probing_cancellable)) return FALSE; - mm_dbg ("(%s/%s) requested to cancel all AT probing", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "requested to cancel all AT probing"); g_cancellable_cancel (ctx->at_probing_cancellable); return TRUE; } @@ -1478,44 +1423,34 @@ mm_port_probe_run (MMPortProbe *self, /* If we're told to completely ignore the port, don't do any probing */ if (self->priv->is_ignored) { - mm_dbg ("(%s/%s) port probing finished: skipping for blacklisted port", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port probing finished: skipping for blacklisted port"); port_probe_task_return_boolean (self, TRUE); return; } /* If this is a port flagged as a GPS port, don't do any AT or QCDM probing */ if (self->priv->is_gps) { - mm_dbg ("(%s/%s) GPS port detected", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "GPS port detected"); mm_port_probe_set_result_at (self, FALSE); mm_port_probe_set_result_qcdm (self, FALSE); } /* If this is a port flagged as an audio port, don't do any AT or QCDM probing */ if (self->priv->is_audio) { - mm_dbg ("(%s/%s) audio port detected", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "audio port detected"); mm_port_probe_set_result_at (self, FALSE); mm_port_probe_set_result_qcdm (self, FALSE); } /* If this is a port flagged as being an AT port, don't do any QCDM probing */ if (self->priv->maybe_at_primary || self->priv->maybe_at_secondary || self->priv->maybe_at_ppp) { - mm_dbg ("(%s/%s) no QCDM probing in possible AT port", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "no QCDM probing in possible AT port"); mm_port_probe_set_result_qcdm (self, FALSE); } /* If this is a port flagged as being a QCDM port, don't do any AT probing */ if (self->priv->maybe_qcdm) { - mm_dbg ("(%s/%s) no AT probing in possible QCDM port", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "no AT probing in possible QCDM port"); mm_port_probe_set_result_at (self, FALSE); } @@ -1529,19 +1464,14 @@ mm_port_probe_run (MMPortProbe *self, /* All requested probings already available? If so, we're done */ if (!ctx->flags) { - mm_dbg ("(%s/%s) port probing finished: no more probings needed", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port)); + mm_obj_dbg (self, "port probing finished: no more probings needed"); port_probe_task_return_boolean (self, TRUE); return; } /* Log the probes scheduled to be run */ probe_list_str = mm_port_probe_flag_build_string_from_mask (ctx->flags); - mm_dbg ("(%s/%s) launching port probing: '%s'", - mm_kernel_device_get_subsystem (self->priv->port), - mm_kernel_device_get_name (self->priv->port), - probe_list_str); + mm_obj_dbg (self, "launching port probing: '%s'", probe_list_str); g_free (probe_list_str); /* If any AT probing is needed, start by opening as AT port */ @@ -1893,6 +1823,17 @@ mm_port_probe_get_port_subsys (MMPortProbe *self) /*****************************************************************************/ +static gchar * +log_object_build_id (MMLogObject *_self) +{ + MMPortProbe *self; + + self = MM_PORT_PROBE (_self); + return g_strdup_printf ("%s/probe", mm_kernel_device_get_name (self->priv->port)); +} + +/*****************************************************************************/ + MMPortProbe * mm_port_probe_new (MMDevice *device, MMKernelDevice *port) @@ -1989,6 +1930,12 @@ dispose (GObject *object) G_OBJECT_CLASS (mm_port_probe_parent_class)->dispose (object); } +static void +log_object_iface_init (MMLogObjectInterface *iface) +{ + iface->build_id = log_object_build_id; +} + static void mm_port_probe_class_init (MMPortProbeClass *klass) { From d628db12fe432846675844cee9753a77d22ca451 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 19:18:37 +0200 Subject: [PATCH 071/675] port-probe-at: remove explicit logging --- src/mm-port-probe-at.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mm-port-probe-at.c b/src/mm-port-probe-at.c index 10cce9e5..37a5ab27 100644 --- a/src/mm-port-probe-at.c +++ b/src/mm-port-probe-at.c @@ -40,8 +40,6 @@ mm_port_probe_response_processor_is_at (const gchar *command, GError **result_error) { if (error) { - mm_dbg ("Parsing AT got: '%s'", error->message); - /* Timeout errors are the only ones not fatal; * they will just go on to the next command. */ if (g_error_matches (error, From b682d7ec673b78446ed5cbd1d276e4e6f363ee3d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 31 Mar 2020 19:19:22 +0200 Subject: [PATCH 072/675] tests,test-sms-part-cdma: remove explicit logging --- src/tests/test-sms-part-cdma.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tests/test-sms-part-cdma.c b/src/tests/test-sms-part-cdma.c index 0f36fe36..7bb2bf65 100644 --- a/src/tests/test-sms-part-cdma.c +++ b/src/tests/test-sms-part-cdma.c @@ -38,7 +38,6 @@ common_test_part_from_hexpdu (const gchar *hexpdu, MMSmsPart *part; GError *error = NULL; - mm_dbg (" "); part = mm_sms_part_cdma_new_from_pdu (0, hexpdu, NULL, &error); g_assert_no_error (error); g_assert (part != NULL); @@ -88,7 +87,6 @@ common_test_invalid_part_from_hexpdu (const gchar *hexpdu) MMSmsPart *part; GError *error = NULL; - mm_dbg (" "); part = mm_sms_part_cdma_new_from_pdu (0, hexpdu, NULL, &error); g_assert (part == NULL); /* We don't care for the specific error type */ From fd1464cff04017f283ee296f81acb18f0c2ae7ab Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 3 Apr 2020 15:34:42 +0200 Subject: [PATCH 073/675] modem-helpers: port device identifier to use object logging and autoptr --- src/mm-broadband-modem.c | 1 + src/mm-modem-helpers.c | 31 +++++++++++++------------------ src/mm-modem-helpers.h | 5 +++-- src/tests/test-modem-helpers.c | 1 + 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 011662d1..2a27fdd7 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -11760,6 +11760,7 @@ mm_broadband_modem_create_device_identifier (MMBroadbandModem *self, return (mm_create_device_identifier ( mm_base_modem_get_vendor_id (MM_BASE_MODEM (self)), mm_base_modem_get_product_id (MM_BASE_MODEM (self)), + self, ati, ati1, mm_gdbus_modem_get_equipment_identifier ( diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 15fba359..ac9802a4 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -31,7 +31,7 @@ #include "mm-sms-part.h" #include "mm-modem-helpers.h" #include "mm-helper-enums-types.h" -#include "mm-log.h" +#include "mm-log-object.h" /*****************************************************************************/ @@ -254,8 +254,9 @@ mm_find_bit_set (gulong number) /*****************************************************************************/ gchar * -mm_create_device_identifier (guint vid, - guint pid, +mm_create_device_identifier (guint vid, + guint pid, + gpointer log_object, const gchar *ati, const gchar *ati1, const gchar *gsn, @@ -263,9 +264,11 @@ mm_create_device_identifier (guint vid, const gchar *model, const gchar *manf) { - GString *devid, *msg = NULL; - GChecksum *sum; - gchar *p, *ret = NULL; + g_autoptr(GString) devid = NULL; + g_autoptr(GString) msg = NULL; + g_autoptr(GChecksum) sum = NULL; + const gchar *ret; + gchar *p = NULL; gchar str_vid[10], str_pid[10]; /* Build up the device identifier */ @@ -286,14 +289,11 @@ mm_create_device_identifier (guint vid, if (manf) g_string_append (devid, manf); - if (!strlen (devid->str)) { - g_string_free (devid, TRUE); + if (!strlen (devid->str)) return NULL; - } p = devid->str; msg = g_string_sized_new (strlen (devid->str) + 17); - sum = g_checksum_new (G_CHECKSUM_SHA1); if (vid) { @@ -315,15 +315,10 @@ mm_create_device_identifier (guint vid, } p++; } - ret = g_strdup (g_checksum_get_string (sum)); - g_checksum_free (sum); - mm_dbg ("Device ID source '%s'", msg->str); - mm_dbg ("Device ID '%s'", ret); - g_string_free (msg, TRUE); - g_string_free (devid, TRUE); - - return ret; + ret = g_checksum_get_string (sum); + mm_obj_dbg (log_object, "device identifier built: %s -> %s", msg->str, ret); + return g_strdup (ret); } /*****************************************************************************/ diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 9c1be81f..f22b880c 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -59,8 +59,9 @@ GArray *mm_parse_uint_list (const gchar *str, guint mm_count_bits_set (gulong number); guint mm_find_bit_set (gulong number); -gchar *mm_create_device_identifier (guint vid, - guint pid, +gchar *mm_create_device_identifier (guint vid, + guint pid, + gpointer log_object, const gchar *ati, const gchar *ati1, const gchar *gsn, diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 551603df..33f53b9e 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1911,6 +1911,7 @@ test_devid_item (void *f, gpointer d) g_debug ("%s... ", item->desc); devid = mm_create_device_identifier (item->vid, item->pid, + NULL, item->ati, item->ati1, item->gsn, From 0f708daf0b9bfa26193d0efbd2591bcc81ef1d44 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 3 Apr 2020 15:47:37 +0200 Subject: [PATCH 074/675] modem-helpers: port supported modes filtering to use object logging --- plugins/cinterion/mm-broadband-modem-cinterion.c | 2 +- plugins/linktop/mm-broadband-modem-linktop.c | 2 +- plugins/longcheer/mm-broadband-modem-longcheer.c | 2 +- plugins/novatel/mm-broadband-modem-novatel.c | 2 +- plugins/option/mm-broadband-modem-option.c | 2 +- plugins/sierra/mm-broadband-modem-sierra.c | 2 +- plugins/simtech/mm-broadband-modem-simtech.c | 2 +- plugins/telit/mm-broadband-modem-mbim-telit.c | 2 +- plugins/telit/mm-broadband-modem-telit.c | 2 +- plugins/ublox/mm-broadband-modem-ublox.c | 2 +- plugins/ublox/mm-modem-helpers-ublox.c | 3 ++- plugins/ublox/mm-modem-helpers-ublox.h | 1 + plugins/ublox/tests/test-modem-helpers-ublox.c | 2 +- plugins/wavecom/mm-broadband-modem-wavecom.c | 2 +- plugins/x22x/mm-broadband-modem-x22x.c | 2 +- plugins/xmm/mm-modem-helpers-xmm.c | 3 ++- plugins/xmm/mm-modem-helpers-xmm.h | 1 + plugins/xmm/mm-shared-xmm.c | 1 + plugins/xmm/tests/test-modem-helpers-xmm.c | 2 +- plugins/zte/mm-broadband-modem-zte.c | 2 +- src/mm-modem-helpers.c | 13 ++++++++++--- src/mm-modem-helpers.h | 3 ++- src/mm-shared-qmi.c | 2 +- src/tests/test-modem-helpers.c | 10 +++++----- 24 files changed, 40 insertions(+), 27 deletions(-) diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 97c4bcbc..c517288f 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -1019,7 +1019,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, } /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/linktop/mm-broadband-modem-linktop.c b/plugins/linktop/mm-broadband-modem-linktop.c index 9c3ecb79..42818920 100644 --- a/plugins/linktop/mm-broadband-modem-linktop.c +++ b/plugins/linktop/mm-broadband-modem-linktop.c @@ -88,7 +88,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, g_array_append_val (combinations, mode); /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/longcheer/mm-broadband-modem-longcheer.c b/plugins/longcheer/mm-broadband-modem-longcheer.c index 7dc6d372..8e07bdf8 100644 --- a/plugins/longcheer/mm-broadband-modem-longcheer.c +++ b/plugins/longcheer/mm-broadband-modem-longcheer.c @@ -88,7 +88,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, g_array_append_val (combinations, mode); /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/novatel/mm-broadband-modem-novatel.c b/plugins/novatel/mm-broadband-modem-novatel.c index 2675a7e0..3a07b555 100644 --- a/plugins/novatel/mm-broadband-modem-novatel.c +++ b/plugins/novatel/mm-broadband-modem-novatel.c @@ -104,7 +104,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, g_array_append_val (combinations, mode); /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/option/mm-broadband-modem-option.c b/plugins/option/mm-broadband-modem-option.c index eaf5a00c..46a70aa0 100644 --- a/plugins/option/mm-broadband-modem-option.c +++ b/plugins/option/mm-broadband-modem-option.c @@ -111,7 +111,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, g_array_append_val (combinations, mode); /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/sierra/mm-broadband-modem-sierra.c b/plugins/sierra/mm-broadband-modem-sierra.c index c1ac89ab..80db350f 100644 --- a/plugins/sierra/mm-broadband-modem-sierra.c +++ b/plugins/sierra/mm-broadband-modem-sierra.c @@ -589,7 +589,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, } /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/simtech/mm-broadband-modem-simtech.c b/plugins/simtech/mm-broadband-modem-simtech.c index f967479e..c8011862 100644 --- a/plugins/simtech/mm-broadband-modem-simtech.c +++ b/plugins/simtech/mm-broadband-modem-simtech.c @@ -850,7 +850,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, g_array_append_val (combinations, mode); /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/telit/mm-broadband-modem-mbim-telit.c b/plugins/telit/mm-broadband-modem-mbim-telit.c index 43bce7fa..248461b5 100644 --- a/plugins/telit/mm-broadband-modem-mbim-telit.c +++ b/plugins/telit/mm-broadband-modem-mbim-telit.c @@ -102,7 +102,7 @@ load_supported_modes_ready (MMIfaceModem *self, /* Filter out those unsupported modes */ combinations = mm_telit_build_modes_list(); - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/telit/mm-broadband-modem-telit.c b/plugins/telit/mm-broadband-modem-telit.c index dde60a9b..a240bb1c 100644 --- a/plugins/telit/mm-broadband-modem-telit.c +++ b/plugins/telit/mm-broadband-modem-telit.c @@ -1241,7 +1241,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, /* Filter out those unsupported modes */ combinations = mm_telit_build_modes_list(); - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/ublox/mm-broadband-modem-ublox.c b/plugins/ublox/mm-broadband-modem-ublox.c index d5ce452a..67474d2b 100644 --- a/plugins/ublox/mm-broadband-modem-ublox.c +++ b/plugins/ublox/mm-broadband-modem-ublox.c @@ -690,7 +690,7 @@ load_supported_modes_finish (MMIfaceModem *self, if (!(combinations = mm_ublox_parse_urat_test_response (response, error))) return FALSE; - if (!(combinations = mm_ublox_filter_supported_modes (mm_iface_modem_get_model (self), combinations, error))) + if (!(combinations = mm_ublox_filter_supported_modes (mm_iface_modem_get_model (self), combinations, self, error))) return FALSE; /* Decide and store which combination to apply when ANY requested */ diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c index df6b6a26..fde9c962 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.c +++ b/plugins/ublox/mm-modem-helpers-ublox.c @@ -980,6 +980,7 @@ supported_modes_per_model (const gchar *model) GArray * mm_ublox_filter_supported_modes (const gchar *model, GArray *combinations, + gpointer logger, GError **error) { MMModemModeCombination mode; @@ -1002,7 +1003,7 @@ mm_ublox_filter_supported_modes (const gchar *model, all = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 1); g_array_append_val (all, mode); - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, logger); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h index 121a9839..0b01b3df 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.h +++ b/plugins/ublox/mm-modem-helpers-ublox.h @@ -115,6 +115,7 @@ gboolean mm_ublox_get_support_config (const gchar *model, GArray *mm_ublox_filter_supported_modes (const gchar *model, GArray *combinations, + gpointer logger, GError **error); /*****************************************************************************/ diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c index 8f2f3664..0aa20f2b 100644 --- a/plugins/ublox/tests/test-modem-helpers-ublox.c +++ b/plugins/ublox/tests/test-modem-helpers-ublox.c @@ -294,7 +294,7 @@ compare_combinations (const gchar *response, g_assert_no_error (error); g_assert (combinations); - combinations = mm_ublox_filter_supported_modes (model, combinations, &error); + combinations = mm_ublox_filter_supported_modes (model, combinations, NULL, &error); g_assert_no_error (error); g_assert (combinations); diff --git a/plugins/wavecom/mm-broadband-modem-wavecom.c b/plugins/wavecom/mm-broadband-modem-wavecom.c index 47980d86..500d8895 100644 --- a/plugins/wavecom/mm-broadband-modem-wavecom.c +++ b/plugins/wavecom/mm-broadband-modem-wavecom.c @@ -176,7 +176,7 @@ supported_ms_classes_query_ready (MMBaseModem *self, g_array_append_val (combinations, mode); /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/x22x/mm-broadband-modem-x22x.c b/plugins/x22x/mm-broadband-modem-x22x.c index 0d7794ad..a86b7a57 100644 --- a/plugins/x22x/mm-broadband-modem-x22x.c +++ b/plugins/x22x/mm-broadband-modem-x22x.c @@ -90,7 +90,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, g_array_append_val (combinations, mode); /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/plugins/xmm/mm-modem-helpers-xmm.c b/plugins/xmm/mm-modem-helpers-xmm.c index 4ccbc745..2e52d162 100644 --- a/plugins/xmm/mm-modem-helpers-xmm.c +++ b/plugins/xmm/mm-modem-helpers-xmm.c @@ -172,6 +172,7 @@ static const MMModemMode xmm_modes[] = { gboolean mm_xmm_parse_xact_test_response (const gchar *response, + gpointer logger, GArray **modes_out, GArray **bands_out, GError **error) @@ -318,7 +319,7 @@ mm_xmm_parse_xact_test_response (const gchar *response, all_modes = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 1); g_array_append_val (all_modes, all); - filtered = mm_filter_supported_modes (all_modes, modes); + filtered = mm_filter_supported_modes (all_modes, modes, logger); if (!filtered || filtered->len == 0) { inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Empty supported mode list after frequency band filtering"); diff --git a/plugins/xmm/mm-modem-helpers-xmm.h b/plugins/xmm/mm-modem-helpers-xmm.h index f70fc346..79676cfa 100644 --- a/plugins/xmm/mm-modem-helpers-xmm.h +++ b/plugins/xmm/mm-modem-helpers-xmm.h @@ -21,6 +21,7 @@ /* AT+XACT=? response parser */ gboolean mm_xmm_parse_xact_test_response (const gchar *response, + gpointer logger, GArray **modes_out, GArray **bands_out, GError **error); diff --git a/plugins/xmm/mm-shared-xmm.c b/plugins/xmm/mm-shared-xmm.c index 2f40d787..8dfa135f 100644 --- a/plugins/xmm/mm-shared-xmm.c +++ b/plugins/xmm/mm-shared-xmm.c @@ -154,6 +154,7 @@ xact_test_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (self, res, &error); if (!response || !mm_xmm_parse_xact_test_response (response, + self, &priv->supported_modes, &priv->supported_bands, &error)) diff --git a/plugins/xmm/tests/test-modem-helpers-xmm.c b/plugins/xmm/tests/test-modem-helpers-xmm.c index 0e65c7cc..c6a3f33d 100644 --- a/plugins/xmm/tests/test-modem-helpers-xmm.c +++ b/plugins/xmm/tests/test-modem-helpers-xmm.c @@ -45,7 +45,7 @@ validate_xact_test_response (const gchar *response, gboolean ret; guint i; - ret = mm_xmm_parse_xact_test_response (response, &modes, &bands, &error); + ret = mm_xmm_parse_xact_test_response (response, NULL, &modes, &bands, &error); g_assert_no_error (error); g_assert (ret); diff --git a/plugins/zte/mm-broadband-modem-zte.c b/plugins/zte/mm-broadband-modem-zte.c index a1b24bc3..a3c81a66 100644 --- a/plugins/zte/mm-broadband-modem-zte.c +++ b/plugins/zte/mm-broadband-modem-zte.c @@ -303,7 +303,7 @@ parent_load_supported_modes_ready (MMIfaceModem *self, } /* Filter out those unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index ac9802a4..e73bff11 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -418,7 +418,8 @@ mm_new_iso8601_time (guint year, GArray * mm_filter_supported_modes (const GArray *all, - const GArray *supported_combinations) + const GArray *supported_combinations, + gpointer log_object) { MMModemModeCombination all_item; guint i; @@ -429,6 +430,9 @@ mm_filter_supported_modes (const GArray *all, g_return_val_if_fail (all->len == 1, NULL); g_return_val_if_fail (supported_combinations != NULL, NULL); + mm_obj_dbg (log_object, "filtering %u supported mode combinations with %u modes", + supported_combinations->len, all->len); + all_item = g_array_index (all, MMModemModeCombination, 0); g_return_val_if_fail (all_item.allowed != MM_MODEM_MODE_NONE, NULL); @@ -450,14 +454,17 @@ mm_filter_supported_modes (const GArray *all, } if (filtered_combinations->len == 0) - mm_warn ("All supported mode combinations were filtered out."); + mm_obj_warn (log_object, "all supported mode combinations were filtered out"); /* Add default entry with the generic mask including all items */ if (!all_item_added) { - mm_dbg ("Adding an explicit item with all supported modes allowed"); + mm_obj_dbg (log_object, "adding an explicit item with all supported modes allowed"); g_array_append_val (filtered_combinations, all_item); } + mm_obj_dbg (log_object, "device supports %u different mode combinations", + filtered_combinations->len); + return filtered_combinations; } diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index f22b880c..87c39b08 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -84,7 +84,8 @@ gchar *mm_new_iso8601_time (guint year, gint offset_minutes); GArray *mm_filter_supported_modes (const GArray *all, - const GArray *supported_combinations); + const GArray *supported_combinations, + gpointer log_object); GArray *mm_filter_supported_capabilities (MMModemCapability all, const GArray *supported_combinations); diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 13b873f2..95b270a3 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -1624,7 +1624,7 @@ mm_shared_qmi_load_supported_modes (MMIfaceModem *self, } /* Filter out unsupported modes */ - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, self); g_array_unref (all); g_array_unref (combinations); diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 33f53b9e..f2233dc4 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -3423,7 +3423,7 @@ test_supported_mode_filter (void *f, gpointer d) /* Only 2G supported */ all = build_mode_all (MM_MODEM_MODE_2G); - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, NULL); g_assert_cmpuint (filtered->len, ==, 1); g_assert (find_mode_combination (filtered, MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE)); g_array_unref (filtered); @@ -3431,7 +3431,7 @@ test_supported_mode_filter (void *f, gpointer d) /* Only 3G supported */ all = build_mode_all (MM_MODEM_MODE_3G); - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, NULL); g_assert_cmpuint (filtered->len, ==, 1); g_assert (find_mode_combination (filtered, MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE)); g_array_unref (filtered); @@ -3439,7 +3439,7 @@ test_supported_mode_filter (void *f, gpointer d) /* 2G and 3G supported */ all = build_mode_all (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G); - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, NULL); g_assert_cmpuint (filtered->len, ==, 3); g_assert (find_mode_combination (filtered, MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE)); g_assert (find_mode_combination (filtered, MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE)); @@ -3449,7 +3449,7 @@ test_supported_mode_filter (void *f, gpointer d) /* 3G and 4G supported */ all = build_mode_all (MM_MODEM_MODE_3G | MM_MODEM_MODE_4G); - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, NULL); g_assert_cmpuint (filtered->len, ==, 3); g_assert (find_mode_combination (filtered, MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE)); g_assert (find_mode_combination (filtered, MM_MODEM_MODE_4G, MM_MODEM_MODE_NONE)); @@ -3459,7 +3459,7 @@ test_supported_mode_filter (void *f, gpointer d) /* 2G, 3G and 4G supported */ all = build_mode_all (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G); - filtered = mm_filter_supported_modes (all, combinations); + filtered = mm_filter_supported_modes (all, combinations, NULL); g_assert_cmpuint (filtered->len, ==, 6); g_assert (find_mode_combination (filtered, MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE)); g_assert (find_mode_combination (filtered, MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE)); From fb61243b7dd37d020e5bc357340ed97a6e4a8857 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 3 Apr 2020 15:52:00 +0200 Subject: [PATCH 075/675] modem-helpers: port ifc test parser to use object logging --- src/mm-broadband-modem.c | 2 +- src/mm-modem-helpers.c | 17 ++++++++++------- src/mm-modem-helpers.h | 1 + src/tests/test-modem-helpers.c | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 2a27fdd7..723b2b2a 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -3851,7 +3851,7 @@ ifc_test_ready (MMBaseModem *_self, goto out; /* Parse response */ - flow_control_supported = mm_parse_ifc_test_response (response, &error); + flow_control_supported = mm_parse_ifc_test_response (response, self, &error); if (flow_control_supported == MM_FLOW_CONTROL_UNKNOWN) goto out; flow_control_supported_str = mm_flow_control_build_string_from_mask (flow_control_supported); diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index e73bff11..fbbc06ef 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -705,7 +705,8 @@ mm_3gpp_call_info_list_free (GList *call_info_list) static MMFlowControl flow_control_array_to_mask (GArray *array, - const gchar *item) + const gchar *item, + gpointer log_object) { MMFlowControl mask = MM_FLOW_CONTROL_UNKNOWN; guint i; @@ -716,15 +717,15 @@ flow_control_array_to_mask (GArray *array, mode = g_array_index (array, guint, i); switch (mode) { case 0: - mm_dbg ("%s supports no flow control", item); + mm_obj_dbg (log_object, "%s supports no flow control", item); mask |= MM_FLOW_CONTROL_NONE; break; case 1: - mm_dbg ("%s supports XON/XOFF flow control", item); + mm_obj_dbg (log_object, "%s supports XON/XOFF flow control", item); mask |= MM_FLOW_CONTROL_XON_XOFF; break; case 2: - mm_dbg ("%s supports RTS/CTS flow control", item); + mm_obj_dbg (log_object, "%s supports RTS/CTS flow control", item); mask |= MM_FLOW_CONTROL_RTS_CTS; break; default: @@ -739,6 +740,7 @@ static MMFlowControl flow_control_match_info_to_mask (GMatchInfo *match_info, guint index, const gchar *item, + gpointer log_object, GError **error) { MMFlowControl mask = MM_FLOW_CONTROL_UNKNOWN; @@ -756,7 +758,7 @@ flow_control_match_info_to_mask (GMatchInfo *match_info, goto out; } - if ((mask = flow_control_array_to_mask (array, item)) == MM_FLOW_CONTROL_UNKNOWN) { + if ((mask = flow_control_array_to_mask (array, item, log_object)) == MM_FLOW_CONTROL_UNKNOWN) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "No known %s flow control method given", item); goto out; @@ -771,6 +773,7 @@ flow_control_match_info_to_mask (GMatchInfo *match_info, MMFlowControl mm_parse_ifc_test_response (const gchar *response, + gpointer log_object, GError **error) { GRegex *r; @@ -793,11 +796,11 @@ mm_parse_ifc_test_response (const gchar *response, } /* Parse TE flow control methods */ - if ((te_mask = flow_control_match_info_to_mask (match_info, 1, "TE", &inner_error)) == MM_FLOW_CONTROL_UNKNOWN) + if ((te_mask = flow_control_match_info_to_mask (match_info, 1, "TE", log_object, &inner_error)) == MM_FLOW_CONTROL_UNKNOWN) goto out; /* Parse TA flow control methods */ - if ((ta_mask = flow_control_match_info_to_mask (match_info, 2, "TA", &inner_error)) == MM_FLOW_CONTROL_UNKNOWN) + if ((ta_mask = flow_control_match_info_to_mask (match_info, 2, "TA", log_object, &inner_error)) == MM_FLOW_CONTROL_UNKNOWN) goto out; /* Only those methods in both TA and TE will be the ones we report */ diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 87c39b08..2f454104 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -128,6 +128,7 @@ typedef enum { /*< underscore_name=mm_flow_control >*/ } MMFlowControl; MMFlowControl mm_parse_ifc_test_response (const gchar *response, + gpointer log_object, GError **error); MMFlowControl mm_flow_control_from_string (const gchar *str, diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index f2233dc4..1cba8148 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -37,7 +37,7 @@ test_ifc_response (const gchar *str, MMFlowControl mask; GError *error = NULL; - mask = mm_parse_ifc_test_response (str, &error); + mask = mm_parse_ifc_test_response (str, NULL, &error); g_assert_no_error (error); g_assert_cmpuint (mask, ==, expected); } From 2b23ef3fa62de79f6ec0f23f2971f3528125246a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 3 Apr 2020 15:54:42 +0200 Subject: [PATCH 076/675] modem-helpers: port cops test parser to use object logging --- src/mm-broadband-modem.c | 2 +- src/mm-modem-helpers.c | 54 +++++++++++++--------------------- src/mm-modem-helpers.h | 1 + src/tests/test-modem-helpers.c | 6 ++-- 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 723b2b2a..be0c9992 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -4710,7 +4710,7 @@ modem_3gpp_scan_networks_finish (MMIfaceModem3gpp *self, if (!result) return NULL; - return mm_3gpp_parse_cops_test_response (result, MM_BROADBAND_MODEM (self)->priv->modem_current_charset, error); + return mm_3gpp_parse_cops_test_response (result, MM_BROADBAND_MODEM (self)->priv->modem_current_charset, self, error); } static void diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index fbbc06ef..aefe95b1 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1243,14 +1243,15 @@ get_mm_access_tech_from_etsi_access_tech (guint act) } static MMModem3gppNetworkAvailability -parse_network_status (const gchar *str) +parse_network_status (const gchar *str, + gpointer log_object) { /* Expecting a value between '0' and '3' inclusive */ if (!str || strlen (str) != 1 || str[0] < '0' || str[0] > '3') { - mm_warn ("Cannot parse network status: '%s'", str); + mm_obj_warn (log_object, "cannot parse network status value '%s'", str); return MM_MODEM_3GPP_NETWORK_AVAILABILITY_UNKNOWN; } @@ -1258,14 +1259,15 @@ parse_network_status (const gchar *str) } static MMModemAccessTechnology -parse_access_tech (const gchar *str) +parse_access_tech (const gchar *str, + gpointer log_object) { /* Recognized access technologies are between '0' and '7' inclusive... */ if (!str || strlen (str) != 1 || str[0] < '0' || str[0] > '7') { - mm_warn ("Cannot parse access tech: '%s'", str); + mm_obj_warn (log_object, "cannot parse access technology value '%s'", str); return MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; } @@ -1275,13 +1277,13 @@ parse_access_tech (const gchar *str) GList * mm_3gpp_parse_cops_test_response (const gchar *reply, MMModemCharset cur_charset, + gpointer log_object, GError **error) { GRegex *r; GList *info_list = NULL; GMatchInfo *match_info; gboolean umts_format = TRUE; - GError *inner_error = NULL; g_return_val_if_fail (reply != NULL, NULL); if (error) @@ -1310,15 +1312,8 @@ mm_3gpp_parse_cops_test_response (const gchar *reply, * +COPS: (2,"","T-Mobile","31026",0),(1,"AT&T","AT&T","310410"),0) */ - r = g_regex_new ("\\((\\d),\"([^\"\\)]*)\",([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, &inner_error); - if (inner_error) { - mm_err ("Invalid regular expression: %s", inner_error->message); - g_error_free (inner_error); - g_set_error_literal (error, - MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Could not parse scan results"); - return NULL; - } + r = g_regex_new ("\\((\\d),\"([^\"\\)]*)\",([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, NULL); + g_assert (r); /* If we didn't get any hits, try the pre-UMTS format match */ if (!g_regex_match (r, reply, 0, &match_info)) { @@ -1339,15 +1334,8 @@ mm_3gpp_parse_cops_test_response (const gchar *reply, * +COPS: (2,"T - Mobile",,"31026"),(1,"Einstein PCS",,"31064"),(1,"Cingular",,"31041"),,(0,1,3),(0,2) */ - r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^\\)]*)\\)", G_REGEX_UNGREEDY, 0, &inner_error); - if (inner_error) { - mm_err ("Invalid regular expression: %s", inner_error->message); - g_error_free (inner_error); - g_set_error_literal (error, - MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Could not parse scan results"); - return NULL; - } + r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^\\)]*)\\)", G_REGEX_UNGREEDY, 0, NULL); + g_assert (r); g_regex_match (r, reply, 0, &match_info); umts_format = FALSE; @@ -1362,7 +1350,7 @@ mm_3gpp_parse_cops_test_response (const gchar *reply, info = g_new0 (MM3gppNetworkInfo, 1); tmp = mm_get_string_unquoted_from_match_info (match_info, 1); - info->status = parse_network_status (tmp); + info->status = parse_network_status (tmp, log_object); g_free (tmp); info->operator_long = mm_get_string_unquoted_from_match_info (match_info, 2); @@ -1380,7 +1368,7 @@ mm_3gpp_parse_cops_test_response (const gchar *reply, mm_get_string_unquoted_from_match_info (match_info, 5) : NULL); info->access_tech = (tmp ? - parse_access_tech (tmp) : + parse_access_tech (tmp, log_object) : MM_MODEM_ACCESS_TECHNOLOGY_GSM); g_free (tmp); @@ -1402,17 +1390,15 @@ mm_3gpp_parse_cops_test_response (const gchar *reply, } if (valid) { - gchar *access_tech_str; + g_autofree gchar *access_tech_str = NULL; access_tech_str = mm_modem_access_technology_build_string_from_mask (info->access_tech); - mm_dbg ("Found network '%s' ('%s','%s'); availability: %s, access tech: %s", - info->operator_code, - info->operator_short ? info->operator_short : "no short name", - info->operator_long ? info->operator_long : "no long name", - mm_modem_3gpp_network_availability_get_string (info->status), - access_tech_str); - g_free (access_tech_str); - + mm_obj_dbg (log_object, "found network '%s' ('%s','%s'); availability: %s, access tech: %s", + info->operator_code, + info->operator_short ? info->operator_short : "no short name", + info->operator_long ? info->operator_long : "no long name", + mm_modem_3gpp_network_availability_get_string (info->status), + access_tech_str); info_list = g_list_prepend (info_list, info); } else diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 2f454104..df86bc0f 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -162,6 +162,7 @@ typedef struct { void mm_3gpp_network_info_list_free (GList *info_list); GList *mm_3gpp_parse_cops_test_response (const gchar *reply, MMModemCharset cur_charset, + gpointer log_object, GError **error); /* AT+COPS? (current operator) response parser */ diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 1cba8148..51b28950 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -486,7 +486,7 @@ test_cops_results (const gchar *desc, g_debug ("Testing %s +COPS response...", desc); - results = mm_3gpp_parse_cops_test_response (reply, cur_charset, &error); + results = mm_3gpp_parse_cops_test_response (reply, cur_charset, NULL, &error); g_assert (results); g_assert_no_error (error); g_assert_cmpuint (g_list_length (results), ==, expected_results_len); @@ -916,7 +916,7 @@ test_cops_response_gsm_invalid (void *f, gpointer d) GList *results; GError *error = NULL; - results = mm_3gpp_parse_cops_test_response (reply, MM_MODEM_CHARSET_GSM, &error); + results = mm_3gpp_parse_cops_test_response (reply, MM_MODEM_CHARSET_GSM, NULL, &error); g_assert (results == NULL); g_assert_no_error (error); } @@ -928,7 +928,7 @@ test_cops_response_umts_invalid (void *f, gpointer d) GList *results; GError *error = NULL; - results = mm_3gpp_parse_cops_test_response (reply, MM_MODEM_CHARSET_GSM, &error); + results = mm_3gpp_parse_cops_test_response (reply, MM_MODEM_CHARSET_GSM, NULL, &error); g_assert (results == NULL); g_assert_no_error (error); } From f76489cd8179000c1f4e6bc7b72d60933a6c08b9 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 3 Apr 2020 16:01:06 +0200 Subject: [PATCH 077/675] modem-helpers: port cid selection helper to use object logging --- src/mm-broadband-bearer.c | 1 + src/mm-modem-helpers.c | 48 ++++++++++++++++++---------------- src/mm-modem-helpers.h | 5 ++-- src/tests/test-modem-helpers.c | 1 + 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/mm-broadband-bearer.c b/src/mm-broadband-bearer.c index 1b1892fc..d5917706 100644 --- a/src/mm-broadband-bearer.c +++ b/src/mm-broadband-bearer.c @@ -718,6 +718,7 @@ cid_selection_3gpp_select_context (GTask *task) ctx->ip_family, ctx->context_list, ctx->context_format_list, + self, &ctx->cid_reused, &ctx->cid_overwritten); diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index aefe95b1..347ee06f 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1567,8 +1567,9 @@ mm_3gpp_select_best_cid (const gchar *apn, MMBearerIpFamily ip_family, GList *context_list, GList *context_format_list, - gboolean *cid_reused, - gboolean *cid_overwritten) + gpointer log_object, + gboolean *out_cid_reused, + gboolean *out_cid_overwritten) { GList *l; guint prev_cid = 0; @@ -1579,9 +1580,12 @@ mm_3gpp_select_best_cid (const gchar *apn, guint blank_cid = 0; gchar *ip_family_str; + g_assert (out_cid_reused); + g_assert (out_cid_overwritten); + ip_family_str = mm_bearer_ip_family_build_string_from_mask (ip_family); - mm_dbg ("Looking for best CID matching APN '%s' and PDP type '%s'...", - apn, ip_family_str); + mm_obj_dbg (log_object, "looking for best CID matching APN '%s' and PDP type '%s'...", + apn, ip_family_str); g_free (ip_family_str); /* Look for the exact PDP context we want */ @@ -1622,17 +1626,17 @@ mm_3gpp_select_best_cid (const gchar *apn, /* Always prefer an exact match */ if (exact_cid) { - mm_dbg ("Found exact context at CID %u", exact_cid); - *cid_reused = TRUE; - *cid_overwritten = FALSE; + mm_obj_dbg (log_object, "found exact context at CID %u", exact_cid); + *out_cid_reused = TRUE; + *out_cid_overwritten = FALSE; return exact_cid; } /* Try to use an unused CID detected in between the already defined contexts */ if (unused_cid) { - mm_dbg ("Found unused context at CID %u", unused_cid); - *cid_reused = FALSE; - *cid_overwritten = FALSE; + mm_obj_dbg (log_object, "found unused context at CID %u", unused_cid); + *out_cid_reused = FALSE; + *out_cid_overwritten = FALSE; return unused_cid; } @@ -1640,32 +1644,32 @@ mm_3gpp_select_best_cid (const gchar *apn, * CID, then we can use the next available CID because it's an unused one. */ max_allowed_cid = find_max_allowed_cid (context_format_list, ip_family); if (max_cid && (max_cid < max_allowed_cid)) { - mm_dbg ("Found unused context at CID %u (<%u)", max_cid + 1, max_allowed_cid); - *cid_reused = FALSE; - *cid_overwritten = FALSE; + mm_obj_dbg (log_object, "found unused context at CID %u (<%u)", max_cid + 1, max_allowed_cid); + *out_cid_reused = FALSE; + *out_cid_overwritten = FALSE; return (max_cid + 1); } /* Rewrite a context defined with no APN, if any */ if (blank_cid) { - mm_dbg ("Rewriting context with empty APN at CID %u", blank_cid); - *cid_reused = FALSE; - *cid_overwritten = TRUE; + mm_obj_dbg (log_object, "rewriting context with empty APN at CID %u", blank_cid); + *out_cid_reused = FALSE; + *out_cid_overwritten = TRUE; return blank_cid; } /* Rewrite the last existing one found */ if (max_cid) { - mm_dbg ("Rewriting last context detected at CID %u", max_cid); - *cid_reused = FALSE; - *cid_overwritten = TRUE; + mm_obj_dbg (log_object, "rewriting last context detected at CID %u", max_cid); + *out_cid_reused = FALSE; + *out_cid_overwritten = TRUE; return max_cid; } /* Otherwise, just fallback to CID=1 */ - mm_dbg ("Falling back to CID 1"); - *cid_reused = FALSE; - *cid_overwritten = TRUE; + mm_obj_dbg (log_object, "falling back to CID 1"); + *out_cid_reused = FALSE; + *out_cid_overwritten = TRUE; return 1; } diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index df86bc0f..ee36309b 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -202,8 +202,9 @@ guint mm_3gpp_select_best_cid (const gchar *apn, MMBearerIpFamily ip_family, GList *context_list, GList *context_format_list, - gboolean *cid_reused, - gboolean *cid_overwritten); + gpointer log_object, + gboolean *out_cid_reused, + gboolean *out_cid_overwritten); /* AT+CGACT? (active PDP context query) response parser */ typedef struct { diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 51b28950..3968850a 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -2864,6 +2864,7 @@ test_cid_selection (void) cid = mm_3gpp_select_best_cid (test->apn, test->ip_family, context_list, context_format_list, + NULL, &cid_reused, &cid_overwritten); g_assert_cmpuint (cid, ==, test->expected_cid); From 740827bde1d03c5f8b187f70be8ffb6ae3ca1785 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 3 Apr 2020 16:05:17 +0200 Subject: [PATCH 078/675] modem-helpers: parse cgdcont test parser to use object logging --- src/mm-broadband-bearer.c | 2 +- src/mm-broadband-modem.c | 2 +- src/mm-modem-helpers.c | 11 ++++++----- src/mm-modem-helpers.h | 5 +++-- src/tests/test-modem-helpers.c | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/mm-broadband-bearer.c b/src/mm-broadband-bearer.c index d5917706..004ef1f0 100644 --- a/src/mm-broadband-bearer.c +++ b/src/mm-broadband-bearer.c @@ -828,7 +828,7 @@ cgdcont_test_ready (MMBaseModem *modem, goto out; } - ctx->context_format_list = mm_3gpp_parse_cgdcont_test_response (response, &error); + ctx->context_format_list = mm_3gpp_parse_cgdcont_test_response (response, self, &error); if (error) { mm_obj_dbg (self, "error parsing +CGDCONT test response: %s", error->message); g_clear_error (&error); diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index be0c9992..1c244519 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -1906,7 +1906,7 @@ supported_ip_families_cgdcont_test_ready (MMBaseModem *self, if (response) { GList *formats, *l; - formats = mm_3gpp_parse_cgdcont_test_response (response, &error); + formats = mm_3gpp_parse_cgdcont_test_response (response, self, &error); for (l = formats; l; l = g_list_next (l)) mask |= ((MM3gppPdpContextFormat *)(l->data))->pdp_type; diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 347ee06f..1bc9db52 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1688,8 +1688,9 @@ mm_3gpp_pdp_context_format_list_free (GList *pdp_format_list) } GList * -mm_3gpp_parse_cgdcont_test_response (const gchar *response, - GError **error) +mm_3gpp_parse_cgdcont_test_response (const gchar *response, + gpointer log_object, + GError **error) { GRegex *r; GMatchInfo *match_info; @@ -1717,11 +1718,11 @@ mm_3gpp_parse_cgdcont_test_response (const gchar *response, pdp_type_str = mm_get_string_unquoted_from_match_info (match_info, 3); pdp_type = mm_3gpp_get_ip_family_from_pdp_type (pdp_type_str); if (pdp_type == MM_BEARER_IP_FAMILY_NONE) - mm_dbg ("Unhandled PDP type in CGDCONT=? reply: '%s'", pdp_type_str); + mm_obj_dbg (log_object, "unhandled PDP type in CGDCONT=? reply: '%s'", pdp_type_str); else { /* Read min CID */ if (!mm_get_uint_from_match_info (match_info, 1, &min_cid)) - mm_warn ("Invalid min CID in CGDCONT=? reply for PDP type '%s'", pdp_type_str); + mm_obj_warn (log_object, "invalid min CID in CGDCONT=? reply for PDP type '%s'", pdp_type_str); else { MM3gppPdpContextFormat *format; @@ -1746,7 +1747,7 @@ mm_3gpp_parse_cgdcont_test_response (const gchar *response, g_regex_unref (r); if (inner_error) { - mm_warn ("Unexpected error matching +CGDCONT response: '%s'", inner_error->message); + mm_obj_warn (log_object, "unexpected error matching +CGDCONT response: '%s'", inner_error->message); g_error_free (inner_error); } diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index ee36309b..9a92a79b 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -184,8 +184,9 @@ typedef struct { MMBearerIpFamily pdp_type; } MM3gppPdpContextFormat; void mm_3gpp_pdp_context_format_list_free (GList *pdp_format_list); -GList *mm_3gpp_parse_cgdcont_test_response (const gchar *reply, - GError **error); +GList *mm_3gpp_parse_cgdcont_test_response (const gchar *reply, + gpointer log_object, + GError **error); /* AT+CGDCONT? (PDP context query) response parser */ typedef struct { diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 3968850a..f4947904 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -2440,7 +2440,7 @@ test_cgdcont_test_results (const gchar *desc, g_debug ("Testing %s +CGDCONT test response...", desc); - results = mm_3gpp_parse_cgdcont_test_response (reply, &error); + results = mm_3gpp_parse_cgdcont_test_response (reply, NULL, &error); g_assert (results); g_assert_no_error (error); g_assert_cmpuint (g_list_length (results), ==, expected_results_len); @@ -2859,7 +2859,7 @@ test_cid_selection (void) test = &cid_selection_tests[i]; - context_format_list = test->cgdcont_test ? mm_3gpp_parse_cgdcont_test_response (test->cgdcont_test, NULL) : NULL; + context_format_list = test->cgdcont_test ? mm_3gpp_parse_cgdcont_test_response (test->cgdcont_test, NULL, NULL) : NULL; context_list = test->cgdcont_query ? mm_3gpp_parse_cgdcont_read_response (test->cgdcont_query, NULL) : NULL; cid = mm_3gpp_select_best_cid (test->apn, test->ip_family, From 3747f9e669204f0e609e36d629c708dafa1bb990 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 10:58:57 +0200 Subject: [PATCH 079/675] modem-helpers: remove logging from cgdcont response parser --- src/mm-modem-helpers.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 1bc9db52..d8415caa 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1803,9 +1803,7 @@ mm_3gpp_parse_cgdcont_read_response (const gchar *reply, str = mm_get_string_unquoted_from_match_info (match_info, 2); ip_family = mm_3gpp_get_ip_family_from_pdp_type (str); - if (ip_family == MM_BEARER_IP_FAMILY_NONE) - mm_dbg ("Ignoring PDP context type: '%s'", str); - else { + if (ip_family != MM_BEARER_IP_FAMILY_NONE) { MM3gppPdpContext *pdp; pdp = g_slice_new0 (MM3gppPdpContext); From 5b1b33a894e3677dd633f032d5d9a07931096719 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 11:01:27 +0200 Subject: [PATCH 080/675] modem-helpers: port cmer test parser to use object logging --- src/mm-broadband-modem.c | 2 +- src/mm-modem-helpers.c | 5 +++-- src/mm-modem-helpers.h | 1 + src/tests/test-modem-helpers.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 1c244519..39faef42 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -3244,7 +3244,7 @@ cmer_format_check_ready (MMBroadbandModem *self, gchar *aux; result = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); - if (error || !mm_3gpp_parse_cmer_test_response (result, &supported_modes, &supported_inds, &error)) { + if (error || !mm_3gpp_parse_cmer_test_response (result, self, &supported_modes, &supported_inds, &error)) { mm_obj_dbg (self, "+CMER check failed: %s", error->message); mm_obj_dbg (self, "generic indications are unsupported"); g_error_free (error); diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index d8415caa..51577a90 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -3331,6 +3331,7 @@ mm_3gpp_build_cmer_set_request (MM3gppCmerMode mode, gboolean mm_3gpp_parse_cmer_test_response (const gchar *response, + gpointer log_object, MM3gppCmerMode *out_supported_modes, MM3gppCmerInd *out_supported_inds, GError **error) @@ -3385,7 +3386,7 @@ mm_3gpp_parse_cmer_test_response (const gchar *response, if (mode_val <= 3) supported_modes |= (MM3gppCmerMode) (1 << mode_val); else - mm_dbg ("Unknown +CMER mode reported: %u", mode_val); + mm_obj_dbg (log_object, "unknown +CMER mode reported: %u", mode_val); } for (i = 0; i < array_supported_inds->len; i++) { @@ -3395,7 +3396,7 @@ mm_3gpp_parse_cmer_test_response (const gchar *response, if (ind_val <= 2) supported_inds |= (MM3gppCmerInd) (1 << ind_val); else - mm_dbg ("Unknown +CMER ind reported: %u", ind_val); + mm_obj_dbg (log_object, "unknown +CMER ind reported: %u", ind_val); } if (out_supported_modes) diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 9a92a79b..61da24dd 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -285,6 +285,7 @@ typedef enum { /*< underscore_name=mm_3gpp_cmer_ind >*/ gchar *mm_3gpp_build_cmer_set_request (MM3gppCmerMode mode, MM3gppCmerInd ind); gboolean mm_3gpp_parse_cmer_test_response (const gchar *reply, + gpointer log_object, MM3gppCmerMode *supported_modes, MM3gppCmerInd *supported_inds, GError **error); diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index f4947904..f1b236bd 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1938,7 +1938,7 @@ test_cmer_response (const gchar *str, MM3gppCmerInd inds = MM_3GPP_CMER_IND_NONE; GError *error = NULL; - ret = mm_3gpp_parse_cmer_test_response (str, &modes, &inds, &error); + ret = mm_3gpp_parse_cmer_test_response (str, NULL, &modes, &inds, &error); g_assert_no_error (error); g_assert (ret); From 78cad902ef342d6da628f26e1282782aa8361316 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 11:18:28 +0200 Subject: [PATCH 081/675] modem-helpers: remove unused supported capabilities filter --- src/mm-modem-helpers.c | 28 ---------- src/mm-modem-helpers.h | 3 -- src/tests/test-modem-helpers.c | 94 ---------------------------------- 3 files changed, 125 deletions(-) diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 51577a90..67a5f0a6 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -470,34 +470,6 @@ mm_filter_supported_modes (const GArray *all, /*****************************************************************************/ -GArray * -mm_filter_supported_capabilities (MMModemCapability all, - const GArray *supported_combinations) -{ - guint i; - GArray *filtered_combinations; - - g_return_val_if_fail (all != MM_MODEM_CAPABILITY_NONE, NULL); - g_return_val_if_fail (supported_combinations != NULL, NULL); - - /* We will filter out all combinations which have modes not listed in 'all' */ - filtered_combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), supported_combinations->len); - for (i = 0; i < supported_combinations->len; i++) { - MMModemCapability capability; - - capability = g_array_index (supported_combinations, MMModemCapability, i); - if (!(capability & ~all)) - g_array_append_val (filtered_combinations, capability); - } - - if (filtered_combinations->len == 0) - mm_warn ("All supported capability combinations were filtered out."); - - return filtered_combinations; -} - -/*****************************************************************************/ - static const gchar bcd_chars[] = "0123456789\0\0\0\0\0\0"; gchar * diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 61da24dd..25d94357 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -87,9 +87,6 @@ GArray *mm_filter_supported_modes (const GArray *all, const GArray *supported_combinations, gpointer log_object); -GArray *mm_filter_supported_capabilities (MMModemCapability all, - const GArray *supported_combinations); - gchar *mm_bcd_to_string (const guint8 *bcd, gsize bcd_len); /*****************************************************************************/ diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index f1b236bd..f991f023 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -3474,98 +3474,6 @@ test_supported_mode_filter (void *f, gpointer d) g_array_unref (combinations); } -/*****************************************************************************/ - -static gboolean -find_capability_combination (GArray *capabilities, - MMModemCapability capability) -{ - guint i; - - for (i = 0; i < capabilities->len; i++) { - MMModemCapability capability_i; - - capability_i = g_array_index (capabilities, MMModemCapability, i); - if (capability_i == capability) - return TRUE; - } - - return FALSE; -} - -static void -test_supported_capability_filter (void *f, gpointer d) -{ - MMModemCapability capability; - GArray *combinations; - GArray *filtered; - - combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), 6); - - /* GSM/UMTS only */ - capability = MM_MODEM_CAPABILITY_GSM_UMTS; - g_array_append_val (combinations, capability); - /* CDMA/EVDO only */ - capability = MM_MODEM_CAPABILITY_CDMA_EVDO; - g_array_append_val (combinations, capability); - /* GSM/UMTS and CDMA/EVDO */ - capability = (MM_MODEM_CAPABILITY_CDMA_EVDO | MM_MODEM_CAPABILITY_GSM_UMTS); - g_array_append_val (combinations, capability); - /* GSM/UMTS+LTE */ - capability = (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_LTE); - g_array_append_val (combinations, capability); - /* CDMA/EVDO+LTE */ - capability = (MM_MODEM_CAPABILITY_CDMA_EVDO | MM_MODEM_CAPABILITY_LTE); - g_array_append_val (combinations, capability); - /* GSM/UMTS+CDMA/EVDO+LTE */ - capability = (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO | MM_MODEM_CAPABILITY_LTE); - g_array_append_val (combinations, capability); - - /* Only GSM-UMTS supported */ - filtered = mm_filter_supported_capabilities (MM_MODEM_CAPABILITY_GSM_UMTS, combinations); - g_assert_cmpuint (filtered->len, ==, 1); - g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_GSM_UMTS)); - g_array_unref (filtered); - - /* Only CDMA-EVDO supported */ - filtered = mm_filter_supported_capabilities (MM_MODEM_CAPABILITY_CDMA_EVDO, combinations); - g_assert_cmpuint (filtered->len, ==, 1); - g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_CDMA_EVDO)); - g_array_unref (filtered); - - /* GSM-UMTS and CDMA-EVDO supported */ - filtered = mm_filter_supported_capabilities ((MM_MODEM_CAPABILITY_CDMA_EVDO | - MM_MODEM_CAPABILITY_GSM_UMTS), - combinations); - g_assert_cmpuint (filtered->len, ==, 3); - g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_CDMA_EVDO)); - g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_GSM_UMTS)); - g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_GSM_UMTS | - MM_MODEM_CAPABILITY_CDMA_EVDO))); - g_array_unref (filtered); - - /* GSM-UMTS, CDMA-EVDO and LTE supported */ - filtered = mm_filter_supported_capabilities ((MM_MODEM_CAPABILITY_CDMA_EVDO | - MM_MODEM_CAPABILITY_GSM_UMTS | - MM_MODEM_CAPABILITY_LTE), - combinations); - g_assert_cmpuint (filtered->len, ==, 6); - g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_CDMA_EVDO)); - g_assert (find_capability_combination (filtered, MM_MODEM_CAPABILITY_GSM_UMTS)); - g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_GSM_UMTS | - MM_MODEM_CAPABILITY_CDMA_EVDO))); - g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_GSM_UMTS | - MM_MODEM_CAPABILITY_LTE))); - g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_CDMA_EVDO | - MM_MODEM_CAPABILITY_LTE))); - g_assert (find_capability_combination (filtered, (MM_MODEM_CAPABILITY_GSM_UMTS | - MM_MODEM_CAPABILITY_CDMA_EVDO | - MM_MODEM_CAPABILITY_LTE))); - g_array_unref (filtered); - - g_array_unref (combinations); -} - /*****************************************************************************/ /* Test +CCLK responses */ @@ -4721,8 +4629,6 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test_supported_mode_filter, NULL)); - g_test_suite_add (suite, TESTCASE (test_supported_capability_filter, NULL)); - g_test_suite_add (suite, TESTCASE (test_cclk_response, NULL)); g_test_suite_add (suite, TESTCASE (test_crsm_response, NULL)); From 39dd4c166d2750a00dfe1a3505a02bccaaf7f755 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 11:53:36 +0200 Subject: [PATCH 082/675] modem-helpers: port clcc list parser to use object logging --- plugins/simtech/mm-modem-helpers-simtech.c | 3 ++- plugins/simtech/mm-modem-helpers-simtech.h | 1 + plugins/simtech/mm-shared-simtech.c | 2 +- plugins/simtech/tests/test-modem-helpers-simtech.c | 2 +- src/mm-broadband-modem.c | 6 +++--- src/mm-modem-helpers.c | 7 ++++--- src/mm-modem-helpers.h | 1 + src/tests/test-modem-helpers.c | 2 +- 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/simtech/mm-modem-helpers-simtech.c b/plugins/simtech/mm-modem-helpers-simtech.c index d452e0b6..cce549df 100644 --- a/plugins/simtech/mm-modem-helpers-simtech.c +++ b/plugins/simtech/mm-modem-helpers-simtech.c @@ -79,13 +79,14 @@ mm_simtech_get_clcc_urc_regex (void) gboolean mm_simtech_parse_clcc_list (const gchar *str, + gpointer log_object, GList **out_list, GError **error) { /* Parse the URC contents as a plain +CLCC response, but make sure to skip first * EOL in the string because the plain +CLCC response would never have that. */ - return mm_3gpp_parse_clcc_response (mm_strip_tag (str, "\r\n"), out_list, error); + return mm_3gpp_parse_clcc_response (mm_strip_tag (str, "\r\n"), log_object, out_list, error); } void diff --git a/plugins/simtech/mm-modem-helpers-simtech.h b/plugins/simtech/mm-modem-helpers-simtech.h index efcc23f5..1949d2e7 100644 --- a/plugins/simtech/mm-modem-helpers-simtech.h +++ b/plugins/simtech/mm-modem-helpers-simtech.h @@ -32,6 +32,7 @@ gboolean mm_simtech_parse_clcc_test (const gchar *response, GRegex *mm_simtech_get_clcc_urc_regex (void); gboolean mm_simtech_parse_clcc_list (const gchar *str, + gpointer log_object, GList **out_list, GError **error); void mm_simtech_call_info_list_free (GList *call_info_list); diff --git a/plugins/simtech/mm-shared-simtech.c b/plugins/simtech/mm-shared-simtech.c index aa5a66a3..ad313cf0 100644 --- a/plugins/simtech/mm-shared-simtech.c +++ b/plugins/simtech/mm-shared-simtech.c @@ -781,7 +781,7 @@ clcc_urc_received (MMPortSerialAt *port, full = g_match_info_fetch (match_info, 0); - if (!mm_simtech_parse_clcc_list (full, &call_info_list, &error)) { + if (!mm_simtech_parse_clcc_list (full, self, &call_info_list, &error)) { mm_warn ("couldn't parse +CLCC list in URC: %s", error->message); g_error_free (error); } else diff --git a/plugins/simtech/tests/test-modem-helpers-simtech.c b/plugins/simtech/tests/test-modem-helpers-simtech.c index af93b7ba..f1109534 100644 --- a/plugins/simtech/tests/test-modem-helpers-simtech.c +++ b/plugins/simtech/tests/test-modem-helpers-simtech.c @@ -52,7 +52,7 @@ common_test_clcc_urc (const gchar *urc, str = g_match_info_fetch (match_info, 0); g_assert (str); - result = mm_simtech_parse_clcc_list (str, &call_info_list, &error); + result = mm_simtech_parse_clcc_list (str, NULL, &call_info_list, &error); g_assert_no_error (error); g_assert (result); diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 39faef42..1782253e 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -7560,7 +7560,7 @@ modem_voice_load_call_list_finish (MMIfaceModemVoice *self, } static void -clcc_ready (MMBaseModem *modem, +clcc_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) { @@ -7568,8 +7568,8 @@ clcc_ready (MMBaseModem *modem, GError *error = NULL; GList *call_info_list = NULL; - response = mm_base_modem_at_command_finish (modem, res, &error); - if (!response || !mm_3gpp_parse_clcc_response (response, &call_info_list, &error)) + response = mm_base_modem_at_command_finish (self, res, &error); + if (!response || !mm_3gpp_parse_clcc_response (response, self, &call_info_list, &error)) g_task_return_error (task, error); else g_task_return_pointer (task, call_info_list, (GDestroyNotify)mm_3gpp_call_info_list_free); diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 67a5f0a6..4264e230 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -560,6 +560,7 @@ call_info_free (MMCallInfo *info) gboolean mm_3gpp_parse_clcc_response (const gchar *str, + gpointer log_object, GList **out_list, GError **error) { @@ -623,20 +624,20 @@ mm_3gpp_parse_clcc_response (const gchar *str, call_info = g_slice_new0 (MMCallInfo); if (!mm_get_uint_from_match_info (match_info, 1, &call_info->index)) { - mm_warn ("couldn't parse call index from +CLCC line"); + mm_obj_warn (log_object, "couldn't parse call index from +CLCC line"); goto next; } if (!mm_get_uint_from_match_info (match_info, 2, &aux) || (aux >= G_N_ELEMENTS (call_direction))) { - mm_warn ("couldn't parse call direction from +CLCC line"); + mm_obj_warn (log_object, "couldn't parse call direction from +CLCC line"); goto next; } call_info->direction = call_direction[aux]; if (!mm_get_uint_from_match_info (match_info, 3, &aux) || (aux >= G_N_ELEMENTS (call_state))) { - mm_warn ("couldn't parse call state from +CLCC line"); + mm_obj_warn (log_object, "couldn't parse call state from +CLCC line"); goto next; } call_info->state = call_state[aux]; diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 25d94357..88bc71f4 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -106,6 +106,7 @@ typedef struct { gchar *number; /* optional */ } MMCallInfo; gboolean mm_3gpp_parse_clcc_response (const gchar *str, + gpointer log_object, GList **out_list, GError **error); void mm_3gpp_call_info_list_free (GList *call_info_list); diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index f991f023..65ead935 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -4190,7 +4190,7 @@ common_test_clcc_response (const gchar *str, GList *call_info_list = NULL; GList *l; - result = mm_3gpp_parse_clcc_response (str, &call_info_list, &error); + result = mm_3gpp_parse_clcc_response (str, NULL, &call_info_list, &error); g_assert_no_error (error); g_assert (result); From ef1a570afe38537db18a0a3e384dc49c550d0749 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 11:57:19 +0200 Subject: [PATCH 083/675] modem-helpers: port creg response parser to use object logging --- src/mm-broadband-modem.c | 2 ++ src/mm-modem-helpers.c | 19 ++++++++++--------- src/mm-modem-helpers.h | 17 +++++++++-------- src/tests/test-modem-helpers.c | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 1782253e..fab66f79 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -4565,6 +4565,7 @@ registration_state_changed (MMPortSerialAt *port, GError *error = NULL; if (!mm_3gpp_parse_creg_response (match_info, + self, &state, &lac, &cell_id, @@ -4968,6 +4969,7 @@ registration_status_check_ready (MMBroadbandModem *self, lac = 0; cid = 0; parsed = mm_3gpp_parse_creg_response (match_info, + self, &state, &lac, &cid, diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 4264e230..3d281abe 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1942,14 +1942,15 @@ item_is_lac_not_stat (GMatchInfo *info, guint32 item) } gboolean -mm_3gpp_parse_creg_response (GMatchInfo *info, - MMModem3gppRegistrationState *out_reg_state, - gulong *out_lac, - gulong *out_ci, - MMModemAccessTechnology *out_act, - gboolean *out_cgreg, - gboolean *out_cereg, - GError **error) +mm_3gpp_parse_creg_response (GMatchInfo *info, + gpointer log_object, + MMModem3gppRegistrationState *out_reg_state, + gulong *out_lac, + gulong *out_ci, + MMModemAccessTechnology *out_act, + gboolean *out_cgreg, + gboolean *out_cereg, + GError **error) { gboolean success = FALSE, foo; gint n_matches, act = -1; @@ -2057,7 +2058,7 @@ mm_3gpp_parse_creg_response (GMatchInfo *info, /* 'roaming (csfb not preferred)' is the last valid state */ if (stat > MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_CSFB_NOT_PREFERRED) { - mm_warn ("Registration State '%lu' is unknown", stat); + mm_obj_warn (log_object, "unknown registration state value '%lu'", stat); stat = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; } diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 88bc71f4..68611d87 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -217,14 +217,15 @@ GList *mm_3gpp_parse_cgact_read_response (const gchar *reply, GError **error); /* CREG/CGREG response/unsolicited message parser */ -gboolean mm_3gpp_parse_creg_response (GMatchInfo *info, - MMModem3gppRegistrationState *out_reg_state, - gulong *out_lac, - gulong *out_ci, - MMModemAccessTechnology *out_act, - gboolean *out_cgreg, - gboolean *out_cereg, - GError **error); +gboolean mm_3gpp_parse_creg_response (GMatchInfo *info, + gpointer log_object, + MMModem3gppRegistrationState *out_reg_state, + gulong *out_lac, + gulong *out_ci, + MMModemAccessTechnology *out_act, + gboolean *out_cgreg, + gboolean *out_cereg, + GError **error); /* AT+CMGF=? (SMS message format) response parser */ gboolean mm_3gpp_parse_cmgf_test_response (const gchar *reply, diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 65ead935..e025fe2e 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1143,7 +1143,7 @@ test_creg_match (const char *test, g_assert (info != NULL); g_assert_cmpuint (regex_num, ==, result->regex_num); - success = mm_3gpp_parse_creg_response (info, &state, &lac, &ci, &access_tech, &cgreg, &cereg, &error); + success = mm_3gpp_parse_creg_response (info, NULL, &state, &lac, &ci, &access_tech, &cgreg, &cereg, &error); g_match_info_free (info); g_assert (success); g_assert_no_error (error); From ecd766796a4bb3cd1962bfe0b42d187931dd12f6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 12:05:58 +0200 Subject: [PATCH 084/675] modem-helpers: port cesq response parser to use object logging --- plugins/xmm/mm-modem-helpers-xmm.c | 11 +++--- plugins/xmm/mm-modem-helpers-xmm.h | 1 + plugins/xmm/mm-shared-xmm.c | 2 +- plugins/xmm/tests/test-modem-helpers-xmm.c | 1 + src/mm-broadband-modem.c | 2 +- src/mm-modem-helpers.c | 46 ++++++++++++---------- src/mm-modem-helpers.h | 31 +++++++++------ src/tests/test-modem-helpers.c | 1 + 8 files changed, 56 insertions(+), 39 deletions(-) diff --git a/plugins/xmm/mm-modem-helpers-xmm.c b/plugins/xmm/mm-modem-helpers-xmm.c index 2e52d162..7c283dba 100644 --- a/plugins/xmm/mm-modem-helpers-xmm.c +++ b/plugins/xmm/mm-modem-helpers-xmm.c @@ -716,6 +716,7 @@ rssnr_level_to_rssnr (gint rssnr_level, gboolean mm_xmm_xcesq_response_to_signal_info (const gchar *response, + gpointer log_object, MMSignal **out_gsm, MMSignal **out_umts, MMSignal **out_lte, @@ -746,7 +747,7 @@ mm_xmm_xcesq_response_to_signal_info (const gchar *response, return FALSE; /* GERAN RSSI */ - if (mm_3gpp_rxlev_to_rssi (rxlev, &rssi)) { + if (mm_3gpp_rxlev_to_rssi (rxlev, log_object, &rssi)) { gsm = mm_signal_new (); mm_signal_set_rssi (gsm, rssi); } @@ -754,13 +755,13 @@ mm_xmm_xcesq_response_to_signal_info (const gchar *response, /* ignore BER */ /* UMTS RSCP */ - if (mm_3gpp_rscp_level_to_rscp (rscp_level, &rscp)) { + if (mm_3gpp_rscp_level_to_rscp (rscp_level, log_object, &rscp)) { umts = mm_signal_new (); mm_signal_set_rscp (umts, rscp); } /* UMTS EcIo (assumed EcN0) */ - if (mm_3gpp_ecn0_level_to_ecio (ecn0_level, &ecio)) { + if (mm_3gpp_ecn0_level_to_ecio (ecn0_level, log_object, &ecio)) { if (!umts) umts = mm_signal_new (); mm_signal_set_ecio (umts, ecio); @@ -772,13 +773,13 @@ mm_xmm_xcesq_response_to_signal_info (const gchar *response, } /* LTE RSRQ */ - if (mm_3gpp_rsrq_level_to_rsrq (rsrq_level, &rsrq)) { + if (mm_3gpp_rsrq_level_to_rsrq (rsrq_level, log_object, &rsrq)) { lte = mm_signal_new (); mm_signal_set_rsrq (lte, rsrq); } /* LTE RSRP */ - if (mm_3gpp_rsrp_level_to_rsrp (rsrp_level, &rsrp)) { + if (mm_3gpp_rsrp_level_to_rsrp (rsrp_level, log_object, &rsrp)) { if (!lte) lte = mm_signal_new (); mm_signal_set_rsrp (lte, rsrp); diff --git a/plugins/xmm/mm-modem-helpers-xmm.h b/plugins/xmm/mm-modem-helpers-xmm.h index 79676cfa..a18f0667 100644 --- a/plugins/xmm/mm-modem-helpers-xmm.h +++ b/plugins/xmm/mm-modem-helpers-xmm.h @@ -51,6 +51,7 @@ gboolean mm_xmm_parse_xcesq_query_response (const gchar *response, GError **error); gboolean mm_xmm_xcesq_response_to_signal_info (const gchar *response, + gpointer log_object, MMSignal **out_gsm, MMSignal **out_umts, MMSignal **out_lte, diff --git a/plugins/xmm/mm-shared-xmm.c b/plugins/xmm/mm-shared-xmm.c index 8dfa135f..d447fec9 100644 --- a/plugins/xmm/mm-shared-xmm.c +++ b/plugins/xmm/mm-shared-xmm.c @@ -765,7 +765,7 @@ mm_shared_xmm_signal_load_values_finish (MMIfaceModemSignal *self, const gchar *response; response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error); - if (!response || !mm_xmm_xcesq_response_to_signal_info (response, gsm, umts, lte, error)) + if (!response || !mm_xmm_xcesq_response_to_signal_info (response, self, gsm, umts, lte, error)) return FALSE; if (cdma) diff --git a/plugins/xmm/tests/test-modem-helpers-xmm.c b/plugins/xmm/tests/test-modem-helpers-xmm.c index c6a3f33d..39aa8ccc 100644 --- a/plugins/xmm/tests/test-modem-helpers-xmm.c +++ b/plugins/xmm/tests/test-modem-helpers-xmm.c @@ -617,6 +617,7 @@ test_xcesq_response_to_signal (void) MMSignal *lte = NULL; success = mm_xmm_xcesq_response_to_signal_info (xcesq_response_tests[i].str, + NULL, &gsm, &umts, <e, &error); g_assert_no_error (error); diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index fab66f79..5d5a219a 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -9948,7 +9948,7 @@ modem_signal_load_values_finish (MMIfaceModemSignal *self, const gchar *response; response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error); - if (!response || !mm_3gpp_cesq_response_to_signal_info (response, gsm, umts, lte, error)) + if (!response || !mm_3gpp_cesq_response_to_signal_info (response, self, gsm, umts, lte, error)) return FALSE; /* No 3GPP2 support */ diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 3d281abe..36f3dfb4 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -2615,8 +2615,9 @@ mm_3gpp_parse_cesq_response (const gchar *response, } gboolean -mm_3gpp_rxlev_to_rssi (guint rxlev, - gdouble *out_rssi) +mm_3gpp_rxlev_to_rssi (guint rxlev, + gpointer log_object, + gdouble *out_rssi) { if (rxlev <= 63) { *out_rssi = -111.0 + rxlev; @@ -2624,13 +2625,14 @@ mm_3gpp_rxlev_to_rssi (guint rxlev, } if (rxlev != 99) - mm_warn ("unexpected rxlev: %u", rxlev); + mm_obj_warn (log_object, "unexpected rxlev: %u", rxlev); return FALSE; } gboolean -mm_3gpp_rscp_level_to_rscp (guint rscp_level, - gdouble *out_rscp) +mm_3gpp_rscp_level_to_rscp (guint rscp_level, + gpointer log_object, + gdouble *out_rscp) { if (rscp_level <= 96) { *out_rscp = -121.0 + rscp_level; @@ -2638,13 +2640,14 @@ mm_3gpp_rscp_level_to_rscp (guint rscp_level, } if (rscp_level != 255) - mm_warn ("unexpected rscp level: %u", rscp_level); + mm_obj_warn (log_object, "unexpected rscp level: %u", rscp_level); return FALSE; } gboolean -mm_3gpp_ecn0_level_to_ecio (guint ecn0_level, - gdouble *out_ecio) +mm_3gpp_ecn0_level_to_ecio (guint ecn0_level, + gpointer log_object, + gdouble *out_ecio) { if (ecn0_level <= 49) { *out_ecio = -24.5 + (((gdouble) ecn0_level) * 0.5); @@ -2652,13 +2655,14 @@ mm_3gpp_ecn0_level_to_ecio (guint ecn0_level, } if (ecn0_level != 255) - mm_warn ("unexpected Ec/N0 level: %u", ecn0_level); + mm_obj_warn (log_object, "unexpected Ec/N0 level: %u", ecn0_level); return FALSE; } gboolean -mm_3gpp_rsrq_level_to_rsrq (guint rsrq_level, - gdouble *out_rsrq) +mm_3gpp_rsrq_level_to_rsrq (guint rsrq_level, + gpointer log_object, + gdouble *out_rsrq) { if (rsrq_level <= 34) { *out_rsrq = -20.0 + (((gdouble) rsrq_level) * 0.5); @@ -2666,13 +2670,14 @@ mm_3gpp_rsrq_level_to_rsrq (guint rsrq_level, } if (rsrq_level != 255) - mm_warn ("unexpected RSRQ level: %u", rsrq_level); + mm_obj_warn (log_object, "unexpected RSRQ level: %u", rsrq_level); return FALSE; } gboolean -mm_3gpp_rsrp_level_to_rsrp (guint rsrp_level, - gdouble *out_rsrp) +mm_3gpp_rsrp_level_to_rsrp (guint rsrp_level, + gpointer log_object, + gdouble *out_rsrp) { if (rsrp_level <= 97) { *out_rsrp = -141.0 + rsrp_level; @@ -2680,12 +2685,13 @@ mm_3gpp_rsrp_level_to_rsrp (guint rsrp_level, } if (rsrp_level != 255) - mm_warn ("unexpected RSRP level: %u", rsrp_level); + mm_obj_warn (log_object, "unexpected RSRP level: %u", rsrp_level); return FALSE; } gboolean mm_3gpp_cesq_response_to_signal_info (const gchar *response, + gpointer log_object, MMSignal **out_gsm, MMSignal **out_umts, MMSignal **out_lte, @@ -2714,7 +2720,7 @@ mm_3gpp_cesq_response_to_signal_info (const gchar *response, return FALSE; /* GERAN RSSI */ - if (mm_3gpp_rxlev_to_rssi (rxlev, &rssi)) { + if (mm_3gpp_rxlev_to_rssi (rxlev, log_object, &rssi)) { gsm = mm_signal_new (); mm_signal_set_rssi (gsm, rssi); } @@ -2722,26 +2728,26 @@ mm_3gpp_cesq_response_to_signal_info (const gchar *response, /* ignore BER */ /* UMTS RSCP */ - if (mm_3gpp_rscp_level_to_rscp (rscp_level, &rscp)) { + if (mm_3gpp_rscp_level_to_rscp (rscp_level, log_object, &rscp)) { umts = mm_signal_new (); mm_signal_set_rscp (umts, rscp); } /* UMTS EcIo (assumed EcN0) */ - if (mm_3gpp_ecn0_level_to_ecio (ecn0_level, &ecio)) { + if (mm_3gpp_ecn0_level_to_ecio (ecn0_level, log_object, &ecio)) { if (!umts) umts = mm_signal_new (); mm_signal_set_ecio (umts, ecio); } /* LTE RSRQ */ - if (mm_3gpp_rsrq_level_to_rsrq (rsrq_level, &rsrq)) { + if (mm_3gpp_rsrq_level_to_rsrq (rsrq_level, log_object, &rsrq)) { lte = mm_signal_new (); mm_signal_set_rsrq (lte, rsrq); } /* LTE RSRP */ - if (mm_3gpp_rsrp_level_to_rsrp (rsrp_level, &rsrp)) { + if (mm_3gpp_rsrp_level_to_rsrp (rsrp_level, log_object, &rsrp)) { if (!lte) lte = mm_signal_new (); mm_signal_set_rsrp (lte, rsrp); diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 68611d87..d2c1a5a6 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -401,6 +401,7 @@ gboolean mm_3gpp_parse_cesq_response (const gchar *response, GError **error); gboolean mm_3gpp_cesq_response_to_signal_info (const gchar *response, + gpointer log_object, MMSignal **out_gsm, MMSignal **out_umts, MMSignal **out_lte, @@ -439,18 +440,24 @@ MMBearerIpFamily mm_3gpp_get_ip_family_from_pdp_type (const gchar *pdp_type); char *mm_3gpp_parse_iccid (const char *raw_iccid, GError **error); -gboolean mm_3gpp_rscp_level_to_rscp (guint rscp_level, - gdouble *out_rscp); -gboolean mm_3gpp_rxlev_to_rssi (guint rxlev, - gdouble *out_rssi); -gboolean mm_3gpp_ecn0_level_to_ecio (guint ecn0_level, - gdouble *out_ecio); -gboolean mm_3gpp_rsrq_level_to_rsrq (guint rsrq_level, - gdouble *out_rsrq); -gboolean mm_3gpp_rsrp_level_to_rsrp (guint rsrp_level, - gdouble *out_rsrp); -gboolean mm_3gpp_rssnr_level_to_rssnr (gint rssnr_level, - gdouble *out_rssnr); +gboolean mm_3gpp_rscp_level_to_rscp (guint rscp_level, + gpointer log_object, + gdouble *out_rscp); +gboolean mm_3gpp_rxlev_to_rssi (guint rxlev, + gpointer log_object, + gdouble *out_rssi); +gboolean mm_3gpp_ecn0_level_to_ecio (guint ecn0_level, + gpointer log_object, + gdouble *out_ecio); +gboolean mm_3gpp_rsrq_level_to_rsrq (guint rsrq_level, + gpointer log_object, + gdouble *out_rsrq); +gboolean mm_3gpp_rsrp_level_to_rsrp (guint rsrp_level, + gpointer log_object, + gdouble *out_rsrp); +gboolean mm_3gpp_rssnr_level_to_rssnr (gint rssnr_level, + gpointer log_object, + gdouble *out_rssnr); GStrv mm_3gpp_parse_emergency_numbers (const char *raw, GError **error); diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index e025fe2e..8b39f90e 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -3910,6 +3910,7 @@ test_cesq_response_to_signal (void) MMSignal *lte = NULL; success = mm_3gpp_cesq_response_to_signal_info (cesq_response_tests[i].str, + NULL, &gsm, &umts, <e, &error); g_assert_no_error (error); From 105cb31e8cb423ff9b1e4bbeffce0124006be5fd Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 12:15:49 +0200 Subject: [PATCH 085/675] modem-helpers: port ccwa service query parser to use object logging --- src/mm-broadband-modem.c | 2 +- src/mm-modem-helpers.c | 5 +++-- src/mm-modem-helpers.h | 1 + src/tests/test-modem-helpers.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 5d5a219a..21600d77 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -8311,7 +8311,7 @@ modem_voice_call_waiting_query_finish (MMIfaceModemVoice *self, if (!response) return FALSE; - return mm_3gpp_parse_ccwa_service_query_response (response, status, error); + return mm_3gpp_parse_ccwa_service_query_response (response, self, status, error); } static void diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 36f3dfb4..e7ee6e20 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -2846,6 +2846,7 @@ mm_3gpp_parse_cemode_query_response (const gchar *response, gboolean mm_3gpp_parse_ccwa_service_query_response (const gchar *response, + gpointer log_object, gboolean *status, GError **error) { @@ -2881,10 +2882,10 @@ mm_3gpp_parse_ccwa_service_query_response (const gchar *response, guint class; if (!mm_get_uint_from_match_info (match_info, 2, &class)) - mm_warn ("couldn't parse class from +CCWA line"); + mm_obj_warn (log_object, "couldn't parse class from +CCWA line"); else if (class == 1 || class == 255) { if (!mm_get_uint_from_match_info (match_info, 1, &st)) - mm_warn ("couldn't parse status from +CCWA line"); + mm_obj_warn (log_object, "couldn't parse status from +CCWA line"); else { class_1_status = st; break; diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index d2c1a5a6..316b26d3 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -415,6 +415,7 @@ gboolean mm_3gpp_parse_cemode_query_response (const gchar *r /* CCWA service query response parser */ gboolean mm_3gpp_parse_ccwa_service_query_response (const gchar *response, + gpointer log_object, gboolean *status, GError **error); diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 8b39f90e..a01b0fd9 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -4133,7 +4133,7 @@ common_test_ccwa_response (const gchar *response, GError *error = NULL; gboolean result; - result = mm_3gpp_parse_ccwa_service_query_response (response, &status, &error); + result = mm_3gpp_parse_ccwa_service_query_response (response, NULL, &status, &error); if (expected_error) { g_assert (!result); From 7004f97093a3b44c793dcb930e432940d0663137 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 12:24:46 +0200 Subject: [PATCH 086/675] modem-helpers: make cpms test parser return error on failure --- src/mm-broadband-modem.c | 9 ++---- src/mm-modem-helpers.c | 50 ++++++++++++++-------------------- src/mm-modem-helpers.h | 9 +++--- src/tests/test-modem-helpers.c | 24 ++++++++++++---- 4 files changed, 47 insertions(+), 45 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 21600d77..d2812051 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -6298,13 +6298,10 @@ cpms_format_check_ready (MMBroadbandModem *self, if (!mm_3gpp_parse_cpms_test_response (response, &result->mem1, &result->mem2, - &result->mem3)) { + &result->mem3, + &error)) { supported_storages_result_free (result); - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't parse supported storages reply: '%s'", - response); + g_task_return_error (task, error); g_object_unref (task); return; } diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index e7ee6e20..e12a26b7 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -2942,17 +2942,18 @@ storage_from_str (const gchar *str) } gboolean -mm_3gpp_parse_cpms_test_response (const gchar *reply, - GArray **mem1, - GArray **mem2, - GArray **mem3) +mm_3gpp_parse_cpms_test_response (const gchar *reply, + GArray **mem1, + GArray **mem2, + GArray **mem3, + GError **error) { - GRegex *r; - gchar **split; guint i; - GArray *tmp1 = NULL; - GArray *tmp2 = NULL; - GArray *tmp3 = NULL; + g_autoptr(GRegex) r = NULL; + g_autoptr(GArray) tmp1 = NULL; + g_autoptr(GArray) tmp2 = NULL; + g_autoptr(GArray) tmp3 = NULL; + g_auto(GStrv) split = NULL; g_assert (mem1 != NULL); g_assert (mem2 != NULL); @@ -2965,9 +2966,9 @@ mm_3gpp_parse_cpms_test_response (const gchar *reply, return FALSE; if (g_strv_length (split) != N_EXPECTED_GROUPS) { - mm_warn ("Cannot parse +CPMS test response: invalid number of groups (%u != %u)", - g_strv_length (split), N_EXPECTED_GROUPS); - g_strfreev (split); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Cannot parse +CPMS test response: invalid number of groups (%u != %u)", + g_strv_length (split), N_EXPECTED_GROUPS); return FALSE; } @@ -3010,29 +3011,20 @@ mm_3gpp_parse_cpms_test_response (const gchar *reply, g_assert_not_reached (); } - g_strfreev (split); - g_regex_unref (r); - - g_warn_if_fail (tmp1 != NULL); - g_warn_if_fail (tmp2 != NULL); - g_warn_if_fail (tmp3 != NULL); - /* Only return TRUE if all sets have been parsed correctly * (even if the arrays may be empty) */ if (tmp1 && tmp2 && tmp3) { - *mem1 = tmp1; - *mem2 = tmp2; - *mem3 = tmp3; + *mem1 = g_steal_pointer (&tmp1); + *mem2 = g_steal_pointer (&tmp2); + *mem3 = g_steal_pointer (&tmp3); return TRUE; } - /* Otherwise, cleanup and return FALSE */ - if (tmp1) - g_array_unref (tmp1); - if (tmp2) - g_array_unref (tmp2); - if (tmp3) - g_array_unref (tmp3); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Cannot parse +CPMS test response: mem1 %s, mem2 %s, mem3 %s", + tmp1 ? "yes" : "no", + tmp2 ? "yes" : "no", + tmp3 ? "yes" : "no"); return FALSE; } diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 316b26d3..3ad03ef8 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -234,10 +234,11 @@ gboolean mm_3gpp_parse_cmgf_test_response (const gchar *reply, GError **error); /* AT+CPMS=? (Preferred SMS storage) response parser */ -gboolean mm_3gpp_parse_cpms_test_response (const gchar *reply, - GArray **mem1, - GArray **mem2, - GArray **mem3); +gboolean mm_3gpp_parse_cpms_test_response (const gchar *reply, + GArray **mem1, + GArray **mem2, + GArray **mem3, + GError **error); /* AT+CPMS? (Current SMS storage) response parser */ gboolean mm_3gpp_parse_cpms_query_response (const gchar *reply, diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index a01b0fd9..3a4fdd63 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -2901,10 +2901,12 @@ test_cpms_response_cinterion (void *f, gpointer d) GArray *mem1 = NULL; GArray *mem2 = NULL; GArray *mem3 = NULL; + GError *error = NULL; g_debug ("Testing Cinterion +CPMS=? response..."); - g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3)); + g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error)); + g_assert_no_error (error); g_assert_cmpuint (mem1->len, ==, 2); g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME)); g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT)); @@ -2929,10 +2931,12 @@ test_cpms_response_huawei_mu609 (void *f, gpointer d) GArray *mem1 = NULL; GArray *mem2 = NULL; GArray *mem3 = NULL; + GError *error = NULL; g_debug ("Testing Huawei MU609 +CPMS=? response..."); - g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3)); + g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error)); + g_assert_no_error (error); g_assert_cmpuint (mem1->len, ==, 1); g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME)); g_assert_cmpuint (mem2->len, ==, 1); @@ -2953,10 +2957,12 @@ test_cpms_response_nokia_c6 (void *f, gpointer d) GArray *mem1 = NULL; GArray *mem2 = NULL; GArray *mem3 = NULL; + GError *error = NULL; g_debug ("Testing Nokia C6 response..."); - g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3)); + g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error)); + g_assert_no_error (error); g_assert_cmpuint (mem1->len, ==, 0); g_assert_cmpuint (mem2->len, ==, 0); g_assert_cmpuint (mem3->len, ==, 0); @@ -2978,10 +2984,12 @@ test_cpms_response_mixed (void *f, gpointer d) GArray *mem1 = NULL; GArray *mem2 = NULL; GArray *mem3 = NULL; + GError *error = NULL; g_debug ("Testing mixed +CPMS=? response..."); - g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3)); + g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error)); + g_assert_no_error (error); g_assert_cmpuint (mem1->len, ==, 2); g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME)); g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT)); @@ -3003,10 +3011,12 @@ test_cpms_response_mixed_spaces (void *f, gpointer d) GArray *mem1 = NULL; GArray *mem2 = NULL; GArray *mem3 = NULL; + GError *error = NULL; g_debug ("Testing mixed +CPMS=? response with spaces..."); - g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3)); + g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error)); + g_assert_no_error (error); g_assert_cmpuint (mem1->len, ==, 2); g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME)); g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT)); @@ -3032,10 +3042,12 @@ test_cpms_response_empty_fields (void *f, gpointer d) GArray *mem1 = NULL; GArray *mem2 = NULL; GArray *mem3 = NULL; + GError *error = NULL; g_debug ("Testing mixed +CPMS=? response..."); - g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3)); + g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error)); + g_assert_no_error (error); g_assert_cmpuint (mem1->len, ==, 0); g_assert_cmpuint (mem2->len, ==, 0); g_assert_cmpuint (mem3->len, ==, 0); From 4be88b899ecc1102973c541dec0e916b22178e0d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 13:53:28 +0200 Subject: [PATCH 087/675] modem-helpers-mbim: port to use object logging --- src/mm-bearer-mbim.c | 2 +- src/mm-broadband-modem-mbim.c | 2 +- src/mm-modem-helpers-mbim.c | 5 +++-- src/mm-modem-helpers-mbim.h | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mm-bearer-mbim.c b/src/mm-bearer-mbim.c index ce413a71..57f10cb7 100644 --- a/src/mm-bearer-mbim.c +++ b/src/mm-bearer-mbim.c @@ -964,7 +964,7 @@ connect_context_step (GTask *task) MMBearerAllowedAuth bearer_auth; bearer_auth = mm_bearer_properties_get_allowed_auth (ctx->properties); - auth = mm_bearer_allowed_auth_to_mbim_auth_protocol (bearer_auth, &error); + auth = mm_bearer_allowed_auth_to_mbim_auth_protocol (bearer_auth, self, &error); if (error) { g_task_return_error (task, error); g_object_unref (task); diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index c524b7ff..bd2a0b3f 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -2830,7 +2830,7 @@ before_set_lte_attach_configuration_query_ready (MbimDevice *device, if (auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) configurations[i]->auth_protocol = MBIM_AUTH_PROTOCOL_NONE; else { - configurations[i]->auth_protocol = mm_bearer_allowed_auth_to_mbim_auth_protocol (auth, &error); + configurations[i]->auth_protocol = mm_bearer_allowed_auth_to_mbim_auth_protocol (auth, self, &error); if (error) { configurations[i]->auth_protocol = MBIM_AUTH_PROTOCOL_NONE; mm_obj_warn (self, "unexpected auth settings requested: %s", error->message); diff --git a/src/mm-modem-helpers-mbim.c b/src/mm-modem-helpers-mbim.c index eb68467e..8d8697b9 100644 --- a/src/mm-modem-helpers-mbim.c +++ b/src/mm-modem-helpers-mbim.c @@ -17,7 +17,7 @@ #include "mm-modem-helpers.h" #include "mm-enums-types.h" #include "mm-errors-types.h" -#include "mm-log.h" +#include "mm-log-object.h" /*****************************************************************************/ @@ -367,6 +367,7 @@ mm_bearer_allowed_auth_from_mbim_auth_protocol (MbimAuthProtocol auth_protocol) MbimAuthProtocol mm_bearer_allowed_auth_to_mbim_auth_protocol (MMBearerAllowedAuth bearer_auth, + gpointer log_object, GError **error) { gchar *str; @@ -374,7 +375,7 @@ mm_bearer_allowed_auth_to_mbim_auth_protocol (MMBearerAllowedAuth bearer_auth, /* NOTE: the input is a BITMASK, so we try to find a "best match" */ if (bearer_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { - mm_dbg ("Using default (PAP) authentication method"); + mm_obj_dbg (log_object, "using default (PAP) authentication method"); return MBIM_AUTH_PROTOCOL_PAP; } if (bearer_auth & MM_BEARER_ALLOWED_AUTH_PAP) diff --git a/src/mm-modem-helpers-mbim.h b/src/mm-modem-helpers-mbim.h index a648cac9..f9d509f8 100644 --- a/src/mm-modem-helpers-mbim.h +++ b/src/mm-modem-helpers-mbim.h @@ -41,6 +41,7 @@ GError *mm_mobile_equipment_error_from_mbim_nw_error (MbimNwError nw_error); MMBearerAllowedAuth mm_bearer_allowed_auth_from_mbim_auth_protocol (MbimAuthProtocol auth_protocol); MbimAuthProtocol mm_bearer_allowed_auth_to_mbim_auth_protocol (MMBearerAllowedAuth bearer_auth, + gpointer log_object, GError **error); MMBearerIpFamily mm_bearer_ip_family_from_mbim_context_ip_type (MbimContextIpType ip_type); MbimContextIpType mm_bearer_ip_family_to_mbim_context_ip_type (MMBearerIpFamily ip_family, From fc76e797d7eeb8c13677ecc4eb24f8096497ffc3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 13:57:53 +0200 Subject: [PATCH 088/675] modem-helpers-qmi: port qmi band parser to use object logging --- src/mm-modem-helpers-qmi.c | 77 ++++++++++++++++++++------------------ src/mm-modem-helpers-qmi.h | 25 +++++++------ src/mm-shared-qmi.c | 8 ++-- 3 files changed, 60 insertions(+), 50 deletions(-) diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index baf6f3d2..90366d32 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -22,7 +22,7 @@ #include "mm-modem-helpers-qmi.h" #include "mm-modem-helpers.h" #include "mm-enums-types.h" -#include "mm-log.h" +#include "mm-log-object.h" /*****************************************************************************/ @@ -217,8 +217,9 @@ static const DmsBandsMap dms_bands_map [] = { }; static void -dms_add_qmi_bands (GArray *mm_bands, - QmiDmsBandCapability qmi_bands) +dms_add_qmi_bands (GArray *mm_bands, + QmiDmsBandCapability qmi_bands, + gpointer log_object) { static QmiDmsBandCapability qmi_bands_expected = 0; QmiDmsBandCapability not_expected; @@ -236,11 +237,10 @@ dms_add_qmi_bands (GArray *mm_bands, /* Log about the bands that cannot be represented in ModemManager */ not_expected = ((qmi_bands_expected ^ qmi_bands) & qmi_bands); if (not_expected) { - gchar *aux; + g_autofree gchar *aux = NULL; aux = qmi_dms_band_capability_build_string_from_mask (not_expected); - mm_dbg ("Cannot add the following bands: '%s'", aux); - g_free (aux); + mm_obj_dbg (log_object, "cannot add the following bands: '%s'", aux); } /* And add the expected ones */ @@ -314,8 +314,9 @@ dms_add_qmi_lte_bands (GArray *mm_bands, } static void -dms_add_extended_qmi_lte_bands (GArray *mm_bands, - GArray *extended_qmi_bands) +dms_add_extended_qmi_lte_bands (GArray *mm_bands, + GArray *extended_qmi_bands, + gpointer log_object) { guint i; @@ -334,7 +335,7 @@ dms_add_extended_qmi_lte_bands (GArray *mm_bands, * MM_MODEM_BAND_EUTRAN_71 = 101 */ if (val < 1 || val > 71) - mm_dbg ("Unexpected LTE band supported by module: EUTRAN %u", val); + mm_obj_dbg (log_object, "unexpected LTE band supported by module: EUTRAN %u", val); else { MMModemBand band; @@ -345,17 +346,18 @@ dms_add_extended_qmi_lte_bands (GArray *mm_bands, } GArray * -mm_modem_bands_from_qmi_band_capabilities (QmiDmsBandCapability qmi_bands, - QmiDmsLteBandCapability qmi_lte_bands, - GArray *extended_qmi_lte_bands) +mm_modem_bands_from_qmi_band_capabilities (QmiDmsBandCapability qmi_bands, + QmiDmsLteBandCapability qmi_lte_bands, + GArray *extended_qmi_lte_bands, + gpointer log_object) { GArray *mm_bands; mm_bands = g_array_new (FALSE, FALSE, sizeof (MMModemBand)); - dms_add_qmi_bands (mm_bands, qmi_bands); + dms_add_qmi_bands (mm_bands, qmi_bands, log_object); if (extended_qmi_lte_bands) - dms_add_extended_qmi_lte_bands (mm_bands, extended_qmi_lte_bands); + dms_add_extended_qmi_lte_bands (mm_bands, extended_qmi_lte_bands, log_object); else dms_add_qmi_lte_bands (mm_bands, qmi_lte_bands); @@ -421,8 +423,9 @@ static const NasBandsMap nas_bands_map [] = { }; static void -nas_add_qmi_bands (GArray *mm_bands, - QmiNasBandPreference qmi_bands) +nas_add_qmi_bands (GArray *mm_bands, + QmiNasBandPreference qmi_bands, + gpointer log_object) { static QmiNasBandPreference qmi_bands_expected = 0; QmiNasBandPreference not_expected; @@ -440,11 +443,10 @@ nas_add_qmi_bands (GArray *mm_bands, /* Log about the bands that cannot be represented in ModemManager */ not_expected = ((qmi_bands_expected ^ qmi_bands) & qmi_bands); if (not_expected) { - gchar *aux; + g_autofree gchar *aux = NULL; aux = qmi_nas_band_preference_build_string_from_mask (not_expected); - mm_dbg ("Cannot add the following bands: '%s'", aux); - g_free (aux); + mm_obj_dbg (log_object, "cannot add the following bands: '%s'", aux); } /* And add the expected ones */ @@ -518,9 +520,10 @@ nas_add_qmi_lte_bands (GArray *mm_bands, } static void -nas_add_extended_qmi_lte_bands (GArray *mm_bands, +nas_add_extended_qmi_lte_bands (GArray *mm_bands, const guint64 *extended_qmi_lte_bands, - guint extended_qmi_lte_bands_size) + guint extended_qmi_lte_bands_size, + gpointer log_object) { guint i; @@ -542,7 +545,7 @@ nas_add_extended_qmi_lte_bands (GArray *mm_bands, * MM_MODEM_BAND_EUTRAN_71 = 101 */ if (val < 1 || val > 71) - mm_dbg ("Unexpected LTE band supported by module: EUTRAN %u", val); + mm_obj_dbg (log_object, "unexpected LTE band supported by module: EUTRAN %u", val); else { MMModemBand band; @@ -554,18 +557,19 @@ nas_add_extended_qmi_lte_bands (GArray *mm_bands, } GArray * -mm_modem_bands_from_qmi_band_preference (QmiNasBandPreference qmi_bands, - QmiNasLteBandPreference qmi_lte_bands, - const guint64 *extended_qmi_lte_bands, - guint extended_qmi_lte_bands_size) +mm_modem_bands_from_qmi_band_preference (QmiNasBandPreference qmi_bands, + QmiNasLteBandPreference qmi_lte_bands, + const guint64 *extended_qmi_lte_bands, + guint extended_qmi_lte_bands_size, + gpointer log_object) { GArray *mm_bands; mm_bands = g_array_new (FALSE, FALSE, sizeof (MMModemBand)); - nas_add_qmi_bands (mm_bands, qmi_bands); + nas_add_qmi_bands (mm_bands, qmi_bands, log_object); if (extended_qmi_lte_bands && extended_qmi_lte_bands_size) - nas_add_extended_qmi_lte_bands (mm_bands, extended_qmi_lte_bands, extended_qmi_lte_bands_size); + nas_add_extended_qmi_lte_bands (mm_bands, extended_qmi_lte_bands, extended_qmi_lte_bands_size, log_object); else nas_add_qmi_lte_bands (mm_bands, qmi_lte_bands); @@ -573,11 +577,12 @@ mm_modem_bands_from_qmi_band_preference (QmiNasBandPreference qmi_bands, } void -mm_modem_bands_to_qmi_band_preference (GArray *mm_bands, - QmiNasBandPreference *qmi_bands, +mm_modem_bands_to_qmi_band_preference (GArray *mm_bands, + QmiNasBandPreference *qmi_bands, QmiNasLteBandPreference *qmi_lte_bands, - guint64 *extended_qmi_lte_bands, - guint extended_qmi_lte_bands_size) + guint64 *extended_qmi_lte_bands, + guint extended_qmi_lte_bands_size, + gpointer log_object) { guint i; @@ -618,8 +623,8 @@ mm_modem_bands_to_qmi_band_preference (GArray *mm_bands, } if (j == G_N_ELEMENTS (nas_lte_bands_map)) - mm_dbg ("Cannot add the following LTE band: '%s'", - mm_modem_band_get_string (band)); + mm_obj_dbg (log_object, "cannot add the following LTE band: '%s'", + mm_modem_band_get_string (band)); } } else { /* Add non-LTE band preference */ @@ -633,8 +638,8 @@ mm_modem_bands_to_qmi_band_preference (GArray *mm_bands, } if (j == G_N_ELEMENTS (nas_bands_map)) - mm_dbg ("Cannot add the following band: '%s'", - mm_modem_band_get_string (band)); + mm_obj_dbg (log_object, "cannot add the following band: '%s'", + mm_modem_band_get_string (band)); } } } diff --git a/src/mm-modem-helpers-qmi.h b/src/mm-modem-helpers-qmi.h index 5c0200e4..995a0634 100644 --- a/src/mm-modem-helpers-qmi.h +++ b/src/mm-modem-helpers-qmi.h @@ -34,9 +34,10 @@ MMModemLock mm_modem_lock_from_qmi_uim_pin_status (QmiDmsUimPinStatus status, gboolean mm_pin_enabled_from_qmi_uim_pin_status (QmiDmsUimPinStatus status); QmiDmsUimFacility mm_3gpp_facility_to_qmi_uim_facility (MMModem3gppFacility mm); -GArray *mm_modem_bands_from_qmi_band_capabilities (QmiDmsBandCapability qmi_bands, - QmiDmsLteBandCapability qmi_lte_bands, - GArray *extended_qmi_lte_bands); +GArray *mm_modem_bands_from_qmi_band_capabilities (QmiDmsBandCapability qmi_bands, + QmiDmsLteBandCapability qmi_lte_bands, + GArray *extended_qmi_lte_bands, + gpointer log_object); /*****************************************************************************/ /* QMI/NAS to MM translations */ @@ -77,15 +78,17 @@ QmiNasGsmWcdmaAcquisitionOrderPreference mm_modem_mode_to_qmi_gsm_wcdma_acquisit GArray *mm_modem_bands_from_qmi_rf_band_information_array (GArray *info_array); -GArray *mm_modem_bands_from_qmi_band_preference (QmiNasBandPreference qmi_bands, - QmiNasLteBandPreference qmi_lte_bands, - const guint64 *extended_qmi_lte_bands, - guint extended_qmi_lte_bands_size); -void mm_modem_bands_to_qmi_band_preference (GArray *mm_bands, - QmiNasBandPreference *qmi_bands, +GArray *mm_modem_bands_from_qmi_band_preference (QmiNasBandPreference qmi_bands, + QmiNasLteBandPreference qmi_lte_bands, + const guint64 *extended_qmi_lte_bands, + guint extended_qmi_lte_bands_size, + gpointer log_object); +void mm_modem_bands_to_qmi_band_preference (GArray *mm_bands, + QmiNasBandPreference *qmi_bands, QmiNasLteBandPreference *qmi_lte_bands, - guint64 *extended_qmi_lte_bands, - guint extended_qmi_lte_bands_size); + guint64 *extended_qmi_lte_bands, + guint extended_qmi_lte_bands_size, + gpointer log_object); MMModem3gppRegistrationState mm_modem_3gpp_registration_state_from_qmi_registration_state (QmiNasAttachState attach_state, QmiNasRegistrationState registration_state, diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 95b270a3..dbfab627 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -1679,7 +1679,7 @@ dms_get_band_capabilities_ready (QmiClientDms *client, &extended_qmi_lte_bands, NULL); - mm_bands = mm_modem_bands_from_qmi_band_capabilities (qmi_bands, qmi_lte_bands, extended_qmi_lte_bands); + mm_bands = mm_modem_bands_from_qmi_band_capabilities (qmi_bands, qmi_lte_bands, extended_qmi_lte_bands, self); if (mm_bands->len == 0) { g_clear_pointer (&mm_bands, g_array_unref); error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, @@ -1787,7 +1787,8 @@ load_bands_get_system_selection_preference_ready (QmiClientNas *client, mm_bands = mm_modem_bands_from_qmi_band_preference (band_preference_mask, lte_band_preference_mask, extended_lte_band_preference_size ? extended_lte_band_preference : NULL, - extended_lte_band_preference_size); + extended_lte_band_preference_size, + self); if (mm_bands->len == 0) { g_clear_pointer (&mm_bands, g_array_unref); @@ -1902,7 +1903,8 @@ mm_shared_qmi_set_current_bands (MMIfaceModem *self, &qmi_bands, &qmi_lte_bands, priv->feature_extended_lte_band_preference == FEATURE_SUPPORTED ? extended_qmi_lte_bands : NULL, - G_N_ELEMENTS (extended_qmi_lte_bands)); + G_N_ELEMENTS (extended_qmi_lte_bands), + self); input = qmi_message_nas_set_system_selection_preference_input_new (); qmi_message_nas_set_system_selection_preference_input_set_band_preference (input, qmi_bands, NULL); From f03fb06d8eed9678629ec31fd8611e6e70f341ae Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 13:59:46 +0200 Subject: [PATCH 089/675] modem-helpers-qmi: port qmi interface parser to use object logging --- src/mm-modem-helpers-qmi.c | 12 ++++++------ src/mm-modem-helpers-qmi.h | 6 ++++-- src/mm-shared-qmi.c | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 90366d32..05d5fa0a 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -27,7 +27,8 @@ /*****************************************************************************/ MMModemCapability -mm_modem_capability_from_qmi_radio_interface (QmiDmsRadioInterface network) +mm_modem_capability_from_qmi_radio_interface (QmiDmsRadioInterface network, + gpointer log_object) { switch (network) { case QMI_DMS_RADIO_INTERFACE_CDMA20001X: @@ -42,8 +43,7 @@ mm_modem_capability_from_qmi_radio_interface (QmiDmsRadioInterface network) return MM_MODEM_CAPABILITY_LTE; case QMI_DMS_RADIO_INTERFACE_5GNR: default: - mm_warn ("Unhandled QMI radio interface (%u)", - (guint)network); + mm_obj_warn (log_object, "unhandled QMI radio interface '%u'", (guint)network); return MM_MODEM_CAPABILITY_NONE; } } @@ -51,7 +51,8 @@ mm_modem_capability_from_qmi_radio_interface (QmiDmsRadioInterface network) /*****************************************************************************/ MMModemMode -mm_modem_mode_from_qmi_radio_interface (QmiDmsRadioInterface network) +mm_modem_mode_from_qmi_radio_interface (QmiDmsRadioInterface network, + gpointer log_object) { switch (network) { case QMI_DMS_RADIO_INTERFACE_CDMA20001X: @@ -66,8 +67,7 @@ mm_modem_mode_from_qmi_radio_interface (QmiDmsRadioInterface network) return MM_MODEM_MODE_4G; case QMI_DMS_RADIO_INTERFACE_5GNR: default: - mm_warn ("Unhandled QMI radio interface (%u)", - (guint)network); + mm_obj_warn (log_object, "unhandled QMI radio interface '%u'", (guint)network); return MM_MODEM_MODE_NONE; } } diff --git a/src/mm-modem-helpers-qmi.h b/src/mm-modem-helpers-qmi.h index 995a0634..319ae64b 100644 --- a/src/mm-modem-helpers-qmi.h +++ b/src/mm-modem-helpers-qmi.h @@ -24,9 +24,11 @@ /*****************************************************************************/ /* QMI/DMS to MM translations */ -MMModemCapability mm_modem_capability_from_qmi_radio_interface (QmiDmsRadioInterface network); +MMModemCapability mm_modem_capability_from_qmi_radio_interface (QmiDmsRadioInterface network, + gpointer log_object); -MMModemMode mm_modem_mode_from_qmi_radio_interface (QmiDmsRadioInterface network); +MMModemMode mm_modem_mode_from_qmi_radio_interface (QmiDmsRadioInterface network, + gpointer log_object); MMModemLock mm_modem_lock_from_qmi_uim_pin_status (QmiDmsUimPinStatus status, gboolean pin1); diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index dbfab627..3faa3bd3 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -761,7 +761,7 @@ load_current_capabilities_get_capabilities_ready (QmiClientDms *client, for (i = 0; i < radio_interface_list->len; i++) ctx->capabilities_context.dms_capabilities |= - mm_modem_capability_from_qmi_radio_interface (g_array_index (radio_interface_list, QmiDmsRadioInterface, i)); + mm_modem_capability_from_qmi_radio_interface (g_array_index (radio_interface_list, QmiDmsRadioInterface, i), self); out: if (output) @@ -997,7 +997,7 @@ mm_shared_qmi_load_supported_capabilities (MMIfaceModem *self, /* Build mask with all supported capabilities */ mask = MM_MODEM_CAPABILITY_NONE; for (i = 0; i < priv->supported_radio_interfaces->len; i++) - mask |= mm_modem_capability_from_qmi_radio_interface (g_array_index (priv->supported_radio_interfaces, QmiDmsRadioInterface, i)); + mask |= mm_modem_capability_from_qmi_radio_interface (g_array_index (priv->supported_radio_interfaces, QmiDmsRadioInterface, i), self); supported_combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), 3); @@ -1541,7 +1541,7 @@ mm_shared_qmi_load_supported_modes (MMIfaceModem *self, /* Build all, based on the supported radio interfaces */ mask_all = MM_MODEM_MODE_NONE; for (i = 0; i < priv->supported_radio_interfaces->len; i++) - mask_all |= mm_modem_mode_from_qmi_radio_interface (g_array_index (priv->supported_radio_interfaces, QmiDmsRadioInterface, i)); + mask_all |= mm_modem_mode_from_qmi_radio_interface (g_array_index (priv->supported_radio_interfaces, QmiDmsRadioInterface, i), self); mode.allowed = mask_all; mode.preferred = MM_MODEM_MODE_NONE; all = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 1); From 07b492c8879656aaaa795228edd3368f64c5504f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 14:21:43 +0200 Subject: [PATCH 090/675] modem-helpers-qmi: port acquisition order preference parser to use object logging --- src/mm-modem-helpers-qmi.c | 15 ++++++++------- src/mm-modem-helpers-qmi.h | 6 ++++-- src/mm-shared-qmi.c | 7 +++++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 05d5fa0a..21ff7618 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1257,7 +1257,8 @@ mm_modem_capability_from_qmi_band_preference (QmiNasBandPreference qmi) /*****************************************************************************/ MMModemMode -mm_modem_mode_from_qmi_gsm_wcdma_acquisition_order_preference (QmiNasGsmWcdmaAcquisitionOrderPreference qmi) +mm_modem_mode_from_qmi_gsm_wcdma_acquisition_order_preference (QmiNasGsmWcdmaAcquisitionOrderPreference qmi, + gpointer log_object) { switch (qmi) { case QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_AUTOMATIC: @@ -1267,16 +1268,17 @@ mm_modem_mode_from_qmi_gsm_wcdma_acquisition_order_preference (QmiNasGsmWcdmaAcq case QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_WCDMA: return MM_MODEM_MODE_3G; default: - mm_dbg ("Unknown acquisition order preference: '%s'", - qmi_nas_gsm_wcdma_acquisition_order_preference_get_string (qmi)); + mm_obj_dbg (log_object, "unknown acquisition order preference: '%s'", + qmi_nas_gsm_wcdma_acquisition_order_preference_get_string (qmi)); return MM_MODEM_MODE_NONE; } } QmiNasGsmWcdmaAcquisitionOrderPreference -mm_modem_mode_to_qmi_gsm_wcdma_acquisition_order_preference (MMModemMode mode) +mm_modem_mode_to_qmi_gsm_wcdma_acquisition_order_preference (MMModemMode mode, + gpointer log_object) { - gchar *str; + g_autofree gchar *str = NULL; /* mode is not a mask in this case, only a value */ @@ -1295,8 +1297,7 @@ mm_modem_mode_to_qmi_gsm_wcdma_acquisition_order_preference (MMModemMode mode) } str = mm_modem_mode_build_string_from_mask (mode); - mm_dbg ("Unhandled modem mode: '%s'", str); - g_free (str); + mm_obj_dbg (log_object, "unhandled modem mode: '%s'", str); return QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_AUTOMATIC; } diff --git a/src/mm-modem-helpers-qmi.h b/src/mm-modem-helpers-qmi.h index 319ae64b..a66b76ef 100644 --- a/src/mm-modem-helpers-qmi.h +++ b/src/mm-modem-helpers-qmi.h @@ -75,8 +75,10 @@ QmiNasRadioTechnologyPreference mm_modem_capability_to_qmi_radio_technology_pref MMModemCapability mm_modem_capability_from_qmi_band_preference (QmiNasBandPreference qmi); -MMModemMode mm_modem_mode_from_qmi_gsm_wcdma_acquisition_order_preference (QmiNasGsmWcdmaAcquisitionOrderPreference qmi); -QmiNasGsmWcdmaAcquisitionOrderPreference mm_modem_mode_to_qmi_gsm_wcdma_acquisition_order_preference (MMModemMode mode); +MMModemMode mm_modem_mode_from_qmi_gsm_wcdma_acquisition_order_preference (QmiNasGsmWcdmaAcquisitionOrderPreference qmi, + gpointer log_object); +QmiNasGsmWcdmaAcquisitionOrderPreference mm_modem_mode_to_qmi_gsm_wcdma_acquisition_order_preference (MMModemMode mode, + gpointer log_object); GArray *mm_modem_bands_from_qmi_rf_band_information_array (GArray *info_array); diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 3faa3bd3..6d0f22e7 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -1192,7 +1192,7 @@ set_current_modes_system_selection_preference (GTask *task) if (mm_iface_modem_is_3gpp (self) && ((ctx->allowed & (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G)) == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G))) { QmiNasGsmWcdmaAcquisitionOrderPreference order; - order = mm_modem_mode_to_qmi_gsm_wcdma_acquisition_order_preference (ctx->preferred); + order = mm_modem_mode_to_qmi_gsm_wcdma_acquisition_order_preference (ctx->preferred, self); qmi_message_nas_set_system_selection_preference_input_set_gsm_wcdma_acquisition_order_preference (input, order, NULL); } } @@ -1371,12 +1371,15 @@ load_current_modes_system_selection_preference_ready (QmiClientNas *client, GAsyncResult *res, GTask *task) { + MMSharedQmi *self; LoadCurrentModesResult *result = NULL; QmiMessageNasGetSystemSelectionPreferenceOutput *output = NULL; GError *error = NULL; QmiNasRatModePreference mode_preference_mask = 0; MMModemMode allowed; + self = g_task_get_source_object (task); + output = qmi_client_nas_get_system_selection_preference_finish (client, res, &error); if (!output || !qmi_message_nas_get_system_selection_preference_output_get_result (output, &error)) { g_task_return_error (task, error); @@ -1416,7 +1419,7 @@ load_current_modes_system_selection_preference_ready (QmiClientNas *client, output, &gsm_or_wcdma, NULL)) - result->preferred = mm_modem_mode_from_qmi_gsm_wcdma_acquisition_order_preference (gsm_or_wcdma); + result->preferred = mm_modem_mode_from_qmi_gsm_wcdma_acquisition_order_preference (gsm_or_wcdma, self); } /* Otherwise, rely on the acquisition order array TLV */ else { From bca5c5e42363646d3d91daef3d328cecc2a205e3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 14:25:46 +0200 Subject: [PATCH 091/675] modem-helpers-qmi: port qmi capabilities parser to use object logging --- src/mm-modem-helpers-qmi.c | 32 ++++++++++++++---------------- src/mm-modem-helpers-qmi.h | 3 ++- src/mm-shared-qmi.c | 2 +- src/tests/test-modem-helpers-qmi.c | 2 +- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 21ff7618..90a25996 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1456,13 +1456,14 @@ mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth) * as there would be no capability switching support. */ MMModemCapability -mm_modem_capability_from_qmi_capabilities_context (MMQmiCapabilitiesContext *ctx) +mm_modem_capability_from_qmi_capabilities_context (MMQmiCapabilitiesContext *ctx, + gpointer log_object) { MMModemCapability tmp = MM_MODEM_CAPABILITY_NONE; - gchar *nas_ssp_mode_preference_str; - gchar *nas_tp_str; - gchar *dms_capabilities_str; - gchar *tmp_str; + g_autofree gchar *nas_ssp_mode_preference_str = NULL; + g_autofree gchar *nas_tp_str = NULL; + g_autofree gchar *dms_capabilities_str = NULL; + g_autofree gchar *tmp_str = NULL; /* If not a multimode device, we're done */ #define MULTIMODE (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO) @@ -1494,18 +1495,15 @@ mm_modem_capability_from_qmi_capabilities_context (MMQmiCapabilitiesContext *ctx nas_tp_str = qmi_nas_radio_technology_preference_build_string_from_mask (ctx->nas_tp_mask); dms_capabilities_str = mm_modem_capability_build_string_from_mask (ctx->dms_capabilities); tmp_str = mm_modem_capability_build_string_from_mask (tmp); - mm_dbg ("Current capabilities built: '%s'\n" - " SSP mode preference: '%s'\n" - " TP: '%s'\n" - " DMS Capabilities: '%s'", - tmp_str, - nas_ssp_mode_preference_str ? nas_ssp_mode_preference_str : "unknown", - nas_tp_str ? nas_tp_str : "unknown", - dms_capabilities_str); - g_free (nas_ssp_mode_preference_str); - g_free (nas_tp_str); - g_free (dms_capabilities_str); - g_free (tmp_str); + mm_obj_dbg (log_object, + "Current capabilities built: '%s'\n" + " SSP mode preference: '%s'\n" + " TP: '%s'\n" + " DMS Capabilities: '%s'", + tmp_str, + nas_ssp_mode_preference_str ? nas_ssp_mode_preference_str : "unknown", + nas_tp_str ? nas_tp_str : "unknown", + dms_capabilities_str); return tmp; } diff --git a/src/mm-modem-helpers-qmi.h b/src/mm-modem-helpers-qmi.h index a66b76ef..42cb6711 100644 --- a/src/mm-modem-helpers-qmi.h +++ b/src/mm-modem-helpers-qmi.h @@ -143,7 +143,8 @@ typedef struct { MMModemCapability dms_capabilities; } MMQmiCapabilitiesContext; -MMModemCapability mm_modem_capability_from_qmi_capabilities_context (MMQmiCapabilitiesContext *ctx); +MMModemCapability mm_modem_capability_from_qmi_capabilities_context (MMQmiCapabilitiesContext *ctx, + gpointer log_object); /*****************************************************************************/ /* QMI unique id manipulation */ diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 6d0f22e7..982bfd0b 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -897,7 +897,7 @@ load_current_capabilities_step (GTask *task) case LOAD_CURRENT_CAPABILITIES_STEP_LAST: g_assert (priv->feature_nas_technology_preference != FEATURE_UNKNOWN); g_assert (priv->feature_nas_system_selection_preference != FEATURE_UNKNOWN); - priv->current_capabilities = mm_modem_capability_from_qmi_capabilities_context (&ctx->capabilities_context); + priv->current_capabilities = mm_modem_capability_from_qmi_capabilities_context (&ctx->capabilities_context, self); g_task_return_int (task, priv->current_capabilities); g_object_unref (task); return; diff --git a/src/tests/test-modem-helpers-qmi.c b/src/tests/test-modem-helpers-qmi.c index e14a2282..e1f6af64 100644 --- a/src/tests/test-modem-helpers-qmi.c +++ b/src/tests/test-modem-helpers-qmi.c @@ -31,7 +31,7 @@ test_capabilities_expected (MMQmiCapabilitiesContext *ctx, gchar *expected_str; gchar *built_str; - built = mm_modem_capability_from_qmi_capabilities_context (ctx); + built = mm_modem_capability_from_qmi_capabilities_context (ctx, NULL); expected_str = mm_modem_capability_build_string_from_mask (expected); built_str = mm_modem_capability_build_string_from_mask (built); From bac9ed21cbe806280ff999facbd02935ccdefaba Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 14:29:44 +0200 Subject: [PATCH 092/675] kerneldevice,generic: remove logging --- src/kerneldevice/mm-kernel-device-generic-rules.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/kerneldevice/mm-kernel-device-generic-rules.c b/src/kerneldevice/mm-kernel-device-generic-rules.c index 1d874452..2e955a8c 100644 --- a/src/kerneldevice/mm-kernel-device-generic-rules.c +++ b/src/kerneldevice/mm-kernel-device-generic-rules.c @@ -316,7 +316,6 @@ load_rules_from_file (GArray *rules, gchar *line; guint first_rule_index; - mm_dbg ("[rules] loading rules from: %s", path); first_rule_index = rules->len; file = g_file_new_for_path (path); @@ -406,8 +405,6 @@ mm_kernel_device_generic_rules_load (const gchar *rules_dir, GArray *rules; GError *inner_error = NULL; - mm_dbg ("[rules] rules directory set to '%s'...", rules_dir); - rules = g_array_new (FALSE, FALSE, sizeof (MMUdevRule)); g_array_set_clear_func (rules, (GDestroyNotify) udev_rule_clear); @@ -431,8 +428,6 @@ mm_kernel_device_generic_rules_load (const gchar *rules_dir, goto out; } - mm_dbg ("[rules] %u loaded", rules->len); - out: if (rule_files) g_list_free_full (rule_files, g_free); From a2b57474dc60759416bc2a5a8808806fd3317c01 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 14:37:42 +0200 Subject: [PATCH 093/675] error-helpers: port to use object logging --- plugins/icera/mm-broadband-bearer-icera.c | 10 +++++---- src/mm-base-call.c | 2 +- src/mm-broadband-modem-mbim.c | 6 +++--- src/mm-broadband-modem.c | 2 +- src/mm-error-helpers.c | 25 ++++++++++++++--------- src/mm-error-helpers.h | 10 ++++----- src/mm-iface-modem-3gpp.c | 4 ++-- src/mm-iface-modem-simple.c | 2 +- src/mm-serial-parsers.c | 16 +++++++-------- src/mm-sim-mbim.c | 8 ++++---- src/tests/test-error-helpers.c | 2 +- 11 files changed, 47 insertions(+), 40 deletions(-) diff --git a/plugins/icera/mm-broadband-bearer-icera.c b/plugins/icera/mm-broadband-bearer-icera.c index b0c996de..567d12dc 100644 --- a/plugins/icera/mm-broadband-bearer-icera.c +++ b/plugins/icera/mm-broadband-bearer-icera.c @@ -483,8 +483,11 @@ ier_query_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { - const gchar *response; - GError *activation_error = NULL; + MMBroadbandBearerIcera *self; + const gchar *response; + GError *activation_error = NULL; + + self = g_task_get_source_object (task); response = mm_base_modem_at_command_full_finish (modem, res, NULL); if (response) { @@ -497,8 +500,7 @@ ier_query_ready (MMBaseModem *modem, * 33 - Requested service option not subscribed */ if (nw_activation_err == 27 || nw_activation_err == 33) - activation_error = mm_mobile_equipment_error_for_code ( - MM_MOBILE_EQUIPMENT_ERROR_GPRS_SERVICE_OPTION_NOT_SUBSCRIBED); + activation_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_GPRS_SERVICE_OPTION_NOT_SUBSCRIBED, self); } } diff --git a/src/mm-base-call.c b/src/mm-base-call.c index 792c6adb..149cfbd4 100644 --- a/src/mm-base-call.c +++ b/src/mm-base-call.c @@ -169,7 +169,7 @@ handle_start_ready (MMBaseCall *self, if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) || g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_CANCELLED)) { g_clear_error (&error); - error = mm_connection_error_for_code (MM_CONNECTION_ERROR_NO_DIALTONE); + error = mm_connection_error_for_code (MM_CONNECTION_ERROR_NO_DIALTONE, self); } /* Convert errors into call state updates */ diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index bd2a0b3f..7ccf74b1 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -995,12 +995,12 @@ unlock_required_subscriber_ready_state_ready (MbimDevice *device, * The MC7710 may use this while the SIM is not ready yet. */ break; case MBIM_SUBSCRIBER_READY_STATE_BAD_SIM: - error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG); + error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG, self); break; case MBIM_SUBSCRIBER_READY_STATE_FAILURE: case MBIM_SUBSCRIBER_READY_STATE_NOT_ACTIVATED: default: - error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_FAILURE); + error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_FAILURE, self); break; } } @@ -1020,7 +1020,7 @@ unlock_required_subscriber_ready_state_ready (MbimDevice *device, /* All retries consumed? issue error */ if (ctx->last_attempt) { if (ready_state == MBIM_SUBSCRIBER_READY_STATE_SIM_NOT_INSERTED) - g_task_return_error (task, mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_NOT_INSERTED)); + g_task_return_error (task, mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_NOT_INSERTED, self)); else g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Error waiting for SIM to get initialized"); diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index d2812051..143c736f 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -9682,7 +9682,7 @@ run_cdma_registration_checks_ready (MMBroadbandModem *self, mm_iface_modem_cdma_update_access_technologies ( MM_IFACE_MODEM_CDMA (self), MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN); - error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT); + error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT, self); g_task_return_error (task, error); g_object_unref (task); return; diff --git a/src/mm-error-helpers.c b/src/mm-error-helpers.c index 7ce32113..57486d8b 100644 --- a/src/mm-error-helpers.c +++ b/src/mm-error-helpers.c @@ -29,7 +29,8 @@ typedef struct { /* --- Connection errors --- */ GError * -mm_connection_error_for_code (MMConnectionError code) +mm_connection_error_for_code (MMConnectionError code, + gpointer log_object) { const gchar *msg; @@ -51,7 +52,7 @@ mm_connection_error_for_code (MMConnectionError code) break; default: - mm_dbg ("Invalid connection error code: %u", code); + mm_obj_dbg (log_object, "invalid connection error code: %u", code); /* uhm... make something up (yes, ok, lie!). */ code = MM_CONNECTION_ERROR_NO_CARRIER; msg = "No carrier"; @@ -149,7 +150,8 @@ static ErrorTable me_errors[] = { }; GError * -mm_mobile_equipment_error_for_code (MMMobileEquipmentError code) +mm_mobile_equipment_error_for_code (MMMobileEquipmentError code, + gpointer log_object) { guint i; @@ -162,14 +164,15 @@ mm_mobile_equipment_error_for_code (MMMobileEquipmentError code) } /* Not found? Then, default */ - mm_dbg ("Invalid mobile equipment error code: %u", (guint)code); + mm_obj_dbg (log_object, "invalid mobile equipment error code: %u", (guint)code); return g_error_new (MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, "Unknown error"); } GError * -mm_mobile_equipment_error_for_string (const gchar *str) +mm_mobile_equipment_error_for_string (const gchar *str, + gpointer log_object) { MMMobileEquipmentError code = MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN; const gchar *msg = NULL; @@ -198,7 +201,7 @@ mm_mobile_equipment_error_for_string (const gchar *str) /* Not found? Then, default */ if (!msg) { - mm_dbg ("Invalid mobile equipment error string: '%s' (%s)", str, buf); + mm_obj_dbg (log_object, "invalid mobile equipment error string: '%s' (%s)", str, buf); code = MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN; msg = "Unknown error"; } @@ -236,7 +239,8 @@ static ErrorTable msg_errors[] = { }; GError * -mm_message_error_for_code (MMMessageError code) +mm_message_error_for_code (MMMessageError code, + gpointer log_object) { guint i; @@ -249,14 +253,15 @@ mm_message_error_for_code (MMMessageError code) } /* Not found? Then, default */ - mm_dbg ("Invalid message error code: %u", (guint)code); + mm_obj_dbg (log_object, "invalid message error code: %u", (guint)code); return g_error_new (MM_MESSAGE_ERROR, MM_MESSAGE_ERROR_UNKNOWN, "Unknown error"); } GError * -mm_message_error_for_string (const gchar *str) +mm_message_error_for_string (const gchar *str, + gpointer log_object) { MMMessageError code = MM_MESSAGE_ERROR_UNKNOWN; const gchar *msg = NULL; @@ -285,7 +290,7 @@ mm_message_error_for_string (const gchar *str) /* Not found? Then, default */ if (!msg) { - mm_dbg ("Invalid message error string: '%s' (%s)", str, buf); + mm_obj_dbg (log_object, "invalid message error string: '%s' (%s)", str, buf); code = MM_MESSAGE_ERROR_UNKNOWN; msg = "Unknown error"; } diff --git a/src/mm-error-helpers.h b/src/mm-error-helpers.h index 379afb24..e99d1662 100644 --- a/src/mm-error-helpers.h +++ b/src/mm-error-helpers.h @@ -23,10 +23,10 @@ #include #include -GError *mm_connection_error_for_code (MMConnectionError code); -GError *mm_mobile_equipment_error_for_code (MMMobileEquipmentError code); -GError *mm_mobile_equipment_error_for_string (const gchar *str); -GError *mm_message_error_for_code (MMMessageError code); -GError *mm_message_error_for_string (const gchar *str); +GError *mm_connection_error_for_code (MMConnectionError code, gpointer log_object); +GError *mm_mobile_equipment_error_for_code (MMMobileEquipmentError code, gpointer log_object); +GError *mm_mobile_equipment_error_for_string (const gchar *str, gpointer log_object); +GError *mm_message_error_for_code (MMMessageError code, gpointer log_object); +GError *mm_message_error_for_string (const gchar *str, gpointer log_object); #endif /* MM_ERROR_HELPERS_H */ diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index fc8cdc79..cbd989f6 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -311,7 +311,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self, mm_obj_dbg (self, "registration denied"); register_in_network_context_complete_failed ( task, - mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_NOT_ALLOWED)); + mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_NOT_ALLOWED, self)); return; } @@ -333,7 +333,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self, mm_obj_dbg (self, "3GPP registration check timed out"); register_in_network_context_complete_failed ( task, - mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT)); + mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT, self)); return; } diff --git a/src/mm-iface-modem-simple.c b/src/mm-iface-modem-simple.c index 61ae662b..b0cf5e22 100644 --- a/src/mm-iface-modem-simple.c +++ b/src/mm-iface-modem-simple.c @@ -164,7 +164,7 @@ check_next_registration (GTask *task) /* No more tries of anything */ g_task_return_error ( task, - mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT)); + mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT, self)); g_object_unref (task); } diff --git a/src/mm-serial-parsers.c b/src/mm-serial-parsers.c index 62592455..b511302e 100644 --- a/src/mm-serial-parsers.c +++ b/src/mm-serial-parsers.c @@ -239,7 +239,7 @@ mm_serial_parser_v1_parse (gpointer data, if (found) { str = g_match_info_fetch (match_info, 1); g_assert (str); - local_error = mm_mobile_equipment_error_for_code (atoi (str)); + local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object); goto done; } g_match_info_free (match_info); @@ -252,7 +252,7 @@ mm_serial_parser_v1_parse (gpointer data, if (found) { str = g_match_info_fetch (match_info, 1); g_assert (str); - local_error = mm_mobile_equipment_error_for_code (atoi (str)); + local_error = mm_mobile_equipment_error_for_code (atoi (str), log_object); goto done; } g_match_info_free (match_info); @@ -264,7 +264,7 @@ mm_serial_parser_v1_parse (gpointer data, if (found) { str = g_match_info_fetch (match_info, 1); g_assert (str); - local_error = mm_message_error_for_code (atoi (str)); + local_error = mm_message_error_for_code (atoi (str), log_object); goto done; } g_match_info_free (match_info); @@ -276,7 +276,7 @@ mm_serial_parser_v1_parse (gpointer data, if (found) { str = g_match_info_fetch (match_info, 1); g_assert (str); - local_error = mm_mobile_equipment_error_for_string (str); + local_error = mm_mobile_equipment_error_for_string (str, log_object); goto done; } g_match_info_free (match_info); @@ -288,7 +288,7 @@ mm_serial_parser_v1_parse (gpointer data, if (found) { str = g_match_info_fetch (match_info, 1); g_assert (str); - local_error = mm_message_error_for_string (str); + local_error = mm_message_error_for_string (str, log_object); goto done; } g_match_info_free (match_info); @@ -300,7 +300,7 @@ mm_serial_parser_v1_parse (gpointer data, if (found) { str = g_match_info_fetch (match_info, 1); g_assert (str); - local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN); + local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object); goto done; } g_match_info_free (match_info); @@ -310,7 +310,7 @@ mm_serial_parser_v1_parse (gpointer data, response->str, response->len, 0, 0, &match_info, NULL); if (found) { - local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN); + local_error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN, log_object); goto done; } g_match_info_free (match_info); @@ -338,7 +338,7 @@ mm_serial_parser_v1_parse (gpointer data, code = MM_CONNECTION_ERROR_NO_CARRIER; } - local_error = mm_connection_error_for_code (code); + local_error = mm_connection_error_for_code (code, log_object); goto done; } g_match_info_free (match_info); diff --git a/src/mm-sim-mbim.c b/src/mm-sim-mbim.c index d1fc145f..f48bb31d 100644 --- a/src/mm-sim-mbim.c +++ b/src/mm-sim-mbim.c @@ -382,10 +382,10 @@ pin_set_enter_ready (MbimDevice *device, /* Sending PIN failed, build a better error to report */ if (pin_type == MBIM_PIN_TYPE_PIN1 && pin_state == MBIM_PIN_STATE_LOCKED) { g_error_free (error); - error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD); + error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD, self); } else if (pin_type == MBIM_PIN_TYPE_PUK1 && pin_state == MBIM_PIN_STATE_LOCKED) { g_error_free (error); - error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_PUK); + error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_PUK, self); } } } @@ -480,9 +480,9 @@ puk_set_enter_ready (MbimDevice *device, if (pin_type == MBIM_PIN_TYPE_PUK1 && pin_state == MBIM_PIN_STATE_LOCKED) { g_error_free (error); if (remaining_attempts == 0) - error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG); + error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG, self); else - error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD); + error = mm_mobile_equipment_error_for_code (MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD, self); } } } diff --git a/src/tests/test-error-helpers.c b/src/tests/test-error-helpers.c index ff67ed80..ae2b8626 100644 --- a/src/tests/test-error-helpers.c +++ b/src/tests/test-error-helpers.c @@ -38,7 +38,7 @@ \ enum_value = g_enum_get_value (enum_class, i); \ if (enum_value) { \ - error = mm_## ERROR_SMALL ## _for_code ((MM##ERROR_CAMEL)i); \ + error = mm_## ERROR_SMALL ## _for_code ((MM##ERROR_CAMEL)i, NULL); \ g_assert_error (error, MM_ ## ERROR_CAPS, i); \ g_error_free (error); \ } \ From 2376859f36f56b2a63f8f6c13094aad0b129b279 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 14:51:22 +0200 Subject: [PATCH 094/675] charsets: report GError in byte_array_append() failures --- src/mm-broadband-modem-mbim.c | 12 ++++++------ src/mm-broadband-modem.c | 19 +++++++++---------- src/mm-charsets.c | 28 ++++++++++++---------------- src/mm-charsets.h | 9 +++++---- src/mm-sms-part-3gpp.c | 28 ++++++++++++++-------------- src/mm-sms-part-cdma.c | 29 ++++++++++++++++++----------- 6 files changed, 64 insertions(+), 61 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 7ccf74b1..d834beb0 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4561,7 +4561,7 @@ ussd_encode (const gchar *command, guint32 *scheme, GError **error) { - GByteArray *array; + g_autoptr(GByteArray) array = NULL; if (mm_charset_can_convert_to (command, MM_MODEM_CHARSET_GSM)) { guint8 *gsm; @@ -4581,12 +4581,13 @@ ussd_encode (const gchar *command, array = g_byte_array_new_take (packed, packed_len); } else { + g_autoptr(GError) inner_error = NULL; + *scheme = MM_MODEM_GSM_USSD_SCHEME_UCS2; array = g_byte_array_sized_new (strlen (command) * 2); - if (!mm_modem_charset_byte_array_append (array, command, FALSE, MM_MODEM_CHARSET_UCS2)) { + if (!mm_modem_charset_byte_array_append (array, command, FALSE, MM_MODEM_CHARSET_UCS2, &inner_error)) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, - "Failed to encode USSD command in UCS2 charset"); - g_byte_array_unref (array); + "Failed to encode USSD command in UCS2 charset: %s", inner_error->message); return NULL; } } @@ -4594,11 +4595,10 @@ ussd_encode (const gchar *command, if (array->len > 160) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, "Failed to encode USSD command: encoded data too long (%u > 160)", array->len); - g_byte_array_unref (array); return NULL; } - return array; + return g_steal_pointer (&array); } static gchar * diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 143c736f..deb3aa15 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -5800,14 +5800,14 @@ modem_3gpp_ussd_send (MMIfaceModem3gppUssd *_self, /* USSD Encode/Decode (3GPP/USSD interface) */ static gchar * -modem_3gpp_ussd_encode (MMIfaceModem3gppUssd *self, - const gchar *command, - guint *scheme, - GError **error) +modem_3gpp_ussd_encode (MMIfaceModem3gppUssd *self, + const gchar *command, + guint *scheme, + GError **error) { - MMBroadbandModem *broadband = MM_BROADBAND_MODEM (self); - GByteArray *ussd_command; - gchar *hex = NULL; + MMBroadbandModem *broadband = MM_BROADBAND_MODEM (self); + gchar *hex = NULL; + g_autoptr(GByteArray) ussd_command = NULL; ussd_command = g_byte_array_new (); @@ -5816,7 +5816,8 @@ modem_3gpp_ussd_encode (MMIfaceModem3gppUssd *self, if (mm_modem_charset_byte_array_append (ussd_command, command, FALSE, - broadband->priv->modem_current_charset)) { + broadband->priv->modem_current_charset, + NULL)) { /* The scheme value does NOT represent the encoding used to encode the string * we're giving. This scheme reflects the encoding that the modem should use when * sending the data out to the network. We're hardcoding this to GSM-7 because @@ -5827,8 +5828,6 @@ modem_3gpp_ussd_encode (MMIfaceModem3gppUssd *self, hex = mm_utils_bin2hexstr (ussd_command->data, ussd_command->len); } - g_byte_array_free (ussd_command, TRUE); - return hex; } diff --git a/src/mm-charsets.c b/src/mm-charsets.c index a5c70165..bf0de2b2 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -112,29 +112,26 @@ charset_iconv_from (MMModemCharset charset) } gboolean -mm_modem_charset_byte_array_append (GByteArray *array, - const char *utf8, - gboolean quoted, - MMModemCharset charset) +mm_modem_charset_byte_array_append (GByteArray *array, + const gchar *utf8, + gboolean quoted, + MMModemCharset charset, + GError **error) { - const char *iconv_to; - char *converted; - GError *error = NULL; - gsize written = 0; + g_autofree gchar *converted = NULL; + const gchar *iconv_to; + gsize written = 0; g_return_val_if_fail (array != NULL, FALSE); g_return_val_if_fail (utf8 != NULL, FALSE); iconv_to = charset_iconv_to (charset); - g_return_val_if_fail (iconv_to != NULL, FALSE); + g_assert (iconv_to); - converted = g_convert (utf8, -1, iconv_to, "UTF-8", NULL, &written, &error); + converted = g_convert (utf8, -1, iconv_to, "UTF-8", NULL, &written, error); if (!converted) { - if (error) { - mm_warn ("failed to convert '%s' to %s character set: (%d) %s", - utf8, iconv_to, error->code, error->message); - g_error_free (error); - } + g_prefix_error (error, "Failed to convert '%s' to %s character set", + utf8, iconv_to); return FALSE; } @@ -144,7 +141,6 @@ mm_modem_charset_byte_array_append (GByteArray *array, if (quoted) g_byte_array_append (array, (const guint8 *) "\"", 1); - g_free (converted); return TRUE; } diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 2e3e6f38..9e9215d5 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -38,10 +38,11 @@ MMModemCharset mm_modem_charset_from_string (const char *string); * into the given charset first. The original string is assumed to be * UTF-8 encoded. */ -gboolean mm_modem_charset_byte_array_append (GByteArray *array, - const char *utf8, - gboolean quoted, - MMModemCharset charset); +gboolean mm_modem_charset_byte_array_append (GByteArray *array, + const gchar *utf8, + gboolean quoted, + MMModemCharset charset, + GError **error); /* Take a string encoded in the given charset in binary form, and * convert it to UTF-8. */ diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index 7b8689ed..183d2868 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -1013,16 +1013,16 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, g_free (packed); offset += packlen; } else if (mm_sms_part_get_encoding (part) == MM_SMS_ENCODING_UCS2) { - GByteArray *array; + g_autoptr(GByteArray) array = NULL; + g_autoptr(GError) inner_error = NULL; /* Try to guess a good value for the array */ array = g_byte_array_sized_new (strlen (mm_sms_part_get_text (part)) * 2); - if (!mm_modem_charset_byte_array_append (array, mm_sms_part_get_text (part), FALSE, MM_MODEM_CHARSET_UCS2)) { - g_byte_array_free (array, TRUE); - g_set_error_literal (error, - MM_MESSAGE_ERROR, - MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER, - "Failed to convert message text to UCS2"); + if (!mm_modem_charset_byte_array_append (array, mm_sms_part_get_text (part), FALSE, MM_MODEM_CHARSET_UCS2, &inner_error)) { + g_set_error (error, + MM_MESSAGE_ERROR, + MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER, + "Failed to convert message text to UCS2: %s", inner_error->message); goto error; } @@ -1031,12 +1031,11 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, */ *udl_ptr = mm_sms_part_get_concat_sequence (part) ? (6 + array->len) : array->len; mm_obj_dbg (log_object, " user data length is %u octets (%s UDH)", - *udl_ptr, - mm_sms_part_get_concat_sequence (part) ? "with" : "without"); + *udl_ptr, + mm_sms_part_get_concat_sequence (part) ? "with" : "without"); memcpy (&pdu[offset], array->data, array->len); offset += array->len; - g_byte_array_free (array, TRUE); } else if (mm_sms_part_get_encoding (part) == MM_SMS_ENCODING_8BIT) { const GByteArray *data; @@ -1102,7 +1101,8 @@ mm_sms_part_3gpp_util_split_text (const gchar *text, /* Check if we can do GSM encoding */ if (!mm_charset_can_convert_to (text, MM_MODEM_CHARSET_GSM)) { /* If cannot do it in GSM encoding, do it in UCS-2 */ - GByteArray *array; + g_autoptr(GByteArray) array = NULL; + g_autoptr(GError) error = NULL; *encoding = MM_SMS_ENCODING_UCS2; @@ -1112,8 +1112,9 @@ mm_sms_part_3gpp_util_split_text (const gchar *text, if (!mm_modem_charset_byte_array_append (array, text, FALSE, - MM_MODEM_CHARSET_UCS2)) { - g_byte_array_unref (array); + MM_MODEM_CHARSET_UCS2, + &error)) { + mm_obj_warn (log_object, "failed to append UCS2: %s", error->message); return NULL; } @@ -1145,7 +1146,6 @@ mm_sms_part_3gpp_util_split_text (const gchar *text, log_object); } } - g_byte_array_unref (array); } else { /* Do it with GSM encoding */ *encoding = MM_SMS_ENCODING_GSM7; diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index 96302261..2903e846 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -1377,14 +1377,16 @@ write_bearer_data_message_identifier (MMSmsPart *part, static void decide_best_encoding (const gchar *text, + gpointer log_object, GByteArray **out, - guint *num_fields, - guint *num_bits_per_field, - Encoding *encoding) + guint *num_fields, + guint *num_bits_per_field, + Encoding *encoding) { guint ascii_unsupported = 0; guint i; guint len; + g_autoptr(GError) error = NULL; len = strlen (text); @@ -1409,10 +1411,12 @@ decide_best_encoding (const gchar *text, /* Check if we can do Latin encoding */ if (mm_charset_can_convert_to (text, MM_MODEM_CHARSET_8859_1)) { *out = g_byte_array_sized_new (len); - mm_modem_charset_byte_array_append (*out, - text, - FALSE, - MM_MODEM_CHARSET_8859_1); + if (!mm_modem_charset_byte_array_append (*out, + text, + FALSE, + MM_MODEM_CHARSET_8859_1, + &error)) + mm_obj_warn (log_object, "failed to convert to latin encoding: %s", error->message); *num_fields = (*out)->len; *num_bits_per_field = 8; *encoding = ENCODING_LATIN; @@ -1421,10 +1425,12 @@ decide_best_encoding (const gchar *text, /* If no Latin and no ASCII, default to UTF-16 */ *out = g_byte_array_sized_new (len * 2); - mm_modem_charset_byte_array_append (*out, - text, - FALSE, - MM_MODEM_CHARSET_UCS2); + if (!mm_modem_charset_byte_array_append (*out, + text, + FALSE, + MM_MODEM_CHARSET_UCS2, + &error)) + mm_obj_warn (log_object, "failed to convert to UTF-16 encoding: %s", error->message); *num_fields = (*out)->len / 2; *num_bits_per_field = 16; *encoding = ENCODING_UNICODE; @@ -1472,6 +1478,7 @@ write_bearer_data_user_data (MMSmsPart *part, /* Text or Data */ if (text) { decide_best_encoding (text, + log_object, &converted, &num_fields, &num_bits_per_field, From f5ce4a722a4c5d89778470cdf774ca822fee7ace Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 15:15:45 +0200 Subject: [PATCH 095/675] altair: port to use object logging --- .../altair/mm-broadband-bearer-altair-lte.c | 13 +---- .../altair/mm-broadband-modem-altair-lte.c | 58 +++++++------------ 2 files changed, 24 insertions(+), 47 deletions(-) diff --git a/plugins/altair/mm-broadband-bearer-altair-lte.c b/plugins/altair/mm-broadband-bearer-altair-lte.c index d8e1a0f8..4a5b0573 100644 --- a/plugins/altair/mm-broadband-bearer-altair-lte.c +++ b/plugins/altair/mm-broadband-bearer-altair-lte.c @@ -76,14 +76,11 @@ connect_3gpp_connect_ready (MMBaseModem *modem, result = mm_base_modem_at_command_full_finish (modem, res, &error); if (!result) { - mm_warn ("connect failed: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; } - mm_dbg ("Connected"); - ctx = g_task_get_task_data (task); config = mm_bearer_ip_config_new (); @@ -111,7 +108,7 @@ connect_3gpp_apnsettings_ready (MMBaseModem *modem, result = mm_base_modem_at_command_full_finish (modem, res, &error); if (!result) { - mm_warn ("setting APN failed: %s", error->message); + g_prefix_error (&error, "setting APN failed: "); g_task_return_error (task, error); g_object_unref (task); return; @@ -119,7 +116,6 @@ connect_3gpp_apnsettings_ready (MMBaseModem *modem, ctx = g_task_get_task_data (task); - mm_dbg ("APN set - connecting bearer"); mm_base_modem_at_command_full (ctx->modem, ctx->primary, "%DPDNACT=1", @@ -168,7 +164,7 @@ connect_3gpp (MMBroadbandBearer *self, * refresh. * */ if (mm_broadband_modem_altair_lte_is_sim_refresh_detach_in_progress (modem)) { - mm_dbg ("Detached from network to process SIM refresh, failing connect request"); + mm_obj_dbg (self, "detached from network to process SIM refresh, failing connect request"); g_task_report_new_error (self, callback, user_data, @@ -251,13 +247,10 @@ disconnect_3gpp_check_status (MMBaseModem *modem, GError *error = NULL; result = mm_base_modem_at_command_full_finish (modem, res, &error); - if (!result) { - mm_warn ("Disconnect failed: %s", error->message); + if (!result) g_task_return_error (task, error); - } else g_task_return_boolean (task, TRUE); - g_object_unref (task); } diff --git a/plugins/altair/mm-broadband-modem-altair-lte.c b/plugins/altair/mm-broadband-modem-altair-lte.c index 03912eae..5fafd94e 100644 --- a/plugins/altair/mm-broadband-modem-altair-lte.c +++ b/plugins/altair/mm-broadband-modem-altair-lte.c @@ -35,7 +35,7 @@ #include "mm-iface-modem-3gpp.h" #include "mm-iface-modem-3gpp-ussd.h" #include "mm-iface-modem-messaging.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-altair-lte.h" #include "mm-serial-parsers.h" @@ -50,7 +50,7 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemAltairLte, mm_broadband_modem_altair_lte G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP_USSD, iface_modem_3gpp_ussd_init) - G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_MESSAGING, iface_modem_messaging_init)); + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_MESSAGING, iface_modem_messaging_init)) struct _MMBroadbandModemAltairLtePrivate { /* Regex for SIM refresh notifications */ @@ -165,7 +165,6 @@ load_unlock_retries_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (self, res, &error); if (!response) { - mm_dbg ("Couldn't query unlock retries: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -234,8 +233,6 @@ load_current_capabilities (MMIfaceModem *self, { GTask *task; - mm_dbg ("Loading (Altair LTE) current capabilities..."); - task = g_task_new (self, NULL, callback, user_data); /* This modem is LTE only.*/ g_task_return_int (task, MM_MODEM_CAPABILITY_LTE); @@ -266,7 +263,6 @@ load_supported_bands_done (MMIfaceModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query supported bands: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -279,7 +275,6 @@ load_supported_bands_done (MMIfaceModem *self, bands = mm_altair_parse_bands_response (response); if (!bands) { - mm_dbg ("Failed to parse supported bands response"); g_task_return_new_error ( task, MM_CORE_ERROR, @@ -335,7 +330,6 @@ load_current_bands_done (MMIfaceModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query current bands: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -348,7 +342,6 @@ load_current_bands_done (MMIfaceModem *self, bands = mm_altair_parse_bands_response (response); if (!bands) { - mm_dbg ("Failed to parse current bands response"); g_task_return_new_error ( task, MM_CORE_ERROR, @@ -455,7 +448,7 @@ run_registration_checks_subscription_state_ready (MMIfaceModem3gpp *self, at_response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!at_response) { g_assert (error); - mm_warn ("AT+CEER failed: %s", error->message); + mm_obj_warn (self, "AT+CEER failed: %s", error->message); g_error_free (error); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -465,7 +458,7 @@ run_registration_checks_subscription_state_ready (MMIfaceModem3gpp *self, ceer_response = mm_altair_parse_ceer_response (at_response, &error); if (!ceer_response) { g_assert (error); - mm_warn ("Failed to parse AT+CEER response: %s", error->message); + mm_obj_warn (self, "Failed to parse AT+CEER response: %s", error->message); g_error_free (error); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -473,10 +466,10 @@ run_registration_checks_subscription_state_ready (MMIfaceModem3gpp *self, } if (g_strcmp0 ("EPS_AND_NON_EPS_SERVICES_NOT_ALLOWED", ceer_response) == 0) { - mm_dbg ("Registration failed due to unprovisioned SIM."); + mm_obj_dbg (self, "registration failed due to unprovisioned SIM"); simulate_unprovisioned_subscription_pco_update (MM_BROADBAND_MODEM_ALTAIR_LTE (self)); } else { - mm_dbg ("Failed to find a better reason for registration failure."); + mm_obj_dbg (self, "failed to find a better reason for registration failure"); } g_task_return_boolean (task, TRUE); @@ -501,7 +494,7 @@ run_registration_checks_ready (MMIfaceModem3gpp *self, return; } - mm_dbg ("Checking if SIM is unprovisioned (ignoring registration state)."); + mm_obj_dbg (self, "checking if SIM is unprovisioned (ignoring registration state)"); mm_base_modem_at_command (MM_BASE_MODEM (self), "+CEER", 6, @@ -593,11 +586,10 @@ altair_reregister_ready (MMBaseModem *self, GAsyncResult *res, gpointer user_data) { - if (!mm_base_modem_at_command_finish (self, res, NULL)) { - mm_dbg ("Failed to reregister modem"); - } else { - mm_dbg ("Modem reregistered successfully"); - } + if (!mm_base_modem_at_command_finish (self, res, NULL)) + mm_obj_dbg (self, "failed to reregister modem"); + else + mm_obj_dbg (self, "modem reregistered successfully"); MM_BROADBAND_MODEM_ALTAIR_LTE (self)->priv->sim_refresh_detach_in_progress = FALSE; } @@ -607,12 +599,12 @@ altair_deregister_ready (MMBaseModem *self, gpointer user_data) { if (!mm_base_modem_at_command_finish (self, res, NULL)) { - mm_dbg ("Deregister modem failed"); + mm_obj_dbg (self, "deregister modem failed"); MM_BROADBAND_MODEM_ALTAIR_LTE (self)->priv->sim_refresh_detach_in_progress = FALSE; return; } - mm_dbg ("Deregistered modem, now reregistering"); + mm_obj_dbg (self, "deregistered modem, now reregistering"); /* Register */ mm_base_modem_at_command ( @@ -634,7 +626,7 @@ altair_load_own_numbers_ready (MMIfaceModem *iface_modem, str_list = MM_IFACE_MODEM_GET_INTERFACE (self)->load_own_numbers_finish (MM_IFACE_MODEM (self), res, &error); if (error) { - mm_warn ("Couldn't reload Own Numbers: '%s'", error->message); + mm_obj_warn (self, "Couldn't reload Own Numbers: '%s'", error->message); g_error_free (error); } if (str_list) { @@ -647,7 +639,7 @@ altair_load_own_numbers_ready (MMIfaceModem *iface_modem, self->priv->sim_refresh_detach_in_progress = TRUE; /* Deregister */ - mm_dbg ("Reregistering modem"); + mm_obj_dbg (self, "reregistering modem"); mm_base_modem_at_command ( MM_BASE_MODEM (self), "%CMATT=0", @@ -660,7 +652,7 @@ altair_load_own_numbers_ready (MMIfaceModem *iface_modem, static gboolean altair_sim_refresh_timer_expired (MMBroadbandModemAltairLte *self) { - mm_dbg ("No more SIM refreshes, reloading Own Numbers and reregistering modem"); + mm_obj_dbg (self, "no more SIM refreshes, reloading own numbers and reregistering modem"); g_assert (MM_IFACE_MODEM_GET_INTERFACE (self)->load_own_numbers); g_assert (MM_IFACE_MODEM_GET_INTERFACE (self)->load_own_numbers_finish); @@ -678,7 +670,7 @@ altair_sim_refresh_changed (MMPortSerialAt *port, GMatchInfo *match_info, MMBroadbandModemAltairLte *self) { - mm_dbg ("Received SIM refresh notification"); + mm_obj_dbg (self, "received SIM refresh notification"); if (self->priv->sim_refresh_timer_id) { g_source_remove (self->priv->sim_refresh_timer_id); } @@ -716,7 +708,7 @@ altair_statcm_changed (MMPortSerialAt *port, mm_get_int_from_match_info (match_info, 1, &pdn_event); - mm_dbg ("altair_statcm_changed %d", pdn_event); + mm_obj_dbg (self, "altair PDN event detected: %d", pdn_event); /* Currently we only care about bearer disconnection */ @@ -1046,7 +1038,6 @@ modem_3gpp_load_operator_code_finish (MMIfaceModem3gpp *self, error)) return NULL; - mm_dbg ("loaded Operator Code: %s", operator_code); return operator_code; } @@ -1055,8 +1046,6 @@ modem_3gpp_load_operator_code (MMIfaceModem3gpp *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading Operator Code..."); - mm_base_modem_at_command (MM_BASE_MODEM (self), "+COPS=3,2", 6, @@ -1096,8 +1085,6 @@ modem_3gpp_load_operator_name_finish (MMIfaceModem3gpp *self, return NULL; mm_3gpp_normalize_operator (&operator_name, MM_MODEM_CHARSET_UNKNOWN); - if (operator_name) - mm_dbg ("loaded Operator Name: %s", operator_name); return operator_name; } @@ -1106,8 +1093,6 @@ modem_3gpp_load_operator_name (MMIfaceModem3gpp *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("Loading Operator Name..."); - mm_base_modem_at_command (MM_BASE_MODEM (self), "+COPS=3,0", 6, @@ -1133,15 +1118,14 @@ altair_pco_info_changed (MMPortSerialAt *port, { const gchar *pco_info; MMPco *pco; - GError *error = NULL; + g_autoptr(GError) error = NULL; pco_info = g_match_info_fetch (match_info, 0); - mm_dbg ("Parsing vendor PCO info: %s", pco_info); + mm_obj_dbg (self, "parsing vendor PCO info: %s", pco_info); pco = mm_altair_parse_vendor_pco_info (pco_info, &error); if (error) { - mm_warn ("Error parsing vendor PCO info: %s", error->message); - g_error_free (error); + mm_obj_warn (self, "error parsing vendor PCO info: %s", error->message); return; } From fe4b8f6817490763103b0b52ec19a0173ea13537 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 15:19:52 +0200 Subject: [PATCH 096/675] anydata: port to use object logging --- plugins/anydata/mm-broadband-modem-anydata.c | 8 ++++---- plugins/anydata/mm-plugin-anydata.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/anydata/mm-broadband-modem-anydata.c b/plugins/anydata/mm-broadband-modem-anydata.c index a4acaf27..55804fcd 100644 --- a/plugins/anydata/mm-broadband-modem-anydata.c +++ b/plugins/anydata/mm-broadband-modem-anydata.c @@ -25,7 +25,7 @@ #include "ModemManager.h" #include "mm-serial-parsers.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-errors-types.h" #include "mm-base-modem-at.h" @@ -38,7 +38,7 @@ static void iface_modem_cdma_init (MMIfaceModemCdma *iface); G_DEFINE_TYPE_EXTENDED (MMBroadbandModemAnydata, mm_broadband_modem_anydata, MM_TYPE_BROADBAND_MODEM, 0, G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) - G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_CDMA, iface_modem_cdma_init)); + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_CDMA, iface_modem_cdma_init)) /*****************************************************************************/ /* Detailed registration state (CDMA interface) */ @@ -119,7 +119,7 @@ hstate_ready (MMIfaceModemCdma *self, results->detailed_evdo_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; break; default: - mm_warn ("ANYDATA: unknown *STATE (%d); assuming no service.", val); + mm_obj_warn (self, "unknown *HSTATE (%d); assuming no service", val); /* fall through */ case 0: /* NO SERVICE */ case 1: /* ACQUISITION */ @@ -186,7 +186,7 @@ state_ready (MMIfaceModemCdma *self, results->detailed_cdma1x_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; break; default: - mm_warn ("ANYDATA: unknown *STATE (%d); assuming no service.", val); + mm_obj_warn (self, "unknown *HSTATE (%d); assuming no service", val); /* fall through */ case 0: /* NO SERVICE */ break; diff --git a/plugins/anydata/mm-plugin-anydata.c b/plugins/anydata/mm-plugin-anydata.c index 8037fb7a..62039022 100644 --- a/plugins/anydata/mm-plugin-anydata.c +++ b/plugins/anydata/mm-plugin-anydata.c @@ -21,7 +21,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-anydata.h" #include "mm-broadband-modem-anydata.h" @@ -47,7 +47,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered AnyDATA modem found..."); + mm_obj_dbg (self, "QMI-powered AnyDATA modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), From 261ba90d088e6e7b6c4c628b4fd02267111cc7ae Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 15:23:19 +0200 Subject: [PATCH 097/675] cinterion: port to use object logging --- .../cinterion/mm-broadband-bearer-cinterion.c | 69 +++++---- .../cinterion/mm-broadband-modem-cinterion.c | 91 +++++------ .../cinterion/mm-modem-helpers-cinterion.c | 21 +-- .../cinterion/mm-modem-helpers-cinterion.h | 5 +- plugins/cinterion/mm-plugin-cinterion.c | 16 +- plugins/cinterion/mm-shared-cinterion.c | 146 +++++++----------- .../tests/test-modem-helpers-cinterion.c | 8 +- 7 files changed, 164 insertions(+), 192 deletions(-) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index 5c893b69..2f895efb 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -24,7 +24,7 @@ #include #include "mm-base-modem-at.h" #include "mm-broadband-bearer-cinterion.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-cinterion.h" #include "mm-daemon-enums-types.h" @@ -101,11 +101,13 @@ swwan_check_status_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { - const gchar *response; - GError *error = NULL; - MMBearerConnectionStatus status; - guint cid; + MMBroadbandBearerCinterion *self; + const gchar *response; + GError *error = NULL; + MMBearerConnectionStatus status; + guint cid; + self = g_task_get_source_object (task); cid = GPOINTER_TO_UINT (g_task_get_task_data (task)); response = mm_base_modem_at_command_finish (modem, res, &error); @@ -114,7 +116,7 @@ swwan_check_status_ready (MMBaseModem *modem, goto out; } - status = mm_cinterion_parse_swwan_response (response, cid, &error); + status = mm_cinterion_parse_swwan_response (response, cid, self, &error); if (status == MM_BEARER_CONNECTION_STATUS_UNKNOWN) { g_task_return_error (task, error); goto out; @@ -197,8 +199,9 @@ parse_auth_type (MMBearerAllowedAuth mm_auth) /* AT^SGAUTH=[, [, , ]] */ static gchar * -build_auth_string (MMBearerProperties *config, - guint cid) +build_auth_string (MMBroadbandBearerCinterion *self, + MMBearerProperties *config, + guint cid) { const gchar *user; const gchar *passwd; @@ -218,7 +221,7 @@ build_auth_string (MMBearerProperties *config, /* When 'none' requested, we won't require user/password */ if (encoded_auth == BEARER_CINTERION_AUTH_NONE) { if (has_user || has_passwd) - mm_warn ("APN user/password given but 'none' authentication requested"); + mm_obj_warn (self, "APN user/password given but 'none' authentication requested"); return g_strdup_printf ("^SGAUTH=%u,%d", cid, encoded_auth); } @@ -229,7 +232,7 @@ build_auth_string (MMBearerProperties *config, return NULL; /* If user/passwd given, default to PAP */ - mm_dbg ("APN user/password given but no authentication type explicitly requested: defaulting to 'PAP'"); + mm_obj_dbg (self, "APN user/password given but no authentication type explicitly requested: defaulting to 'PAP'"); encoded_auth = BEARER_CINTERION_AUTH_PAP; } @@ -356,9 +359,11 @@ handle_cancel_dial (GTask *task) static void dial_3gpp_context_step (GTask *task) { - Dial3gppContext *ctx; + MMBroadbandBearerCinterion *self; + Dial3gppContext *ctx; - ctx = (Dial3gppContext *) g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* Check for cancellation */ if (g_task_return_error_if_cancelled (task)) { @@ -378,7 +383,7 @@ dial_3gpp_context_step (GTask *task) ip_family = mm_base_bearer_get_default_ip_family (MM_BASE_BEARER (ctx->self)); ip_family_str = mm_bearer_ip_family_build_string_from_mask (ip_family); - mm_dbg ("No specific IP family requested, defaulting to %s", ip_family_str); + mm_obj_dbg (self, "no specific IP family requested, defaulting to %s", ip_family_str); g_free (ip_family_str); } @@ -395,9 +400,9 @@ dial_3gpp_context_step (GTask *task) case DIAL_3GPP_CONTEXT_STEP_AUTH: { gchar *command; - command = build_auth_string (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)), ctx->cid); + command = build_auth_string (self, mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)), ctx->cid); if (command) { - mm_dbg ("cinterion dial step %u/%u: authenticating...", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); + mm_obj_dbg (self, "cinterion dial step %u/%u: authenticating...", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); /* Send SGAUTH write, if User & Pass are provided. * advance to next state by callback */ mm_base_modem_at_command_full (ctx->modem, @@ -413,15 +418,15 @@ dial_3gpp_context_step (GTask *task) return; } - mm_dbg ("cinterion dial step %u/%u: authentication not required", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); + mm_obj_dbg (self, "cinterion dial step %u/%u: authentication not required", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); ctx->step++; } /* fall through */ case DIAL_3GPP_CONTEXT_STEP_START_SWWAN: { gchar *command; - mm_dbg ("cinterion dial step %u/%u: starting SWWAN interface %u connection...", - ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); + mm_obj_dbg (self, "cinterion dial step %u/%u: starting SWWAN interface %u connection...", + ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); command = g_strdup_printf ("^SWWAN=1,%u,%u", ctx->cid, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); @@ -439,8 +444,8 @@ dial_3gpp_context_step (GTask *task) } case DIAL_3GPP_CONTEXT_STEP_VALIDATE_CONNECTION: - mm_dbg ("cinterion dial step %u/%u: checking SWWAN interface %u status...", - ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); + mm_obj_dbg (self, "cinterion dial step %u/%u: checking SWWAN interface %u status...", + ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); load_connection_status_by_cid (ctx->self, ctx->cid, (GAsyncReadyCallback) dial_connection_status_ready, @@ -448,7 +453,7 @@ dial_3gpp_context_step (GTask *task) return; case DIAL_3GPP_CONTEXT_STEP_LAST: - mm_dbg ("cinterion dial step %u/%u: finished", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); + mm_obj_dbg (self, "cinterion dial step %u/%u: finished", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); g_task_return_pointer (task, g_object_ref (ctx->data), g_object_unref); g_object_unref (task); return; @@ -562,7 +567,7 @@ disconnect_connection_status_ready (MMBroadbandBearerCinterion *self, switch (status) { case MM_BEARER_CONNECTION_STATUS_UNKNOWN: /* Assume disconnected */ - mm_dbg ("couldn't get CID %u status, assume disconnected: %s", ctx->cid, error->message); + mm_obj_dbg (self, "couldn't get CID %u status, assume disconnected: %s", ctx->cid, error->message); g_clear_error (&error); break; case MM_BEARER_CONNECTION_STATUS_DISCONNECTED: @@ -604,9 +609,11 @@ swwan_disconnect_ready (MMBaseModem *modem, static void disconnect_3gpp_context_step (GTask *task) { - Disconnect3gppContext *ctx; + MMBroadbandBearerCinterion *self; + Disconnect3gppContext *ctx; - ctx = (Disconnect3gppContext *) g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); switch (ctx->step) { case DISCONNECT_3GPP_CONTEXT_STEP_FIRST: @@ -618,8 +625,8 @@ disconnect_3gpp_context_step (GTask *task) command = g_strdup_printf ("^SWWAN=0,%u,%u", ctx->cid, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); - mm_dbg ("cinterion disconnect step %u/%u: disconnecting PDP CID %u...", - ctx->step, DISCONNECT_3GPP_CONTEXT_STEP_LAST, ctx->cid); + mm_obj_dbg (self, "cinterion disconnect step %u/%u: disconnecting PDP CID %u...", + ctx->step, DISCONNECT_3GPP_CONTEXT_STEP_LAST, ctx->cid); mm_base_modem_at_command_full (ctx->modem, ctx->primary, command, @@ -634,9 +641,9 @@ disconnect_3gpp_context_step (GTask *task) } case DISCONNECT_3GPP_CONTEXT_STEP_CONNECTION_STATUS: - mm_dbg ("cinterion disconnect step %u/%u: checking SWWAN interface %u status...", - ctx->step, DISCONNECT_3GPP_CONTEXT_STEP_LAST, - usb_interface_configs[ctx->usb_interface_config_index].swwan_index); + mm_obj_dbg (self, "cinterion disconnect step %u/%u: checking SWWAN interface %u status...", + ctx->step, DISCONNECT_3GPP_CONTEXT_STEP_LAST, + usb_interface_configs[ctx->usb_interface_config_index].swwan_index); load_connection_status_by_cid (MM_BROADBAND_BEARER_CINTERION (ctx->self), ctx->cid, (GAsyncReadyCallback) disconnect_connection_status_ready, @@ -644,8 +651,8 @@ disconnect_3gpp_context_step (GTask *task) return; case DISCONNECT_3GPP_CONTEXT_STEP_LAST: - mm_dbg ("cinterion disconnect step %u/%u: finished", - ctx->step, DISCONNECT_3GPP_CONTEXT_STEP_LAST); + mm_obj_dbg (self, "cinterion disconnect step %u/%u: finished", + ctx->step, DISCONNECT_3GPP_CONTEXT_STEP_LAST); g_task_return_boolean (task, TRUE); g_object_unref (task); return; diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index c517288f..09b4e13c 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -28,7 +28,7 @@ #include "ModemManager.h" #include "mm-modem-helpers.h" #include "mm-serial-parsers.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-errors-types.h" #include "mm-iface-modem.h" #include "mm-iface-modem-3gpp.h" @@ -256,7 +256,7 @@ cnmi_format_check_ready (MMBaseModem *_self, &self->priv->cnmi_supported_ds, &self->priv->cnmi_supported_bfr, &error)) { - mm_warn ("error reading SMS setup: %s", error->message); + mm_obj_warn (self, "error reading SMS setup: %s", error->message); g_error_free (error); } @@ -333,13 +333,10 @@ sleep_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; + g_autoptr(GError) error = NULL; - if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error)) { - /* Ignore errors */ - mm_dbg ("Couldn't send power down command: '%s'", error->message); - g_error_free (error); - } + if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error)) + mm_obj_dbg (self, "couldn't send power down command: %s", error->message); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -374,14 +371,13 @@ supported_functionality_status_query_ready (MMBaseModem *_self, { MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self); const gchar *response; - GError *error = NULL; + g_autoptr(GError) error = NULL; g_assert (self->priv->sleep_mode_cmd == NULL); response = mm_base_modem_at_command_finish (_self, res, &error); if (!response) { - mm_warn ("Couldn't query supported functionality status: '%s'", error->message); - g_error_free (error); + mm_obj_warn (self, "couldn't query supported functionality status: %s", error->message); self->priv->sleep_mode_cmd = g_strdup (""); } else { /* We need to get which power-off command to use to put the modem in low @@ -395,13 +391,13 @@ supported_functionality_status_query_ready (MMBaseModem *_self, * not found, report warning and don't use any. */ if (strstr (response, "4") != NULL) { - mm_dbg ("Device supports CFUN=4 sleep mode"); + mm_obj_dbg (self, "device supports CFUN=4 sleep mode"); self->priv->sleep_mode_cmd = g_strdup ("+CFUN=4"); } else if (strstr (response, "7") != NULL) { - mm_dbg ("Device supports CFUN=7 sleep mode"); + mm_obj_dbg (self, "device supports CFUN=7 sleep mode"); self->priv->sleep_mode_cmd = g_strdup ("+CFUN=7"); } else { - mm_warn ("Unknown functionality mode to go into sleep mode"); + mm_obj_warn (self, "unknown functionality mode to go into sleep mode"); self->priv->sleep_mode_cmd = g_strdup (""); } } @@ -684,12 +680,10 @@ parent_disable_unsolicited_events_ready (MMIfaceModem3gpp *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; + g_autoptr(GError) error = NULL; - if (!iface_modem_3gpp_parent->disable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't disable parent 3GPP unsolicited events: %s", error->message); - g_error_free (error); - } + if (!iface_modem_3gpp_parent->disable_unsolicited_events_finish (self, res, &error)) + mm_obj_warn (self, "couldn't disable parent 3GPP unsolicited events: %s", error->message); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -710,12 +704,10 @@ sind_psinfo_disable_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; + g_autoptr(GError) error = NULL; - if (!mm_base_modem_at_command_finish (self, res, &error)) { - mm_warn ("Couldn't disable ^SIND psinfo notifications: %s", error->message); - g_error_free (error); - } + if (!mm_base_modem_at_command_finish (self, res, &error)) + mm_obj_warn (self, "Couldn't disable ^SIND psinfo notifications: %s", error->message); parent_disable_unsolicited_messages (task); } @@ -763,7 +755,7 @@ sind_psinfo_enable_ready (MMBaseModem *_self, GTask *task) { MMBroadbandModemCinterion *self; - GError *error = NULL; + g_autoptr(GError) error = NULL; const gchar *response; guint mode; guint val; @@ -771,20 +763,18 @@ sind_psinfo_enable_ready (MMBaseModem *_self, self = MM_BROADBAND_MODEM_CINTERION (_self); if (!(response = mm_base_modem_at_command_finish (_self, res, &error))) { self->priv->sind_psinfo_support = FEATURE_NOT_SUPPORTED; - mm_warn ("Couldn't enable ^SIND psinfo notifications: %s", error->message); - g_error_free (error); + mm_obj_warn (self, "couldn't enable ^SIND psinfo notifications: %s", error->message); } else if (!mm_cinterion_parse_sind_response (response, NULL, &mode, &val, &error)) { self->priv->sind_psinfo_support = FEATURE_NOT_SUPPORTED; - mm_warn ("Couldn't parse ^SIND psinfo response: %s", error->message); - g_error_free (error); + mm_obj_warn (self, "couldn't parse ^SIND psinfo response: %s", error->message); } else { /* Flag ^SIND psinfo supported so that we don't poll */ self->priv->sind_psinfo_support = FEATURE_SUPPORTED; /* Report initial access technology gathered right away */ - mm_dbg ("Reporting initial access technologies..."); + mm_obj_dbg (self, "reporting initial access technologies..."); mm_iface_modem_update_access_technologies (MM_IFACE_MODEM (self), - mm_cinterion_get_access_technology_from_sind_psinfo (val), + mm_cinterion_get_access_technology_from_sind_psinfo (val, self), MM_IFACE_MODEM_3GPP_ALL_ACCESS_TECHNOLOGIES_MASK); } @@ -798,14 +788,12 @@ parent_enable_unsolicited_events_ready (MMIfaceModem3gpp *_self, GTask *task) { MMBroadbandModemCinterion *self; - GError *error = NULL; + g_autoptr(GError) error = NULL; self = MM_BROADBAND_MODEM_CINTERION (_self); - if (!iface_modem_3gpp_parent->enable_unsolicited_events_finish (_self, res, &error)) { - mm_warn ("Couldn't enable parent 3GPP unsolicited events: %s", error->message); - g_error_free (error); - } + if (!iface_modem_3gpp_parent->enable_unsolicited_events_finish (_self, res, &error)) + mm_obj_warn (self, "couldn't enable parent 3GPP unsolicited events: %s", error->message); if (self->priv->sind_psinfo_support != FEATURE_NOT_SUPPORTED) { /* Enable access technology update reporting */ @@ -851,12 +839,12 @@ sind_ciev_received (MMPortSerialAt *port, indicator = mm_get_string_unquoted_from_match_info (match_info, 1); if (!mm_get_uint_from_match_info (match_info, 2, &val)) - mm_dbg ("couldn't parse indicator '%s' value", indicator); + mm_obj_dbg (self, "couldn't parse indicator '%s' value", indicator); else { - mm_dbg ("received indicator '%s' update: %u", indicator, val); + mm_obj_dbg (self, "received indicator '%s' update: %u", indicator, val); if (g_strcmp0 (indicator, "psinfo") == 0) { mm_iface_modem_update_access_technologies (MM_IFACE_MODEM (self), - mm_cinterion_get_access_technology_from_sind_psinfo (val), + mm_cinterion_get_access_technology_from_sind_psinfo (val, self), MM_IFACE_MODEM_3GPP_ALL_ACCESS_TECHNOLOGIES_MASK); } } @@ -1467,23 +1455,22 @@ spic_ready (MMBaseModem *self, { LoadUnlockRetriesContext *ctx; const gchar *response; - GError *error = NULL; + g_autoptr(GError) error = NULL; ctx = g_task_get_task_data (task); response = mm_base_modem_at_command_finish (self, res, &error); if (!response) { - mm_dbg ("Couldn't load retry count for lock '%s': %s", - mm_modem_lock_get_string (unlock_retries_map[ctx->i].lock), - error->message); - g_error_free (error); + mm_obj_dbg (self, "Couldn't load retry count for lock '%s': %s", + mm_modem_lock_get_string (unlock_retries_map[ctx->i].lock), + error->message); } else { guint val; response = mm_strip_tag (response, "^SPIC:"); if (!mm_get_uint_from_str (response, &val)) - mm_dbg ("Couldn't parse retry count value for lock '%s'", - mm_modem_lock_get_string (unlock_retries_map[ctx->i].lock)); + mm_obj_dbg (self, "couldn't parse retry count value for lock '%s'", + mm_modem_lock_get_string (unlock_retries_map[ctx->i].lock)); else mm_unlock_retries_set (ctx->retries, unlock_retries_map[ctx->i].lock, val); } @@ -1698,7 +1685,7 @@ common_create_bearer (GTask *task) switch (self->priv->swwan_support) { case FEATURE_NOT_SUPPORTED: - mm_dbg ("^SWWAN not supported, creating default bearer..."); + mm_obj_dbg (self, "^SWWAN not supported, creating default bearer..."); mm_broadband_bearer_new (MM_BROADBAND_MODEM (self), g_task_get_task_data (task), NULL, /* cancellable */ @@ -1706,7 +1693,7 @@ common_create_bearer (GTask *task) task); return; case FEATURE_SUPPORTED: - mm_dbg ("^SWWAN supported, creating cinterion bearer..."); + mm_obj_dbg (self, "^SWWAN supported, creating cinterion bearer..."); mm_broadband_bearer_cinterion_new (MM_BROADBAND_MODEM_CINTERION (self), g_task_get_task_data (task), NULL, /* cancellable */ @@ -1729,10 +1716,10 @@ swwan_test_ready (MMBaseModem *_self, /* Fetch the result to the SWWAN test. If no response given (error triggered), * assume unsupported */ if (!mm_base_modem_at_command_finish (_self, res, NULL)) { - mm_dbg ("SWWAN unsupported"); + mm_obj_dbg (self, "SWWAN unsupported"); self->priv->swwan_support = FEATURE_NOT_SUPPORTED; } else { - mm_dbg ("SWWAN supported"); + mm_obj_dbg (self, "SWWAN supported"); self->priv->swwan_support = FEATURE_SUPPORTED; } @@ -1762,13 +1749,13 @@ cinterion_modem_create_bearer (MMIfaceModem *_self, /* If we don't have a data port, don't even bother checking for ^SWWAN * support. */ if (!mm_base_modem_peek_best_data_port (MM_BASE_MODEM (self), MM_PORT_TYPE_NET)) { - mm_dbg ("skipping ^SWWAN check as no data port is available"); + mm_obj_dbg (self, "skipping ^SWWAN check as no data port is available"); self->priv->swwan_support = FEATURE_NOT_SUPPORTED; common_create_bearer (task); return; } - mm_dbg ("checking ^SWWAN support..."); + mm_obj_dbg (self, "checking ^SWWAN support..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "^SWWAN=?", 6, diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index 0eac9125..da2dd643 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -24,7 +24,7 @@ #include "ModemManager.h" #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-charsets.h" #include "mm-errors-types.h" #include "mm-modem-helpers-cinterion.h" @@ -500,6 +500,7 @@ enum { MMBearerConnectionStatus mm_cinterion_parse_swwan_response (const gchar *response, guint cid, + gpointer log_object, GError **error) { GRegex *r; @@ -531,9 +532,9 @@ mm_cinterion_parse_swwan_response (const gchar *response, guint read_cid; if (!mm_get_uint_from_match_info (match_info, 1, &read_cid)) - mm_warn ("Couldn't read cid in ^SWWAN response: '%s'", response); + mm_obj_warn (log_object, "couldn't read cid in ^SWWAN response: %s", response); else if (!mm_get_uint_from_match_info (match_info, 2, &read_state)) - mm_warn ("Couldn't read state in ^SWWAN response: '%s'", response); + mm_obj_warn (log_object, "couldn't read state in ^SWWAN response: %s", response); else if (read_cid == cid) { if (read_state == MM_SWWAN_STATE_CONNECTED) { status = MM_BEARER_CONNECTION_STATUS_CONNECTED; @@ -543,7 +544,7 @@ mm_cinterion_parse_swwan_response (const gchar *response, status = MM_BEARER_CONNECTION_STATUS_DISCONNECTED; break; } - mm_warn ("Invalid state read in ^SWWAN response: %u", read_state); + mm_obj_warn (log_object, "invalid state read in ^SWWAN response: %u", read_state); break; } g_match_info_next (match_info, &inner_error); @@ -640,7 +641,8 @@ mm_cinterion_parse_smong_response (const gchar *response, /* ^SIND psinfo helper */ MMModemAccessTechnology -mm_cinterion_get_access_technology_from_sind_psinfo (guint val) +mm_cinterion_get_access_technology_from_sind_psinfo (guint val, + gpointer log_object) { switch (val) { case 0: @@ -664,7 +666,7 @@ mm_cinterion_get_access_technology_from_sind_psinfo (guint val) case 17: return MM_MODEM_ACCESS_TECHNOLOGY_LTE; default: - mm_dbg ("Unable to identify access technology from psinfo reported value: %u", val); + mm_obj_dbg (log_object, "unable to identify access technology from psinfo reported value: %u", val); return MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; } } @@ -694,6 +696,7 @@ cinterion_call_info_free (MMCallInfo *info) gboolean mm_cinterion_parse_slcc_list (const gchar *str, + gpointer log_object, GList **out_list, GError **error) { @@ -747,20 +750,20 @@ mm_cinterion_parse_slcc_list (const gchar *str, call_info = g_slice_new0 (MMCallInfo); if (!mm_get_uint_from_match_info (match_info, 1, &call_info->index)) { - mm_warn ("couldn't parse call index from ^SLCC line"); + mm_obj_warn (log_object, "couldn't parse call index from ^SLCC line"); goto next; } if (!mm_get_uint_from_match_info (match_info, 2, &aux) || (aux >= G_N_ELEMENTS (cinterion_call_direction))) { - mm_warn ("couldn't parse call direction from ^SLCC line"); + mm_obj_warn (log_object, "couldn't parse call direction from ^SLCC line"); goto next; } call_info->direction = cinterion_call_direction[aux]; if (!mm_get_uint_from_match_info (match_info, 3, &aux) || (aux >= G_N_ELEMENTS (cinterion_call_state))) { - mm_warn ("couldn't parse call state from ^SLCC line"); + mm_obj_warn (log_object, "couldn't parse call state from ^SLCC line"); goto next; } call_info->state = cinterion_call_state[aux]; diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.h b/plugins/cinterion/mm-modem-helpers-cinterion.h index a318b8d0..ad6a5fa1 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.h +++ b/plugins/cinterion/mm-modem-helpers-cinterion.h @@ -76,6 +76,7 @@ gboolean mm_cinterion_parse_sind_response (const gchar *response, MMBearerConnectionStatus mm_cinterion_parse_swwan_response (const gchar *response, guint swwan_index, + gpointer log_object, GError **error); /*****************************************************************************/ @@ -88,7 +89,8 @@ gboolean mm_cinterion_parse_smong_response (const gchar *response, /*****************************************************************************/ /* ^SIND psinfo helper */ -MMModemAccessTechnology mm_cinterion_get_access_technology_from_sind_psinfo (guint val); +MMModemAccessTechnology mm_cinterion_get_access_technology_from_sind_psinfo (guint val, + gpointer log_object); /*****************************************************************************/ /* ^SLCC URC helpers */ @@ -97,6 +99,7 @@ GRegex *mm_cinterion_get_slcc_regex (void); /* MMCallInfo list management */ gboolean mm_cinterion_parse_slcc_list (const gchar *str, + gpointer log_object, GList **out_list, GError **error); void mm_cinterion_call_info_list_free (GList *call_info_list); diff --git a/plugins/cinterion/mm-plugin-cinterion.c b/plugins/cinterion/mm-plugin-cinterion.c index bdca6188..30c0f481 100644 --- a/plugins/cinterion/mm-plugin-cinterion.c +++ b/plugins/cinterion/mm-plugin-cinterion.c @@ -29,7 +29,7 @@ #include "mm-plugin-cinterion.h" #include "mm-broadband-modem-cinterion.h" -#include "mm-log.h" +#include "mm-log-object.h" #if defined WITH_QMI #include "mm-broadband-modem-qmi-cinterion.h" @@ -115,7 +115,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered Cinterion modem found..."); + mm_obj_dbg (self, "QMI-powered Cinterion modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_cinterion_new (uid, drivers, mm_plugin_get_name (self), @@ -143,14 +143,14 @@ grab_port (MMPlugin *self, ptype = mm_port_probe_get_port_type (probe); if (g_object_get_data (G_OBJECT (probe), TAG_CINTERION_APP_PORT)) { - mm_dbg ("(%s/%s)' Port flagged as primary", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port '%s/%s' flagged as primary", + mm_port_probe_get_port_subsys (probe), + mm_port_probe_get_port_name (probe)); pflags = MM_PORT_SERIAL_AT_FLAG_PRIMARY; } else if (g_object_get_data (G_OBJECT (probe), TAG_CINTERION_MODEM_PORT)) { - mm_dbg ("(%s/%s)' Port flagged as PPP", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port '%s/%s' flagged as PPP", + mm_port_probe_get_port_subsys (probe), + mm_port_probe_get_port_name (probe)); pflags = MM_PORT_SERIAL_AT_FLAG_PPP; } diff --git a/plugins/cinterion/mm-shared-cinterion.c b/plugins/cinterion/mm-shared-cinterion.c index 8ae8e88e..9ad03a75 100644 --- a/plugins/cinterion/mm-shared-cinterion.c +++ b/plugins/cinterion/mm-shared-cinterion.c @@ -23,7 +23,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-iface-modem.h" #include "mm-iface-modem-location.h" #include "mm-base-modem.h" @@ -217,7 +217,7 @@ probe_gps_features (GTask *task) sources = GPOINTER_TO_UINT (g_task_get_task_data (task)); if (priv->sgpss_support == FEATURE_SUPPORTED || priv->sgpsc_support == FEATURE_SUPPORTED) { - mm_dbg ("GPS commands supported: GPS capabilities enabled"); + mm_obj_dbg (self, "GPS commands supported: GPS capabilities enabled"); /* We only flag as supported by this implementation those sources not already * supported by the parent implementation */ @@ -236,7 +236,7 @@ probe_gps_features (GTask *task) self, NULL); } else - mm_dbg ("No GPS command supported: no GPS capabilities"); + mm_obj_dbg (self, "no GPS command supported: no GPS capabilities"); g_task_return_int (task, (gssize) sources); g_object_unref (task); @@ -262,7 +262,7 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self, /* Now our own check. If we don't have any GPS port, we're done */ if (!mm_base_modem_peek_port_gps (MM_BASE_MODEM (self))) { - mm_dbg ("No GPS data port found: no GPS capabilities"); + mm_obj_dbg (self, "no GPS data port found: no GPS capabilities"); g_task_return_int (task, sources); g_object_unref (task); return; @@ -610,7 +610,7 @@ enable_sgpsc_or_sgpss_ready (MMBaseModem *self, * Engine; so we'll run some retries of the same command ourselves. */ if (ctx->gps_step == ENABLE_LOCATION_GATHERING_GPS_STEP_SGPSC_ENGINE) { ctx->sgpsc_engine_retries++; - mm_dbg ("GPS Engine setup failed (%u/%u)", ctx->sgpsc_engine_retries, MAX_SGPSC_ENGINE_RETRIES); + mm_obj_dbg (self, "GPS engine setup failed (%u/%u)", ctx->sgpsc_engine_retries, MAX_SGPSC_ENGINE_RETRIES); if (ctx->sgpsc_engine_retries < MAX_SGPSC_ENGINE_RETRIES) { g_clear_error (&error); goto schedule; @@ -803,7 +803,7 @@ mm_shared_cinterion_create_call (MMIfaceModemVoice *self, /* If ^SLCC is supported create a cinterion call object */ priv = get_private (MM_SHARED_CINTERION (self)); if (priv->slcc_support == FEATURE_SUPPORTED) { - mm_dbg ("Created new call with ^SLCC support"); + mm_obj_dbg (self, "created new call with ^SLCC support"); return mm_base_call_new (MM_BASE_MODEM (self), direction, number, @@ -857,16 +857,14 @@ slcc_command_ready (MMBaseModem *self, GTask *task) { VoiceUnsolicitedEventsContext *ctx; - GError *error = NULL; + g_autoptr(GError) error = NULL; ctx = g_task_get_task_data (task); - if (!mm_base_modem_at_command_full_finish (self, res, &error)) { - mm_dbg ("Couldn't %s ^SLCC reporting: '%s'", - ctx->enable ? "enable" : "disable", - error->message); - g_error_free (error); - } + if (!mm_base_modem_at_command_full_finish (self, res, &error)) + mm_obj_dbg (self, "couldn't %s ^SLCC reporting: %s", + ctx->enable ? "enable" : "disable", + error->message); /* Continue on next port */ run_voice_enable_disable_unsolicited_events (task); @@ -892,13 +890,13 @@ run_voice_enable_disable_unsolicited_events (GTask *task) } if (!ctx->slcc_primary_done && ctx->primary) { - mm_dbg ("%s ^SLCC extended list of current calls reporting in primary port...", - ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s ^SLCC extended list of current calls reporting in primary port...", + ctx->enable ? "enabling" : "disabling"); ctx->slcc_primary_done = TRUE; port = ctx->primary; } else if (!ctx->slcc_secondary_done && ctx->secondary) { - mm_dbg ("%s ^SLCC extended list of current calls reporting in secondary port...", - ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s ^SLCC extended list of current calls reporting in secondary port...", + ctx->enable ? "enabling" : "disabling"); ctx->slcc_secondary_done = TRUE; port = ctx->secondary; } @@ -961,15 +959,13 @@ parent_voice_disable_unsolicited_events_ready (MMIfaceModemVoice *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; - Private *priv; + g_autoptr(GError) error = NULL; + Private *priv; priv = get_private (MM_SHARED_CINTERION (self)); - if (!priv->iface_modem_voice_parent->disable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't disable parent voice unsolicited events: %s", error->message); - g_error_free (error); - } + if (!priv->iface_modem_voice_parent->disable_unsolicited_events_finish (self, res, &error)) + mm_obj_warn (self, "couldn't disable parent voice unsolicited events: %s", error->message); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -980,13 +976,11 @@ voice_disable_unsolicited_events_ready (MMSharedCinterion *self, GAsyncResult *res, GTask *task) { - Private *priv; - GError *error = NULL; + Private *priv; + g_autoptr(GError) error = NULL; - if (!common_voice_enable_disable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't disable Cinterion-specific voice unsolicited events: %s", error->message); - g_error_free (error); - } + if (!common_voice_enable_disable_unsolicited_events_finish (self, res, &error)) + mm_obj_warn (self, "couldn't disable Cinterion-specific voice unsolicited events: %s", error->message); priv = get_private (MM_SHARED_CINTERION (self)); g_assert (priv->iface_modem_voice_parent); @@ -1032,12 +1026,10 @@ voice_enable_unsolicited_events_ready (MMSharedCinterion *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; + g_autoptr(GError) error = NULL; - if (!common_voice_enable_disable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't enable Cinterion-specific voice unsolicited events: %s", error->message); - g_error_free (error); - } + if (!common_voice_enable_disable_unsolicited_events_finish (self, res, &error)) + mm_obj_warn (self, "couldn't enable Cinterion-specific voice unsolicited events: %s", error->message); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -1048,15 +1040,13 @@ parent_voice_enable_unsolicited_events_ready (MMIfaceModemVoice *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; - Private *priv; + g_autoptr(GError) error = NULL; + Private *priv; priv = get_private (MM_SHARED_CINTERION (self)); - if (!priv->iface_modem_voice_parent->enable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't enable parent voice unsolicited events: %s", error->message); - g_error_free (error); - } + if (!priv->iface_modem_voice_parent->enable_unsolicited_events_finish (self, res, &error)) + mm_obj_warn (self, "couldn't enable parent voice unsolicited events: %s", error->message); /* our own enabling next */ common_voice_enable_disable_unsolicited_events (MM_SHARED_CINTERION (self), @@ -1095,20 +1085,16 @@ slcc_received (MMPortSerialAt *port, GMatchInfo *match_info, MMSharedCinterion *self) { - gchar *full; - GError *error = NULL; - GList *call_info_list = NULL; + g_autofree gchar *full = NULL; + g_autoptr(GError) error = NULL; + GList *call_info_list = NULL; full = g_match_info_fetch (match_info, 0); - - if (!mm_cinterion_parse_slcc_list (full, &call_info_list, &error)) { - mm_warn ("couldn't parse ^SLCC list: %s", error->message); - g_error_free (error); - } else + if (!mm_cinterion_parse_slcc_list (full, self, &call_info_list, &error)) + mm_obj_warn (self, "couldn't parse ^SLCC list: %s", error->message); + else mm_iface_modem_voice_report_all_calls (MM_IFACE_MODEM_VOICE (self), call_info_list); - mm_cinterion_call_info_list_free (call_info_list); - g_free (full); } static void @@ -1152,15 +1138,13 @@ parent_voice_cleanup_unsolicited_events_ready (MMIfaceModemVoice *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; - Private *priv; + g_autoptr(GError) error = NULL; + Private *priv; priv = get_private (MM_SHARED_CINTERION (self)); - if (!priv->iface_modem_voice_parent->cleanup_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't cleanup parent voice unsolicited events: %s", error->message); - g_error_free (error); - } + if (!priv->iface_modem_voice_parent->cleanup_unsolicited_events_finish (self, res, &error)) + mm_obj_warn (self, "couldn't cleanup parent voice unsolicited events: %s", error->message); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -1207,15 +1191,13 @@ parent_voice_setup_unsolicited_events_ready (MMIfaceModemVoice *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; - Private *priv; + g_autoptr(GError) error = NULL; + Private *priv; priv = get_private (MM_SHARED_CINTERION (self)); - if (!priv->iface_modem_voice_parent->setup_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't setup parent voice unsolicited events: %s", error->message); - g_error_free (error); - } + if (!priv->iface_modem_voice_parent->setup_unsolicited_events_finish (self, res, &error)) + mm_obj_warn (self, "Couldn't setup parent voice unsolicited events: %s", error->message); /* our own setup next */ common_voice_setup_cleanup_unsolicited_events (MM_SHARED_CINTERION (self), TRUE); @@ -1337,24 +1319,18 @@ ctzu_received (MMPortSerialAt *port, GMatchInfo *match_info, MMSharedCinterion *self) { - gchar *iso8601 = NULL; - MMNetworkTimezone *tz = NULL; - GError *error = NULL; + g_autofree gchar *iso8601 = NULL; + g_autoptr(MMNetworkTimezone) tz = NULL; + g_autoptr(GError) error = NULL; if (!mm_cinterion_parse_ctzu_urc (match_info, &iso8601, &tz, &error)) { - mm_dbg ("Couldn't process +CTZU URC: %s", error->message); - g_error_free (error); + mm_obj_dbg (self, "couldn't process +CTZU URC: %s", error->message); return; } - g_assert (iso8601); - mm_dbg ("+CTZU URC received: %s", iso8601); + mm_obj_dbg (self, "+CTZU URC received: %s", iso8601); mm_iface_modem_time_update_network_time (MM_IFACE_MODEM_TIME (self), iso8601); - g_free (iso8601); - - g_assert (tz); mm_iface_modem_time_update_network_timezone (MM_IFACE_MODEM_TIME (self), tz); - g_object_unref (tz); } static void @@ -1370,8 +1346,8 @@ common_time_setup_cleanup_unsolicited_events (MMSharedCinterion *self, ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); - mm_dbg ("%s up time unsolicited events...", - enable ? "Setting" : "Cleaning"); + mm_obj_dbg (self, "%s up time unsolicited events...", + enable ? "setting" : "cleaning"); for (i = 0; i < G_N_ELEMENTS (ports); i++) { if (!ports[i]) @@ -1401,15 +1377,13 @@ parent_time_cleanup_unsolicited_events_ready (MMIfaceModemTime *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; - Private *priv; + g_autoptr(GError) error = NULL; + Private *priv; priv = get_private (MM_SHARED_CINTERION (self)); - if (!priv->iface_modem_time_parent->cleanup_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't cleanup parent time unsolicited events: %s", error->message); - g_error_free (error); - } + if (!priv->iface_modem_time_parent->cleanup_unsolicited_events_finish (self, res, &error)) + mm_obj_warn (self, "couldn't cleanup parent time unsolicited events: %s", error->message); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -1475,15 +1449,13 @@ parent_time_setup_unsolicited_events_ready (MMIfaceModemTime *self, GAsyncResult *res, GTask *task) { - GError *error = NULL; - Private *priv; + g_autoptr(GError) error = NULL; + Private *priv; priv = get_private (MM_SHARED_CINTERION (self)); - if (!priv->iface_modem_time_parent->cleanup_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't cleanup parent time unsolicited events: %s", error->message); - g_error_free (error); - } + if (!priv->iface_modem_time_parent->cleanup_unsolicited_events_finish (self, res, &error)) + mm_obj_warn (self, "Couldn't cleanup parent time unsolicited events: %s", error->message); own_time_setup_unsolicited_events (task); } diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c index f1d6cddb..88e0f74c 100644 --- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c +++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c @@ -565,7 +565,7 @@ test_swwan_pls8 (void) /* Query for the expected items (CIDs 2 and 3) */ for (j = 0; j < SWWAN_TEST_MAX_CIDS; j++) { - read_state = mm_cinterion_parse_swwan_response (swwan_tests[i].response, swwan_tests[i].expected_items[j].cid, &error); + read_state = mm_cinterion_parse_swwan_response (swwan_tests[i].response, swwan_tests[i].expected_items[j].cid, NULL, &error); if (swwan_tests[i].expected_items[j].state == MM_BEARER_CONNECTION_STATUS_UNKNOWN) { g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED); g_clear_error (&error); @@ -576,7 +576,7 @@ test_swwan_pls8 (void) /* Query for a CID which isn't replied (e.g. 12) */ if (!swwan_tests[i].skip_test_other_cids) { - read_state = mm_cinterion_parse_swwan_response (swwan_tests[i].response, 12, &error); + read_state = mm_cinterion_parse_swwan_response (swwan_tests[i].response, 12, NULL, &error); g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED); g_assert_cmpint (read_state, ==, MM_BEARER_CONNECTION_STATUS_UNKNOWN); g_clear_error (&error); @@ -584,7 +584,7 @@ test_swwan_pls8 (void) } /* Additional tests for errors */ - read_state = mm_cinterion_parse_swwan_response ("^GARBAGE", 2, &error); + read_state = mm_cinterion_parse_swwan_response ("^GARBAGE", 2, NULL, &error); g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED); g_assert_cmpint (read_state, ==, MM_BEARER_CONNECTION_STATUS_UNKNOWN); g_clear_error (&error); @@ -695,7 +695,7 @@ common_test_slcc_urc (const gchar *urc, str = g_match_info_fetch (match_info, 0); g_assert (str); - result = mm_cinterion_parse_slcc_list (str, &call_info_list, &error); + result = mm_cinterion_parse_slcc_list (str, NULL, &call_info_list, &error); g_assert_no_error (error); g_assert (result); From 784fd9b7405badc1a7a45cbc19575dea309ded44 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 15:43:05 +0200 Subject: [PATCH 098/675] dell: port to use object logging --- plugins/dell/mm-plugin-dell.c | 37 +++++++++++++++-------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/plugins/dell/mm-plugin-dell.c b/plugins/dell/mm-plugin-dell.c index e9f8a0bd..1d383ede 100644 --- a/plugins/dell/mm-plugin-dell.c +++ b/plugins/dell/mm-plugin-dell.c @@ -36,7 +36,7 @@ #include "mm-broadband-modem-telit.h" #include "mm-broadband-modem-xmm.h" #include "mm-common-telit.h" -#include "mm-log.h" +#include "mm-log-object.h" #if defined WITH_QMI #include "mm-broadband-modem-qmi.h" @@ -170,7 +170,7 @@ response_ready (MMPortSerialAt *port, if (error) { /* Non-timeout error, jump to next command */ if (!g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) { - mm_dbg ("(Dell) Error probing AT port: %s", error->message); + mm_obj_dbg (probe, "error probing AT port: %s", error->message); g_error_free (error); custom_init_step_next_command (task); return; @@ -250,8 +250,7 @@ custom_init_step (GTask *task) /* If cancelled, end without error right away */ if (g_cancellable_is_cancelled (g_task_get_cancellable (task))) { - mm_dbg ("(Dell) no need to keep on running custom init in (%s)", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "no need to keep on running custom init: cancelled"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -260,8 +259,7 @@ custom_init_step (GTask *task) #if defined WITH_QMI /* If device has a QMI port, don't run anything else, as we don't care */ if (mm_port_probe_list_has_qmi_port (mm_device_peek_port_probe_list (mm_port_probe_peek_device (probe)))) { - mm_dbg ("(Dell) no need to run custom init in (%s): device has QMI port", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "no need to run custom init: device has QMI port"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -271,8 +269,7 @@ custom_init_step (GTask *task) #if defined WITH_MBIM /* If device has a MBIM port, don't run anything else, as we don't care */ if (mm_port_probe_list_has_mbim_port (mm_device_peek_port_probe_list (mm_port_probe_peek_device (probe)))) { - mm_dbg ("(Dell) no need to run custom init in (%s): device has MBIM port", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "no need to run custom init: device has MBIM port"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -280,8 +277,7 @@ custom_init_step (GTask *task) #endif if (ctx->timeouts >= MAX_PORT_PROBE_TIMEOUTS) { - mm_dbg ("(Dell) couldn't detect real manufacturer in (%s): too many timeouts", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "couldn't detect real manufacturer: too many timeouts"); mm_port_probe_set_result_at (probe, FALSE); goto out; } @@ -326,8 +322,7 @@ custom_init_step (GTask *task) return; } - mm_dbg ("(Dell) couldn't detect real manufacturer in (%s): all retries consumed", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "couldn't detect real manufacturer: all retries consumed"); out: /* Finish custom_init */ g_task_return_boolean (task, TRUE); @@ -387,7 +382,7 @@ create_modem (MMPlugin *self, #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered Dell-branded modem found..."); + mm_obj_dbg (self, "QMI-powered Dell-branded modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), @@ -400,7 +395,7 @@ create_modem (MMPlugin *self, if (mm_port_probe_list_has_mbim_port (probes)) { /* Specific implementation for the DW5821e */ if (vendor == 0x413c && (product == 0x81d7 || product == 0x81e0)) { - mm_dbg ("MBIM-powered DW5821e (T77W968) modem found..."); + mm_obj_dbg (self, "MBIM-powered DW5821e (T77W968) modem found..."); return MM_BASE_MODEM (mm_broadband_modem_foxconn_t77w968_new (uid, drivers, mm_plugin_get_name (self), @@ -409,7 +404,7 @@ create_modem (MMPlugin *self, } if (mm_port_probe_list_is_xmm (probes)) { - mm_dbg ("MBIM-powered XMM-based modem found..."); + mm_obj_dbg (self, "MBIM-powered XMM-based modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_xmm_new (uid, drivers, mm_plugin_get_name (self), @@ -417,7 +412,7 @@ create_modem (MMPlugin *self, product)); } - mm_dbg ("MBIM-powered Dell-branded modem found..."); + mm_obj_dbg (self, "MBIM-powered Dell-branded modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, drivers, mm_plugin_get_name (self), @@ -427,7 +422,7 @@ create_modem (MMPlugin *self, #endif if (port_probe_list_has_manufacturer_port (probes, DELL_MANUFACTURER_NOVATEL)) { - mm_dbg ("Novatel-powered Dell-branded modem found..."); + mm_obj_dbg (self, "Novatel-powered Dell-branded modem found..."); return MM_BASE_MODEM (mm_broadband_modem_novatel_new (uid, drivers, mm_plugin_get_name (self), @@ -436,7 +431,7 @@ create_modem (MMPlugin *self, } if (port_probe_list_has_manufacturer_port (probes, DELL_MANUFACTURER_SIERRA)) { - mm_dbg ("Sierra-powered Dell-branded modem found..."); + mm_obj_dbg (self, "Sierra-powered Dell-branded modem found..."); return MM_BASE_MODEM (mm_broadband_modem_sierra_new (uid, drivers, mm_plugin_get_name (self), @@ -445,7 +440,7 @@ create_modem (MMPlugin *self, } if (port_probe_list_has_manufacturer_port (probes, DELL_MANUFACTURER_TELIT)) { - mm_dbg ("Telit-powered Dell-branded modem found..."); + mm_obj_dbg (self, "Telit-powered Dell-branded modem found..."); return MM_BASE_MODEM (mm_broadband_modem_telit_new (uid, drivers, mm_plugin_get_name (self), @@ -454,7 +449,7 @@ create_modem (MMPlugin *self, } if (mm_port_probe_list_is_xmm (probes)) { - mm_dbg ("XMM-based modem found..."); + mm_obj_dbg (self, "XMM-based modem found..."); return MM_BASE_MODEM (mm_broadband_modem_xmm_new (uid, drivers, mm_plugin_get_name (self), @@ -462,7 +457,7 @@ create_modem (MMPlugin *self, product)); } - mm_dbg ("Dell-branded generic modem found..."); + mm_obj_dbg (self, "Dell-branded generic modem found..."); return MM_BASE_MODEM (mm_broadband_modem_new (uid, drivers, mm_plugin_get_name (self), From b3e56bc576a36a4aaa5675c4c650c49388afc250 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 15:44:00 +0200 Subject: [PATCH 099/675] dlink: port to use object logging --- plugins/dlink/mm-plugin-dlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/dlink/mm-plugin-dlink.c b/plugins/dlink/mm-plugin-dlink.c index e7c68164..d891ee88 100644 --- a/plugins/dlink/mm-plugin-dlink.c +++ b/plugins/dlink/mm-plugin-dlink.c @@ -20,7 +20,7 @@ #include #include "mm-port-enums-types.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-dlink.h" #include "mm-broadband-modem.h" @@ -46,7 +46,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered D-Link modem found..."); + mm_obj_dbg (self, "QMI-powered D-Link modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), From 77080d5f26681aed9e43c9bdaba58139f291d591 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 15:44:34 +0200 Subject: [PATCH 100/675] fibocom: port to use object logging --- plugins/fibocom/mm-plugin-fibocom.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/fibocom/mm-plugin-fibocom.c b/plugins/fibocom/mm-plugin-fibocom.c index d41dc6ae..8447ab60 100644 --- a/plugins/fibocom/mm-plugin-fibocom.c +++ b/plugins/fibocom/mm-plugin-fibocom.c @@ -19,7 +19,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-fibocom.h" #include "mm-broadband-modem.h" #include "mm-broadband-modem-xmm.h" @@ -48,14 +48,14 @@ create_modem (MMPlugin *self, #if defined WITH_MBIM if (mm_port_probe_list_has_mbim_port (probes)) { if (mm_port_probe_list_is_xmm (probes)) { - mm_dbg ("MBIM-powered XMM-based Fibocom modem found..."); + mm_obj_dbg (self, "MBIM-powered XMM-based Fibocom modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_xmm_new (uid, drivers, mm_plugin_get_name (self), vendor, product)); } - mm_dbg ("MBIM-powered Fibocom modem found..."); + mm_obj_dbg (self, "MBIM-powered Fibocom modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, drivers, mm_plugin_get_name (self), @@ -65,7 +65,7 @@ create_modem (MMPlugin *self, #endif if (mm_port_probe_list_is_xmm (probes)) { - mm_dbg ("XMM-based Fibocom modem found..."); + mm_obj_dbg (self, "XMM-based Fibocom modem found..."); return MM_BASE_MODEM (mm_broadband_modem_xmm_new (uid, drivers, mm_plugin_get_name (self), @@ -73,7 +73,7 @@ create_modem (MMPlugin *self, product)); } - mm_dbg ("Fibocom modem found..."); + mm_obj_dbg (self, "Fibocom modem found..."); return MM_BASE_MODEM (mm_broadband_modem_new (uid, drivers, mm_plugin_get_name (self), From a5df49c5f47b50548150ae9795172e424ff70de9 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 15:46:02 +0200 Subject: [PATCH 101/675] foxconn: port to use object logging --- plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c | 1 - plugins/foxconn/mm-plugin-foxconn.c | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c b/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c index c5940194..95db6ee7 100644 --- a/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c +++ b/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c @@ -26,7 +26,6 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-errors-types.h" #include "mm-modem-helpers.h" #include "mm-base-modem-at.h" diff --git a/plugins/foxconn/mm-plugin-foxconn.c b/plugins/foxconn/mm-plugin-foxconn.c index 5bd2f886..5a2c6120 100644 --- a/plugins/foxconn/mm-plugin-foxconn.c +++ b/plugins/foxconn/mm-plugin-foxconn.c @@ -26,7 +26,7 @@ #include #include "mm-plugin-foxconn.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-broadband-modem.h" #if defined WITH_QMI @@ -55,7 +55,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered Foxconn-branded modem found..."); + mm_obj_dbg (self, "QMI-powered Foxconn-branded modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), @@ -68,7 +68,7 @@ create_modem (MMPlugin *self, if (mm_port_probe_list_has_mbim_port (probes)) { /* Specific implementation for the T77W968 */ if (product == 0xe0b4 || product == 0xe0b5) { - mm_dbg ("MBIM-powered T77W968 modem found..."); + mm_obj_dbg (self, "MBIM-powered T77W968 modem found..."); return MM_BASE_MODEM (mm_broadband_modem_foxconn_t77w968_new (uid, drivers, mm_plugin_get_name (self), @@ -76,7 +76,7 @@ create_modem (MMPlugin *self, product)); } - mm_dbg ("MBIM-powered Foxconn-branded modem found..."); + mm_obj_dbg (self, "MBIM-powered Foxconn-branded modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, drivers, mm_plugin_get_name (self), @@ -85,7 +85,7 @@ create_modem (MMPlugin *self, } #endif - mm_dbg ("Foxconn-branded generic modem found..."); + mm_obj_dbg (self, "Foxconn-branded generic modem found..."); return MM_BASE_MODEM (mm_broadband_modem_new (uid, drivers, mm_plugin_get_name (self), From fb85b5cbf98ae37fe3d727b271ebec84479dd835 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 15:47:09 +0200 Subject: [PATCH 102/675] generic: port to use object logging --- plugins/generic/mm-plugin-generic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/generic/mm-plugin-generic.c b/plugins/generic/mm-plugin-generic.c index 8f429302..242ddf42 100644 --- a/plugins/generic/mm-plugin-generic.c +++ b/plugins/generic/mm-plugin-generic.c @@ -31,7 +31,7 @@ #include "mm-plugin-generic.h" #include "mm-broadband-modem.h" #include "mm-serial-parsers.h" -#include "mm-log.h" +#include "mm-log-object.h" #if defined WITH_QMI #include "mm-broadband-modem-qmi.h" @@ -59,7 +59,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered generic modem found..."); + mm_obj_dbg (self, "QMI-powered generic modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), @@ -70,7 +70,7 @@ create_modem (MMPlugin *self, #if defined WITH_MBIM if (mm_port_probe_list_has_mbim_port (probes)) { - mm_dbg ("MBIM-powered generic modem found..."); + mm_obj_dbg (self, "MBIM-powered generic modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, drivers, mm_plugin_get_name (self), From 59e6e3b1411b511689b94e95ed2aa1c8a4eaa2fc Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 15:47:57 +0200 Subject: [PATCH 103/675] haier: no logging in plugin --- plugins/haier/mm-plugin-haier.c | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/haier/mm-plugin-haier.c b/plugins/haier/mm-plugin-haier.c index 86f17300..27f67dcf 100644 --- a/plugins/haier/mm-plugin-haier.c +++ b/plugins/haier/mm-plugin-haier.c @@ -19,7 +19,6 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-broadband-modem.h" #include "mm-plugin-haier.h" From 1cb39536e9bbbf22f08fe5f05b359f18d6152d10 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Apr 2020 16:17:08 +0200 Subject: [PATCH 104/675] huawei: port to use object logging --- plugins/huawei/mm-broadband-bearer-huawei.c | 24 ++- plugins/huawei/mm-broadband-modem-huawei.c | 147 ++++++++---------- plugins/huawei/mm-modem-helpers-huawei.c | 31 ++-- plugins/huawei/mm-modem-helpers-huawei.h | 10 +- plugins/huawei/mm-plugin-huawei.c | 119 +++++++------- plugins/huawei/mm-sim-huawei.c | 2 - .../huawei/tests/test-modem-helpers-huawei.c | 53 ++----- 7 files changed, 174 insertions(+), 212 deletions(-) diff --git a/plugins/huawei/mm-broadband-bearer-huawei.c b/plugins/huawei/mm-broadband-bearer-huawei.c index a15edc60..81a2e5a7 100644 --- a/plugins/huawei/mm-broadband-bearer-huawei.c +++ b/plugins/huawei/mm-broadband-bearer-huawei.c @@ -27,7 +27,7 @@ #include #include "mm-base-modem-at.h" #include "mm-broadband-bearer-huawei.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-huawei.h" #include "mm-daemon-enums-types.h" @@ -175,7 +175,7 @@ connect_dhcp_check_ready (MMBaseModem *modem, g_free (strarr[0]); g_free (strarr[1]); } else { - mm_dbg ("Unexpected response to ^DHCP command: %s", error->message); + mm_obj_dbg (self, "unexpected response to ^DHCP command: %s", error->message); } } @@ -233,8 +233,8 @@ connect_ndisstatqry_check_ready (MMBaseModem *modem, &ipv6_connected, &error)) { ctx->failed_ndisstatqry_count++; - mm_dbg ("Unexpected response to ^NDISSTATQRY command: %s (Attempts so far: %u)", - error->message, ctx->failed_ndisstatqry_count); + mm_obj_dbg (self, "unexpected response to ^NDISSTATQRY command: %s (%u attempts so far)", + error->message, ctx->failed_ndisstatqry_count); g_error_free (error); } @@ -358,8 +358,7 @@ connect_3gpp_context_step (GTask *task) ip_family = mm_base_bearer_get_default_ip_family (MM_BASE_BEARER (self)); ip_family_str = mm_bearer_ip_family_build_string_from_mask (ip_family); - mm_dbg ("No specific IP family requested, defaulting to %s", - ip_family_str); + mm_obj_dbg (self, "no specific IP family requested, defaulting to %s", ip_family_str); g_free (ip_family_str); } @@ -633,8 +632,8 @@ disconnect_ndisstatqry_check_ready (MMBaseModem *modem, &ipv6_connected, &error)) { ctx->failed_ndisstatqry_count++; - mm_dbg ("Unexpected response to ^NDISSTATQRY command: %s (Attempts so far: %u)", - error->message, ctx->failed_ndisstatqry_count); + mm_obj_dbg (self, "unexpected response to ^NDISSTATQRY command: %s (%u attempts so far)", + error->message, ctx->failed_ndisstatqry_count); g_error_free (error); } @@ -808,8 +807,7 @@ disconnect_3gpp (MMBroadbandBearer *_self, static gboolean network_disconnect_3gpp_delayed (MMBroadbandBearerHuawei *self) { - mm_dbg ("Disconnect bearer '%s' on network request.", - mm_base_bearer_get_path (MM_BASE_BEARER (self))); + mm_obj_dbg (self, "disconnect bearer on network request"); self->priv->network_disconnect_pending_id = 0; mm_base_bearer_report_connection_status (MM_BASE_BEARER (self), @@ -833,8 +831,7 @@ report_connection_status (MMBaseBearer *bearer, if (self->priv->connect_pending || self->priv->disconnect_pending) return; - mm_dbg ("Received spontaneous ^NDISSTAT (%s)", - mm_bearer_connection_status_get_string (status)); + mm_obj_dbg (self, "received spontaneous ^NDISSTAT (%s)", mm_bearer_connection_status_get_string (status)); /* Ignore 'CONNECTED' */ if (status == MM_BEARER_CONNECTION_STATUS_CONNECTED) @@ -848,8 +845,7 @@ report_connection_status (MMBaseBearer *bearer, * bearer_report_connection_status for details. */ if (mm_base_bearer_get_status (bearer) == MM_BEARER_STATUS_CONNECTED && self->priv->network_disconnect_pending_id == 0) { - mm_dbg ("Delay network-initiated disconnection of bearer '%s'", - mm_base_bearer_get_path (MM_BASE_BEARER (self))); + mm_obj_dbg (self, "delay network-initiated disconnection of bearer"); self->priv->network_disconnect_pending_id = (g_timeout_add_seconds ( 4, (GSourceFunc) network_disconnect_3gpp_delayed, diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index 20e5fe50..e6f45750 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -31,7 +31,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-errors-types.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-huawei.h" @@ -245,7 +245,7 @@ run_sysinfo_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (self, res, &error); if (!response) { - mm_dbg ("^SYSINFO failed: %s", error->message); + mm_obj_dbg (self, "^SYSINFO failed: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -262,7 +262,7 @@ run_sysinfo_ready (MMBaseModem *self, &result->sys_submode_valid, &result->sys_submode, &error)) { - mm_dbg ("^SYSINFO parsing failed: %s", error->message); + mm_obj_dbg (self, "^SYSINFO parsing failed: %s", error->message); g_task_return_error (task, error); g_object_unref (task); g_free (result); @@ -300,14 +300,14 @@ run_sysinfoex_ready (MMBaseModem *_self, /* First time we try, we fallback to ^SYSINFO */ if (self->priv->sysinfoex_support == FEATURE_SUPPORT_UNKNOWN) { self->priv->sysinfoex_support = FEATURE_NOT_SUPPORTED; - mm_dbg ("^SYSINFOEX failed: %s, assuming unsupported", error->message); + mm_obj_dbg (self, "^SYSINFOEX failed: %s, assuming unsupported", error->message); g_error_free (error); run_sysinfo (self, task); return; } /* Otherwise, propagate error */ - mm_dbg ("^SYSINFOEX failed: %s", error->message); + mm_obj_dbg (self, "^SYSINFOEX failed: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -326,7 +326,7 @@ run_sysinfoex_ready (MMBaseModem *_self, &result->sys_mode, &result->sys_submode, &error)) { - mm_dbg ("^SYSINFOEX parsing failed: %s", error->message); + mm_obj_dbg (self, "^SYSINFOEX parsing failed: %s", error->message); g_task_return_error (task, error); g_object_unref (task); g_free (result); @@ -571,7 +571,6 @@ load_access_technologies_finish (MMIfaceModem *self, guint *mask, GError **error) { - gchar *str; MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; gboolean extended = FALSE; guint srv_status = 0; @@ -605,10 +604,6 @@ load_access_technologies_finish (MMIfaceModem *self, huawei_sysinfo_mode_to_act (sys_mode)); } - str = mm_modem_access_technology_build_string_from_mask (act); - mm_dbg ("Access Technology: '%s'", str); - g_free (str); - *access_technologies = act; *mask = MM_MODEM_ACCESS_TECHNOLOGY_ANY; return TRUE; @@ -619,7 +614,6 @@ load_access_technologies (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading access technology (huawei)..."); sysinfo (MM_BROADBAND_MODEM_HUAWEI (self), callback, user_data); } @@ -698,7 +692,6 @@ load_unlock_retries (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading unlock retries (huawei)..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "^CPIN?", 3, @@ -872,7 +865,6 @@ load_current_bands (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading current bands (huawei)..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "^SYSCFG?", 3, @@ -973,9 +965,9 @@ syscfg_test_ready (MMBroadbandModemHuawei *self, * string to get parsed. Ugly, ugly, blame Huawei. */ if (response[0]) - self->priv->syscfg_supported_modes = mm_huawei_parse_syscfg_test (response, &error); + self->priv->syscfg_supported_modes = mm_huawei_parse_syscfg_test (response, self, &error); else { - self->priv->syscfg_supported_modes = mm_huawei_parse_syscfg_test (MM_HUAWEI_DEFAULT_SYSCFG_FMT, NULL); + self->priv->syscfg_supported_modes = mm_huawei_parse_syscfg_test (MM_HUAWEI_DEFAULT_SYSCFG_FMT, self, NULL); g_assert (self->priv->syscfg_supported_modes != NULL); } } @@ -1006,7 +998,7 @@ syscfg_test_ready (MMBroadbandModemHuawei *self, combinations, (GDestroyNotify)g_array_unref); } else { - mm_dbg ("Error while checking ^SYSCFG format: %s", error->message); + mm_obj_dbg (self, "error while checking ^SYSCFG format: %s", error->message); /* If SIM-PIN error, don't mark as feature unsupported; we'll retry later */ if (!g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, @@ -1062,7 +1054,7 @@ syscfgex_test_ready (MMBroadbandModemHuawei *self, /* If SIM-PIN error, don't mark as feature unsupported; we'll retry later */ if (error) { - mm_dbg ("Error while checking ^SYSCFGEX format: %s", error->message); + mm_obj_dbg (self, "error while checking ^SYSCFGEX format: %s", error->message); if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_SIM_PIN)) { @@ -1094,7 +1086,7 @@ prefmode_test_ready (MMBroadbandModemHuawei *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (response) - self->priv->prefmode_supported_modes = mm_huawei_parse_prefmode_test (response, &error); + self->priv->prefmode_supported_modes = mm_huawei_parse_prefmode_test (response, self, &error); if (self->priv->prefmode_supported_modes) { MMModemModeCombination mode; @@ -1122,7 +1114,7 @@ prefmode_test_ready (MMBroadbandModemHuawei *self, combinations, (GDestroyNotify)g_array_unref); } else { - mm_dbg ("Error while checking ^PREFMODE format: %s", error->message); + mm_obj_dbg (self, "error while checking ^PREFMODE format: %s", error->message); /* If SIM-PIN error, don't mark as feature unsupported; we'll retry later */ if (!g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, @@ -1281,8 +1273,6 @@ load_current_modes (MMIfaceModem *_self, MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); GTask *task; - mm_dbg ("loading current modes (huawei)..."); - task = g_task_new (self, NULL, callback, user_data); if (self->priv->syscfgex_support == FEATURE_SUPPORTED) { @@ -1498,8 +1488,6 @@ set_current_modes (MMIfaceModem *_self, GTask *task; GError *error = NULL; - mm_dbg ("setting current modes (huawei)..."); - task = g_task_new (self, NULL, callback, user_data); if (self->priv->syscfgex_support == FEATURE_SUPPORTED) @@ -1540,7 +1528,6 @@ huawei_signal_changed (MMPortSerialAt *port, quality = MM_CLAMP_HIGH (quality, 31) * 100 / 31; } - mm_dbg ("3GPP signal quality: %u", quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); } @@ -1571,7 +1558,7 @@ huawei_mode_changed (MMPortSerialAt *port, (act < MM_MODEM_ACCESS_TECHNOLOGY_GSM || act > MM_MODEM_ACCESS_TECHNOLOGY_EDGE)) { str = mm_modem_access_technology_build_string_from_mask (act); - mm_warn ("Unexpected access technology (%s) in GSM/GPRS mode", str); + mm_obj_warn (self, "unexpected access technology (%s) in GSM/GPRS mode", str); g_free (str); act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; } @@ -1584,7 +1571,7 @@ huawei_mode_changed (MMPortSerialAt *port, (act < MM_MODEM_ACCESS_TECHNOLOGY_UMTS || act > MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS)) { str = mm_modem_access_technology_build_string_from_mask (act); - mm_warn ("Unexpected access technology (%s) in WCDMA mode", str); + mm_obj_warn (self, "unexpected access technology (%s) in WCDMA mode", str); g_free (str); act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; } @@ -1596,7 +1583,7 @@ huawei_mode_changed (MMPortSerialAt *port, if (act != MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN && act != MM_MODEM_ACCESS_TECHNOLOGY_1XRTT) { str = mm_modem_access_technology_build_string_from_mask (act); - mm_warn ("Unexpected access technology (%s) in CDMA mode", str); + mm_obj_warn (self, "unexpected access technology (%s) in CDMA mode", str); g_free (str); act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; } @@ -1611,7 +1598,7 @@ huawei_mode_changed (MMPortSerialAt *port, (act < MM_MODEM_ACCESS_TECHNOLOGY_EVDO0 || act > MM_MODEM_ACCESS_TECHNOLOGY_EVDOB)) { str = mm_modem_access_technology_build_string_from_mask (act); - mm_warn ("Unexpected access technology (%s) in EVDO mode", str); + mm_obj_warn (self, "unexpected access technology (%s) in EVDO mode", str); g_free (str); act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; } @@ -1625,14 +1612,10 @@ huawei_mode_changed (MMPortSerialAt *port, break; default: - mm_warn ("Unexpected mode change value reported: '%d'", a); + mm_obj_warn (self, "unexpected mode change value reported: '%d'", a); return; } - str = mm_modem_access_technology_build_string_from_mask (act); - mm_dbg ("Access Technology: '%s'", str); - g_free (str); - mm_iface_modem_update_access_technologies (MM_IFACE_MODEM (self), act, mask); } @@ -1645,10 +1628,9 @@ huawei_status_changed (MMPortSerialAt *port, gint n1, n2, n3, n4, n5, n6, n7; str = g_match_info_fetch (match_info, 1); - if (sscanf (str, "%x,%x,%x,%x,%x,%x,%x", &n1, &n2, &n3, &n4, &n5, &n6, &n7)) { - mm_dbg ("Duration: %d Up: %d Kbps Down: %d Kbps Total: %d Total: %d\n", - n1, n2 * 8 / 1000, n3 * 8 / 1000, n4 / 1024, n5 / 1024); - } + if (sscanf (str, "%x,%x,%x,%x,%x,%x,%x", &n1, &n2, &n3, &n4, &n5, &n6, &n7)) + mm_obj_dbg (self, "duration: %d up: %d Kbps down: %d Kbps total: %d total: %d\n", + n1, n2 * 8 / 1000, n3 * 8 / 1000, n4 / 1024, n5 / 1024); g_free (str); } @@ -1693,19 +1675,19 @@ huawei_ndisstat_changed (MMPortSerialAt *port, &ndisstat_result.ipv6_available, &ndisstat_result.ipv6_connected, &error)) { - mm_dbg ("Ignore invalid ^NDISSTAT unsolicited message: '%s' (error %s)", - str, error->message); + mm_obj_dbg (self, "ignored invalid ^NDISSTAT unsolicited message '%s': %s", + str, error->message); g_error_free (error); g_free (str); return; } g_free (str); - mm_dbg ("NDIS status: IPv4 %s, IPv6 %s", - ndisstat_result.ipv4_available ? - (ndisstat_result.ipv4_connected ? "connected" : "disconnected") : "not available", - ndisstat_result.ipv6_available ? - (ndisstat_result.ipv6_connected ? "connected" : "disconnected") : "not available"); + mm_obj_dbg (self, "NDIS status: IPv4 %s, IPv6 %s", + ndisstat_result.ipv4_available ? + (ndisstat_result.ipv4_connected ? "connected" : "disconnected") : "not available", + ndisstat_result.ipv6_available ? + (ndisstat_result.ipv6_connected ? "connected" : "disconnected") : "not available"); /* If empty bearer list, nothing else to do */ g_object_get (self, @@ -1805,7 +1787,7 @@ huawei_hcsq_changed (MMPortSerialAt *port, &value4, &value5, &error)) { - mm_dbg ("Ignored invalid ^HCSQ message: %s (error %s)", str, error->message); + mm_obj_dbg (self, "ignored invalid ^HCSQ message '%s': %s", str, error->message); g_error_free (error); g_free (str); return; @@ -2180,7 +2162,7 @@ create_bearer_for_net_port (GTask *task) switch (self->priv->ndisdup_support) { case FEATURE_NOT_SUPPORTED: - mm_dbg ("^NDISDUP not supported, creating default bearer..."); + mm_obj_dbg (self, "^NDISDUP not supported, creating default bearer..."); mm_broadband_bearer_new (MM_BROADBAND_MODEM (self), properties, NULL, /* cancellable */ @@ -2188,7 +2170,7 @@ create_bearer_for_net_port (GTask *task) task); return; case FEATURE_SUPPORTED: - mm_dbg ("^NDISDUP supported, creating huawei bearer..."); + mm_obj_dbg (self, "^NDISDUP supported, creating huawei bearer..."); mm_broadband_bearer_huawei_new (MM_BROADBAND_MODEM_HUAWEI (self), properties, NULL, /* cancellable */ @@ -2212,7 +2194,7 @@ peek_port_at_for_data (MMBroadbandModemHuawei *self, g_warn_if_fail (mm_port_get_subsys (port) == MM_PORT_SUBSYS_NET); net_port_parent_path = mm_kernel_device_get_interface_sysfs_path (mm_port_peek_kernel_device (port)); if (!net_port_parent_path) { - mm_warn ("(%s) no parent path for net port", mm_port_get_device (port)); + mm_obj_warn (self, "no parent path for net port %s", mm_port_get_device (port)); return NULL; } @@ -2245,8 +2227,7 @@ mm_broadband_modem_huawei_peek_port_at_for_data (MMBroadbandModemHuawei *self, found = peek_port_at_for_data (self, port); if (!found) - mm_warn ("Couldn't find associated cdc-wdm port for 'net/%s'", - mm_port_get_device (port)); + mm_obj_warn (self, "couldn't find associated cdc-wdm port for %s", mm_port_get_device (port)); return found; } @@ -2261,22 +2242,21 @@ ensure_ndisdup_support_checked (MMBroadbandModemHuawei *self, /* First, check for devices which support NDISDUP on any AT port. These * devices are tagged by udev */ if (mm_kernel_device_get_global_property_as_boolean (mm_port_peek_kernel_device (port), "ID_MM_HUAWEI_NDISDUP_SUPPORTED")) { - mm_dbg ("This device (%s) can support ndisdup feature", mm_port_get_device (port)); + mm_obj_dbg (self, "^NDISDUP is supported"); self->priv->ndisdup_support = FEATURE_SUPPORTED; } /* Then, look for devices which have both a net port and a cdc-wdm * AT-capable port. We assume that these devices allow NDISDUP only * when issued in the cdc-wdm port. */ else if (peek_port_at_for_data (self, port)) { - mm_dbg ("This device (%s) can support ndisdup feature on non-serial AT port", - mm_port_get_device (port)); + mm_obj_dbg (self, "^NDISDUP is supported on non-serial AT port"); self->priv->ndisdup_support = FEATURE_SUPPORTED; } if (self->priv->ndisdup_support != FEATURE_SUPPORT_UNKNOWN) return; - mm_dbg ("This device (%s) can not support ndisdup feature", mm_port_get_device (port)); + mm_obj_dbg (self, "^NDISDUP is not supported"); self->priv->ndisdup_support = FEATURE_NOT_SUPPORTED; } @@ -2299,7 +2279,7 @@ huawei_modem_create_bearer (MMIfaceModem *self, return; } - mm_dbg ("Creating default bearer..."); + mm_obj_dbg (self, "creating default bearer..."); mm_broadband_bearer_new (MM_BROADBAND_MODEM (self), properties, NULL, /* cancellable */ @@ -2380,7 +2360,7 @@ huawei_1x_signal_changed (MMPortSerialAt *port, return; quality = MM_CLAMP_HIGH (quality, 100); - mm_dbg ("1X signal quality: %u", quality); + mm_obj_dbg (self, "1X signal quality: %u", quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); } @@ -2395,7 +2375,7 @@ huawei_evdo_signal_changed (MMPortSerialAt *port, return; quality = MM_CLAMP_HIGH (quality, 100); - mm_dbg ("EVDO signal quality: %u", quality); + mm_obj_dbg (self, "EVDO signal quality: %u", quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); } @@ -2487,7 +2467,6 @@ modem_load_signal_quality (MMIfaceModem *self, MMModemCdmaRegistrationState evdo_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; const char *command = "^CSQLVL"; - mm_dbg ("loading signal quality..."); task = g_task_new (self, NULL, callback, user_data); /* 3GPP modems can just run parent's signal quality loading */ @@ -2838,7 +2817,7 @@ registration_state_sysinfo_ready (MMBroadbandModemHuawei *self, if (!cdma1x && !evdo) { /* Say we're registered to something even though sysmode parsing failed */ - mm_dbg ("Assuming registered at least in CDMA1x"); + mm_obj_dbg (self, "assuming registered at least in CDMA1x"); ctx->state.detailed_cdma1x_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; } } @@ -2911,7 +2890,7 @@ cvoice_check_ready (MMBaseModem *_self, &self->priv->audio_bits, &error)) { self->priv->cvoice_support = FEATURE_NOT_SUPPORTED; - mm_dbg ("Huawei-specific CVOICE is unsupported: %s", error->message); + mm_obj_dbg (self, "Huawei-specific CVOICE is unsupported: %s", error->message); g_clear_error (&error); /* Now check generic support */ @@ -2921,7 +2900,7 @@ cvoice_check_ready (MMBaseModem *_self, return; } - mm_dbg ("Huawei-specific CVOICE is supported"); + mm_obj_dbg (self, "Huawei-specific CVOICE is supported"); self->priv->cvoice_support = FEATURE_SUPPORTED; g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -3097,23 +3076,23 @@ orig_received (MMPortSerialAt *port, guint aux = 0; if (!mm_get_uint_from_match_info (match_info, 2, &aux)) { - mm_warn ("couldn't parse call type from ^ORIG"); + mm_obj_warn (self, "couldn't parse call type from ^ORIG"); return; } if (aux != HUAWEI_CALL_TYPE_VOICE && aux != HUAWEI_CALL_TYPE_EMERGENCY) { - mm_dbg ("ignored ^ORIG for non-voice call"); + mm_obj_dbg (self, "ignored ^ORIG for non-voice call"); return; } if (!mm_get_uint_from_match_info (match_info, 1, &aux)) { - mm_warn ("couldn't parse call index from ^ORIG"); + mm_obj_warn (self, "couldn't parse call index from ^ORIG"); return; } call_info.index = aux; call_info.state = MM_CALL_STATE_DIALING; call_info.direction = MM_CALL_DIRECTION_OUTGOING; - mm_dbg ("call %u state updated: dialing", call_info.index); + mm_obj_dbg (self, "call %u state updated: dialing", call_info.index); mm_iface_modem_voice_report_call (MM_IFACE_MODEM_VOICE (self), &call_info); } @@ -3127,14 +3106,14 @@ conf_received (MMPortSerialAt *port, guint aux = 0; if (!mm_get_uint_from_match_info (match_info, 1, &aux)) { - mm_warn ("couldn't parse call index from ^CONF"); + mm_obj_warn (self, "couldn't parse call index from ^CONF"); return; } call_info.index = aux; call_info.state = MM_CALL_STATE_RINGING_OUT; call_info.direction = MM_CALL_DIRECTION_OUTGOING; - mm_dbg ("call %u state updated: ringing-out", call_info.index); + mm_obj_dbg (self, "call %u state updated: ringing-out", call_info.index); mm_iface_modem_voice_report_call (MM_IFACE_MODEM_VOICE (self), &call_info); } @@ -3148,14 +3127,14 @@ conn_received (MMPortSerialAt *port, guint aux = 0; if (!mm_get_uint_from_match_info (match_info, 1, &aux)) { - mm_warn ("couldn't parse call index from ^CONN"); + mm_obj_warn (self, "couldn't parse call index from ^CONN"); return; } call_info.index = aux; call_info.state = MM_CALL_STATE_ACTIVE; call_info.direction = MM_CALL_DIRECTION_UNKNOWN; - mm_dbg ("call %u state updated: active", aux); + mm_obj_dbg (self, "call %u state updated: active", aux); mm_iface_modem_voice_report_call (MM_IFACE_MODEM_VOICE (self), &call_info); } @@ -3170,20 +3149,20 @@ cend_received (MMPortSerialAt *port, /* only index is mandatory */ if (!mm_get_uint_from_match_info (match_info, 1, &aux)) { - mm_warn ("couldn't parse call index from ^CEND"); + mm_obj_warn (self, "couldn't parse call index from ^CEND"); return; } call_info.index = aux; call_info.state = MM_CALL_STATE_TERMINATED; call_info.direction = MM_CALL_DIRECTION_UNKNOWN; - mm_dbg ("call %u state updated: terminated", call_info.index); + mm_obj_dbg (self, "call %u state updated: terminated", call_info.index); if (mm_get_uint_from_match_info (match_info, 2, &aux)) - mm_dbg (" call duration: %u seconds", aux); + mm_obj_dbg (self, " call duration: %u seconds", aux); if (mm_get_uint_from_match_info (match_info, 3, &aux)) - mm_dbg (" end status code: %u", aux); + mm_obj_dbg (self, " end status code: %u", aux); if (mm_get_uint_from_match_info (match_info, 4, &aux)) - mm_dbg (" call control cause: %u", aux); + mm_obj_dbg (self, " call control cause: %u", aux); mm_iface_modem_voice_report_call (MM_IFACE_MODEM_VOICE (self), &call_info); } @@ -3196,7 +3175,7 @@ ddtmf_received (MMPortSerialAt *port, gchar *dtmf; dtmf = g_match_info_fetch (match_info, 1); - mm_dbg ("received DTMF: %s", dtmf); + mm_obj_dbg (self, "received DTMF: %s", dtmf); /* call index unknown */ mm_iface_modem_voice_received_dtmf (MM_IFACE_MODEM_VOICE (self), 0, dtmf); g_free (dtmf); @@ -3582,8 +3561,8 @@ enable_disable_unsolicited_rfswitch_event_handler (MMBroadbandModemHuawei *self, ports = mm_broadband_modem_huawei_get_at_port_list (self); - mm_dbg ("%s ^RFSWITCH unsolicited event handler", - enable ? "Enable" : "Disable"); + mm_obj_dbg (self, "%s ^RFSWITCH unsolicited event handler", + enable ? "enable" : "disable"); for (l = ports; l; l = g_list_next (l)) { MMPortSerialAt *port = MM_PORT_SERIAL_AT (l->data); @@ -3639,17 +3618,17 @@ huawei_rfswitch_check_ready (MMBaseModem *_self, response = mm_strip_tag (response, "^RFSWITCH:"); if (sscanf (response, "%d", &sw_state) != 1 || (sw_state != 0 && sw_state != 1)) { - mm_warn ("Couldn't parse ^RFSWITCH response: '%s'", response); + mm_obj_warn (self, "couldn't parse ^RFSWITCH response '%s'", response); error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Couldn't parse ^RFSWITCH response: '%s'", + "Couldn't parse ^RFSWITCH response '%s'", response); } } if (self->priv->rfswitch_support == FEATURE_SUPPORT_UNKNOWN) { if (error) { - mm_dbg ("The device does not support ^RFSWITCH"); + mm_obj_dbg (self, "^RFSWITCH is not supported"); self->priv->rfswitch_support = FEATURE_NOT_SUPPORTED; g_error_free (error); /* Fall back to parent's load_power_state */ @@ -3659,7 +3638,7 @@ huawei_rfswitch_check_ready (MMBaseModem *_self, return; } - mm_dbg ("The device supports ^RFSWITCH"); + mm_obj_dbg (self, "^RFSWITCH is supported"); self->priv->rfswitch_support = FEATURE_SUPPORTED; } @@ -4304,7 +4283,7 @@ hcsq_get_ready (MMBaseModem *_self, * be updated. */ if (!mm_base_modem_at_command_finish (_self, res, &error)) { - mm_dbg ("^HCSQ failed: %s", error->message); + mm_obj_dbg (self, "^HCSQ failed: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -4330,8 +4309,6 @@ signal_load_values (MMIfaceModemSignal *_self, MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); GTask *task; - mm_dbg ("loading extended signal information..."); - task = g_task_new (self, cancellable, callback, user_data); /* Clear any previous detailed signal values to get new ones */ diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c index c7fc124d..c582dfbb 100644 --- a/plugins/huawei/mm-modem-helpers-huawei.c +++ b/plugins/huawei/mm-modem-helpers-huawei.c @@ -22,7 +22,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-huawei.h" @@ -429,8 +429,9 @@ mode_from_prefmode (guint huawei_mode, } GArray * -mm_huawei_parse_prefmode_test (const gchar *response, - GError **error) +mm_huawei_parse_prefmode_test (const gchar *response, + gpointer log_object, + GError **error) { gchar **split; guint i; @@ -461,12 +462,12 @@ mm_huawei_parse_prefmode_test (const gchar *response, continue; if (!mm_get_uint_from_str (split[i], &val)) { - mm_dbg ("Error parsing ^PREFMODE value: %s", split[i]); + mm_obj_dbg (log_object, "error parsing ^PREFMODE value '%s'", split[i]); continue; } if (!mode_from_prefmode (val, &preferred, &inner_error)) { - mm_dbg ("Unhandled ^PREFMODE: %s", inner_error->message); + mm_obj_dbg (log_object, "unhandled ^PREFMODE value: %s", inner_error->message); g_error_free (inner_error); continue; } @@ -708,9 +709,10 @@ mode_from_syscfg (guint huawei_mode, } static GArray * -parse_syscfg_modes (const gchar *modes_str, - const gchar *acqorder_str, - GError **error) +parse_syscfg_modes (const gchar *modes_str, + const gchar *acqorder_str, + gpointer log_object, + GError **error) { GArray *out; gchar **split; @@ -720,7 +722,7 @@ parse_syscfg_modes (const gchar *modes_str, /* Start parsing acquisition order */ if (!sscanf (acqorder_str, "%d-%d", &min_acqorder, &max_acqorder)) - mm_dbg ("Error parsing ^SYSCFG acquisition order range (%s)", acqorder_str); + mm_obj_dbg (log_object, "error parsing ^SYSCFG acquisition order range '%s'", acqorder_str); /* Just in case, we default to supporting only auto */ if (max_acqorder < min_acqorder) { @@ -741,13 +743,13 @@ parse_syscfg_modes (const gchar *modes_str, MMHuaweiSyscfgCombination combination; if (!mm_get_uint_from_str (mm_strip_quotes (split[i]), &val)) { - mm_dbg ("Error parsing ^SYSCFG mode value: %s", split[i]); + mm_obj_dbg (log_object, "error parsing ^SYSCFG mode value: %s", split[i]); continue; } if (!mode_from_syscfg (val, &allowed, &inner_error)) { if (inner_error) { - mm_dbg ("Unhandled ^SYSCFG: %s", inner_error->message); + mm_obj_dbg (log_object, "unhandled ^SYSCFG: %s", inner_error->message); g_error_free (inner_error); } continue; @@ -808,8 +810,9 @@ parse_syscfg_modes (const gchar *modes_str, } GArray * -mm_huawei_parse_syscfg_test (const gchar *response, - GError **error) +mm_huawei_parse_syscfg_test (const gchar *response, + gpointer log_object, + GError **error) { gchar **split; GError *inner_error = NULL; @@ -846,7 +849,7 @@ mm_huawei_parse_syscfg_test (const gchar *response, } /* Parse supported mode combinations */ - out = parse_syscfg_modes (split[0], split[1], &inner_error); + out = parse_syscfg_modes (split[0], split[1], log_object, &inner_error); g_strfreev (split); diff --git a/plugins/huawei/mm-modem-helpers-huawei.h b/plugins/huawei/mm-modem-helpers-huawei.h index 502f694f..2d740b3a 100644 --- a/plugins/huawei/mm-modem-helpers-huawei.h +++ b/plugins/huawei/mm-modem-helpers-huawei.h @@ -70,8 +70,9 @@ typedef struct { MMModemMode preferred; } MMHuaweiPrefmodeCombination; -GArray *mm_huawei_parse_prefmode_test (const gchar *response, - GError **error); +GArray *mm_huawei_parse_prefmode_test (const gchar *response, + gpointer log_object, + GError **error); /*****************************************************************************/ /* ^PREFMODE response parser */ @@ -94,8 +95,9 @@ typedef struct { MMModemMode preferred; } MMHuaweiSyscfgCombination; -GArray *mm_huawei_parse_syscfg_test (const gchar *response, - GError **error); +GArray *mm_huawei_parse_syscfg_test (const gchar *response, + gpointer log_object, + GError **error); /*****************************************************************************/ /* ^SYSCFG response parser */ diff --git a/plugins/huawei/mm-plugin-huawei.c b/plugins/huawei/mm-plugin-huawei.c index 09189058..2f6febfa 100644 --- a/plugins/huawei/mm-plugin-huawei.c +++ b/plugins/huawei/mm-plugin-huawei.c @@ -52,9 +52,10 @@ MM_PLUGIN_DEFINE_MINOR_VERSION #define MAX_WAIT_TIME 5 typedef struct { - guint first_usbif; - guint timeout_id; - gboolean custom_init_run; + MMPortProbe *probe; + guint first_usbif; + guint timeout_id; + gboolean custom_init_run; } FirstInterfaceContext; static void @@ -62,6 +63,7 @@ first_interface_context_free (FirstInterfaceContext *ctx) { if (ctx->timeout_id) g_source_remove (ctx->timeout_id); + g_object_unref (ctx->probe); g_slice_free (FirstInterfaceContext, ctx); } @@ -73,19 +75,17 @@ first_interface_context_free (FirstInterfaceContext *ctx) #define TAG_AT_PORT_FLAGS "at-port-flags" typedef struct { - MMPortProbe *probe; MMPortSerialAt *port; - gboolean curc_done; - guint curc_retries; - gboolean getportmode_done; - guint getportmode_retries; + gboolean curc_done; + guint curc_retries; + gboolean getportmode_done; + guint getportmode_retries; } HuaweiCustomInitContext; static void huawei_custom_init_context_free (HuaweiCustomInitContext *ctx) { g_object_unref (ctx->port); - g_object_unref (ctx->probe); g_slice_free (HuaweiCustomInitContext, ctx); } @@ -124,19 +124,20 @@ cache_port_mode (MMDevice *device, static void getportmode_ready (MMPortSerialAt *port, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { + MMPortProbe *probe; HuaweiCustomInitContext *ctx; - const gchar *response; - GError *error = NULL; + const gchar *response; + GError *error = NULL; - ctx = g_task_get_task_data (task); + probe = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mm_port_serial_at_command_finish (port, res, &error); if (error) { - mm_dbg ("(Huawei) couldn't get port mode: '%s'", - error->message); + mm_obj_dbg (probe, "couldn't get port mode: '%s'", error->message); /* If any error occurred that was not ERROR or COMMAND NOT SUPPORT then * retry the command. @@ -151,10 +152,10 @@ getportmode_ready (MMPortSerialAt *port, MMDevice *device; guint n_cached_port_modes = 0; - mm_dbg ("(Huawei) port mode layout retrieved"); + mm_obj_dbg (probe, "(Huawei) port mode layout retrieved"); /* Results are cached in the parent device object */ - device = mm_port_probe_peek_device (ctx->probe); + device = mm_port_probe_peek_device (probe); n_cached_port_modes += cache_port_mode (device, response, "PCUI:", TAG_HUAWEI_PCUI_PORT); n_cached_port_modes += cache_port_mode (device, response, "MDM:", TAG_HUAWEI_MODEM_PORT); n_cached_port_modes += cache_port_mode (device, response, "NDIS:", TAG_HUAWEI_NDIS_PORT); @@ -167,7 +168,7 @@ getportmode_ready (MMPortSerialAt *port, g_object_set_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED, GUINT_TO_POINTER (TRUE)); /* Mark port as being AT already */ - mm_port_probe_set_result_at (ctx->probe, TRUE); + mm_port_probe_set_result_at (probe, TRUE); } ctx->getportmode_done = TRUE; @@ -181,13 +182,15 @@ getportmode_ready (MMPortSerialAt *port, static void curc_ready (MMPortSerialAt *port, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { + MMPortProbe *probe; HuaweiCustomInitContext *ctx; - GError *error = NULL; + g_autoptr(GError) error = NULL; - ctx = g_task_get_task_data (task); + probe = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); mm_port_serial_at_command_finish (port, res, &error); if (error) { @@ -197,23 +200,20 @@ curc_ready (MMPortSerialAt *port, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) goto out; - mm_dbg ("(Huawei) couldn't turn off unsolicited messages in secondary ports: '%s'", - error->message); + mm_obj_dbg (probe, "(Huawei) couldn't turn off unsolicited messages in secondary ports: %s", error->message); } - mm_dbg ("(Huawei) unsolicited messages in secondary ports turned off"); + mm_obj_dbg (probe, "(Huawei) unsolicited messages in secondary ports turned off"); ctx->curc_done = TRUE; out: - if (error) - g_error_free (error); - huawei_custom_init_step (task); } static void -try_next_usbif (MMDevice *device) +try_next_usbif (MMPortProbe *probe, + MMDevice *device) { FirstInterfaceContext *fi_ctx; GList *l; @@ -226,13 +226,13 @@ try_next_usbif (MMDevice *device) * and enable that one as being first */ closest = G_MAXUINT; for (l = mm_device_peek_port_probe_list (device); l; l = g_list_next (l)) { - MMPortProbe *probe = MM_PORT_PROBE (l->data); + MMPortProbe *iter = MM_PORT_PROBE (l->data); /* Only expect ttys for next probing attempt */ - if (g_str_equal (mm_port_probe_get_port_subsys (probe), "tty")) { + if (g_str_equal (mm_port_probe_get_port_subsys (iter), "tty")) { guint usbif; - usbif = mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (probe), "ID_USB_INTERFACE_NUM"); + usbif = mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (iter), "ID_USB_INTERFACE_NUM"); if (usbif == fi_ctx->first_usbif) { /* This is the one we just probed, which wasn't yet removed, so just skip it */ } else if (usbif > fi_ctx->first_usbif && @@ -245,10 +245,9 @@ try_next_usbif (MMDevice *device) if (closest == G_MAXUINT) { /* No more ttys to try! Just return something */ closest = 0; - mm_dbg ("(Huawei) No more ports to run initial probing"); - } else { - mm_dbg ("(Huawei) Will try initial probing with interface '%d' instead", closest); - } + mm_obj_dbg (probe, "(Huawei) no more ports to run initial probing"); + } else + mm_obj_dbg (probe, "(Huawei) will try initial probing with interface '%d' instead", closest); fi_ctx->first_usbif = closest; } @@ -256,16 +255,17 @@ try_next_usbif (MMDevice *device) static void huawei_custom_init_step (GTask *task) { + MMPortProbe *probe; HuaweiCustomInitContext *ctx; - FirstInterfaceContext *fi_ctx; - MMKernelDevice *port; + FirstInterfaceContext *fi_ctx; + MMKernelDevice *port; - ctx = g_task_get_task_data (task); + probe = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* If cancelled, end */ if (g_task_return_error_if_cancelled (task)) { - mm_dbg ("(Huawei) no need to keep on running custom init in (%s)", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "(Huawei) no need to keep on running custom init"); g_object_unref (task); return; } @@ -273,9 +273,9 @@ huawei_custom_init_step (GTask *task) if (!ctx->curc_done) { if (ctx->curc_retries == 0) { /* All retries consumed, probably not an AT port */ - mm_port_probe_set_result_at (ctx->probe, FALSE); + mm_port_probe_set_result_at (probe, FALSE); /* Try with next */ - try_next_usbif (mm_port_probe_peek_device (ctx->probe)); + try_next_usbif (probe, mm_port_probe_peek_device (probe)); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -296,7 +296,7 @@ huawei_custom_init_step (GTask *task) } /* Try to get a port map from the modem */ - port = mm_port_probe_peek_port (ctx->probe); + port = mm_port_probe_peek_port (probe); if (!ctx->getportmode_done && !mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_HUAWEI_DISABLE_GETPORTMODE")) { if (ctx->getportmode_retries == 0) { g_task_return_boolean (task, TRUE); @@ -318,7 +318,7 @@ huawei_custom_init_step (GTask *task) } /* All done it seems */ - fi_ctx = g_object_get_data (G_OBJECT (mm_port_probe_peek_device (ctx->probe)), TAG_FIRST_INTERFACE_CONTEXT); + fi_ctx = g_object_get_data (G_OBJECT (mm_port_probe_peek_device (probe)), TAG_FIRST_INTERFACE_CONTEXT); g_assert (fi_ctx != NULL); fi_ctx->custom_init_run = TRUE; @@ -329,7 +329,11 @@ huawei_custom_init_step (GTask *task) static gboolean first_interface_missing_timeout_cb (MMDevice *device) { - try_next_usbif (device); + FirstInterfaceContext *fi_ctx; + + fi_ctx = g_object_get_data (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT); + g_assert (fi_ctx != NULL); + try_next_usbif (fi_ctx->probe, device); /* Reload the timeout, just in case we end up not having the next interface to probe... * which is anyway very unlikely as we got it by looking at the real probe list, but anyway... */ @@ -363,6 +367,7 @@ huawei_custom_init (MMPortProbe *probe, if (!fi_ctx) { /* This is the first time we ask for the context. Set it up. */ fi_ctx = g_slice_new0 (FirstInterfaceContext); + fi_ctx->probe = g_object_ref (probe); g_object_set_data_full (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT, fi_ctx, @@ -383,7 +388,6 @@ huawei_custom_init (MMPortProbe *probe, } ctx = g_slice_new (HuaweiCustomInitContext); - ctx->probe = g_object_ref (probe); ctx->port = g_object_ref (port); ctx->curc_done = FALSE; ctx->curc_retries = 3; @@ -423,7 +427,8 @@ huawei_custom_init (MMPortProbe *probe, /*****************************************************************************/ static void -propagate_port_mode_results (GList *probes) +propagate_port_mode_results (MMPlugin *self, + GList *probes) { MMDevice *device; GList *l; @@ -466,7 +471,7 @@ propagate_port_mode_results (GList *probes) if (description) { gchar *lower_description; - mm_dbg ("(Huawei) %s interface description: %s", mm_port_probe_get_port_name (probe), description); + mm_obj_dbg (probe, "%s interface description: %s", mm_port_probe_get_port_name (probe), description); lower_description = g_ascii_strdown (description, -1); if (strstr (lower_description, "modem")) @@ -517,11 +522,11 @@ create_modem (MMPlugin *self, GList *probes, GError **error) { - propagate_port_mode_results (probes); + propagate_port_mode_results (self, probes); #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered Huawei modem found..."); + mm_obj_dbg (self, "QMI-powered Huawei modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), @@ -532,7 +537,7 @@ create_modem (MMPlugin *self, #if defined WITH_MBIM if (mm_port_probe_list_has_mbim_port (probes)) { - mm_dbg ("MBIM-powered Huawei modem found..."); + mm_obj_dbg (self, "MBIM-powered Huawei modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, drivers, mm_plugin_get_name (self), @@ -566,10 +571,10 @@ grab_port (MMPlugin *self, gchar *str; str = mm_port_serial_at_flag_build_string_from_mask (pflags); - mm_dbg ("(%s/%s) huawei port will have AT flags '%s'", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe), - str); + mm_obj_dbg (self, "(%s/%s) huawei port will have AT flags '%s'", + mm_port_probe_get_port_subsys (probe), + mm_port_probe_get_port_name (probe), + str); g_free (str); } diff --git a/plugins/huawei/mm-sim-huawei.c b/plugins/huawei/mm-sim-huawei.c index 49c19c14..54b388b3 100644 --- a/plugins/huawei/mm-sim-huawei.c +++ b/plugins/huawei/mm-sim-huawei.c @@ -25,7 +25,6 @@ #include #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-modem-helpers.h" #include "mm-base-modem-at.h" @@ -105,7 +104,6 @@ load_sim_identifier (MMBaseSim *self, MM_BASE_SIM_MODEM, &modem, NULL); - mm_dbg ("loading (Huawei) SIM identifier..."); mm_base_modem_at_command ( modem, "^ICCID?", diff --git a/plugins/huawei/tests/test-modem-helpers-huawei.c b/plugins/huawei/tests/test-modem-helpers-huawei.c index 4f83f49c..18ac85a5 100644 --- a/plugins/huawei/tests/test-modem-helpers-huawei.c +++ b/plugins/huawei/tests/test-modem-helpers-huawei.c @@ -22,7 +22,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-huawei.h" @@ -386,27 +386,21 @@ test_prefmode (void) n_expected_combinations++; } - combinations = mm_huawei_parse_prefmode_test (prefmode_tests[i].str, &error); + combinations = mm_huawei_parse_prefmode_test (prefmode_tests[i].str, NULL, &error); g_assert_no_error (error); g_assert (combinations != NULL); g_assert_cmpuint (combinations->len, ==, n_expected_combinations); for (j = 0; j < combinations->len; j++) { MMHuaweiPrefmodeCombination *single; - gchar *allowed_str; - gchar *preferred_str; + g_autofree gchar *allowed_str = NULL; + g_autofree gchar *preferred_str = NULL; single = &g_array_index (combinations, MMHuaweiPrefmodeCombination, j); allowed_str = mm_modem_mode_build_string_from_mask (single->allowed); preferred_str = mm_modem_mode_build_string_from_mask (single->preferred); - mm_dbg ("Test[%u], Combination[%u]: %u, \"%s\", \"%s\"", - i, - j, - single->prefmode, - allowed_str, - preferred_str); - g_free (allowed_str); - g_free (preferred_str); + mm_obj_dbg (NULL, "test[%u], combination[%u]: %u, \"%s\", \"%s\"", + i, j, single->prefmode, allowed_str, preferred_str); } for (j = 0; j < combinations->len; j++) { @@ -472,7 +466,7 @@ test_prefmode_response (void) const MMHuaweiPrefmodeCombination *found; GError *error = NULL; - combinations = mm_huawei_parse_prefmode_test (prefmode_response_tests[i].format, NULL); + combinations = mm_huawei_parse_prefmode_test (prefmode_response_tests[i].format, NULL, NULL); g_assert (combinations != NULL); found = mm_huawei_parse_prefmode_response (prefmode_response_tests[i].str, @@ -622,28 +616,21 @@ test_syscfg (void) n_expected_combinations++; } - combinations = mm_huawei_parse_syscfg_test (syscfg_tests[i].str, &error); + combinations = mm_huawei_parse_syscfg_test (syscfg_tests[i].str, NULL, &error); g_assert_no_error (error); g_assert (combinations != NULL); g_assert_cmpuint (combinations->len, ==, n_expected_combinations); for (j = 0; j < combinations->len; j++) { MMHuaweiSyscfgCombination *single; - gchar *allowed_str; - gchar *preferred_str; + g_autofree gchar *allowed_str = NULL; + g_autofree gchar *preferred_str = NULL; single = &g_array_index (combinations, MMHuaweiSyscfgCombination, j); allowed_str = mm_modem_mode_build_string_from_mask (single->allowed); preferred_str = mm_modem_mode_build_string_from_mask (single->preferred); - mm_dbg ("Test[%u], Combination[%u]: %u, %u, \"%s\", \"%s\"", - i, - j, - single->mode, - single->acqorder, - allowed_str, - preferred_str); - g_free (allowed_str); - g_free (preferred_str); + mm_obj_dbg (NULL, "test[%u], combination[%u]: %u, %u, \"%s\", \"%s\"", + i, j, single->mode, single->acqorder, allowed_str, preferred_str); } for (j = 0; j < combinations->len; j++) { @@ -736,7 +723,7 @@ test_syscfg_response (void) const MMHuaweiSyscfgCombination *found; GError *error = NULL; - combinations = mm_huawei_parse_syscfg_test (syscfg_response_tests[i].format, NULL); + combinations = mm_huawei_parse_syscfg_test (syscfg_response_tests[i].format, NULL, NULL); g_assert (combinations != NULL); found = mm_huawei_parse_syscfg_response (syscfg_response_tests[i].str, @@ -896,20 +883,14 @@ test_syscfgex (void) for (j = 0; j < combinations->len; j++) { MMHuaweiSyscfgexCombination *single; - gchar *allowed_str; - gchar *preferred_str; + g_autofree gchar *allowed_str = NULL; + g_autofree gchar *preferred_str = NULL; single = &g_array_index (combinations, MMHuaweiSyscfgexCombination, j); allowed_str = mm_modem_mode_build_string_from_mask (single->allowed); preferred_str = mm_modem_mode_build_string_from_mask (single->preferred); - mm_dbg ("Test[%u], Combination[%u]: \"%s\", \"%s\", \"%s\"", - i, - j, - single->mode_str, - allowed_str, - preferred_str); - g_free (allowed_str); - g_free (preferred_str); + mm_obj_dbg (NULL, "test[%u], combination[%u]: \"%s\", \"%s\", \"%s\"", + i, j, single->mode_str, allowed_str, preferred_str); } for (j = 0; j < combinations->len; j++) { From fe78612d6d546604b3a2fc0569f070060c0233f2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:00:31 +0200 Subject: [PATCH 105/675] icera: port to use object logging --- plugins/icera/mm-broadband-bearer-icera.c | 44 +++++++++++----------- plugins/icera/mm-broadband-modem-icera.c | 45 ++++++++++------------- 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/plugins/icera/mm-broadband-bearer-icera.c b/plugins/icera/mm-broadband-bearer-icera.c index 567d12dc..48bcf49a 100644 --- a/plugins/icera/mm-broadband-bearer-icera.c +++ b/plugins/icera/mm-broadband-bearer-icera.c @@ -29,7 +29,7 @@ #include "mm-broadband-bearer-icera.h" #include "mm-base-modem-at.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-error-helpers.h" #include "mm-daemon-enums-types.h" @@ -299,37 +299,39 @@ disconnect_ipdpact_ready (MMBaseModem *modem, GAsyncResult *res, MMBroadbandBearerIcera *self) { - GTask *task; GError *error = NULL; + GTask *task; /* Try to recover the disconnection task. If none found, it means the * task was already completed and we have nothing else to do. */ - task = self->priv->disconnect_pending; - - /* Balance refcount with the extra ref we passed to command_full() */ - g_object_unref (self); + task = g_steal_pointer (&self->priv->disconnect_pending); if (!task) { - mm_dbg ("Disconnection context was finished already by an unsolicited message"); - + mm_obj_dbg (self, "disconnection context was finished already by an unsolicited message"); /* Run _finish() to finalize the async call, even if we don't care - * the result */ + * about the result */ mm_base_modem_at_command_full_finish (modem, res, NULL); - return; + goto out; } mm_base_modem_at_command_full_finish (modem, res, &error); if (error) { - self->priv->disconnect_pending = NULL; g_task_return_error (task, error); g_object_unref (task); - return; + goto out; } + /* Track again */ + self->priv->disconnect_pending = task; + /* Set a 60-second disconnection-failure timeout */ self->priv->disconnect_pending_id = g_timeout_add_seconds (60, (GSourceFunc)disconnect_3gpp_timed_out_cb, self); + +out: + /* Balance refcount with the extra ref we passed to command_full() */ + g_object_unref (self); } static void @@ -596,13 +598,12 @@ activate_ready (MMBaseModem *modem, Dial3gppContext *ctx; GError *error = NULL; - task = self->priv->connect_pending; - self->priv->connect_pending = NULL; + task = g_steal_pointer (&self->priv->connect_pending); /* Try to recover the connection context. If none found, it means the * context was already completed and we have nothing else to do. */ if (!task) { - mm_dbg ("Connection context was finished already by an unsolicited message"); + mm_obj_dbg (self, "connection context was finished already by an unsolicited message"); /* Run _finish() to finalize the async call, even if we don't care * the result */ mm_base_modem_at_command_full_finish (modem, res, NULL); @@ -672,7 +673,7 @@ authenticate_ready (MMBaseModem *modem, * error ["a profile (CID) is currently active"] if a connect * is attempted too soon after a disconnect. */ if (++ctx->authentication_retries < 3) { - mm_dbg ("Authentication failed: '%s'; retrying...", error->message); + mm_obj_dbg (self, "authentication failed: %s; retrying...", error->message); g_error_free (error); g_timeout_add_seconds (1, (GSourceFunc)retry_authentication_cb, task); return; @@ -725,7 +726,7 @@ authenticate (GTask *task) /* Both user and password are required; otherwise firmware returns an error */ if (!user || !password || allowed_auth == MM_BEARER_ALLOWED_AUTH_NONE) { - mm_dbg ("Not using authentication"); + mm_obj_dbg (self, "not using authentication"); command = g_strdup_printf ("%%IPDPCFG=%d,0,0,\"\",\"\"", ctx->cid); } else { gchar *quoted_user; @@ -733,13 +734,13 @@ authenticate (GTask *task) guint icera_auth; if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { - mm_dbg ("Using default (PAP) authentication method"); + mm_obj_dbg (self, "using default (PAP) authentication method"); icera_auth = 1; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { - mm_dbg ("Using PAP authentication method"); + mm_obj_dbg (self, "using PAP authentication method"); icera_auth = 1; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_CHAP) { - mm_dbg ("Using CHAP authentication method"); + mm_obj_dbg (self, "using CHAP authentication method"); icera_auth = 2; } else { gchar *str; @@ -881,8 +882,7 @@ report_connection_status (MMBaseBearer *_self, return; } - mm_dbg ("Received spontaneous %%IPDPACT (%s)", - mm_bearer_connection_status_get_string (status)); + mm_obj_dbg (self, "received spontaneous %%IPDPACT (%s)", mm_bearer_connection_status_get_string (status)); /* Received a random 'DISCONNECTED'...*/ if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED || diff --git a/plugins/icera/mm-broadband-modem-icera.c b/plugins/icera/mm-broadband-modem-icera.c index c57ffa75..b459cb57 100644 --- a/plugins/icera/mm-broadband-modem-icera.c +++ b/plugins/icera/mm-broadband-modem-icera.c @@ -25,7 +25,7 @@ #include "ModemManager.h" #include "mm-serial-parsers.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-errors-types.h" #include "mm-iface-modem.h" @@ -71,38 +71,38 @@ struct _MMBroadbandModemIceraPrivate { /* Load supported modes (Modem interface) */ static void -add_supported_mode (GArray **combinations, - guint mode) +add_supported_mode (MMBroadbandModemIcera *self, + GArray **combinations, + guint mode) { MMModemModeCombination combination; switch (mode) { case 0: - mm_dbg ("Modem supports 2G-only mode"); + mm_obj_dbg (self, "2G-only mode supported"); combination.allowed = MM_MODEM_MODE_2G; combination.preferred = MM_MODEM_MODE_NONE; break; case 1: - mm_dbg ("Modem supports 3G-only mode"); + mm_obj_dbg (self, "3G-only mode supported"); combination.allowed = MM_MODEM_MODE_3G; combination.preferred = MM_MODEM_MODE_NONE; break; case 2: - mm_dbg ("Modem supports 2G/3G mode with 2G preferred"); + mm_obj_dbg (self, "2G/3G mode with 2G preferred supported"); combination.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G); combination.preferred = MM_MODEM_MODE_2G; break; case 3: - mm_dbg ("Modem supports 2G/3G mode with 3G preferred"); + mm_obj_dbg (self, "2G/3G mode with 3G preferred supported"); combination.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G); combination.preferred = MM_MODEM_MODE_3G; break; case 5: - mm_dbg ("Modem supports 'any', but not explicitly listing it"); /* Any, no need to add it to the list */ return; default: - mm_warn ("Unsupported Icera mode found: %u", mode); + mm_obj_warn (self, "unsupported mode found in %%IPSYS=?: %u", mode); return; } @@ -182,18 +182,18 @@ load_supported_modes_finish (MMIfaceModem *self, guint j; for (j = modefirst; j <= modelast; j++) - add_supported_mode (&combinations, j); + add_supported_mode (MM_BROADBAND_MODEM_ICERA (self), &combinations, j); } else - mm_warn ("Couldn't parse mode interval (%s) in %%IPSYS=? response", split[i]); + mm_obj_warn (self, "couldn't parse mode interval in %%IPSYS=? response: %s", split[i]); g_free (first); } else { guint mode; /* Add single */ if (mm_get_uint_from_str (split[i], &mode)) - add_supported_mode (&combinations, mode); + add_supported_mode (MM_BROADBAND_MODEM_ICERA (self), &combinations, mode); else - mm_warn ("Couldn't parse mode (%s) in %%IPSYS=? response", split[i]); + mm_obj_warn (self, "couldn't parse mode in %%IPSYS=? response: %s", split[i]); } } @@ -441,7 +441,7 @@ ipdpact_received (MMPortSerialAt *port, ctx.status = MM_BEARER_CONNECTION_STATUS_CONNECTION_FAILED; break; default: - mm_warn ("Unknown Icera connect status %d", status); + mm_obj_warn (self, "unknown %%IPDPACT connect status %d", status); break; } @@ -614,10 +614,9 @@ nwstate_query_ready (MMBroadbandModemIcera *self, GError *error = NULL; mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); - if (error) { - mm_dbg ("Couldn't query access technology: '%s'", error->message); + if (error) g_task_return_error (task, error); - } else { + else { /* * The unsolicited message handler will already have run and * removed the NWSTATE response, so we use the result from there. @@ -1022,7 +1021,6 @@ load_unlock_retries_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query unlock retries: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -1260,7 +1258,6 @@ load_supported_bands_get_current_bands_ready (MMIfaceModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query current bands: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -1346,7 +1343,6 @@ load_current_bands_ready (MMIfaceModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query current bands: '%s'", error->message); g_task_return_error (task, error); } else { /* Parse bands from Icera response into MM band numbers */ @@ -1413,7 +1409,6 @@ set_current_bands_next (MMIfaceModem *self, GError *error = NULL; if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error)) { - mm_dbg ("Couldn't set current bands: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -1448,15 +1443,15 @@ set_one_band (MMIfaceModem *self, /* Note that ffs() returning 2 corresponds to 1 << 1, not 1 << 2 */ band--; - mm_dbg("1. enablebits %x disablebits %x band %d enable %d", - ctx->enablebits, ctx->disablebits, band, enable); + mm_obj_dbg (self, "preparing %%IPBM command (1/2): enablebits %x, disablebits %x, band %d, enable %d", + ctx->enablebits, ctx->disablebits, band, enable); if (enable) ctx->enablebits &= ~(1 << band); else ctx->disablebits &= ~(1 << band); - mm_dbg("2. enablebits %x disablebits %x", - ctx->enablebits, ctx->disablebits); + mm_obj_dbg (self, "preparing %%IPBM command (2/2): enablebits %x, disablebits %x", + ctx->enablebits, ctx->disablebits); command = g_strdup_printf ("%%IPBM=\"%s\",%d", modem_bands[band].name, From 2da417c7a2d86e8b240f5e044d25789785e4b05d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:04:10 +0200 Subject: [PATCH 106/675] iridium: port to use object logging --- plugins/iridium/mm-bearer-iridium.c | 3 +-- plugins/iridium/mm-broadband-modem-iridium.c | 8 ++++---- plugins/iridium/mm-plugin-iridium.c | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/iridium/mm-bearer-iridium.c b/plugins/iridium/mm-bearer-iridium.c index d0adeb0c..2c4430cc 100644 --- a/plugins/iridium/mm-bearer-iridium.c +++ b/plugins/iridium/mm-bearer-iridium.c @@ -26,12 +26,11 @@ #include "mm-bearer-iridium.h" #include "mm-base-modem-at.h" -#include "mm-log.h" /* Allow up to 200s to get a proper IP connection */ #define BEARER_IRIDIUM_IP_TIMEOUT_DEFAULT 200 -G_DEFINE_TYPE (MMBearerIridium, mm_bearer_iridium, MM_TYPE_BASE_BEARER); +G_DEFINE_TYPE (MMBearerIridium, mm_bearer_iridium, MM_TYPE_BASE_BEARER) /*****************************************************************************/ /* Connect */ diff --git a/plugins/iridium/mm-broadband-modem-iridium.c b/plugins/iridium/mm-broadband-modem-iridium.c index 5cd73b6c..bef4a347 100644 --- a/plugins/iridium/mm-broadband-modem-iridium.c +++ b/plugins/iridium/mm-broadband-modem-iridium.c @@ -23,7 +23,7 @@ #include #include "ModemManager.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-errors-types.h" #include "mm-base-modem-at.h" #include "mm-iface-modem.h" @@ -41,7 +41,7 @@ static void iface_modem_messaging_init (MMIfaceModemMessaging *iface); G_DEFINE_TYPE_EXTENDED (MMBroadbandModemIridium, mm_broadband_modem_iridium, MM_TYPE_BROADBAND_MODEM, 0, G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init) - G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_MESSAGING, iface_modem_messaging_init)); + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_MESSAGING, iface_modem_messaging_init)) /*****************************************************************************/ /* Operator Code loading (3GPP interface) */ @@ -296,7 +296,7 @@ create_bearer (MMIfaceModem *self, MMBaseBearer *bearer; GTask *task; - mm_dbg ("Creating Iridium bearer..."); + mm_obj_dbg (self, "creating Iridium bearer..."); bearer = mm_bearer_iridium_new (MM_BROADBAND_MODEM_IRIDIUM (self), properties); task = g_task_new (self, NULL, callback, user_data); @@ -325,7 +325,7 @@ setup_ports (MMBroadbandModem *self) MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_iridium_parent_class)->setup_ports (self); /* Set 9600 baudrate by default in the AT port */ - mm_dbg ("Baudrate will be set to 9600 bps..."); + mm_obj_dbg (self, "baudrate will be set to 9600 bps..."); primary = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); if (!primary) return; diff --git a/plugins/iridium/mm-plugin-iridium.c b/plugins/iridium/mm-plugin-iridium.c index c8ae131f..1ae8a3f9 100644 --- a/plugins/iridium/mm-plugin-iridium.c +++ b/plugins/iridium/mm-plugin-iridium.c @@ -29,7 +29,6 @@ #include "mm-plugin-iridium.h" #include "mm-broadband-modem-iridium.h" #include "mm-private-boxed-types.h" -#include "mm-log.h" G_DEFINE_TYPE (MMPluginIridium, mm_plugin_iridium, MM_TYPE_PLUGIN) From 62033b1b6e37d944cd3dcc3eb27e3b1056b604df Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:05:08 +0200 Subject: [PATCH 107/675] linktop: no logging in plugin --- plugins/linktop/mm-broadband-modem-linktop.c | 1 - plugins/linktop/mm-modem-helpers-linktop.c | 1 - 2 files changed, 2 deletions(-) diff --git a/plugins/linktop/mm-broadband-modem-linktop.c b/plugins/linktop/mm-broadband-modem-linktop.c index 42818920..9f42cdda 100644 --- a/plugins/linktop/mm-broadband-modem-linktop.c +++ b/plugins/linktop/mm-broadband-modem-linktop.c @@ -28,7 +28,6 @@ #include "ModemManager.h" #include "mm-serial-parsers.h" -#include "mm-log.h" #include "mm-modem-helpers.h" #include "mm-iface-modem.h" #include "mm-base-modem-at.h" diff --git a/plugins/linktop/mm-modem-helpers-linktop.c b/plugins/linktop/mm-modem-helpers-linktop.c index 7b9b5f14..2ca46bb6 100644 --- a/plugins/linktop/mm-modem-helpers-linktop.c +++ b/plugins/linktop/mm-modem-helpers-linktop.c @@ -15,7 +15,6 @@ * Copyright (C) 2016 Aleksander Morgado */ -#include "mm-log.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-linktop.h" From 64ac1c19ff25b43320bbf3b5fea8a49d5c7c207f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:09:40 +0200 Subject: [PATCH 108/675] longcheer: port to use object logging --- .../longcheer/mm-broadband-modem-longcheer.c | 2 -- plugins/longcheer/mm-plugin-longcheer.c | 27 ++++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/plugins/longcheer/mm-broadband-modem-longcheer.c b/plugins/longcheer/mm-broadband-modem-longcheer.c index 8e07bdf8..f158bc41 100644 --- a/plugins/longcheer/mm-broadband-modem-longcheer.c +++ b/plugins/longcheer/mm-broadband-modem-longcheer.c @@ -294,7 +294,6 @@ load_access_technologies (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading access technology (longcheer)..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+PSRAT", 3, @@ -325,7 +324,6 @@ load_unlock_retries_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query unlock retries: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; diff --git a/plugins/longcheer/mm-plugin-longcheer.c b/plugins/longcheer/mm-plugin-longcheer.c index 59b84575..e2d4230e 100644 --- a/plugins/longcheer/mm-plugin-longcheer.c +++ b/plugins/longcheer/mm-plugin-longcheer.c @@ -21,7 +21,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-plugin-longcheer.h" #include "mm-broadband-modem-longcheer.h" @@ -58,18 +58,18 @@ static void longcheer_custom_init_step (GTask *task); static void gmr_ready (MMPortSerialAt *port, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { + MMPortProbe *probe; const gchar *p; const gchar *response; - GError *error = NULL; - response = mm_port_serial_at_command_finish (port, res, &error); - if (error) { - g_error_free (error); + probe = g_task_get_source_object (task); - /* Just retry... */ + response = mm_port_serial_at_command_finish (port, res, NULL); + if (!response) { + mm_obj_dbg (probe, "(Longcheer) retrying custom init step..."); longcheer_custom_init_step (task); return; } @@ -88,7 +88,7 @@ gmr_ready (MMPortSerialAt *port, MM_CORE_ERROR_UNSUPPORTED, "X200 cannot be supported with the Longcheer plugin"); } else { - mm_dbg ("(Longcheer) device is not a X200"); + mm_obj_dbg (probe, "(Longcheer) device is not a X200"); g_task_return_boolean (task, TRUE); } g_object_unref (task); @@ -97,16 +97,17 @@ gmr_ready (MMPortSerialAt *port, static void longcheer_custom_init_step (GTask *task) { + MMPortProbe *probe; LongcheerCustomInitContext *ctx; - GCancellable *cancellable; + GCancellable *cancellable; - ctx = g_task_get_task_data (task); + probe = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); cancellable = g_task_get_cancellable (task); /* If cancelled, end */ if (g_cancellable_is_cancelled (cancellable)) { - mm_dbg ("(Longcheer) no need to keep on running custom init in (%s)", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "(Longcheer) no need to keep on running custom init"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; From 1edd4bb101ed9ff20072c56dad4e07859a9a9202 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:18:55 +0200 Subject: [PATCH 109/675] mbm: port to use object logging --- plugins/mbm/mm-broadband-bearer-mbm.c | 40 +++++++++------------- plugins/mbm/mm-broadband-modem-mbm.c | 19 +++++----- plugins/mbm/mm-modem-helpers-mbm.c | 25 +++++++------- plugins/mbm/mm-modem-helpers-mbm.h | 7 ++-- plugins/mbm/mm-plugin-mbm.c | 4 +-- plugins/mbm/mm-sim-mbm.c | 8 +++-- plugins/mbm/tests/test-modem-helpers-mbm.c | 2 +- 7 files changed, 50 insertions(+), 55 deletions(-) diff --git a/plugins/mbm/mm-broadband-bearer-mbm.c b/plugins/mbm/mm-broadband-bearer-mbm.c index c4795aa1..761ad86a 100644 --- a/plugins/mbm/mm-broadband-bearer-mbm.c +++ b/plugins/mbm/mm-broadband-bearer-mbm.c @@ -38,7 +38,7 @@ #include "mm-base-modem-at.h" #include "mm-broadband-bearer-mbm.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-mbm.h" #include "mm-daemon-enums-types.h" @@ -180,11 +180,10 @@ connect_poll_ready (MMBaseModem *modem, const gchar *response; guint state; - task = self->priv->connect_pending; - self->priv->connect_pending = NULL; + task = g_steal_pointer (&self->priv->connect_pending); if (!task) { - mm_dbg ("Connection context was finished already by an unsolicited message"); + mm_obj_dbg (self, "connection context was finished already by an unsolicited message"); /* Run _finish() to finalize the async call, even if we don't care * the result */ mm_base_modem_at_command_full_finish (modem, res, NULL); @@ -219,8 +218,7 @@ connect_poll_cb (MMBroadbandBearerMbm *self) GTask *task; Dial3gppContext *ctx; - task = self->priv->connect_pending; - self->priv->connect_pending = NULL; + task = g_steal_pointer (&self->priv->connect_pending); g_assert (task); ctx = g_task_get_task_data (task); @@ -269,11 +267,10 @@ activate_ready (MMBaseModem *modem, /* Try to recover the connection context. If none found, it means the * context was already completed and we have nothing else to do. */ - task = self->priv->connect_pending; - self->priv->connect_pending = NULL; + task = g_steal_pointer (&self->priv->connect_pending); if (!task) { - mm_dbg ("Connection context was finished already by an unsolicited message"); + mm_obj_dbg (self, "connection context was finished already by an unsolicited message"); /* Run _finish() to finalize the async call, even if we don't care * the result */ mm_base_modem_at_command_full_finish (modem, res, NULL); @@ -391,7 +388,7 @@ authenticate (GTask *task) return; } - mm_dbg ("Authentication not needed"); + mm_obj_dbg (self, "authentication not needed"); activate (task); } @@ -602,11 +599,8 @@ process_pending_disconnect_attempt (MMBroadbandBearerMbm *self, DisconnectContext *ctx; /* Recover disconnection task */ - task = self->priv->disconnect_pending; - self->priv->disconnect_pending = NULL; - g_assert (task != NULL); - - ctx = g_task_get_task_data (task); + task = g_steal_pointer (&self->priv->disconnect_pending); + ctx = g_task_get_task_data (task); if (ctx->poll_id) { g_source_remove (ctx->poll_id); @@ -615,7 +609,7 @@ process_pending_disconnect_attempt (MMBroadbandBearerMbm *self, /* Received 'DISCONNECTED' during a disconnection attempt? */ if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED) { - mm_dbg ("Connection disconnect indicated by an unsolicited message"); + mm_obj_dbg (self, "connection disconnect indicated by an unsolicited message"); g_task_return_boolean (task, TRUE); } else { /* Otherwise, report error */ @@ -638,11 +632,10 @@ disconnect_poll_ready (MMBaseModem *modem, const gchar *response; guint state; - task = self->priv->disconnect_pending; - self->priv->disconnect_pending = NULL; + task = g_steal_pointer (&self->priv->disconnect_pending); if (!task) { - mm_dbg ("Disconnection context was finished already by an unsolicited message"); + mm_obj_dbg (self, "disconnection context was finished already by an unsolicited message"); /* Run _finish() to finalize the async call, even if we don't care * the result */ mm_base_modem_at_command_full_finish (modem, res, NULL); @@ -722,8 +715,7 @@ disconnect_enap_ready (MMBaseModem *modem, GTask *task; GError *error = NULL; - task = self->priv->disconnect_pending; - self->priv->disconnect_pending = NULL; + task = g_steal_pointer (&self->priv->disconnect_pending); /* Try to recover the disconnection context. If none found, it means the * context was already completed and we have nothing else to do. */ @@ -737,7 +729,7 @@ disconnect_enap_ready (MMBaseModem *modem, /* Ignore errors for now */ mm_base_modem_at_command_full_finish (modem, res, &error); if (error) { - mm_dbg ("Disconnection failed (not fatal): %s", error->message); + mm_obj_dbg (self, "disconnection failed (not fatal): %s", error->message); g_error_free (error); } @@ -815,8 +807,8 @@ report_connection_status (MMBaseBearer *_self, return; } - mm_dbg ("Received spontaneous E2NAP (%s)", - mm_bearer_connection_status_get_string (status)); + mm_obj_dbg (self, "received spontaneous E2NAP (%s)", + mm_bearer_connection_status_get_string (status)); /* Received a random 'DISCONNECTED'...*/ if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED || diff --git a/plugins/mbm/mm-broadband-modem-mbm.c b/plugins/mbm/mm-broadband-modem-mbm.c index a4b89fd4..49f94213 100644 --- a/plugins/mbm/mm-broadband-modem-mbm.c +++ b/plugins/mbm/mm-broadband-modem-mbm.c @@ -31,7 +31,7 @@ #include #include "ModemManager.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-bearer-list.h" #include "mm-errors-types.h" #include "mm-modem-helpers.h" @@ -115,7 +115,7 @@ modem_create_bearer (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("Creating MBM bearer..."); + mm_obj_dbg (self, "creating MBM bearer..."); mm_broadband_bearer_mbm_new (MM_BROADBAND_MODEM_MBM (self), properties, NULL, /* cancellable */ @@ -196,7 +196,7 @@ load_supported_modes_finish (MMIfaceModem *_self, if (!response) return FALSE; - if (!mm_mbm_parse_cfun_test (response, &mask, error)) + if (!mm_mbm_parse_cfun_test (response, self, &mask, error)) return FALSE; /* Build list of combinations */ @@ -448,7 +448,7 @@ emrdy_ready (MMBaseModem *self, if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) - mm_warn ("timed out waiting for EMRDY response."); + mm_obj_warn (self, "timed out waiting for EMRDY response"); else MM_BROADBAND_MODEM_MBM (self)->priv->have_emrdy = TRUE; g_error_free (error); @@ -635,7 +635,7 @@ factory_reset (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("Ignoring factory reset code: '%s'", code); + mm_obj_dbg (self, "ignoring user-provided factory reset code: '%s'", code); mm_base_modem_at_sequence (MM_BASE_MODEM (self), factory_reset_sequence, @@ -695,7 +695,6 @@ load_unlock_retries (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading unlock retries (mbm)..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "*EPIN?", 10, @@ -734,19 +733,19 @@ e2nap_received (MMPortSerialAt *port, switch (state) { case MBM_E2NAP_DISCONNECTED: - mm_dbg ("disconnected"); + mm_obj_dbg (self, "disconnected"); ctx.status = MM_BEARER_CONNECTION_STATUS_DISCONNECTED; break; case MBM_E2NAP_CONNECTED: - mm_dbg ("connected"); + mm_obj_dbg (self, "connected"); ctx.status = MM_BEARER_CONNECTION_STATUS_CONNECTED; break; case MBM_E2NAP_CONNECTING: - mm_dbg ("connecting"); + mm_obj_dbg (self, "connecting"); break; default: /* Should not happen */ - mm_dbg ("unhandled E2NAP state %d", state); + mm_obj_dbg (self, "unhandled E2NAP state %d", state); } /* If unknown status, don't try to report anything */ diff --git a/plugins/mbm/mm-modem-helpers-mbm.c b/plugins/mbm/mm-modem-helpers-mbm.c index 18656e57..31fbb376 100644 --- a/plugins/mbm/mm-modem-helpers-mbm.c +++ b/plugins/mbm/mm-modem-helpers-mbm.c @@ -169,21 +169,22 @@ mm_mbm_parse_e2ipcfg_response (const gchar *response, #define CFUN_TAG "+CFUN:" static void -add_supported_mode (guint32 *mask, - guint mode) +add_supported_mode (guint mode, + gpointer log_object, + guint32 *mask) { g_assert (mask); - if (mode >= 32) - mm_warn ("Ignored unexpected mode in +CFUN match: %d", mode); + mm_obj_warn (log_object, "ignored unexpected mode in +CFUN match: %d", mode); else *mask |= (1 << mode); } gboolean mm_mbm_parse_cfun_test (const gchar *response, - guint32 *supported_mask, - GError **error) + gpointer log_object, + guint32 *supported_mask, + GError **error) { gchar **groups; guint32 mask = 0; @@ -236,20 +237,20 @@ mm_mbm_parse_cfun_test (const gchar *response, last_str = separator + 1; if (!mm_get_uint_from_str (first_str, &first)) - mm_warn ("Couldn't match range start: '%s'", first_str); + mm_obj_warn (log_object, "couldn't match range start: '%s'", first_str); else if (!mm_get_uint_from_str (last_str, &last)) - mm_warn ("Couldn't match range stop: '%s'", last_str); + mm_obj_warn (log_object, "couldn't match range stop: '%s'", last_str); else if (first >= last) - mm_warn ("Couldn't match range: wrong first '%s' and last '%s' items", first_str, last_str); + mm_obj_warn (log_object, "couldn't match range: wrong first '%s' and last '%s' items", first_str, last_str); else { for (mode = first; mode <= last; mode++) - add_supported_mode (&mask, mode); + add_supported_mode (mode, log_object, &mask); } } else { if (!mm_get_uint_from_str (supported_modes[i], &mode)) - mm_warn ("Couldn't match mode: '%s'", supported_modes[i]); + mm_obj_warn (log_object, "couldn't match mode: '%s'", supported_modes[i]); else - add_supported_mode (&mask, mode); + add_supported_mode (mode, log_object, &mask); } } diff --git a/plugins/mbm/mm-modem-helpers-mbm.h b/plugins/mbm/mm-modem-helpers-mbm.h index a7df1b00..3e3bf57a 100644 --- a/plugins/mbm/mm-modem-helpers-mbm.h +++ b/plugins/mbm/mm-modem-helpers-mbm.h @@ -34,9 +34,10 @@ typedef enum { /* AT+CFUN=? test parser * Returns a bitmask, bit index set for the supported modes reported */ -gboolean mm_mbm_parse_cfun_test (const gchar *response, - guint32 *supported_mask, - GError **error); +gboolean mm_mbm_parse_cfun_test (const gchar *response, + gpointer log_object, + guint32 *supported_mask, + GError **error); /* AT+CFUN? response parsers */ gboolean mm_mbm_parse_cfun_query_power_state (const gchar *response, diff --git a/plugins/mbm/mm-plugin-mbm.c b/plugins/mbm/mm-plugin-mbm.c index 4f3b52a3..b27cbf64 100644 --- a/plugins/mbm/mm-plugin-mbm.c +++ b/plugins/mbm/mm-plugin-mbm.c @@ -23,7 +23,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-mbm.h" #include "mm-broadband-modem-mbm.h" @@ -49,7 +49,7 @@ create_modem (MMPlugin *self, { #if defined WITH_MBIM if (mm_port_probe_list_has_mbim_port (probes)) { - mm_dbg ("MBIM-powered Ericsson modem found..."); + mm_obj_dbg (self, "MBIM-powered Ericsson modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, drivers, mm_plugin_get_name (self), diff --git a/plugins/mbm/mm-sim-mbm.c b/plugins/mbm/mm-sim-mbm.c index f3218705..1b160d6c 100644 --- a/plugins/mbm/mm-sim-mbm.c +++ b/plugins/mbm/mm-sim-mbm.c @@ -24,7 +24,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-base-modem-at.h" #include "mm-sim-mbm.h" @@ -93,9 +93,11 @@ cpin_query_cb (GTask *task) static void wait_for_unlocked_status (GTask *task) { + MMSimMbm *self; SendPinPukContext *ctx; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* Oops... :/ */ if (ctx->retries == 0) { @@ -109,7 +111,7 @@ wait_for_unlocked_status (GTask *task) /* Check status */ ctx->retries--; - mm_dbg ("Scheduling lock state check..."); + mm_obj_dbg (self, "scheduling lock state check..."); g_timeout_add_seconds (1, (GSourceFunc)cpin_query_cb, task); } diff --git a/plugins/mbm/tests/test-modem-helpers-mbm.c b/plugins/mbm/tests/test-modem-helpers-mbm.c index e64b25c2..da33522c 100644 --- a/plugins/mbm/tests/test-modem-helpers-mbm.c +++ b/plugins/mbm/tests/test-modem-helpers-mbm.c @@ -179,7 +179,7 @@ test_cfun_test (void) gboolean success; GError *error = NULL; - success = mm_mbm_parse_cfun_test (cfun_tests[i].str, &mask, &error); + success = mm_mbm_parse_cfun_test (cfun_tests[i].str, NULL, &mask, &error); g_assert_no_error (error); g_assert (success); g_assert_cmpuint (mask, ==, cfun_tests[i].expected_mask); From 63955ce52dd85421a1820f89f4296aa667cfa0d7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:21:38 +0200 Subject: [PATCH 110/675] mtk: port to use object logging --- plugins/mtk/mm-broadband-modem-mtk.c | 16 +++++++--------- plugins/mtk/mm-plugin-mtk.c | 1 - 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/plugins/mtk/mm-broadband-modem-mtk.c b/plugins/mtk/mm-broadband-modem-mtk.c index 8170984c..5439b524 100644 --- a/plugins/mtk/mm-broadband-modem-mtk.c +++ b/plugins/mtk/mm-broadband-modem-mtk.c @@ -24,7 +24,7 @@ #include #include "ModemManager.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-errors-types.h" #include "mm-modem-helpers.h" #include "mm-base-modem-at.h" @@ -77,7 +77,6 @@ load_unlock_retries_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query unlock retries: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -190,7 +189,6 @@ get_supported_modes_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Fail to get response"); g_task_return_error (task, error); g_object_unref (task); return; @@ -382,7 +380,7 @@ load_current_modes_finish (MMIfaceModem *self, break; default: result = FALSE; - mm_dbg ("Not supported allowed mode %d", erat_mode); + mm_obj_dbg (self, "unsupported allowed mode reported in +ERAT: %d", erat_mode); goto done; } @@ -401,7 +399,7 @@ load_current_modes_finish (MMIfaceModem *self, break; default: result = FALSE; - mm_dbg ("Not supported preferred mode %d", erat_pref); + mm_obj_dbg (self, "unsupported preferred mode %d", erat_pref); goto done; } @@ -547,7 +545,7 @@ mtk_80_signal_changed (MMPortSerialAt *port, else quality = MM_CLAMP_HIGH (quality, 31) * 100 / 31; - mm_dbg ("6280 signal quality URC received: quality = %u", quality); + mm_obj_dbg (self, "6280 signal quality URC received: %u", quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); } @@ -566,7 +564,7 @@ mtk_90_2g_signal_changed (MMPortSerialAt *port, else quality = MM_CLAMP_HIGH (quality, 63) * 100 / 63; - mm_dbg ("2G signal quality URC received: quality = %u", quality); + mm_obj_dbg (self, "2G signal quality URC received: %u", quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); } @@ -582,7 +580,7 @@ mtk_90_3g_signal_changed (MMPortSerialAt *port, quality = MM_CLAMP_HIGH (quality, 96) * 100 / 96; - mm_dbg ("3G signal quality URC received: quality = %u", quality); + mm_obj_dbg (self, "3G signal quality URC received: %u", quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); } @@ -598,7 +596,7 @@ mtk_90_4g_signal_changed (MMPortSerialAt *port, quality = MM_CLAMP_HIGH (quality, 97) * 100 / 97; - mm_dbg ("4G signal quality URC received: quality = %u", quality); + mm_obj_dbg (self, "4G signal quality URC received: %u", quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); } diff --git a/plugins/mtk/mm-plugin-mtk.c b/plugins/mtk/mm-plugin-mtk.c index 3f6745ae..6adfa845 100644 --- a/plugins/mtk/mm-plugin-mtk.c +++ b/plugins/mtk/mm-plugin-mtk.c @@ -21,7 +21,6 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-plugin-mtk.h" #include "mm-broadband-modem-mtk.h" From 793fc1c51a6a7196b9b014377d43170ae5db3f8a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:22:56 +0200 Subject: [PATCH 111/675] nokia: no logging in plugin --- plugins/nokia/mm-broadband-modem-nokia.c | 1 - plugins/nokia/mm-plugin-nokia-icera.c | 1 - plugins/nokia/mm-plugin-nokia.c | 1 - 3 files changed, 3 deletions(-) diff --git a/plugins/nokia/mm-broadband-modem-nokia.c b/plugins/nokia/mm-broadband-modem-nokia.c index 5e5ca5cc..55af164e 100644 --- a/plugins/nokia/mm-broadband-modem-nokia.c +++ b/plugins/nokia/mm-broadband-modem-nokia.c @@ -25,7 +25,6 @@ #include "ModemManager.h" #include "mm-serial-parsers.h" -#include "mm-log.h" #include "mm-errors-types.h" #include "mm-iface-modem.h" #include "mm-iface-modem-messaging.h" diff --git a/plugins/nokia/mm-plugin-nokia-icera.c b/plugins/nokia/mm-plugin-nokia-icera.c index e2d587a4..1d0af832 100644 --- a/plugins/nokia/mm-plugin-nokia-icera.c +++ b/plugins/nokia/mm-plugin-nokia-icera.c @@ -20,7 +20,6 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-plugin-nokia-icera.h" #include "mm-broadband-modem-icera.h" diff --git a/plugins/nokia/mm-plugin-nokia.c b/plugins/nokia/mm-plugin-nokia.c index cb3374ce..03c44c68 100644 --- a/plugins/nokia/mm-plugin-nokia.c +++ b/plugins/nokia/mm-plugin-nokia.c @@ -21,7 +21,6 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-plugin-nokia.h" #include "mm-broadband-modem-nokia.h" From 4e0a9b19853fbda4835918c80570969c808dbe4f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:49:10 +0200 Subject: [PATCH 112/675] novatel: port to use object logging --- .../novatel/mm-broadband-bearer-novatel-lte.c | 69 +++++++------ .../novatel/mm-broadband-modem-novatel-lte.c | 13 +-- plugins/novatel/mm-broadband-modem-novatel.c | 98 ++++++++++--------- plugins/novatel/mm-common-novatel.c | 39 +++----- plugins/novatel/mm-plugin-novatel-lte.c | 1 - plugins/novatel/mm-plugin-novatel.c | 4 +- plugins/novatel/mm-sim-novatel-lte.c | 2 - 7 files changed, 114 insertions(+), 112 deletions(-) diff --git a/plugins/novatel/mm-broadband-bearer-novatel-lte.c b/plugins/novatel/mm-broadband-bearer-novatel-lte.c index 72001efa..43eeed19 100644 --- a/plugins/novatel/mm-broadband-bearer-novatel-lte.c +++ b/plugins/novatel/mm-broadband-bearer-novatel-lte.c @@ -30,7 +30,7 @@ #include "mm-base-modem-at.h" #include "mm-broadband-bearer-novatel-lte.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #define QMISTATUS_TAG "$NWQMISTATUS:" @@ -176,32 +176,36 @@ connect_3gpp_qmistatus_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { + MMBroadbandBearerNovatelLte *self; DetailedConnectContext *ctx; const gchar *result; gchar *normalized_result; GError *error = NULL; + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + if (g_task_return_error_if_cancelled (task)) { g_object_unref (task); return; } - ctx = g_task_get_task_data (task); - result = mm_base_modem_at_command_full_finish (modem, res, &error); if (!result) { - mm_warn ("QMI connection status failed: %s", error->message); if (!g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN)) { g_task_return_error (task, error); g_object_unref (task); return; } + mm_obj_dbg (self, "connection status failed: %s; will retry", error->message); g_error_free (error); - result = "Unknown error"; - } else if (is_qmistatus_connected (result)) { + goto retry; + } + + if (is_qmistatus_connected (result)) { MMBearerIpConfig *config; - mm_dbg("Connected"); + mm_obj_dbg (self, "connected"); config = mm_bearer_ip_config_new (); mm_bearer_ip_config_set_method (config, MM_BEARER_IP_METHOD_DHCP); g_task_return_pointer ( @@ -211,17 +215,18 @@ connect_3gpp_qmistatus_ready (MMBaseModem *modem, g_object_unref (task); g_object_unref (config); return; - } else if (is_qmistatus_call_failed (result)) { - /* Don't retry if the call failed */ - ctx->retries = 0; } - mm_dbg ("Error: '%s'", result); + /* Don't retry if the call failed */ + if (is_qmistatus_call_failed (result)) { + mm_obj_dbg (self, "not retrying: call failed"); + ctx->retries = 0; + } +retry: if (ctx->retries > 0) { ctx->retries--; - mm_dbg ("Retrying status check in a second. %d retries left.", - ctx->retries); + mm_obj_dbg (self, "retrying status check in a second: %d retries left", ctx->retries); g_timeout_add_seconds (1, (GSourceFunc)connect_3gpp_qmistatus, task); return; } @@ -268,7 +273,6 @@ connect_3gpp_qmiconnect_ready (MMBaseModem *modem, result = mm_base_modem_at_command_full_finish (modem, res, &error); if (!result) { - mm_warn ("QMI connection failed: %s", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -381,27 +385,30 @@ disconnect_3gpp_finish (MMBroadbandBearer *self, static gboolean disconnect_3gpp_qmistatus (GTask *task); static void -disconnect_3gpp_status_ready (MMBaseModem *modem, +disconnect_3gpp_status_ready (MMBaseModem *modem, GAsyncResult *res, - GTask *task) + GTask *task) { - DetailedDisconnectContext *ctx; - const gchar *result; - GError *error = NULL; - gboolean is_connected = FALSE; + MMBroadbandBearerNovatelLte *self; + DetailedDisconnectContext *ctx; + const gchar *result; + GError *error = NULL; + gboolean is_connected = FALSE; + + self = g_task_get_source_object (task); result = mm_base_modem_at_command_full_finish (modem, res, &error); if (result) { - mm_dbg ("QMI connection status: %s", result); + mm_obj_dbg (self, "QMI connection status: %s", result); if (is_qmistatus_disconnected (result)) { g_task_return_boolean (task, TRUE); g_object_unref (task); return; - } else if (is_qmistatus_connected (result)) { - is_connected = TRUE; } + if (is_qmistatus_connected (result)) + is_connected = TRUE; } else { - mm_dbg ("QMI connection status failed: %s", error->message); + mm_obj_dbg (self, "QMI connection status failed: %s", error->message); g_error_free (error); result = "Unknown error"; } @@ -410,8 +417,7 @@ disconnect_3gpp_status_ready (MMBaseModem *modem, if (ctx->retries > 0) { ctx->retries--; - mm_dbg ("Retrying status check in a second. %d retries left.", - ctx->retries); + mm_obj_dbg (self, "retrying status check in a second: %d retries left", ctx->retries); g_timeout_add_seconds (1, (GSourceFunc)disconnect_3gpp_qmistatus, task); return; } @@ -457,15 +463,18 @@ disconnect_3gpp_qmistatus (GTask *task) static void -disconnect_3gpp_check_status (MMBaseModem *modem, +disconnect_3gpp_check_status (MMBaseModem *modem, GAsyncResult *res, - GTask *task) + GTask *task) { - GError *error = NULL; + MMBroadbandBearerNovatelLte *self; + GError *error = NULL; + + self = g_task_get_source_object (task); mm_base_modem_at_command_full_finish (modem, res, &error); if (error) { - mm_dbg("Disconnection error: %s", error->message); + mm_obj_dbg (self, "disconnection error: %s", error->message); g_error_free (error); } diff --git a/plugins/novatel/mm-broadband-modem-novatel-lte.c b/plugins/novatel/mm-broadband-modem-novatel-lte.c index 6b5d0490..5628c2e8 100644 --- a/plugins/novatel/mm-broadband-modem-novatel-lte.c +++ b/plugins/novatel/mm-broadband-modem-novatel-lte.c @@ -31,7 +31,7 @@ #include "mm-iface-modem.h" #include "mm-iface-modem-3gpp.h" #include "mm-iface-modem-messaging.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-serial-parsers.h" @@ -256,7 +256,6 @@ load_own_numbers (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading (Novatel LTE) own numbers..."); mm_base_modem_at_sequence ( MM_BASE_MODEM (self), own_numbers_commands, @@ -365,7 +364,6 @@ load_current_bands_done (MMIfaceModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query supported bands: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -424,7 +422,6 @@ load_unlock_retries_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query unlock retries: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -499,7 +496,6 @@ load_access_technologies_ready (MMIfaceModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query access technology: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; @@ -598,7 +594,7 @@ scan_networks (MMIfaceModem3gpp *self, GTask *task; MMModemAccessTechnology access_tech; - mm_dbg ("scanning for networks (Novatel LTE)..."); + mm_obj_dbg (self, "scanning for networks (Novatel LTE)..."); task = g_task_new (self, NULL, callback, user_data); @@ -608,17 +604,16 @@ scan_networks (MMIfaceModem3gpp *self, */ access_tech = mm_iface_modem_get_access_technologies (MM_IFACE_MODEM (self)); if (access_tech & MM_MODEM_ACCESS_TECHNOLOGY_LTE) { - gchar *access_tech_string; + g_autofree gchar *access_tech_string = NULL; access_tech_string = mm_modem_access_technology_build_string_from_mask (access_tech); - mm_warn ("Couldn't scan for networks with access technologies: %s", access_tech_string); + mm_obj_warn (self, "couldn't scan for networks with access technologies: %s", access_tech_string); g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Couldn't scan for networks with access technologies: %s", access_tech_string); g_object_unref (task); - g_free (access_tech_string); return; } diff --git a/plugins/novatel/mm-broadband-modem-novatel.c b/plugins/novatel/mm-broadband-modem-novatel.c index 3a07b555..086ea637 100644 --- a/plugins/novatel/mm-broadband-modem-novatel.c +++ b/plugins/novatel/mm-broadband-modem-novatel.c @@ -35,7 +35,7 @@ #include "mm-modem-helpers.h" #include "libqcdm/src/commands.h" #include "libqcdm/src/result.h" -#include "mm-log.h" +#include "mm-log-object.h" static void iface_modem_init (MMIfaceModem *iface); static void iface_modem_messaging_init (MMIfaceModemMessaging *iface); @@ -413,7 +413,7 @@ nw_snapshot_old_ready (MMPortSerialQcdm *port, response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { /* Just ignore the error and complete with the input info */ - mm_dbg ("Couldn't run QCDM Novatel Modem MSM6500 snapshot: '%s'", error->message); + g_prefix_error (&error, "Couldn't run QCDM Novatel Modem MSM6500 snapshot: "); g_task_return_error (task, error); g_object_unref (task); return; @@ -423,7 +423,7 @@ nw_snapshot_old_ready (MMPortSerialQcdm *port, result = qcdm_cmd_nw_subsys_modem_snapshot_cdma_result ((const gchar *) response->data, response->len, NULL); g_byte_array_unref (response); if (!result) { - mm_dbg ("Failed to get QCDM Novatel Modem MSM6500 snapshot: %s", error->message); + g_prefix_error (&error, "Failed to get QCDM Novatel Modem MSM6500 snapshot: "); g_task_return_error (task, error); g_object_unref (task); return; @@ -439,18 +439,21 @@ nw_snapshot_old_ready (MMPortSerialQcdm *port, static void nw_snapshot_new_ready (MMPortSerialQcdm *port, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { - QcdmResult *result; - GByteArray *nwsnap; - GError *error = NULL; - GByteArray *response; - guint8 hdr_revision = QCDM_HDR_REV_UNKNOWN; + MMBroadbandModemNovatel *self; + QcdmResult *result; + GByteArray *nwsnap; + GError *error = NULL; + GByteArray *response; + guint8 hdr_revision = QCDM_HDR_REV_UNKNOWN; + + self = g_task_get_source_object (task); response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { - mm_dbg ("Couldn't run QCDM Novatel Modem MSM6800 snapshot: '%s'", error->message); + g_prefix_error (&error, "couldn't run QCDM Novatel Modem MSM6800 snapshot: "); g_task_return_error (task, error); g_object_unref (task); return; @@ -469,7 +472,7 @@ nw_snapshot_new_ready (MMPortSerialQcdm *port, return; } - mm_dbg ("Failed to get QCDM Novatel Modem MSM6800 snapshot."); + mm_obj_dbg (self, "failed to get QCDM Novatel Modem MSM6800 snapshot"); /* Try for MSM6500 */ nwsnap = g_byte_array_sized_new (25); @@ -498,9 +501,7 @@ get_evdo_version (MMBaseModem *self, port = mm_base_modem_get_port_qcdm (self); if (!port) { - error = g_error_new (MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "No available QCDM port."); + error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "No available QCDM port"); g_task_return_error (task, error); g_object_unref (task); return; @@ -508,7 +509,7 @@ get_evdo_version (MMBaseModem *self, g_task_set_task_data (task, port, (GDestroyNotify) close_and_unref_port); if (!mm_port_serial_open (MM_PORT_SERIAL (port), &error)) { - g_prefix_error (&error, "Couldn't open QCDM port: "); + g_prefix_error (&error, "couldn't open QCDM port: "); g_task_return_error (task, error); g_object_unref (task); return; @@ -543,24 +544,24 @@ modem_load_access_technologies_finish (MMIfaceModem *self, guint *mask, GError **error) { - GTask *task = G_TASK (res); - AccessTechContext *ctx = g_task_get_task_data (task); + AccessTechContext *ctx; - if (!g_task_propagate_boolean (task, error)) + if (!g_task_propagate_boolean (G_TASK (res), error)) return FALSE; /* Update access technology with specific EVDO revision from QCDM if we have them */ + ctx = g_task_get_task_data (G_TASK (res)); if (ctx->act & MM_IFACE_MODEM_CDMA_ALL_EVDO_ACCESS_TECHNOLOGIES_MASK) { if (ctx->hdr_revision == QCDM_HDR_REV_0) { - mm_dbg ("Novatel Modem Snapshot EVDO revision: 0"); + mm_obj_dbg (self, "novatel modem snapshot EVDO revision: 0"); ctx->act &= ~MM_IFACE_MODEM_CDMA_ALL_EVDO_ACCESS_TECHNOLOGIES_MASK; ctx->act |= MM_MODEM_ACCESS_TECHNOLOGY_EVDO0; } else if (ctx->hdr_revision == QCDM_HDR_REV_A) { - mm_dbg ("Novatel Modem Snapshot EVDO revision: A"); + mm_obj_dbg (self, "novatel modem snapshot EVDO revision: A"); ctx->act &= ~MM_IFACE_MODEM_CDMA_ALL_EVDO_ACCESS_TECHNOLOGIES_MASK; ctx->act |= MM_MODEM_ACCESS_TECHNOLOGY_EVDOA; } else - mm_dbg ("Novatel Modem Snapshot EVDO revision: %d (unknown)", ctx->hdr_revision); + mm_obj_dbg (self, "novatel modem snapshot EVDO revision: %d (unknown)", ctx->hdr_revision); } *access_technologies = ctx->act; @@ -820,7 +821,6 @@ modem_load_signal_quality (MMIfaceModem *self, { GTask *task; - mm_dbg ("loading signal quality..."); task = g_task_new (self, NULL, callback, user_data); /* 3GPP modems can just run parent's signal quality loading */ @@ -865,7 +865,7 @@ qcmipgetp_ready (MMBaseModem *self, if (!response) g_task_return_error (task, error); else { - mm_dbg ("Current profile information retrieved: %s", response); + mm_obj_dbg (self, "current profile information retrieved: %s", response); g_task_return_boolean (task, TRUE); } g_object_unref (task); @@ -1044,14 +1044,14 @@ cdma_activation_step (GTask *task) switch (ctx->step) { case CDMA_ACTIVATION_STEP_FIRST: - mm_dbg ("Launching manual activation..."); + mm_obj_dbg (self, "launching manual activation..."); ctx->step++; /* fall-through */ case CDMA_ACTIVATION_STEP_REQUEST_ACTIVATION: { gchar *command; - mm_info ("Activation step [1/5]: setting up activation details"); + mm_obj_info (self, "activation step [1/5]: setting up activation details"); command = g_strdup_printf ("$NWACTIVATION=%s,%s,%s", mm_cdma_manual_activation_properties_get_spc (ctx->properties), mm_cdma_manual_activation_properties_get_mdn (ctx->properties), @@ -1067,7 +1067,7 @@ cdma_activation_step (GTask *task) } case CDMA_ACTIVATION_STEP_OTA_UPDATE: - mm_info ("Activation step [2/5]: starting OTA activation"); + mm_obj_info (self, "activation step [2/5]: starting OTA activation"); mm_base_modem_at_command (MM_BASE_MODEM (self), "+IOTA=1", 20, @@ -1077,7 +1077,7 @@ cdma_activation_step (GTask *task) return; case CDMA_ACTIVATION_STEP_PRL_UPDATE: - mm_info ("Activation step [3/5]: starting PRL update"); + mm_obj_info (self, "activation step [3/5]: starting PRL update"); mm_base_modem_at_command (MM_BASE_MODEM (self), "+IOTA=2", 20, @@ -1087,7 +1087,7 @@ cdma_activation_step (GTask *task) return; case CDMA_ACTIVATION_STEP_WAIT_UNTIL_FINISHED: - mm_info ("Activation step [4/5]: checking activation process status"); + mm_obj_info (self, "activation step [4/5]: checking activation process status"); mm_base_modem_at_command (MM_BASE_MODEM (self), "+IOTA?", 20, @@ -1097,7 +1097,7 @@ cdma_activation_step (GTask *task) return; case CDMA_ACTIVATION_STEP_LAST: - mm_info ("Activation step [5/5]: activation process finished"); + mm_obj_info (self, "activation step [5/5]: activation process finished"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -1253,18 +1253,22 @@ parse_modem_eri (DetailedRegistrationStateContext *ctx, QcdmResult *result) static void reg_eri_6500_cb (MMPortSerialQcdm *port, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { - DetailedRegistrationStateContext *ctx = g_task_get_task_data (task); - GError *error = NULL; - GByteArray *response; - QcdmResult *result; + MMBroadbandModemNovatel *self; + DetailedRegistrationStateContext *ctx; + GError *error = NULL; + GByteArray *response; + QcdmResult *result; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { /* Just ignore the error and complete with the input info */ - mm_dbg ("Couldn't run QCDM MSM6500 ERI: '%s'", error->message); + mm_obj_dbg (self, "couldn't run QCDM MSM6500 ERI: %s", error->message); g_error_free (error); goto done; } @@ -1286,16 +1290,20 @@ reg_eri_6800_cb (MMPortSerialQcdm *port, GAsyncResult *res, GTask *task) { - DetailedRegistrationStateContext *ctx = g_task_get_task_data (task); - GError *error = NULL; - GByteArray *response; - GByteArray *nweri; - QcdmResult *result; + MMBroadbandModemNovatel *self; + DetailedRegistrationStateContext *ctx; + GError *error = NULL; + GByteArray *response; + GByteArray *nweri; + QcdmResult *result; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mm_port_serial_qcdm_command_finish (port, res, &error); if (error) { /* Just ignore the error and complete with the input info */ - mm_dbg ("Couldn't run QCDM MSM6800 ERI: '%s'", error->message); + mm_obj_dbg (self, "couldn't run QCDM MSM6800 ERI: %s", error->message); g_error_free (error); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -1350,7 +1358,7 @@ modem_cdma_get_detailed_registration_state (MMIfaceModemCdma *self, ctx->port = mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); if (!ctx->port) { /* Ignore errors and use non-detailed registration state */ - mm_dbg ("No available QCDM port."); + mm_obj_dbg (self, "no available QCDM port"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -1358,7 +1366,7 @@ modem_cdma_get_detailed_registration_state (MMIfaceModemCdma *self, if (!mm_port_serial_open (MM_PORT_SERIAL (ctx->port), &error)) { /* Ignore errors and use non-detailed registration state */ - mm_dbg ("Couldn't open QCDM port: %s", error->message); + mm_obj_dbg (self, "couldn't open QCDM port: %s", error->message); g_error_free (error); g_task_return_boolean (task, TRUE); g_object_unref (task); diff --git a/plugins/novatel/mm-common-novatel.c b/plugins/novatel/mm-common-novatel.c index 6932f5a9..0a444418 100644 --- a/plugins/novatel/mm-common-novatel.c +++ b/plugins/novatel/mm-common-novatel.c @@ -14,7 +14,7 @@ */ #include "mm-common-novatel.h" -#include "mm-log.h" +#include "mm-log-object.h" /*****************************************************************************/ /* Custom init */ @@ -44,30 +44,27 @@ static void custom_init_step (GTask *task); static void nwdmat_ready (MMPortSerialAt *port, - GAsyncResult *res, - GTask* task) + GAsyncResult *res, + GTask *task) { - GError *error = NULL; + g_autoptr(GError) error = NULL; + MMPortProbe *probe; + + probe = g_task_get_source_object (task); mm_port_serial_at_command_finish (port, res, &error); if (error) { - if (g_error_matches (error, - MM_SERIAL_ERROR, - MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) { + if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) { custom_init_step (task); - goto out; + return; } - mm_dbg ("(Novatel) Error flipping secondary ports to AT mode: %s", error->message); + mm_obj_dbg (probe, "(Novatel) Error flipping secondary ports to AT mode: %s", error->message); } /* Finish custom_init */ g_task_return_boolean (task, TRUE); g_object_unref (task); - -out: - if (error) - g_error_free (error); } static gboolean @@ -81,24 +78,21 @@ static void custom_init_step (GTask *task) { CustomInitContext *ctx; - MMPortProbe *probe; + MMPortProbe *probe; - ctx = g_task_get_task_data (task); + probe = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* If cancelled, end */ if (g_task_return_error_if_cancelled (task)) { - mm_dbg ("(Novatel) no need to keep on running custom init in (%s)", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "(Novatel) no need to keep on running custom init"); g_object_unref (task); return; } - probe = g_task_get_source_object (task); - /* If device has a QMI port, don't run $NWDMAT */ if (mm_port_probe_list_has_qmi_port (mm_device_peek_port_probe_list (mm_port_probe_peek_device (probe)))) { - mm_dbg ("(Novatel) no need to run custom init in (%s): device has QMI port", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "(Novatel) no need to run custom init: device has QMI port"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -124,8 +118,7 @@ custom_init_step (GTask *task) } /* Finish custom_init */ - mm_dbg ("(Novatel) couldn't flip secondary port to AT in (%s): all retries consumed", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "(Novatel) couldn't flip secondary port to AT: all retries consumed"); g_task_return_boolean (task, TRUE); g_object_unref (task); } diff --git a/plugins/novatel/mm-plugin-novatel-lte.c b/plugins/novatel/mm-plugin-novatel-lte.c index 9182c579..e9bf9c35 100644 --- a/plugins/novatel/mm-plugin-novatel-lte.c +++ b/plugins/novatel/mm-plugin-novatel-lte.c @@ -26,7 +26,6 @@ #include "mm-plugin-novatel-lte.h" #include "mm-private-boxed-types.h" #include "mm-broadband-modem-novatel-lte.h" -#include "mm-log.h" G_DEFINE_TYPE (MMPluginNovatelLte, mm_plugin_novatel_lte, MM_TYPE_PLUGIN) diff --git a/plugins/novatel/mm-plugin-novatel.c b/plugins/novatel/mm-plugin-novatel.c index 292f758e..91662f7c 100644 --- a/plugins/novatel/mm-plugin-novatel.c +++ b/plugins/novatel/mm-plugin-novatel.c @@ -31,7 +31,7 @@ #include "mm-common-novatel.h" #include "mm-private-boxed-types.h" #include "mm-broadband-modem-novatel.h" -#include "mm-log.h" +#include "mm-log-object.h" #if defined WITH_QMI #include "mm-broadband-modem-qmi.h" @@ -55,7 +55,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered Novatel modem found..."); + mm_obj_dbg (self, "QMI-powered Novatel modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), diff --git a/plugins/novatel/mm-sim-novatel-lte.c b/plugins/novatel/mm-sim-novatel-lte.c index 1088d0d0..676db569 100644 --- a/plugins/novatel/mm-sim-novatel-lte.c +++ b/plugins/novatel/mm-sim-novatel-lte.c @@ -23,7 +23,6 @@ #include #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-modem-helpers.h" #include "mm-base-modem-at.h" @@ -172,7 +171,6 @@ load_imsi (MMBaseSim *self, MM_BASE_SIM_MODEM, &modem, NULL); - mm_dbg ("loading (Novatel LTE) IMSI..."); mm_base_modem_at_command ( modem, "+CRSM=176,28423,0,0,9", From 662f8afc5658f8eede857608321558771b630de8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:53:34 +0200 Subject: [PATCH 113/675] option,hso: port to use object logging --- plugins/option/mm-broadband-bearer-hso.c | 30 ++++++++++++---------- plugins/option/mm-broadband-modem-hso.c | 7 +++-- plugins/option/mm-broadband-modem-option.c | 4 +-- plugins/option/mm-plugin-hso.c | 4 +-- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/plugins/option/mm-broadband-bearer-hso.c b/plugins/option/mm-broadband-bearer-hso.c index d626a64f..3ca5cd77 100644 --- a/plugins/option/mm-broadband-bearer-hso.c +++ b/plugins/option/mm-broadband-bearer-hso.c @@ -30,7 +30,7 @@ #include "mm-base-modem-at.h" #include "mm-broadband-bearer-hso.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-daemon-enums-types.h" @@ -380,14 +380,13 @@ activate_ready (MMBaseModem *modem, Dial3gppContext *ctx; GError *error = NULL; - task = self->priv->connect_pending; - self->priv->connect_pending = NULL; + task = g_steal_pointer (&self->priv->connect_pending); /* Try to recover the connection task. If none found, it means the * task was already completed and we have nothing else to do. * But note that we won't take owneship of the task yet! */ if (!task) { - mm_dbg ("Connection context was finished already by an unsolicited message"); + mm_obj_dbg (self, "connection context was finished already by an unsolicited message"); /* Run _finish() to finalize the async call, even if we don't care * about the result */ mm_base_modem_at_command_full_finish (modem, res, NULL); @@ -517,7 +516,7 @@ authenticate (GTask *task) /* Both user and password are required; otherwise firmware returns an error */ if (!user || !password || allowed_auth == MM_BEARER_ALLOWED_AUTH_NONE) { - mm_dbg ("Not using authentication"); + mm_obj_dbg (self, "not using authentication"); command = g_strdup_printf ("%s=%d,0", auth_commands[ctx->auth_idx], ctx->cid); @@ -527,13 +526,13 @@ authenticate (GTask *task) guint hso_auth; if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { - mm_dbg ("Using default (PAP) authentication method"); + mm_obj_dbg (self, "using default (PAP) authentication method"); hso_auth = 1; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { - mm_dbg ("Using PAP authentication method"); + mm_obj_dbg (self, "using PAP authentication method"); hso_auth = 1; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_CHAP) { - mm_dbg ("Using CHAP authentication method"); + mm_obj_dbg (self, "using CHAP authentication method"); hso_auth = 2; } else { gchar *str; @@ -639,16 +638,19 @@ disconnect_3gpp_finish (MMBroadbandBearer *self, } static void -disconnect_owancall_ready (MMBaseModem *modem, +disconnect_owancall_ready (MMBaseModem *modem, GAsyncResult *res, - GTask *task) + GTask *task) { - GError *error = NULL; + MMBroadbandBearerHso *self; + GError *error = NULL; + + self = g_task_get_source_object (task); /* Ignore errors for now */ mm_base_modem_at_command_full_finish (modem, res, &error); if (error) { - mm_dbg ("Disconnection failed (not fatal): %s", error->message); + mm_obj_dbg (self, "disconnection failed (not fatal): %s", error->message); g_error_free (error); } @@ -711,8 +713,8 @@ report_connection_status (MMBaseBearer *_self, return; } - mm_dbg ("Received spontaneous _OWANCALL (%s)", - mm_bearer_connection_status_get_string (status)); + mm_obj_dbg (self, "received spontaneous _OWANCALL (%s)", + mm_bearer_connection_status_get_string (status)); if (status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED) { /* If no connection attempt on-going, make sure we mark ourselves as diff --git a/plugins/option/mm-broadband-modem-hso.c b/plugins/option/mm-broadband-modem-hso.c index 3623d84d..00899446 100644 --- a/plugins/option/mm-broadband-modem-hso.c +++ b/plugins/option/mm-broadband-modem-hso.c @@ -25,7 +25,7 @@ #include "ModemManager.h" #include "mm-modem-helpers.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-errors-types.h" #include "mm-iface-modem.h" #include "mm-iface-modem-3gpp.h" @@ -111,7 +111,7 @@ modem_create_bearer (MMIfaceModem *self, if (mm_bearer_properties_get_ip_type (properties) & (MM_BEARER_IP_FAMILY_IPV6 | MM_BEARER_IP_FAMILY_IPV4V6)) { - mm_dbg ("Creating generic bearer (IPv6 requested)..."); + mm_obj_dbg (self, "creating generic bearer (IPv6 requested)..."); mm_broadband_bearer_new (MM_BROADBAND_MODEM (self), properties, NULL, /* cancellable */ @@ -120,7 +120,7 @@ modem_create_bearer (MMIfaceModem *self, return; } - mm_dbg ("Creating HSO bearer..."); + mm_obj_dbg (self, "creating HSO bearer..."); mm_broadband_bearer_hso_new (MM_BROADBAND_MODEM_HSO (self), properties, NULL, /* cancellable */ @@ -150,7 +150,6 @@ load_unlock_retries_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query unlock retries: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; diff --git a/plugins/option/mm-broadband-modem-option.c b/plugins/option/mm-broadband-modem-option.c index 46a70aa0..b266dac5 100644 --- a/plugins/option/mm-broadband-modem-option.c +++ b/plugins/option/mm-broadband-modem-option.c @@ -25,7 +25,7 @@ #include "ModemManager.h" #include "mm-modem-helpers.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-errors-types.h" #include "mm-iface-modem.h" #include "mm-iface-modem-3gpp.h" @@ -712,7 +712,6 @@ modem_3gpp_load_imei_finish (MMIfaceModem3gpp *self, if (comma) *comma = '\0'; - mm_dbg ("loaded IMEI: %s", imei); return imei; } @@ -721,7 +720,6 @@ modem_3gpp_load_imei (MMIfaceModem3gpp *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading (Option) IMEI..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+CGSN", 3, diff --git a/plugins/option/mm-plugin-hso.c b/plugins/option/mm-plugin-hso.c index a842b0c7..3fce21df 100644 --- a/plugins/option/mm-plugin-hso.c +++ b/plugins/option/mm-plugin-hso.c @@ -24,7 +24,7 @@ #include "mm-private-boxed-types.h" #include "mm-plugin-hso.h" #include "mm-broadband-modem-hso.h" -#include "mm-log.h" +#include "mm-log-object.h" G_DEFINE_TYPE (MMPluginHso, mm_plugin_hso, MM_TYPE_PLUGIN) @@ -70,7 +70,7 @@ hso_custom_init (MMPortProbe *probe, hsotype_path = g_build_filename (sysfs_path, "hsotype", NULL); if (g_file_get_contents (hsotype_path, &contents, NULL, NULL)) { - mm_dbg ("HSO port type %s: %s", hsotype_path, contents); + mm_obj_dbg (probe, "HSO port type %s: %s", hsotype_path, contents); if (g_str_has_prefix (contents, "Control")) { g_object_set_data (G_OBJECT (probe), TAG_HSO_AT_CONTROL, GUINT_TO_POINTER (TRUE)); mm_port_probe_set_result_at (probe, TRUE); From d25163cca11abdcebe590ff720ef475918d71278 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:54:33 +0200 Subject: [PATCH 114/675] pantech: port to use object logging --- plugins/pantech/mm-broadband-modem-pantech.c | 1 - plugins/pantech/mm-plugin-pantech.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/pantech/mm-broadband-modem-pantech.c b/plugins/pantech/mm-broadband-modem-pantech.c index cd18e14c..bc35b287 100644 --- a/plugins/pantech/mm-broadband-modem-pantech.c +++ b/plugins/pantech/mm-broadband-modem-pantech.c @@ -24,7 +24,6 @@ #include "ModemManager.h" #include "mm-iface-modem.h" #include "mm-iface-modem-messaging.h" -#include "mm-log.h" #include "mm-errors-types.h" #include "mm-broadband-modem-pantech.h" #include "mm-sim-pantech.h" diff --git a/plugins/pantech/mm-plugin-pantech.c b/plugins/pantech/mm-plugin-pantech.c index 66eb6453..4ba7b1e1 100644 --- a/plugins/pantech/mm-plugin-pantech.c +++ b/plugins/pantech/mm-plugin-pantech.c @@ -19,7 +19,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-pantech.h" #include "mm-broadband-modem-pantech.h" @@ -85,7 +85,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered Pantech modem found..."); + mm_obj_dbg (self, "QMI-powered Pantech modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), From e623a54d274eea6803043c3ace4168b5ad599ae0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:55:40 +0200 Subject: [PATCH 115/675] quectel: port to use object logging --- plugins/quectel/mm-plugin-quectel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/quectel/mm-plugin-quectel.c b/plugins/quectel/mm-plugin-quectel.c index 383b08c1..bca81f32 100644 --- a/plugins/quectel/mm-plugin-quectel.c +++ b/plugins/quectel/mm-plugin-quectel.c @@ -19,7 +19,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-quectel.h" #include "mm-broadband-modem-quectel.h" @@ -45,7 +45,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered Quectel modem found..."); + mm_obj_dbg (self, "QMI-powered Quectel modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_quectel_new (uid, drivers, mm_plugin_get_name (self), From aed9f46443fe8e195785e54e4f12522520ee3c19 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 15:56:53 +0200 Subject: [PATCH 116/675] samsung: port to use object logging --- plugins/samsung/mm-broadband-modem-samsung.c | 3 +-- plugins/samsung/mm-plugin-samsung.c | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/samsung/mm-broadband-modem-samsung.c b/plugins/samsung/mm-broadband-modem-samsung.c index 9f6fb37c..b0eb17be 100644 --- a/plugins/samsung/mm-broadband-modem-samsung.c +++ b/plugins/samsung/mm-broadband-modem-samsung.c @@ -28,9 +28,8 @@ #include "mm-broadband-modem-samsung.h" #include "mm-broadband-bearer-icera.h" #include "mm-modem-helpers.h" -#include "mm-log.h" -G_DEFINE_TYPE (MMBroadbandModemSamsung, mm_broadband_modem_samsung, MM_TYPE_BROADBAND_MODEM_ICERA); +G_DEFINE_TYPE (MMBroadbandModemSamsung, mm_broadband_modem_samsung, MM_TYPE_BROADBAND_MODEM_ICERA) /*****************************************************************************/ /* Setup ports (Broadband modem class) */ diff --git a/plugins/samsung/mm-plugin-samsung.c b/plugins/samsung/mm-plugin-samsung.c index e78f6895..2b634a6e 100644 --- a/plugins/samsung/mm-plugin-samsung.c +++ b/plugins/samsung/mm-plugin-samsung.c @@ -27,7 +27,6 @@ #include "mm-plugin-samsung.h" #include "mm-private-boxed-types.h" #include "mm-broadband-modem-samsung.h" -#include "mm-log.h" G_DEFINE_TYPE (MMPluginSamsung, mm_plugin_samsung, MM_TYPE_PLUGIN) From d15da9cf60af9cd1a6b7036519ec557712b5dbad Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 16:02:25 +0200 Subject: [PATCH 117/675] sierra: port to use object logging --- plugins/sierra/mm-broadband-bearer-sierra.c | 27 ++++++++++--------- .../sierra/mm-broadband-modem-sierra-icera.c | 4 +-- plugins/sierra/mm-broadband-modem-sierra.c | 26 +++++++++--------- plugins/sierra/mm-common-sierra.c | 18 ++++++------- plugins/sierra/mm-modem-helpers-sierra.c | 1 - plugins/sierra/mm-plugin-sierra-legacy.c | 1 - plugins/sierra/mm-plugin-sierra.c | 6 ++--- plugins/sierra/mm-sim-sierra.c | 2 -- 8 files changed, 41 insertions(+), 44 deletions(-) diff --git a/plugins/sierra/mm-broadband-bearer-sierra.c b/plugins/sierra/mm-broadband-bearer-sierra.c index cdfd63ee..24bde739 100644 --- a/plugins/sierra/mm-broadband-bearer-sierra.c +++ b/plugins/sierra/mm-broadband-bearer-sierra.c @@ -29,7 +29,7 @@ #include "mm-base-modem-at.h" #include "mm-broadband-bearer-sierra.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-sierra.h" @@ -327,7 +327,7 @@ dial_3gpp_context_step (GTask *task) allowed_auth = mm_bearer_properties_get_allowed_auth (mm_base_bearer_peek_config (MM_BASE_BEARER (self))); if (!user || !password || allowed_auth == MM_BEARER_ALLOWED_AUTH_NONE) { - mm_dbg ("Not using authentication"); + mm_obj_dbg (self, "not using authentication"); if (self->priv->is_icera) command = g_strdup_printf ("%%IPDPCFG=%d,0,0,\"\",\"\"", ctx->cid); else @@ -338,13 +338,13 @@ dial_3gpp_context_step (GTask *task) guint sierra_auth; if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { - mm_dbg ("Using default (PAP) authentication method"); + mm_obj_dbg (self, "using default (PAP) authentication method"); sierra_auth = 1; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { - mm_dbg ("Using PAP authentication method"); + mm_obj_dbg (self, "using PAP authentication method"); sierra_auth = 1; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_CHAP) { - mm_dbg ("Using CHAP authentication method"); + mm_obj_dbg (self, "using CHAP authentication method"); sierra_auth = 2; } else { gchar *str; @@ -479,13 +479,13 @@ disconnect_3gpp_finish (MMBroadbandBearer *self, static void parent_disconnect_3gpp_ready (MMBroadbandBearer *self, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { GError *error = NULL; if (!MM_BROADBAND_BEARER_CLASS (mm_broadband_bearer_sierra_parent_class)->disconnect_3gpp_finish (self, res, &error)) { - mm_dbg ("Parent disconnection failed (not fatal): %s", error->message); + mm_obj_dbg (self, "parent disconnection failed (not fatal): %s", error->message); g_error_free (error); } @@ -494,16 +494,19 @@ parent_disconnect_3gpp_ready (MMBroadbandBearer *self, } static void -disconnect_scact_ready (MMBaseModem *modem, +disconnect_scact_ready (MMBaseModem *modem, GAsyncResult *res, - GTask *task) + GTask *task) { - GError *error = NULL; + MMBroadbandBearerSierra *self; + GError *error = NULL; + + self = g_task_get_source_object (task); /* Ignore errors for now */ mm_base_modem_at_command_full_finish (modem, res, &error); if (error) { - mm_dbg ("Disconnection failed (not fatal): %s", error->message); + mm_obj_dbg (self, "disconnection failed (not fatal): %s", error->message); g_error_free (error); } diff --git a/plugins/sierra/mm-broadband-modem-sierra-icera.c b/plugins/sierra/mm-broadband-modem-sierra-icera.c index 5749f55b..796260d9 100644 --- a/plugins/sierra/mm-broadband-modem-sierra-icera.c +++ b/plugins/sierra/mm-broadband-modem-sierra-icera.c @@ -27,7 +27,7 @@ #include "mm-broadband-modem-sierra-icera.h" #include "mm-iface-modem.h" #include "mm-modem-helpers.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-common-sierra.h" #include "mm-broadband-bearer-sierra.h" @@ -74,7 +74,7 @@ modem_create_bearer (MMIfaceModem *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("Creating Sierra bearer..."); + mm_obj_dbg (self, "creating sierra bearer..."); mm_broadband_bearer_sierra_new (MM_BROADBAND_MODEM (self), properties, TRUE, /* is_icera */ diff --git a/plugins/sierra/mm-broadband-modem-sierra.c b/plugins/sierra/mm-broadband-modem-sierra.c index 80db350f..c08aec48 100644 --- a/plugins/sierra/mm-broadband-modem-sierra.c +++ b/plugins/sierra/mm-broadband-modem-sierra.c @@ -26,7 +26,7 @@ #include "ModemManager.h" #include "mm-broadband-modem-sierra.h" #include "mm-base-modem-at.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-errors-types.h" #include "mm-iface-modem.h" @@ -108,7 +108,6 @@ load_unlock_retries (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading unlock retries (sierra)..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+CPINC?", 3, @@ -1004,7 +1003,7 @@ own_numbers_ready (MMBaseModem *self, /* MDNs are 10 digits in length */ if (i != 10) { - mm_warn ("Failed to parse MDN: expected 10 digits, got %d", i); + mm_obj_warn (self, "failed to parse MDN: expected 10 digits, got %d", i); goto fallback; } @@ -1029,7 +1028,6 @@ modem_load_own_numbers (MMIfaceModem *self, { GTask *task; - mm_dbg ("loading own numbers (Sierra)..."); task = g_task_new (self, NULL, callback, user_data); /* 3GPP modems can just run parent's own number loading */ @@ -1091,7 +1089,7 @@ modem_create_bearer (MMIfaceModem *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("Creating Sierra bearer..."); + mm_obj_dbg (self, "creating Sierra bearer..."); mm_broadband_bearer_sierra_new (MM_BROADBAND_MODEM (self), properties, FALSE, /* is_icera */ @@ -1407,7 +1405,7 @@ cdma_automatic_activation_step (GTask *task) /* fall-through */ case CDMA_AUTOMATIC_ACTIVATION_STEP_UNLOCK: - mm_info ("Activation step [1/4]: unlocking device"); + mm_obj_info (self, "activation step [1/4]: unlocking device"); mm_base_modem_at_command (MM_BASE_MODEM (self), "~NAMLCK=000000", 20, @@ -1419,7 +1417,7 @@ cdma_automatic_activation_step (GTask *task) case CDMA_AUTOMATIC_ACTIVATION_STEP_CDV: { gchar *command; - mm_info ("Activation step [2/4]: requesting OTASP"); + mm_obj_info (self, "activation step [2/4]: requesting OTASP"); command = g_strdup_printf ("+CDV%s", ctx->carrier_code); mm_base_modem_at_command (MM_BASE_MODEM (self), command, @@ -1432,7 +1430,7 @@ cdma_automatic_activation_step (GTask *task) } case CDMA_AUTOMATIC_ACTIVATION_STEP_CHECK: - mm_info ("Activation step [3/4]: checking activation info"); + mm_obj_info (self, "activation step [3/4]: checking activation info"); mm_base_modem_at_command (MM_BASE_MODEM (self), "~NAMVAL?0", 3, @@ -1442,7 +1440,7 @@ cdma_automatic_activation_step (GTask *task) return; case CDMA_AUTOMATIC_ACTIVATION_STEP_LAST: - mm_info ("Activation step [4/4]: activation process finished"); + mm_obj_info (self, "activation step [4/4]: activation process finished"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -1539,7 +1537,7 @@ cdma_manual_activation_step (GTask *task) case CDMA_MANUAL_ACTIVATION_STEP_SPC: { gchar *command; - mm_info ("Activation step [1/5]: unlocking device"); + mm_obj_info (self, "activation step [1/5]: unlocking device"); command = g_strdup_printf ("~NAMLCK=%s", mm_cdma_manual_activation_properties_get_spc (ctx->properties)); mm_base_modem_at_command (MM_BASE_MODEM (self), @@ -1555,7 +1553,7 @@ cdma_manual_activation_step (GTask *task) case CDMA_MANUAL_ACTIVATION_STEP_MDN_MIN: { gchar *command; - mm_info ("Activation step [2/5]: setting MDN/MIN/SID"); + mm_obj_info (self, "activation step [2/5]: setting MDN/MIN/SID"); command = g_strdup_printf ("~NAMVAL=0,%s,%s,%" G_GUINT16_FORMAT ",65535", mm_cdma_manual_activation_properties_get_mdn (ctx->properties), mm_cdma_manual_activation_properties_get_min (ctx->properties), @@ -1571,7 +1569,7 @@ cdma_manual_activation_step (GTask *task) } case CDMA_MANUAL_ACTIVATION_STEP_OTASP: - mm_info ("Activation step [3/5]: requesting OTASP"); + mm_obj_info (self, "activation step [3/5]: requesting OTASP"); mm_base_modem_at_command (MM_BASE_MODEM (self), "!IOTASTART", 20, @@ -1581,7 +1579,7 @@ cdma_manual_activation_step (GTask *task) return; case CDMA_MANUAL_ACTIVATION_STEP_CHECK: - mm_info ("Activation step [4/5]: checking activation info"); + mm_obj_info (self, "activation step [4/5]: checking activation info"); mm_base_modem_at_command (MM_BASE_MODEM (self), "~NAMVAL?0", 20, @@ -1591,7 +1589,7 @@ cdma_manual_activation_step (GTask *task) return; case CDMA_MANUAL_ACTIVATION_STEP_LAST: - mm_info ("Activation step [5/5]: activation process finished"); + mm_obj_info (self, "activation step [5/5]: activation process finished"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; diff --git a/plugins/sierra/mm-common-sierra.c b/plugins/sierra/mm-common-sierra.c index 1f14eb03..8a89a166 100644 --- a/plugins/sierra/mm-common-sierra.c +++ b/plugins/sierra/mm-common-sierra.c @@ -160,7 +160,7 @@ gcap_ready (MMPortSerialAt *port, * on the APP1 port or not. */ if (getenv ("MM_SIERRA_APP1_PPP_OK")) { - mm_dbg ("Sierra: APP1 PPP OK '%s'", response); + mm_obj_dbg (probe, "(Sierra) APP1 PPP OK '%s'", response); g_object_set_data (G_OBJECT (probe), TAG_SIERRA_APP1_PPP_OK, GUINT_TO_POINTER (TRUE)); } } else if (strstr (response, "APP2") || @@ -183,24 +183,24 @@ gcap_ready (MMPortSerialAt *port, static void sierra_custom_init_step (GTask *task) { + MMPortProbe *probe; SierraCustomInitContext *ctx; - GCancellable *cancellable; + GCancellable *cancellable; - ctx = g_task_get_task_data (task); + probe = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); cancellable = g_task_get_cancellable (task); /* If cancelled, end */ if (g_cancellable_is_cancelled (cancellable)) { - mm_dbg ("(Sierra) no need to keep on running custom init in '%s'", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "(Sierra) no need to keep on running custom init"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } if (ctx->retries == 0) { - mm_dbg ("(Sierra) Couldn't get port type hints from '%s'", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "(Sierra) couldn't get port type hints"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -328,8 +328,8 @@ mm_common_sierra_modem_power_up (MMIfaceModem *self, return; } - mm_warn ("Not in full functionality status, power-up command is needed. " - "Note that it may reboot the modem."); + mm_obj_warn (self, "not in full functionality status, power-up command is needed"); + mm_obj_warn (self, "device may be rebooted"); /* Try to go to full functionality mode without rebooting the system. * Works well if we previously switched off the power with CFUN=4 diff --git a/plugins/sierra/mm-modem-helpers-sierra.c b/plugins/sierra/mm-modem-helpers-sierra.c index 2d5fd7da..ac07c9ee 100644 --- a/plugins/sierra/mm-modem-helpers-sierra.c +++ b/plugins/sierra/mm-modem-helpers-sierra.c @@ -16,7 +16,6 @@ #include #include -#include "mm-log.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-sierra.h" diff --git a/plugins/sierra/mm-plugin-sierra-legacy.c b/plugins/sierra/mm-plugin-sierra-legacy.c index 47bdf113..d7d7a03e 100644 --- a/plugins/sierra/mm-plugin-sierra-legacy.c +++ b/plugins/sierra/mm-plugin-sierra-legacy.c @@ -22,7 +22,6 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-plugin-sierra-legacy.h" #include "mm-common-sierra.h" #include "mm-broadband-modem-sierra.h" diff --git a/plugins/sierra/mm-plugin-sierra.c b/plugins/sierra/mm-plugin-sierra.c index 03a06bd8..99871a4a 100644 --- a/plugins/sierra/mm-plugin-sierra.c +++ b/plugins/sierra/mm-plugin-sierra.c @@ -22,7 +22,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-sierra.h" #include "mm-broadband-modem.h" @@ -52,7 +52,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered Sierra modem found..."); + mm_obj_dbg (self, "QMI-powered Sierra modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), @@ -63,7 +63,7 @@ create_modem (MMPlugin *self, #if defined WITH_MBIM if (mm_port_probe_list_has_mbim_port (probes)) { - mm_dbg ("MBIM-powered Sierra modem found..."); + mm_obj_dbg (self, "MBIM-powered Sierra modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, drivers, mm_plugin_get_name (self), diff --git a/plugins/sierra/mm-sim-sierra.c b/plugins/sierra/mm-sim-sierra.c index 233bf2f5..d81e82b2 100644 --- a/plugins/sierra/mm-sim-sierra.c +++ b/plugins/sierra/mm-sim-sierra.c @@ -25,7 +25,6 @@ #include #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-modem-helpers.h" #include "mm-base-modem-at.h" @@ -96,7 +95,6 @@ load_sim_identifier (MMBaseSim *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("loading (Sierra) SIM identifier..."); mm_base_modem_at_command ( modem, "!ICCID?", From 9dbc346f93934da5901225f92b11703b23bcf22a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 16:08:57 +0200 Subject: [PATCH 118/675] simtech: port to use object logging --- .../simtech/mm-broadband-modem-qmi-simtech.c | 1 - plugins/simtech/mm-broadband-modem-simtech.c | 10 +-- plugins/simtech/mm-modem-helpers-simtech.c | 1 - plugins/simtech/mm-plugin-simtech.c | 4 +- plugins/simtech/mm-shared-simtech.c | 66 +++++++++---------- 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/plugins/simtech/mm-broadband-modem-qmi-simtech.c b/plugins/simtech/mm-broadband-modem-qmi-simtech.c index 392f5626..72959605 100644 --- a/plugins/simtech/mm-broadband-modem-qmi-simtech.c +++ b/plugins/simtech/mm-broadband-modem-qmi-simtech.c @@ -22,7 +22,6 @@ #include #include "ModemManager.h" -#include "mm-log.h" #include "mm-errors-types.h" #include "mm-iface-modem-location.h" #include "mm-iface-modem-voice.h" diff --git a/plugins/simtech/mm-broadband-modem-simtech.c b/plugins/simtech/mm-broadband-modem-simtech.c index c8011862..c95cffd2 100644 --- a/plugins/simtech/mm-broadband-modem-simtech.c +++ b/plugins/simtech/mm-broadband-modem-simtech.c @@ -28,7 +28,7 @@ #include "ModemManager.h" #include "mm-modem-helpers.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-base-modem-at.h" #include "mm-iface-modem.h" #include "mm-iface-modem-3gpp.h" @@ -261,7 +261,7 @@ autocsq_set_enabled_ready (MMBaseModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (self, res, &error)) { - mm_dbg ("Couldn't enable automatic signal quality reporting: %s", error->message); + mm_obj_dbg (self, "couldn't enable automatic signal quality reporting: %s", error->message); g_error_free (error); } else csq_urcs_enabled = TRUE; @@ -309,7 +309,7 @@ cnsmod_set_enabled_ready (MMBaseModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (self, res, &error)) { - mm_dbg ("Couldn't enable automatic access technology reporting: %s", error->message); + mm_obj_dbg (self, "couldn't enable automatic access technology reporting: %s", error->message); g_error_free (error); } else cnsmod_urcs_enabled = TRUE; @@ -525,7 +525,7 @@ cnsmod_set_disabled_ready (MMBaseModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (self, res, &error)) { - mm_dbg ("Couldn't disable automatic access technology reporting: %s", error->message); + mm_obj_dbg (self, "couldn't disable automatic access technology reporting: %s", error->message); g_error_free (error); } @@ -545,7 +545,7 @@ autocsq_set_disabled_ready (MMBaseModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (self, res, &error)) { - mm_dbg ("Couldn't disable automatic signal quality reporting: %s", error->message); + mm_obj_dbg (self, "couldn't disable automatic signal quality reporting: %s", error->message); g_error_free (error); } diff --git a/plugins/simtech/mm-modem-helpers-simtech.c b/plugins/simtech/mm-modem-helpers-simtech.c index cce549df..0403c145 100644 --- a/plugins/simtech/mm-modem-helpers-simtech.c +++ b/plugins/simtech/mm-modem-helpers-simtech.c @@ -21,7 +21,6 @@ #include "ModemManager.h" #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" #include "mm-errors-types.h" #include "mm-modem-helpers-simtech.h" #include "mm-modem-helpers.h" diff --git a/plugins/simtech/mm-plugin-simtech.c b/plugins/simtech/mm-plugin-simtech.c index 79afeb54..9940573b 100644 --- a/plugins/simtech/mm-plugin-simtech.c +++ b/plugins/simtech/mm-plugin-simtech.c @@ -21,7 +21,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-simtech.h" #include "mm-broadband-modem-simtech.h" @@ -47,7 +47,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered SimTech modem found..."); + mm_obj_dbg (self, "QMI-powered SimTech modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_simtech_new (uid, drivers, mm_plugin_get_name (self), diff --git a/plugins/simtech/mm-shared-simtech.c b/plugins/simtech/mm-shared-simtech.c index ad313cf0..0d3da877 100644 --- a/plugins/simtech/mm-shared-simtech.c +++ b/plugins/simtech/mm-shared-simtech.c @@ -21,7 +21,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-iface-modem.h" #include "mm-iface-modem-voice.h" #include "mm-iface-modem-location.h" @@ -177,7 +177,7 @@ probe_gps_features (GTask *task) sources = GPOINTER_TO_UINT (g_task_get_task_data (task)); if (priv->cgps_support == FEATURE_SUPPORTED) { - mm_dbg ("GPS commands supported: GPS capabilities enabled"); + mm_obj_dbg (self, "GPS commands supported: GPS capabilities enabled"); /* We only flag as supported by this implementation those sources not already * supported by the parent implementation */ @@ -196,7 +196,7 @@ probe_gps_features (GTask *task) self, NULL); } else - mm_dbg ("No GPS command supported: no GPS capabilities"); + mm_obj_dbg (self, "no GPS command supported: no GPS capabilities"); g_task_return_int (task, (gssize) sources); g_object_unref (task); @@ -222,7 +222,7 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self, /* Now our own check. If we don't have any GPS port, we're done */ if (!mm_base_modem_peek_port_gps (MM_BASE_MODEM (self))) { - mm_dbg ("No GPS data port found: no GPS capabilities"); + mm_obj_dbg (self, "no GPS data port found: no GPS capabilities"); g_task_return_int (task, sources); g_object_unref (task); return; @@ -542,9 +542,9 @@ clcc_command_ready (MMBaseModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (self, res, &error)) { - mm_dbg ("Couldn't %s +CLCC reporting: '%s'", - ctx->enable ? "enable" : "disable", - error->message); + mm_obj_dbg (self, "couldn't %s +CLCC reporting: '%s'", + ctx->enable ? "enable" : "disable", + error->message); g_error_free (error); } @@ -572,13 +572,13 @@ run_voice_enable_disable_unsolicited_events (GTask *task) } if (!ctx->clcc_primary_done && ctx->primary) { - mm_dbg ("%s +CLCC extended list of current calls reporting in primary port...", - ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CLCC extended list of current calls reporting in primary port...", + ctx->enable ? "enabling" : "disabling"); ctx->clcc_primary_done = TRUE; port = ctx->primary; } else if (!ctx->clcc_secondary_done && ctx->secondary) { - mm_dbg ("%s +CLCC extended list of current calls reporting in secondary port...", - ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s +CLCC extended list of current calls reporting in secondary port...", + ctx->enable ? "enabling" : "disabling"); ctx->clcc_secondary_done = TRUE; port = ctx->secondary; } @@ -647,7 +647,7 @@ parent_voice_disable_unsolicited_events_ready (MMIfaceModemVoice *self, priv = get_private (MM_SHARED_SIMTECH (self)); if (!priv->iface_modem_voice_parent->disable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't disable parent voice unsolicited events: %s", error->message); + mm_obj_warn (self, "couldn't disable parent voice unsolicited events: %s", error->message); g_error_free (error); } @@ -664,7 +664,7 @@ voice_disable_unsolicited_events_ready (MMSharedSimtech *self, GError *error = NULL; if (!common_voice_enable_disable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't disable Simtech-specific voice unsolicited events: %s", error->message); + mm_obj_warn (self, "couldn't disable Simtech-specific voice unsolicited events: %s", error->message); g_error_free (error); } @@ -715,7 +715,7 @@ voice_enable_unsolicited_events_ready (MMSharedSimtech *self, GError *error = NULL; if (!common_voice_enable_disable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't enable Simtech-specific voice unsolicited events: %s", error->message); + mm_obj_warn (self, "couldn't enable Simtech-specific voice unsolicited events: %s", error->message); g_error_free (error); } @@ -734,7 +734,7 @@ parent_voice_enable_unsolicited_events_ready (MMIfaceModemVoice *self, priv = get_private (MM_SHARED_SIMTECH (self)); if (!priv->iface_modem_voice_parent->enable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't enable parent voice unsolicited events: %s", error->message); + mm_obj_warn (self, "couldn't enable parent voice unsolicited events: %s", error->message); g_error_free (error); } @@ -782,7 +782,7 @@ clcc_urc_received (MMPortSerialAt *port, full = g_match_info_fetch (match_info, 0); if (!mm_simtech_parse_clcc_list (full, self, &call_info_list, &error)) { - mm_warn ("couldn't parse +CLCC list in URC: %s", error->message); + mm_obj_warn (self, "couldn't parse +CLCC list in URC: %s", error->message); g_error_free (error); } else mm_iface_modem_voice_report_all_calls (MM_IFACE_MODEM_VOICE (self), call_info_list); @@ -800,12 +800,12 @@ missed_call_urc_received (MMPortSerialAt *port, gchar *details = NULL; if (!mm_simtech_parse_missed_call_urc (match_info, &details, &error)) { - mm_warn ("couldn't parse missed call URC: %s", error->message); + mm_obj_warn (self, "couldn't parse missed call URC: %s", error->message); g_error_free (error); return; } - mm_dbg ("missed call reported: %s", details); + mm_obj_dbg (self, "missed call reported: %s", details); g_free (details); } @@ -819,22 +819,22 @@ voice_call_urc_received (MMPortSerialAt *port, guint duration = 0; if (!mm_simtech_parse_voice_call_urc (match_info, &start_or_stop, &duration, &error)) { - mm_warn ("couldn't parse VOICE CALL URC: %s", error->message); + mm_obj_warn (self, "couldn't parse voice call URC: %s", error->message); g_error_free (error); return; } if (start_or_stop) { - mm_dbg ("voice call started"); + mm_obj_dbg (self, "voice call started"); return; } if (duration) { - mm_dbg ("voice call finished (duration: %us)", duration); + mm_obj_dbg (self, "voice call finished (duration: %us)", duration); return; } - mm_dbg ("voice call finished"); + mm_obj_dbg (self, "voice call finished"); } static void @@ -842,13 +842,12 @@ cring_urc_received (MMPortSerialAt *port, GMatchInfo *info, MMSharedSimtech *self) { - MMCallInfo call_info; - gchar *str; + MMCallInfo call_info; + g_autofree gchar *str = NULL; /* We could have "VOICE" or "DATA". Now consider only "VOICE" */ str = mm_get_string_unquoted_from_match_info (info, 1); - mm_dbg ("Ringing (%s)", str); - g_free (str); + mm_obj_dbg (self, "ringing (%s)", str); call_info.index = 0; call_info.direction = MM_CALL_DIRECTION_INCOMING; @@ -863,13 +862,12 @@ rxdtmf_urc_received (MMPortSerialAt *port, GMatchInfo *match_info, MMSharedSimtech *self) { - gchar *dtmf; + g_autofree gchar *dtmf = NULL; dtmf = g_match_info_fetch (match_info, 1); - mm_dbg ("Received DTMF: %s", dtmf); + mm_obj_dbg (self, "received DTMF: %s", dtmf); /* call index unknown */ mm_iface_modem_voice_received_dtmf (MM_IFACE_MODEM_VOICE (self), 0, dtmf); - g_free (dtmf); } static void @@ -944,7 +942,7 @@ parent_voice_cleanup_unsolicited_events_ready (MMIfaceModemVoice *self, priv = get_private (MM_SHARED_SIMTECH (self)); if (!priv->iface_modem_voice_parent->cleanup_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't cleanup parent voice unsolicited events: %s", error->message); + mm_obj_warn (self, "couldn't cleanup parent voice unsolicited events: %s", error->message); g_error_free (error); } @@ -999,7 +997,7 @@ parent_voice_setup_unsolicited_events_ready (MMIfaceModemVoice *self, priv = get_private (MM_SHARED_SIMTECH (self)); if (!priv->iface_modem_voice_parent->setup_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't setup parent voice unsolicited events: %s", error->message); + mm_obj_warn (self, "couldn't setup parent voice unsolicited events: %s", error->message); g_error_free (error); } @@ -1150,7 +1148,7 @@ cpcmreg_format_check_ready (MMBroadbandModem *self, priv->cpcmreg_support = (mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, NULL) ? FEATURE_SUPPORTED : FEATURE_NOT_SUPPORTED); - mm_dbg ("modem %s USB audio control", (priv->cpcmreg_support == FEATURE_SUPPORTED) ? "supports" : "doesn't support"); + mm_obj_dbg (self, "modem %s USB audio control", (priv->cpcmreg_support == FEATURE_SUPPORTED) ? "supports" : "doesn't support"); g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -1170,12 +1168,12 @@ clcc_format_check_ready (MMBroadbandModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, NULL); if (response && !mm_simtech_parse_clcc_test (response, &clcc_urc_supported, &error)) { - mm_dbg ("failed checking CLCC URC support: %s", error->message); + mm_obj_dbg (self, "failed checking CLCC URC support: %s", error->message); g_clear_error (&error); } priv->clcc_urc_support = (clcc_urc_supported ? FEATURE_SUPPORTED : FEATURE_NOT_SUPPORTED); - mm_dbg ("modem %s +CLCC URCs", (priv->clcc_urc_support == FEATURE_SUPPORTED) ? "supports" : "doesn't support"); + mm_obj_dbg (self, "modem %s +CLCC URCs", (priv->clcc_urc_support == FEATURE_SUPPORTED) ? "supports" : "doesn't support"); /* If +CLCC URC supported we won't need polling in the parent */ g_object_set (self, From 078c638165b4c060ef6e7537d2cf306fa8cfa5f1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 16:28:16 +0200 Subject: [PATCH 119/675] telit: port to use object logging --- plugins/telit/mm-broadband-modem-mbim-telit.c | 19 +++--- plugins/telit/mm-broadband-modem-telit.c | 60 +++++++++---------- plugins/telit/mm-common-telit.c | 39 ++++++------ plugins/telit/mm-modem-helpers-telit.c | 19 ++++-- plugins/telit/mm-modem-helpers-telit.h | 2 + plugins/telit/mm-plugin-telit.c | 6 +- plugins/telit/mm-shared-telit.c | 6 +- .../telit/tests/test-mm-modem-helpers-telit.c | 2 + 8 files changed, 81 insertions(+), 72 deletions(-) diff --git a/plugins/telit/mm-broadband-modem-mbim-telit.c b/plugins/telit/mm-broadband-modem-mbim-telit.c index 248461b5..1a2c3866 100644 --- a/plugins/telit/mm-broadband-modem-mbim-telit.c +++ b/plugins/telit/mm-broadband-modem-mbim-telit.c @@ -22,7 +22,7 @@ #include #include "ModemManager.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-iface-modem.h" #include "mm-base-modem-at.h" @@ -30,8 +30,8 @@ #include "mm-modem-helpers-telit.h" #include "mm-shared-telit.h" -static void iface_modem_init (MMIfaceModem *iface); -static void shared_telit_init (MMSharedTelit *iface); +static void iface_modem_init (MMIfaceModem *iface); +static void shared_telit_init (MMSharedTelit *iface); G_DEFINE_TYPE_EXTENDED (MMBroadbandModemMbimTelit, mm_broadband_modem_mbim_telit, MM_TYPE_BROADBAND_MODEM_MBIM, 0, G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) @@ -65,7 +65,7 @@ load_supported_modes_ready (MMIfaceModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (error) { - mm_dbg ("Generic query of supported 3GPP networks with WS46=? failed: '%s'", error->message); + g_prefix_error (&error, "ceneric query of supported 3GPP networks with WS46=? failed: "); g_task_return_error (task, error); g_object_unref (task); return; @@ -73,23 +73,22 @@ load_supported_modes_ready (MMIfaceModem *self, modes = mm_3gpp_parse_ws46_test_response (response, &error); if (!modes) { - mm_dbg ("Parsing WS46=? response failed: '%s'", error->message); + g_prefix_error (&error, "parsing WS46=? response failed: "); g_task_return_error (task, error); g_object_unref (task); return; } for (i = 0; i < modes->len; i++) { - MMModemMode mode; - gchar *str; + MMModemMode mode; + g_autofree gchar *str = NULL; mode = g_array_index (modes, MMModemMode, i); modes_mask |= mode; str = mm_modem_mode_build_string_from_mask (mode); - mm_dbg ("Device allows (3GPP) mode combination: %s", str); - g_free (str); + mm_obj_dbg (self, "device allows (3GPP) mode combination: %s", str); } g_array_unref (modes); @@ -117,8 +116,6 @@ load_supported_modes (MMIfaceModem *self, { GTask *task; - mm_dbg ("loading Telit mbim supported modes..."); - task = g_task_new (self, NULL, callback, user_data); mm_base_modem_at_command (MM_BASE_MODEM (self), "+WS46=?", diff --git a/plugins/telit/mm-broadband-modem-telit.c b/plugins/telit/mm-broadband-modem-telit.c index a240bb1c..48ae4de1 100644 --- a/plugins/telit/mm-broadband-modem-telit.c +++ b/plugins/telit/mm-broadband-modem-telit.c @@ -24,7 +24,7 @@ #include #include "ModemManager.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-errors-types.h" #include "mm-modem-helpers.h" #include "mm-base-modem-at.h" @@ -182,7 +182,7 @@ gps_enabled_ready (MMBaseModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (self, res, &error)) { - mm_warn ("telit: couldn't power up GNSS controller: '%s'", error->message); + g_prefix_error (&error, "couldn't power up GNSS controller: "); g_task_return_error (task, error); g_object_unref (task); return; @@ -197,7 +197,9 @@ gps_enabled_ready (MMBaseModem *self, task); return; } - mm_info("telit: GNSS controller is powered up"); + + mm_obj_dbg (self, "GNSS controller is powered up"); + /* Only use the GPS port in NMEA/RAW setups */ if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { @@ -355,7 +357,7 @@ gpsp_test_ready (MMIfaceModemLocation *self, sources = GPOINTER_TO_UINT (g_task_get_task_data (task)); mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (error) { - mm_dbg ("telit: GPS controller not supported: %s", error->message); + mm_obj_dbg (self, "GPS controller not supported: %s", error->message); g_clear_error (&error); } else if (mm_base_modem_get_port_gps (MM_BASE_MODEM (self))) sources |= (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | @@ -473,12 +475,12 @@ telit_qss_unsolicited_handler (MMPortSerialAt *port, if (self->priv->csim_lock_state >= CSIM_LOCK_STATE_LOCK_REQUESTED) { if (prev_qss_status > QSS_STATUS_SIM_REMOVED && cur_qss_status == QSS_STATUS_SIM_REMOVED) { - mm_dbg ("QSS handler: #QSS=0 after +CSIM=1 -> CSIM locked!"); + mm_obj_dbg (self, "QSS handler: #QSS=0 after +CSIM=1: CSIM locked!"); self->priv->csim_lock_state = CSIM_LOCK_STATE_LOCKED; } if (prev_qss_status == QSS_STATUS_SIM_REMOVED && cur_qss_status != QSS_STATUS_SIM_REMOVED) { - mm_dbg ("QSS handler: #QSS>=1 after +CSIM=0 -> CSIM unlocked!"); + mm_obj_dbg (self, "QSS handler: #QSS>=1 after +CSIM=0: CSIM unlocked!"); self->priv->csim_lock_state = CSIM_LOCK_STATE_UNLOCKED; if (self->priv->csim_lock_timeout_id) { @@ -493,18 +495,18 @@ telit_qss_unsolicited_handler (MMPortSerialAt *port, } if (cur_qss_status != prev_qss_status) - mm_dbg ("QSS handler: status changed '%s -> %s'", - mm_telit_qss_status_get_string (prev_qss_status), - mm_telit_qss_status_get_string (cur_qss_status)); + mm_obj_dbg (self, "QSS handler: status changed %s -> %s", + mm_telit_qss_status_get_string (prev_qss_status), + mm_telit_qss_status_get_string (cur_qss_status)); if (self->priv->parse_qss == FALSE) { - mm_dbg ("QSS: message ignored"); + mm_obj_dbg (self, "QSS handler: message ignored"); return; } if ((prev_qss_status == QSS_STATUS_SIM_REMOVED && cur_qss_status != QSS_STATUS_SIM_REMOVED) || (prev_qss_status > QSS_STATUS_SIM_REMOVED && cur_qss_status == QSS_STATUS_SIM_REMOVED)) { - mm_info ("QSS handler: SIM swap detected"); + mm_obj_info (self, "QSS handler: SIM swap detected"); mm_broadband_modem_update_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); } } @@ -549,7 +551,7 @@ telit_qss_enable_ready (MMBaseModem *self, g_assert_not_reached (); if (!mm_base_modem_at_command_full_finish (self, res, error)) { - mm_warn ("QSS: error enabling unsolicited on port %s: %s", mm_port_get_device (MM_PORT (port)), (*error)->message); + mm_obj_warn (self, "QSS: error enabling unsolicited on port %s: %s", mm_port_get_device (MM_PORT (port)), (*error)->message); goto next_step; } @@ -584,19 +586,19 @@ telit_qss_query_ready (MMBaseModem *_self, response = mm_base_modem_at_command_finish (_self, res, &error); if (error) { - mm_warn ("Could not get \"#QSS?\" reply: %s", error->message); + mm_obj_warn (self, "could not get \"#QSS?\" reply: %s", error->message); g_error_free (error); goto next_step; } qss_status = mm_telit_parse_qss_query (response, &error); if (error) { - mm_warn ("QSS query parse error: %s", error->message); + mm_obj_warn (self, "QSS query parse error: %s", error->message); g_error_free (error); goto next_step; } - mm_info ("QSS: current status is '%s'", mm_telit_qss_status_get_string (qss_status)); + mm_obj_dbg (self, "QSS: current status is '%s'", mm_telit_qss_status_get_string (qss_status)); self->priv->qss_status = qss_status; next_step: @@ -754,7 +756,7 @@ csim_unlock_ready (MMBaseModem *_self, MM_MOBILE_EQUIPMENT_ERROR_NOT_SUPPORTED)) { self->priv->csim_lock_support = FEATURE_NOT_SUPPORTED; } - mm_warn ("Couldn't unlock SIM card: %s", error->message); + mm_obj_warn (self, "couldn't unlock SIM card: %s", error->message); g_error_free (error); } @@ -776,7 +778,7 @@ parent_load_unlock_retries_ready (MMIfaceModem *self, ctx = g_task_get_task_data (task); if (!(ctx->retries = iface_modem_parent->load_unlock_retries_finish (self, res, &error))) { - mm_warn ("couldn't load unlock retries with generic logic: %s", error->message); + mm_obj_warn (self, "couldn't load unlock retries with generic logic: %s", error->message); g_error_free (error); } @@ -803,7 +805,7 @@ csim_lock_ready (MMBaseModem *_self, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_NOT_SUPPORTED)) { self->priv->csim_lock_support = FEATURE_NOT_SUPPORTED; - mm_warn ("Couldn't lock SIM card: %s. Continuing without CSIM lock.", error->message); + mm_obj_warn (self, "couldn't lock SIM card: %s; continuing without CSIM lock", error->message); g_error_free (error); } else { g_prefix_error (&error, "Couldn't lock SIM card: "); @@ -853,8 +855,8 @@ handle_csim_locking (GTask *task, } break; case FEATURE_NOT_SUPPORTED: - mm_dbg ("CSIM lock not supported by this modem. Skipping %s command", - is_lock ? "lock" : "unlock"); + mm_obj_dbg (self, "CSIM lock not supported by this modem; skipping %s command", + is_lock ? "lock" : "unlock"); ctx->step++; load_unlock_retries_step (task); break; @@ -884,9 +886,8 @@ pending_csim_unlock_complete (MMBroadbandModemTelit *self) static gboolean csim_unlock_periodic_check (MMBroadbandModemTelit *self) { - if (self->priv->csim_lock_state != CSIM_LOCK_STATE_UNLOCKED) { - mm_warn ("CSIM is still locked after %d seconds. Trying to continue anyway", CSIM_UNLOCK_MAX_TIMEOUT); - } + if (self->priv->csim_lock_state != CSIM_LOCK_STATE_UNLOCKED) + mm_obj_warn (self, "CSIM is still locked after %d seconds; trying to continue anyway", CSIM_UNLOCK_MAX_TIMEOUT); self->priv->csim_lock_timeout_id = 0; pending_csim_unlock_complete (self); @@ -922,7 +923,7 @@ load_unlock_retries_step (GTask *task) case LOAD_UNLOCK_RETRIES_STEP_LAST: self->priv->csim_lock_task = task; if (self->priv->csim_lock_state == CSIM_LOCK_STATE_LOCKED) { - mm_dbg ("CSIM is locked. Waiting for #QSS=1"); + mm_obj_dbg (self, "CSIM is locked, waiting for #QSS=1"); self->priv->csim_lock_timeout_id = g_timeout_add_seconds (CSIM_UNLOCK_MAX_TIMEOUT, (GSourceFunc) csim_unlock_periodic_check, g_object_ref(self)); @@ -977,7 +978,7 @@ modem_after_power_up (MMIfaceModem *self, task = g_task_new (self, NULL, callback, user_data); - mm_dbg ("Stop ignoring #QSS"); + mm_obj_dbg (self, "stop ignoring #QSS"); modem->priv->parse_qss = TRUE; g_task_return_boolean (task, TRUE); @@ -1003,12 +1004,12 @@ telit_modem_power_down_ready (MMBaseModem *self, GError *error = NULL; if (mm_base_modem_at_command_finish (self, res, &error)) { - mm_dbg ("Ignore #QSS unsolicited during power down/low"); + mm_obj_dbg (self, "sgnore #QSS unsolicited during power down/low"); MM_BROADBAND_MODEM_TELIT (self)->priv->parse_qss = FALSE; } if (error) { - mm_err ("modem power down: %s", error->message); + mm_obj_warn (self, "failed modem power down: %s", error->message); g_clear_error (&error); } @@ -1194,7 +1195,6 @@ load_access_technologies (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading access technology (Telit)..."); mm_base_modem_at_sequence ( MM_BASE_MODEM (self), access_tech_commands, @@ -1280,7 +1280,7 @@ cind_set_ready (MMBaseModem *self, GError *error = NULL; if (!mm_base_modem_at_command_finish (self, res, &error)) { - mm_warn ("Couldn't enable custom +CIND settings: %s", error->message); + mm_obj_warn (self, "couldn't enable custom +CIND settings: %s", error->message); g_error_free (error); } @@ -1296,7 +1296,7 @@ parent_enable_unsolicited_events_ready (MMIfaceModem3gpp *self, GError *error = NULL; if (!iface_modem_3gpp_parent->enable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't enable parent 3GPP unsolicited events: %s", error->message); + mm_obj_warn (self, "couldn't enable parent 3GPP unsolicited events: %s", error->message); g_error_free (error); } diff --git a/plugins/telit/mm-common-telit.c b/plugins/telit/mm-common-telit.c index 3cdbd7fd..0493fd54 100644 --- a/plugins/telit/mm-common-telit.c +++ b/plugins/telit/mm-common-telit.c @@ -16,7 +16,7 @@ #include #include "mm-common-telit.h" -#include "mm-log.h" +#include "mm-log-object.h" /*****************************************************************************/ @@ -55,19 +55,19 @@ telit_grab_port (MMPlugin *self, usbif = mm_kernel_device_get_property_as_int_hex (port, "ID_USB_INTERFACE_NUM"); if (usbif == GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_TELIT_MODEM_PORT))) { - mm_dbg ("telit: AT port '%s/%s' flagged as primary", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "AT port '%s/%s' flagged as primary", + mm_port_probe_get_port_subsys (probe), + mm_port_probe_get_port_name (probe)); pflags = MM_PORT_SERIAL_AT_FLAG_PRIMARY; } else if (usbif == GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_TELIT_AUX_PORT))) { - mm_dbg ("telit: AT port '%s/%s' flagged as secondary", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "AT port '%s/%s' flagged as secondary", + mm_port_probe_get_port_subsys (probe), + mm_port_probe_get_port_name (probe)); pflags = MM_PORT_SERIAL_AT_FLAG_SECONDARY; } else if (usbif == GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_TELIT_NMEA_PORT))) { - mm_dbg ("telit: port '%s/%s' flagged as NMEA", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (self, "port '%s/%s' flagged as NMEA", + mm_port_probe_get_port_subsys (probe), + mm_port_probe_get_port_name (probe)); ptype = MM_PORT_TYPE_GPS; } else ptype = MM_PORT_TYPE_IGNORED; @@ -101,7 +101,8 @@ telit_custom_init_finish (MMPortProbe *probe, static void telit_custom_init_step (GTask *task); static gboolean -cache_port_mode (MMDevice *device, +cache_port_mode (MMPortProbe *probe, + MMDevice *device, const gchar *reply) { GRegex *r = NULL; @@ -119,7 +120,7 @@ cache_port_mode (MMDevice *device, goto out; if (!mm_get_uint_from_match_info (match_info, 2, &portcfg_current)) { - mm_dbg ("telit: unrecognized #PORTCFG value"); + mm_obj_dbg (probe, "unrecognized #PORTCFG value"); goto out; } @@ -168,8 +169,8 @@ cache_port_mode (MMDevice *device, g_match_info_free (match_info); g_regex_unref (r); if (error != NULL) { - mm_dbg ("telit: error while matching: %s", error->message); - g_error_free (error); + mm_obj_dbg (probe, "error while matching #PORTCFG: %s", error->message); + g_error_free (error); } return ret; } @@ -189,8 +190,7 @@ getportcfg_ready (MMPortSerialAt *port, response = mm_port_serial_at_command_finish (port, res, &error); if (error) { - mm_dbg ("telit: couldn't get port mode: '%s'", - error->message); + mm_obj_dbg (probe, "couldn't get telit port mode: '%s'", error->message); /* If ERROR or COMMAND NOT SUPPORT occur then do not retry the * command. @@ -206,8 +206,8 @@ getportcfg_ready (MMPortSerialAt *port, /* Results are cached in the parent device object */ if (g_object_get_data (G_OBJECT (device), TAG_GETPORTCFG_SUPPORTED) == NULL) { - mm_dbg ("telit: retrieving port mode layout"); - if (cache_port_mode (device, response)) { + mm_obj_dbg (probe, "retrieving telit port mode layout"); + if (cache_port_mode (probe, device, response)) { g_object_set_data (G_OBJECT (device), TAG_GETPORTCFG_SUPPORTED, GUINT_TO_POINTER (TRUE)); ctx->getportcfg_done = TRUE; } @@ -242,8 +242,7 @@ telit_custom_init_step (GTask *task) /* If cancelled, end */ if (g_cancellable_is_cancelled (g_task_get_cancellable (task))) { - mm_dbg ("telit: no need to keep on running custom init in (%s)", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "no need to keep on running custom init"); goto out; } diff --git a/plugins/telit/mm-modem-helpers-telit.c b/plugins/telit/mm-modem-helpers-telit.c index 07d46b8d..f77afeea 100644 --- a/plugins/telit/mm-modem-helpers-telit.c +++ b/plugins/telit/mm-modem-helpers-telit.c @@ -23,7 +23,7 @@ #define _LIBMM_INSIDE_MMCLI #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-telit.h" @@ -375,6 +375,7 @@ mm_telit_build_bnd_request (GArray *bands_array, static gboolean telit_get_2g_mm_bands (GMatchInfo *match_info, + gpointer log_object, GArray **bands, GError **error) { @@ -406,7 +407,7 @@ telit_get_2g_mm_bands (GMatchInfo *match_info, *bands = g_array_append_val (*bands, j); } } else - mm_dbg ("unhandled telit 2G band value configuration: %u", value); + mm_obj_dbg (log_object, "unhandled telit 2G band value configuration: %u", value); } out: @@ -422,8 +423,9 @@ telit_get_2g_mm_bands (GMatchInfo *match_info, static gboolean telit_get_3g_mm_bands (GMatchInfo *match_info, - GArray **bands, + gpointer log_object, gboolean modem_alternate_3g_bands, + GArray **bands, GError **error) { GError *inner_error = NULL; @@ -472,7 +474,7 @@ telit_get_3g_mm_bands (GMatchInfo *match_info, *bands = g_array_append_val (*bands, j); } } else - mm_dbg ("unhandled telit 3G band value configuration: %u", value); + mm_obj_dbg (log_object, "unhandled telit 3G band value configuration: %u", value); } out: @@ -542,6 +544,7 @@ common_parse_bnd_response (const gchar *response, gboolean modem_is_4g, gboolean modem_alternate_3g_bands, LoadBandsType load_type, + gpointer log_object, GError **error) { GError *inner_error = NULL; @@ -571,10 +574,10 @@ common_parse_bnd_response (const gchar *response, bands = g_array_new (TRUE, TRUE, sizeof (MMModemBand)); - if (modem_is_2g && !telit_get_2g_mm_bands (match_info, &bands, &inner_error)) + if (modem_is_2g && !telit_get_2g_mm_bands (match_info, log_object, &bands, &inner_error)) goto out; - if (modem_is_3g && !telit_get_3g_mm_bands (match_info, &bands, modem_alternate_3g_bands, &inner_error)) + if (modem_is_3g && !telit_get_3g_mm_bands (match_info, log_object, modem_alternate_3g_bands, &bands, &inner_error)) goto out; if (modem_is_4g && !telit_get_4g_mm_bands (match_info, &bands, &inner_error)) @@ -599,12 +602,14 @@ mm_telit_parse_bnd_query_response (const gchar *response, gboolean modem_is_3g, gboolean modem_is_4g, gboolean modem_alternate_3g_bands, + gpointer log_object, GError **error) { return common_parse_bnd_response (response, modem_is_2g, modem_is_3g, modem_is_4g, modem_alternate_3g_bands, LOAD_BANDS_TYPE_CURRENT, + log_object, error); } @@ -614,12 +619,14 @@ mm_telit_parse_bnd_test_response (const gchar *response, gboolean modem_is_3g, gboolean modem_is_4g, gboolean modem_alternate_3g_bands, + gpointer log_object, GError **error) { return common_parse_bnd_response (response, modem_is_2g, modem_is_3g, modem_is_4g, modem_alternate_3g_bands, LOAD_BANDS_TYPE_SUPPORTED, + log_object, error); } diff --git a/plugins/telit/mm-modem-helpers-telit.h b/plugins/telit/mm-modem-helpers-telit.h index 491e8fa6..0c52bb7b 100644 --- a/plugins/telit/mm-modem-helpers-telit.h +++ b/plugins/telit/mm-modem-helpers-telit.h @@ -25,12 +25,14 @@ GArray *mm_telit_parse_bnd_query_response (const gchar *response, gboolean modem_is_3g, gboolean modem_is_4g, gboolean modem_alternate_3g_bands, + gpointer log_object, GError **error); GArray *mm_telit_parse_bnd_test_response (const gchar *response, gboolean modem_is_2g, gboolean modem_is_3g, gboolean modem_is_4g, gboolean modem_alternate_3g_bands, + gpointer log_object, GError **error); gchar *mm_telit_build_bnd_request (GArray *bands_array, gboolean modem_is_2g, diff --git a/plugins/telit/mm-plugin-telit.c b/plugins/telit/mm-plugin-telit.c index 093975a9..926ce977 100644 --- a/plugins/telit/mm-plugin-telit.c +++ b/plugins/telit/mm-plugin-telit.c @@ -22,7 +22,7 @@ #include #include "mm-port-enums-types.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-plugin-telit.h" #include "mm-common-telit.h" @@ -55,7 +55,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered Telit modem found..."); + mm_obj_dbg (self, "QMI-powered Telit modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), @@ -66,7 +66,7 @@ create_modem (MMPlugin *self, #if defined WITH_MBIM if (mm_port_probe_list_has_mbim_port (probes)) { - mm_dbg ("MBIM-powered Telit modem found..."); + mm_obj_dbg (self, "MBIM-powered Telit modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_telit_new (uid, drivers, mm_plugin_get_name (self), diff --git a/plugins/telit/mm-shared-telit.c b/plugins/telit/mm-shared-telit.c index f1eb0518..9a5aa838 100644 --- a/plugins/telit/mm-shared-telit.c +++ b/plugins/telit/mm-shared-telit.c @@ -23,7 +23,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-iface-modem.h" #include "mm-iface-modem-location.h" #include "mm-base-modem.h" @@ -63,7 +63,7 @@ initialize_alternate_3g_band (MMSharedTelit *self, /* Lookup for the tag specifying that we're using the alternate 3G band mapping */ priv->alternate_3g_bands = mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_TELIT_BND_ALTERNATE"); if (priv->alternate_3g_bands) - mm_dbg ("Telit modem using alternate 3G band mask setup"); + mm_obj_dbg (self, "telit modem using alternate 3G band mask setup"); } static Private * @@ -197,6 +197,7 @@ mm_shared_telit_load_supported_bands_ready (MMBaseModem *self, mm_iface_modem_is_3g (MM_IFACE_MODEM (self)), mm_iface_modem_is_4g (MM_IFACE_MODEM (self)), priv->alternate_3g_bands, + self, &error); if (!bands) g_task_return_error (task, error); @@ -256,6 +257,7 @@ mm_shared_telit_load_current_bands_ready (MMBaseModem *self, mm_iface_modem_is_3g (MM_IFACE_MODEM (self)), mm_iface_modem_is_4g (MM_IFACE_MODEM (self)), priv->alternate_3g_bands, + self, &error); if (!bands) g_task_return_error (task, error); diff --git a/plugins/telit/tests/test-mm-modem-helpers-telit.c b/plugins/telit/tests/test-mm-modem-helpers-telit.c index 7561dac2..b6083816 100644 --- a/plugins/telit/tests/test-mm-modem-helpers-telit.c +++ b/plugins/telit/tests/test-mm-modem-helpers-telit.c @@ -170,6 +170,7 @@ test_parse_supported_bands_response (void) supported_band_mapping_tests[i].modem_is_3g, supported_band_mapping_tests[i].modem_is_4g, supported_band_mapping_tests[i].modem_alternate_3g_bands, + NULL, &error); g_assert_no_error (error); g_assert (bands); @@ -278,6 +279,7 @@ test_parse_current_bands_response (void) current_band_mapping_tests[i].modem_is_3g, current_band_mapping_tests[i].modem_is_4g, current_band_mapping_tests[i].modem_alternate_3g_bands, + NULL, &error); g_assert_no_error (error); g_assert (bands); From 98631e140ed9b85462d359503d22900edc30ad32 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 07:07:51 +0200 Subject: [PATCH 120/675] thuraya: return GError in custom CPMS parser --- plugins/thuraya/mm-broadband-modem-thuraya.c | 10 +-- plugins/thuraya/mm-modem-helpers-thuraya.c | 70 ++++++++----------- plugins/thuraya/mm-modem-helpers-thuraya.h | 9 +-- .../tests/test-mm-modem-helpers-thuraya.c | 4 +- 4 files changed, 42 insertions(+), 51 deletions(-) diff --git a/plugins/thuraya/mm-broadband-modem-thuraya.c b/plugins/thuraya/mm-broadband-modem-thuraya.c index 071ef3f9..a4013410 100644 --- a/plugins/thuraya/mm-broadband-modem-thuraya.c +++ b/plugins/thuraya/mm-broadband-modem-thuraya.c @@ -24,7 +24,6 @@ #include #include "ModemManager.h" -#include "mm-log.h" #include "mm-errors-types.h" #include "mm-base-modem-at.h" #include "mm-iface-modem.h" @@ -185,13 +184,10 @@ cpms_format_check_ready (MMBaseModem *self, if (!mm_thuraya_3gpp_parse_cpms_test_response (response, &result->mem1, &result->mem2, - &result->mem3)) { + &result->mem3, + &error)) { supported_storages_result_free (result); - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't parse supported storages reply: '%s'", - response); + g_task_return_error (task, error); g_object_unref (task); return; } diff --git a/plugins/thuraya/mm-modem-helpers-thuraya.c b/plugins/thuraya/mm-modem-helpers-thuraya.c index 1dad59fd..0c713a18 100644 --- a/plugins/thuraya/mm-modem-helpers-thuraya.c +++ b/plugins/thuraya/mm-modem-helpers-thuraya.c @@ -47,29 +47,33 @@ storage_from_str (const gchar *str) } gboolean -mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply, - GArray **mem1, - GArray **mem2, - GArray **mem3) +mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply, + GArray **mem1, + GArray **mem2, + GArray **mem3, + GError **error) { #define N_EXPECTED_GROUPS 3 - GRegex *r; - gchar **split; - gchar **splitp; - const gchar *splita[N_EXPECTED_GROUPS]; - guint i; - GArray *tmp1 = NULL; - GArray *tmp2 = NULL; - GArray *tmp3 = NULL; + gchar **splitp; + const gchar *splita[N_EXPECTED_GROUPS]; + guint i; + g_auto(GStrv) split = NULL; + g_autoptr(GRegex) r = NULL; + g_autoptr(GArray) tmp1 = NULL; + g_autoptr(GArray) tmp2 = NULL; + g_autoptr(GArray) tmp3 = NULL; g_assert (mem1 != NULL); g_assert (mem2 != NULL); g_assert (mem3 != NULL); split = g_strsplit (mm_strip_tag (reply, "+CPMS:"), " ", -1); - if (!split) + if (!split) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't split +CPMS response"); return FALSE; + } /* remove empty strings, and count non-empty strings */ i = 0; @@ -82,9 +86,9 @@ mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply, } if (i != N_EXPECTED_GROUPS) { - mm_warn ("Cannot parse +CPMS test response: invalid number of groups (%u != %u)", - i, N_EXPECTED_GROUPS); - g_strfreev (split); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't parse +CPMS response: invalid number of groups (%u != %u)", + i, N_EXPECTED_GROUPS); return FALSE; } @@ -92,8 +96,8 @@ mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply, g_assert (r); for (i = 0; i < N_EXPECTED_GROUPS; i++) { - GMatchInfo *match_info = NULL; - GArray *array; + g_autoptr(GMatchInfo) match_info = NULL; + GArray *array; /* We always return a valid array, even if it may be empty */ array = g_array_new (FALSE, FALSE, sizeof (MMSmsStorage)); @@ -101,7 +105,7 @@ mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply, /* Got a range group to match */ if (g_regex_match (r, splita[i], 0, &match_info)) { while (g_match_info_matches (match_info)) { - gchar *str; + g_autofree gchar *str = NULL; str = g_match_info_fetch (match_info, 1); if (str) { @@ -109,13 +113,11 @@ mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply, storage = storage_from_str (str); g_array_append_val (array, storage); - g_free (str); } g_match_info_next (match_info, NULL); } } - g_match_info_free (match_info); if (!tmp1) tmp1 = array; @@ -127,30 +129,20 @@ mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply, g_assert_not_reached (); } - g_strfreev (split); - g_regex_unref (r); - - g_warn_if_fail (tmp1 != NULL); - g_warn_if_fail (tmp2 != NULL); - g_warn_if_fail (tmp3 != NULL); - /* Only return TRUE if all sets have been parsed correctly * (even if the arrays may be empty) */ if (tmp1 && tmp2 && tmp3) { - *mem1 = tmp1; - *mem2 = tmp2; - *mem3 = tmp3; + *mem1 = g_steal_pointer (&tmp1); + *mem2 = g_steal_pointer (&tmp2); + *mem3 = g_steal_pointer (&tmp3); return TRUE; } /* Otherwise, cleanup and return FALSE */ - if (tmp1) - g_array_unref (tmp1); - if (tmp2) - g_array_unref (tmp2); - if (tmp3) - g_array_unref (tmp3); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't parse +CPMS response: not all groups detected (mem1 %s, mem2 %s, mem3 %s)", + tmp1 ? "yes" : "no", + tmp2 ? "yes" : "no", + tmp3 ? "yes" : "no"); return FALSE; } - -/*****************************************************************************/ diff --git a/plugins/thuraya/mm-modem-helpers-thuraya.h b/plugins/thuraya/mm-modem-helpers-thuraya.h index 454baf47..33bb079f 100644 --- a/plugins/thuraya/mm-modem-helpers-thuraya.h +++ b/plugins/thuraya/mm-modem-helpers-thuraya.h @@ -19,9 +19,10 @@ #include /* AT+CPMS=? (Preferred SMS storage) response parser */ -gboolean mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply, - GArray **mem1, - GArray **mem2, - GArray **mem3); +gboolean mm_thuraya_3gpp_parse_cpms_test_response (const gchar *reply, + GArray **mem1, + GArray **mem2, + GArray **mem3, + GError **error); #endif /* MM_MODEM_HELPERS_THURAYA_H */ diff --git a/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c index a3e5f65f..c3c76f09 100644 --- a/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c +++ b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c @@ -55,10 +55,12 @@ test_cpms_response_thuraya (void *f, gpointer d) GArray *mem1 = NULL; GArray *mem2 = NULL; GArray *mem3 = NULL; + GError *error = NULL; g_debug ("Testing thuraya +CPMS=? response..."); - g_assert (mm_thuraya_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3)); + g_assert (mm_thuraya_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3, &error)); + g_assert_no_error (error); g_assert_cmpuint (mem1->len, ==, 5); g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_MT)); g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_SM)); From 94a15597518c2832803af71570fa3d006293c7ff Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 07:08:35 +0200 Subject: [PATCH 121/675] thuraya: no logging in plugin --- plugins/thuraya/mm-plugin-thuraya.c | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/thuraya/mm-plugin-thuraya.c b/plugins/thuraya/mm-plugin-thuraya.c index ce1da626..9db3d61e 100644 --- a/plugins/thuraya/mm-plugin-thuraya.c +++ b/plugins/thuraya/mm-plugin-thuraya.c @@ -31,7 +31,6 @@ #include "mm-broadband-modem.h" #include "mm-broadband-modem-thuraya.h" #include "mm-private-boxed-types.h" -#include "mm-log.h" G_DEFINE_TYPE (MMPluginThuraya, mm_plugin_thuraya, MM_TYPE_PLUGIN) From e04aa0ea5d16ce4f162e8adcd4f42a02d23618ba Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 07:09:19 +0200 Subject: [PATCH 122/675] tplink: port to use object logging --- plugins/tplink/mm-plugin-tplink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/tplink/mm-plugin-tplink.c b/plugins/tplink/mm-plugin-tplink.c index 20cf9db3..93fde158 100644 --- a/plugins/tplink/mm-plugin-tplink.c +++ b/plugins/tplink/mm-plugin-tplink.c @@ -20,7 +20,7 @@ #include #include "mm-port-enums-types.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-tplink.h" #include "mm-broadband-modem.h" @@ -46,7 +46,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered TP-Link modem found..."); + mm_obj_dbg (self, "QMI-powered TP-Link modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), From ccd0f6de5ad875b5ddd73ed5a20aea060b679aea Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 07:53:06 +0200 Subject: [PATCH 123/675] ublox: port to use object logging --- plugins/ublox/mm-broadband-bearer-ublox.c | 219 +++++++------- plugins/ublox/mm-broadband-modem-ublox.c | 282 +++++++++--------- plugins/ublox/mm-modem-helpers-ublox.c | 46 +-- plugins/ublox/mm-modem-helpers-ublox.h | 6 + plugins/ublox/mm-plugin-ublox.c | 38 +-- .../ublox/tests/test-modem-helpers-ublox.c | 10 +- 6 files changed, 300 insertions(+), 301 deletions(-) diff --git a/plugins/ublox/mm-broadband-bearer-ublox.c b/plugins/ublox/mm-broadband-bearer-ublox.c index 377ead59..a453396d 100644 --- a/plugins/ublox/mm-broadband-bearer-ublox.c +++ b/plugins/ublox/mm-broadband-bearer-ublox.c @@ -28,7 +28,7 @@ #include "mm-broadband-bearer-ublox.h" #include "mm-base-modem-at.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-ublox-enums-types.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-ublox.h" @@ -56,14 +56,12 @@ struct _MMBroadbandBearerUbloxPrivate { /* Common connection context and task */ typedef struct { - MMBroadbandBearerUblox *self; - MMBroadbandModem *modem; - MMPortSerialAt *primary; - MMPort *data; - guint cid; - gboolean auth_required; - /* For IPv4 settings */ - MMBearerIpConfig *ip_config; + MMBroadbandModem *modem; + MMPortSerialAt *primary; + MMPort *data; + guint cid; + gboolean auth_required; + MMBearerIpConfig *ip_config; /* For IPv4 settings */ } CommonConnectContext; static void @@ -73,7 +71,6 @@ common_connect_context_free (CommonConnectContext *ctx) g_object_unref (ctx->ip_config); if (ctx->data) g_object_unref (ctx->data); - g_object_unref (ctx->self); g_object_unref (ctx->modem); g_object_unref (ctx->primary); g_slice_free (CommonConnectContext, ctx); @@ -93,7 +90,6 @@ common_connect_task_new (MMBroadbandBearerUblox *self, GTask *task; ctx = g_slice_new0 (CommonConnectContext); - ctx->self = g_object_ref (self); ctx->modem = g_object_ref (modem); ctx->primary = g_object_ref (primary); ctx->cid = cid; @@ -152,7 +148,7 @@ complete_get_ip_config_3gpp (GTask *task) { CommonConnectContext *ctx; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + ctx = g_task_get_task_data (task); g_assert (mm_bearer_ip_config_get_method (ctx->ip_config) != MM_BEARER_IP_METHOD_UNKNOWN); g_task_return_pointer (task, mm_bearer_connect_result_new (ctx->data, ctx->ip_config, NULL), @@ -165,14 +161,16 @@ cgcontrdp_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { - const gchar *response; - GError *error = NULL; - CommonConnectContext *ctx; - gchar *local_address = NULL; - gchar *subnet = NULL; - gchar *dns_addresses[3] = { NULL, NULL, NULL }; + MMBroadbandBearerUblox *self; + const gchar *response; + GError *error = NULL; + CommonConnectContext *ctx; + gchar *local_address = NULL; + gchar *subnet = NULL; + gchar *dns_addresses[3] = { NULL, NULL, NULL }; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mm_base_modem_at_command_finish (modem, res, &error); if (!response || !mm_3gpp_parse_cgcontrdp_response (response, @@ -190,14 +188,14 @@ cgcontrdp_ready (MMBaseModem *modem, return; } - mm_dbg ("IPv4 address retrieved: %s", local_address); + mm_obj_dbg (self, "IPv4 address retrieved: %s", local_address); mm_bearer_ip_config_set_address (ctx->ip_config, local_address); - mm_dbg ("IPv4 subnet retrieved: %s", subnet); + mm_obj_dbg (self, "IPv4 subnet retrieved: %s", subnet); mm_bearer_ip_config_set_prefix (ctx->ip_config, mm_netmask_to_cidr (subnet)); if (dns_addresses[0]) - mm_dbg ("Primary DNS retrieved: %s", dns_addresses[0]); + mm_obj_dbg (self, "primary DNS retrieved: %s", dns_addresses[0]); if (dns_addresses[1]) - mm_dbg ("Secondary DNS retrieved: %s", dns_addresses[1]); + mm_obj_dbg (self, "secondary DNS retrieved: %s", dns_addresses[1]); mm_bearer_ip_config_set_dns (ctx->ip_config, (const gchar **) dns_addresses); g_free (local_address); @@ -205,7 +203,7 @@ cgcontrdp_ready (MMBaseModem *modem, g_free (dns_addresses[0]); g_free (dns_addresses[1]); - mm_dbg ("finished IP settings retrieval for PDP context #%u...", ctx->cid); + mm_obj_dbg (self, "finished IP settings retrieval for PDP context #%u...", ctx->cid); complete_get_ip_config_3gpp (task); } @@ -215,13 +213,15 @@ uipaddr_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { - const gchar *response; - gchar *cmd; - GError *error = NULL; - CommonConnectContext *ctx; - gchar *gw_ipv4_address = NULL; + MMBroadbandBearerUblox *self; + const gchar *response; + gchar *cmd; + GError *error = NULL; + CommonConnectContext *ctx; + gchar *gw_ipv4_address = NULL; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); response = mm_base_modem_at_command_finish (modem, res, &error); if (!response || !mm_ublox_parse_uipaddr_response (response, @@ -237,12 +237,12 @@ uipaddr_ready (MMBaseModem *modem, return; } - mm_dbg ("IPv4 gateway address retrieved: %s", gw_ipv4_address); + mm_obj_dbg (self, "IPv4 gateway address retrieved: %s", gw_ipv4_address); mm_bearer_ip_config_set_gateway (ctx->ip_config, gw_ipv4_address); g_free (gw_ipv4_address); cmd = g_strdup_printf ("+CGCONTRDP=%u", ctx->cid); - mm_dbg ("gathering IP and DNS information for PDP context #%u...", ctx->cid); + mm_obj_dbg (self, "gathering IP and DNS information for PDP context #%u...", ctx->cid); mm_base_modem_at_command (MM_BASE_MODEM (modem), cmd, 10, @@ -253,7 +253,7 @@ uipaddr_ready (MMBaseModem *modem, } static void -get_ip_config_3gpp (MMBroadbandBearer *self, +get_ip_config_3gpp (MMBroadbandBearer *_self, MMBroadbandModem *modem, MMPortSerialAt *primary, MMPortSerialAt *secondary, @@ -263,8 +263,9 @@ get_ip_config_3gpp (MMBroadbandBearer *self, GAsyncReadyCallback callback, gpointer user_data) { - GTask *task; - CommonConnectContext *ctx; + MMBroadbandBearerUblox *self = MM_BROADBAND_BEARER_UBLOX (_self); + GTask *task; + CommonConnectContext *ctx; if (!(task = common_connect_task_new (MM_BROADBAND_BEARER_UBLOX (self), MM_BROADBAND_MODEM (modem), @@ -276,20 +277,20 @@ get_ip_config_3gpp (MMBroadbandBearer *self, user_data))) return; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + ctx = g_task_get_task_data (task); ctx->ip_config = mm_bearer_ip_config_new (); /* If we're in BRIDGE mode, we need to ask for static IP addressing details: * - AT+UIPADDR=[CID] will give us the default gateway address. * - +CGCONTRDP?[CID] will give us the IP address, subnet and DNS addresses. */ - if (ctx->self->priv->mode == MM_UBLOX_NETWORKING_MODE_BRIDGE) { + if (self->priv->mode == MM_UBLOX_NETWORKING_MODE_BRIDGE) { gchar *cmd; mm_bearer_ip_config_set_method (ctx->ip_config, MM_BEARER_IP_METHOD_STATIC); cmd = g_strdup_printf ("+UIPADDR=%u", cid); - mm_dbg ("gathering gateway information for PDP context #%u...", cid); + mm_obj_dbg (self, "gathering gateway information for PDP context #%u...", cid); mm_base_modem_at_command (MM_BASE_MODEM (modem), cmd, 10, @@ -302,7 +303,7 @@ get_ip_config_3gpp (MMBroadbandBearer *self, /* If we're in ROUTER networking mode, we just need to request DHCP on the * network interface. Early return with that result. */ - if (ctx->self->priv->mode == MM_UBLOX_NETWORKING_MODE_ROUTER) { + if (self->priv->mode == MM_UBLOX_NETWORKING_MODE_ROUTER) { mm_bearer_ip_config_set_method (ctx->ip_config, MM_BEARER_IP_METHOD_DHCP); complete_get_ip_config_3gpp (task); return; @@ -332,7 +333,7 @@ cedata_activate_ready (MMBaseModem *modem, response = mm_base_modem_at_command_finish (modem, res, &error); if (!response) { - mm_warn ("ECM data connection attempt failed: %s", error->message); + mm_obj_warn (self, "ECM data connection attempt failed: %s", error->message); mm_base_bearer_report_connection_status (MM_BASE_BEARER (self), MM_BEARER_CONNECTION_STATUS_DISCONNECTED); g_error_free (error); @@ -350,7 +351,7 @@ cgact_activate_ready (MMBaseModem *modem, GError *error = NULL; CommonConnectContext *ctx; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + ctx = g_task_get_task_data (task); response = mm_base_modem_at_command_finish (modem, res, &error); if (!response) @@ -363,40 +364,42 @@ cgact_activate_ready (MMBaseModem *modem, static void activate_3gpp (GTask *task) { - CommonConnectContext *ctx; - gchar *cmd; + MMBroadbandBearerUblox *self; + CommonConnectContext *ctx; + g_autofree gchar *cmd = NULL; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); - if (ctx->self->priv->profile == MM_UBLOX_USB_PROFILE_ECM && - ctx->self->priv->cedata == FEATURE_SUPPORTED) { - /* SARA-U2xx and LISA-U20x only expose one CDC-ECM interface. Hence, - the fixed 0 as the interface index here. When we see modems with - multiple interfaces, this needs to be revisited. */ + /* SARA-U2xx and LISA-U20x only expose one CDC-ECM interface. Hence, + * the fixed 0 as the interface index here. When we see modems with + * multiple interfaces, this needs to be revisited. */ + if (self->priv->profile == MM_UBLOX_USB_PROFILE_ECM && self->priv->cedata == FEATURE_SUPPORTED) { cmd = g_strdup_printf ("+UCEDATA=%u,0", ctx->cid); - mm_dbg ("establishing ECM data connection for PDP context #%u...", ctx->cid); + mm_obj_dbg (self, "establishing ECM data connection for PDP context #%u...", ctx->cid); mm_base_modem_at_command (MM_BASE_MODEM (ctx->modem), cmd, 180, FALSE, (GAsyncReadyCallback) cedata_activate_ready, - g_object_ref (ctx->self)); + g_object_ref (self)); + /* We'll mark the task done here since the modem expects the DHCP discover packet while +UCEDATA runs. If the command fails, we'll mark the bearer disconnected later in the callback. */ g_task_return_pointer (task, g_object_ref (ctx->data), g_object_unref); g_object_unref (task); - } else { - cmd = g_strdup_printf ("+CGACT=1,%u", ctx->cid); - mm_dbg ("activating PDP context #%u...", ctx->cid); - mm_base_modem_at_command (MM_BASE_MODEM (ctx->modem), - cmd, - 120, - FALSE, - (GAsyncReadyCallback) cgact_activate_ready, - task); - } - g_free (cmd); + return; + } + + cmd = g_strdup_printf ("+CGACT=1,%u", ctx->cid); + mm_obj_dbg (self, "activating PDP context #%u...", ctx->cid); + mm_base_modem_at_command (MM_BASE_MODEM (ctx->modem), + cmd, + 120, + FALSE, + (GAsyncReadyCallback) cgact_activate_ready, + task); } static void @@ -404,18 +407,18 @@ test_cedata_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { - CommonConnectContext *ctx; - const gchar *response; + MMBroadbandBearerUblox *self; + const gchar *response; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + self = g_task_get_source_object (task); response = mm_base_modem_at_command_finish (modem, res, NULL); if (response) - ctx->self->priv->cedata = FEATURE_SUPPORTED; + self->priv->cedata = FEATURE_SUPPORTED; else - ctx->self->priv->cedata = FEATURE_UNSUPPORTED; - mm_dbg ("u-blox: +UCEDATA command%s available", - (ctx->self->priv->cedata == FEATURE_SUPPORTED) ? "" : " not"); + self->priv->cedata = FEATURE_UNSUPPORTED; + mm_obj_dbg (self, "u-blox: +UCEDATA command%s available", + (self->priv->cedata == FEATURE_SUPPORTED) ? "" : " not"); activate_3gpp (task); } @@ -423,19 +426,20 @@ test_cedata_ready (MMBaseModem *modem, static void test_cedata (GTask *task) { - CommonConnectContext *ctx; + MMBroadbandBearerUblox *self; + CommonConnectContext *ctx; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); /* We don't need to test for +UCEDATA if we're not using CDC-ECM or if we have tested before. Instead, we jump right to the activation. */ - if (ctx->self->priv->profile != MM_UBLOX_USB_PROFILE_ECM || - ctx->self->priv->cedata != FEATURE_SUPPORT_UNKNOWN) { + if (self->priv->profile != MM_UBLOX_USB_PROFILE_ECM || self->priv->cedata != FEATURE_SUPPORT_UNKNOWN) { activate_3gpp (task); return; } - mm_dbg ("u-blox: checking availability of +UCEDATA command..."); + mm_obj_dbg (self, "u-blox: checking availability of +UCEDATA command..."); mm_base_modem_at_command (MM_BASE_MODEM (ctx->modem), "+UCEDATA=?", 3, @@ -456,7 +460,7 @@ uauthreq_ready (MMBaseModem *modem, if (!response) { CommonConnectContext *ctx; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + ctx = g_task_get_task_data (task); /* If authentication required and the +UAUTHREQ failed, abort */ if (ctx->auth_required) { g_task_return_error (task, error); @@ -475,23 +479,23 @@ authenticate_3gpp (GTask *task) { MMBroadbandBearerUblox *self; CommonConnectContext *ctx; - gchar *cmd = NULL; + g_autofree gchar *cmd = NULL; MMBearerAllowedAuth allowed_auth; gint ublox_auth = -1; self = g_task_get_source_object (task); - ctx = (CommonConnectContext *) g_task_get_task_data (task); + ctx = g_task_get_task_data (task); - allowed_auth = mm_bearer_properties_get_allowed_auth (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self))); + allowed_auth = mm_bearer_properties_get_allowed_auth (mm_base_bearer_peek_config (MM_BASE_BEARER (self))); if (!ctx->auth_required) { - mm_dbg ("Not using authentication"); + mm_obj_dbg (self, "not using authentication"); ublox_auth = 0; goto out; } if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN || allowed_auth == (MM_BEARER_ALLOWED_AUTH_PAP | MM_BEARER_ALLOWED_AUTH_CHAP)) { - mm_dbg ("Using automatic authentication method"); + mm_obj_dbg (self, "using automatic authentication method"); if (self->priv->allowed_auths & MM_UBLOX_BEARER_ALLOWED_AUTH_AUTO) ublox_auth = 3; else if (self->priv->allowed_auths & MM_UBLOX_BEARER_ALLOWED_AUTH_PAP) @@ -501,34 +505,33 @@ authenticate_3gpp (GTask *task) else if (self->priv->allowed_auths & MM_UBLOX_BEARER_ALLOWED_AUTH_NONE) ublox_auth = 0; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { - mm_dbg ("Using PAP authentication method"); + mm_obj_dbg (self, "using PAP authentication method"); ublox_auth = 1; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_CHAP) { - mm_dbg ("Using CHAP authentication method"); + mm_obj_dbg (self, "using CHAP authentication method"); ublox_auth = 2; } out: if (ublox_auth < 0) { - gchar *str; + g_autofree gchar *str = NULL; str = mm_bearer_allowed_auth_build_string_from_mask (allowed_auth); g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Cannot use any of the specified authentication methods (%s)", str); g_object_unref (task); - g_free (str); return; } if (ublox_auth > 0) { - const gchar *user; - const gchar *password; - gchar *quoted_user; - gchar *quoted_password; + const gchar *user; + const gchar *password; + g_autofree gchar *quoted_user = NULL; + g_autofree gchar *quoted_password = NULL; - user = mm_bearer_properties_get_user (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self))); - password = mm_bearer_properties_get_password (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self))); + user = mm_bearer_properties_get_user (mm_base_bearer_peek_config (MM_BASE_BEARER (self))); + password = mm_bearer_properties_get_password (mm_base_bearer_peek_config (MM_BASE_BEARER (self))); quoted_user = mm_port_serial_at_quote_string (user); quoted_password = mm_port_serial_at_quote_string (password); @@ -538,20 +541,16 @@ authenticate_3gpp (GTask *task) ublox_auth, quoted_user, quoted_password); - - g_free (quoted_user); - g_free (quoted_password); } else cmd = g_strdup_printf ("+UAUTHREQ=%u,0,\"\",\"\"", ctx->cid); - mm_dbg ("setting up authentication preferences in PDP context #%u...", ctx->cid); + mm_obj_dbg (self, "setting up authentication preferences in PDP context #%u...", ctx->cid); mm_base_modem_at_command (MM_BASE_MODEM (ctx->modem), cmd, 10, FALSE, (GAsyncReadyCallback) uauthreq_ready, task); - g_free (cmd); } static void @@ -569,12 +568,12 @@ uauthreq_test_ready (MMBaseModem *modem, if (!response) goto out; - self->priv->allowed_auths = mm_ublox_parse_uauthreq_test (response, &error); + self->priv->allowed_auths = mm_ublox_parse_uauthreq_test (response, self, &error); out: if (error) { CommonConnectContext *ctx; - ctx = (CommonConnectContext *) g_task_get_task_data (task); + ctx = g_task_get_task_data (task); /* If authentication required and the +UAUTHREQ test failed, abort */ if (ctx->auth_required) { g_task_return_error (task, error); @@ -601,11 +600,11 @@ check_supported_authentication_methods (GTask *task) MMBearerAllowedAuth allowed_auth; self = g_task_get_source_object (task); - ctx = (CommonConnectContext *) g_task_get_task_data (task); + ctx = g_task_get_task_data (task); - user = mm_bearer_properties_get_user (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self))); - password = mm_bearer_properties_get_password (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self))); - allowed_auth = mm_bearer_properties_get_allowed_auth (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self))); + user = mm_bearer_properties_get_user (mm_base_bearer_peek_config (MM_BASE_BEARER (self))); + password = mm_bearer_properties_get_password (mm_base_bearer_peek_config (MM_BASE_BEARER (self))); + allowed_auth = mm_bearer_properties_get_allowed_auth (mm_base_bearer_peek_config (MM_BASE_BEARER (self))); /* Flag whether authentication is required. If it isn't, we won't fail * connection attempt if the +UAUTHREQ command fails */ @@ -617,7 +616,7 @@ check_supported_authentication_methods (GTask *task) return; } - mm_dbg ("checking supported authentication methods..."); + mm_obj_dbg (self, "checking supported authentication methods..."); mm_base_modem_at_command (MM_BASE_MODEM (ctx->modem), "+UAUTHREQ=?", 10, @@ -666,8 +665,11 @@ cgact_deactivate_ready (MMBaseModem *modem, GAsyncResult *res, GTask *task) { - const gchar *response; - GError *error = NULL; + MMBroadbandBearerUblox *self; + const gchar *response; + GError *error = NULL; + + self = g_task_get_source_object (task); response = mm_base_modem_at_command_finish (modem, res, &error); if (!response) { @@ -693,7 +695,7 @@ cgact_deactivate_ready (MMBaseModem *modem, return; } - mm_dbg ("ignored error when disconnecting last LTE bearer: %s", error->message); + mm_obj_dbg (self, "ignored error when disconnecting last LTE bearer: %s", error->message); g_clear_error (&error); } @@ -711,8 +713,8 @@ disconnect_3gpp (MMBroadbandBearer *self, GAsyncReadyCallback callback, gpointer user_data) { - GTask *task; - gchar *cmd; + GTask *task; + g_autofree gchar *cmd = NULL; if (!(task = common_connect_task_new (MM_BROADBAND_BEARER_UBLOX (self), MM_BROADBAND_MODEM (modem), @@ -725,14 +727,13 @@ disconnect_3gpp (MMBroadbandBearer *self, return; cmd = g_strdup_printf ("+CGACT=0,%u", cid); - mm_dbg ("deactivating PDP context #%u...", cid); + mm_obj_dbg (self, "deactivating PDP context #%u...", cid); mm_base_modem_at_command (MM_BASE_MODEM (modem), cmd, 120, FALSE, (GAsyncReadyCallback) cgact_deactivate_ready, task); - g_free (cmd); } /*****************************************************************************/ diff --git a/plugins/ublox/mm-broadband-modem-ublox.c b/plugins/ublox/mm-broadband-modem-ublox.c index 67474d2b..0af2e93d 100644 --- a/plugins/ublox/mm-broadband-modem-ublox.c +++ b/plugins/ublox/mm-broadband-modem-ublox.c @@ -22,7 +22,7 @@ #include #include "ModemManager.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-iface-modem.h" #include "mm-iface-modem-3gpp.h" #include "mm-iface-modem-voice.h" @@ -87,7 +87,7 @@ preload_support_config (MMBroadbandModemUblox *self) model = mm_iface_modem_get_model (MM_IFACE_MODEM (self)); if (!mm_ublox_get_support_config (model, &self->priv->support_config, &error)) { - mm_warn ("loading support configuration failed: %s", error->message); + mm_obj_warn (self, "loading support configuration failed: %s", error->message); g_error_free (error); /* default to NOT SUPPORTED if unknown model */ @@ -95,14 +95,14 @@ preload_support_config (MMBroadbandModemUblox *self) self->priv->support_config.uact = FEATURE_UNSUPPORTED; self->priv->support_config.ubandsel = FEATURE_UNSUPPORTED; } else - mm_dbg ("support configuration found for '%s'", model); + mm_obj_dbg (self, "support configuration found for '%s'", model); switch (self->priv->support_config.method) { case SETTINGS_UPDATE_METHOD_CFUN: - mm_dbg (" band update requires low-power mode"); + mm_obj_dbg (self, " band update requires low-power mode"); break; case SETTINGS_UPDATE_METHOD_COPS: - mm_dbg (" band update requires explicit unregistration"); + mm_obj_dbg (self, " band update requires explicit unregistration"); break; case SETTINGS_UPDATE_METHOD_UNKNOWN: /* not an error, this just means we don't need anything special */ @@ -113,10 +113,10 @@ preload_support_config (MMBroadbandModemUblox *self) switch (self->priv->support_config.uact) { case FEATURE_SUPPORTED: - mm_dbg (" UACT based band configuration supported"); + mm_obj_dbg (self, " UACT based band configuration supported"); break; case FEATURE_UNSUPPORTED: - mm_dbg (" UACT based band configuration unsupported"); + mm_obj_dbg (self, " UACT based band configuration unsupported"); break; case FEATURE_SUPPORT_UNKNOWN: default: @@ -125,10 +125,10 @@ preload_support_config (MMBroadbandModemUblox *self) switch (self->priv->support_config.ubandsel) { case FEATURE_SUPPORTED: - mm_dbg (" UBANDSEL based band configuration supported"); + mm_obj_dbg (self, " UBANDSEL based band configuration supported"); break; case FEATURE_UNSUPPORTED: - mm_dbg (" UBANDSEL based band configuration unsupported"); + mm_obj_dbg (self, " UBANDSEL based band configuration unsupported"); break; case FEATURE_SUPPORT_UNKNOWN: default: @@ -182,7 +182,7 @@ load_supported_bands (MMIfaceModem *self, model = mm_iface_modem_get_model (self); task = g_task_new (self, NULL, callback, user_data); - bands = mm_ublox_get_supported_bands (model, &error); + bands = mm_ublox_get_supported_bands (model, self, &error); if (!bands) g_task_return_error (task, error); else @@ -246,7 +246,7 @@ ubandsel_load_current_bands_ready (MMBaseModem *self, } model = mm_iface_modem_get_model (MM_IFACE_MODEM (self)); - out = mm_ublox_parse_ubandsel_response (response, model, &error); + out = mm_ublox_parse_ubandsel_response (response, model, self, &error); if (!out) { g_task_return_error (task, error); g_object_unref (task); @@ -311,7 +311,6 @@ typedef enum { } SetCurrentModesBandsStep; typedef struct { - MMBroadbandModemUblox *self; SetCurrentModesBandsStep step; gchar *command; MMModemPowerState initial_state; @@ -323,19 +322,16 @@ set_current_modes_bands_context_free (SetCurrentModesBandsContext *ctx) { g_assert (!ctx->saved_error); g_free (ctx->command); - g_object_unref (ctx->self); g_slice_free (SetCurrentModesBandsContext, ctx); } static void -set_current_modes_bands_context_new (GTask *task, - MMIfaceModem *self, - gchar *command) +set_current_modes_bands_context_new (GTask *task, + gchar *command) { SetCurrentModesBandsContext *ctx; ctx = g_slice_new0 (SetCurrentModesBandsContext); - ctx->self = MM_BROADBAND_MODEM_UBLOX (g_object_ref (self)); ctx->command = command; ctx->initial_state = MM_MODEM_POWER_STATE_UNKNOWN; ctx->step = SET_CURRENT_MODES_BANDS_STEP_FIRST; @@ -359,8 +355,7 @@ set_current_modes_bands_reregister_in_network_ready (MMIfaceModem3gpp *self, { SetCurrentModesBandsContext *ctx; - ctx = (SetCurrentModesBandsContext *) g_task_get_task_data (task); - g_assert (ctx); + ctx = g_task_get_task_data (task); /* propagate the error if none already set */ mm_iface_modem_3gpp_reregister_in_network_finish (self, res, ctx->saved_error ? NULL : &ctx->saved_error); @@ -377,8 +372,7 @@ set_current_modes_bands_after_command_ready (MMBaseModem *self, { SetCurrentModesBandsContext *ctx; - ctx = (SetCurrentModesBandsContext *) g_task_get_task_data (task); - g_assert (ctx); + ctx = g_task_get_task_data (task); /* propagate the error if none already set */ mm_base_modem_at_command_finish (self, res, ctx->saved_error ? NULL : &ctx->saved_error); @@ -395,8 +389,7 @@ set_current_modes_bands_command_ready (MMBaseModem *self, { SetCurrentModesBandsContext *ctx; - ctx = (SetCurrentModesBandsContext *) g_task_get_task_data (task); - g_assert (ctx); + ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (self, res, &ctx->saved_error)) ctx->step = SET_CURRENT_MODES_BANDS_STEP_RELEASE; @@ -413,8 +406,7 @@ set_current_modes_bands_before_command_ready (MMBaseModem *self, { SetCurrentModesBandsContext *ctx; - ctx = (SetCurrentModesBandsContext *) g_task_get_task_data (task); - g_assert (ctx); + ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (self, res, &ctx->saved_error)) ctx->step = SET_CURRENT_MODES_BANDS_STEP_RELEASE; @@ -425,18 +417,19 @@ set_current_modes_bands_before_command_ready (MMBaseModem *self, } static void -set_current_modes_bands_current_power_ready (MMBaseModem *self, +set_current_modes_bands_current_power_ready (MMBaseModem *_self, GAsyncResult *res, GTask *task) { + MMBroadbandModemUblox *self = MM_BROADBAND_MODEM_UBLOX (_self); SetCurrentModesBandsContext *ctx; const gchar *response; - ctx = (SetCurrentModesBandsContext *) g_task_get_task_data (task); - g_assert (ctx); - g_assert (ctx->self->priv->support_config.method == SETTINGS_UPDATE_METHOD_CFUN); + ctx = g_task_get_task_data (task); + + g_assert (self->priv->support_config.method == SETTINGS_UPDATE_METHOD_CFUN); - response = mm_base_modem_at_command_finish (self, res, &ctx->saved_error); + response = mm_base_modem_at_command_finish (_self, res, &ctx->saved_error); if (!response || !mm_ublox_parse_cfun_response (response, &ctx->initial_state, &ctx->saved_error)) ctx->step = SET_CURRENT_MODES_BANDS_STEP_RELEASE; else @@ -448,10 +441,11 @@ set_current_modes_bands_current_power_ready (MMBaseModem *self, static void set_current_modes_bands_step (GTask *task) { + MMBroadbandModemUblox *self; SetCurrentModesBandsContext *ctx; - ctx = (SetCurrentModesBandsContext *) g_task_get_task_data (task); - g_assert (ctx); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); switch (ctx->step) { case SET_CURRENT_MODES_BANDS_STEP_FIRST: @@ -459,8 +453,8 @@ set_current_modes_bands_step (GTask *task) /* fall through */ case SET_CURRENT_MODES_BANDS_STEP_ACQUIRE: - mm_dbg ("acquiring power operation..."); - if (!acquire_power_operation (ctx->self, &ctx->saved_error)) { + mm_obj_dbg (self, "acquiring power operation..."); + if (!acquire_power_operation (self, &ctx->saved_error)) { ctx->step = SET_CURRENT_MODES_BANDS_STEP_LAST; set_current_modes_bands_step (task); return; @@ -472,9 +466,9 @@ set_current_modes_bands_step (GTask *task) /* If using CFUN, we check whether we're already in low-power mode. * And if we are, we just skip triggering low-power mode ourselves. */ - if (ctx->self->priv->support_config.method == SETTINGS_UPDATE_METHOD_CFUN) { - mm_dbg ("checking current power operation..."); - mm_base_modem_at_command (MM_BASE_MODEM (ctx->self), + if (self->priv->support_config.method == SETTINGS_UPDATE_METHOD_CFUN) { + mm_obj_dbg (self, "checking current power operation..."); + mm_base_modem_at_command (MM_BASE_MODEM (self), "+CFUN?", 3, FALSE, @@ -487,10 +481,10 @@ set_current_modes_bands_step (GTask *task) case SET_CURRENT_MODES_BANDS_STEP_BEFORE_COMMAND: /* If COPS required around the set command, run it unconditionally */ - if (ctx->self->priv->support_config.method == SETTINGS_UPDATE_METHOD_COPS) { - mm_dbg ("deregistering from the network for configuration change..."); + if (self->priv->support_config.method == SETTINGS_UPDATE_METHOD_COPS) { + mm_obj_dbg (self, "deregistering from the network for configuration change..."); mm_base_modem_at_command ( - MM_BASE_MODEM (ctx->self), + MM_BASE_MODEM (self), "+COPS=2", 10, FALSE, @@ -499,12 +493,12 @@ set_current_modes_bands_step (GTask *task) return; } /* If CFUN required, check initial state before triggering low-power mode ourselves */ - else if (ctx->self->priv->support_config.method == SETTINGS_UPDATE_METHOD_CFUN) { + else if (self->priv->support_config.method == SETTINGS_UPDATE_METHOD_CFUN) { /* Do nothing if already in low-power mode */ if (ctx->initial_state != MM_MODEM_POWER_STATE_LOW) { - mm_dbg ("powering down for configuration change..."); + mm_obj_dbg (self, "powering down for configuration change..."); mm_base_modem_at_command ( - MM_BASE_MODEM (ctx->self), + MM_BASE_MODEM (self), "+CFUN=4", 3, FALSE, @@ -518,9 +512,9 @@ set_current_modes_bands_step (GTask *task) /* fall through */ case SET_CURRENT_MODES_BANDS_STEP_COMMAND: - mm_dbg ("updating configuration..."); + mm_obj_dbg (self, "updating configuration..."); mm_base_modem_at_command ( - MM_BASE_MODEM (ctx->self), + MM_BASE_MODEM (self), ctx->command, 3, FALSE, @@ -530,20 +524,20 @@ set_current_modes_bands_step (GTask *task) case SET_CURRENT_MODES_BANDS_STEP_AFTER_COMMAND: /* If COPS required around the set command, run it unconditionally */ - if (ctx->self->priv->support_config.method == SETTINGS_UPDATE_METHOD_COPS) { - mm_iface_modem_3gpp_reregister_in_network (MM_IFACE_MODEM_3GPP (ctx->self), + if (self->priv->support_config.method == SETTINGS_UPDATE_METHOD_COPS) { + mm_iface_modem_3gpp_reregister_in_network (MM_IFACE_MODEM_3GPP (self), (GAsyncReadyCallback) set_current_modes_bands_reregister_in_network_ready, task); return; } /* If CFUN required, see if we need to recover power */ - else if (ctx->self->priv->support_config.method == SETTINGS_UPDATE_METHOD_CFUN) { + else if (self->priv->support_config.method == SETTINGS_UPDATE_METHOD_CFUN) { /* If we were in low-power mode before the change, do nothing, otherwise, * full power mode back */ if (ctx->initial_state != MM_MODEM_POWER_STATE_LOW) { - mm_dbg ("recovering power state after configuration change..."); + mm_obj_dbg (self, "recovering power state after configuration change..."); mm_base_modem_at_command ( - MM_BASE_MODEM (ctx->self), + MM_BASE_MODEM (self), "+CFUN=1", 3, FALSE, @@ -556,8 +550,8 @@ set_current_modes_bands_step (GTask *task) /* fall through */ case SET_CURRENT_MODES_BANDS_STEP_RELEASE: - mm_dbg ("releasing power operation..."); - release_power_operation (ctx->self); + mm_obj_dbg (self, "releasing power operation..."); + release_power_operation (self); ctx->step++; /* fall through */ @@ -602,7 +596,7 @@ set_current_modes (MMIfaceModem *self, return; } - set_current_modes_bands_context_new (task, self, command); + set_current_modes_bands_context_new (task, command); set_current_modes_bands_step (task); } @@ -636,7 +630,7 @@ set_current_bands (MMIfaceModem *_self, return; } - set_current_modes_bands_context_new (task, _self, command); + set_current_modes_bands_context_new (task, command); set_current_modes_bands_step (task); } @@ -656,7 +650,7 @@ load_current_modes_finish (MMIfaceModem *self, if (!response) return FALSE; - return mm_ublox_parse_urat_read_response (response, allowed, preferred, error); + return mm_ublox_parse_urat_read_response (response, self, allowed, preferred, error); } static void @@ -687,7 +681,7 @@ load_supported_modes_finish (MMIfaceModem *self, if (!response) return FALSE; - if (!(combinations = mm_ublox_parse_urat_test_response (response, error))) + if (!(combinations = mm_ublox_parse_urat_test_response (response, self, error))) return FALSE; if (!(combinations = mm_ublox_filter_supported_modes (mm_iface_modem_get_model (self), combinations, self, error))) @@ -929,9 +923,9 @@ udtmfd_ready (MMBaseModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_full_finish (self, res, &error)) { - mm_dbg ("Couldn't %s +UUDTMFD reporting: '%s'", - ctx->enable ? "enable" : "disable", - error->message); + mm_obj_dbg (self, "couldn't %s +UUDTMFD reporting: '%s'", + ctx->enable ? "enable" : "disable", + error->message); g_error_free (error); } @@ -950,9 +944,9 @@ ucallstat_ready (MMBaseModem *self, ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_full_finish (self, res, &error)) { - mm_dbg ("Couldn't %s +UCALLSTAT reporting: '%s'", - ctx->enable ? "enable" : "disable", - error->message); + mm_obj_dbg (self, "couldn't %s +UCALLSTAT reporting: '%s'", + ctx->enable ? "enable" : "disable", + error->message); g_error_free (error); } @@ -966,7 +960,7 @@ voice_unsolicited_events_context_step (GTask *task) MMBroadbandModemUblox *self; VoiceUnsolicitedEventsContext *ctx; - self = MM_BROADBAND_MODEM_UBLOX (g_task_get_source_object (task)); + self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); switch (ctx->step) { @@ -976,8 +970,8 @@ voice_unsolicited_events_context_step (GTask *task) case VOICE_UNSOLICITED_EVENTS_STEP_UCALLSTAT_PRIMARY: if (ctx->primary) { - mm_dbg ("%s extended call status reporting in primary port...", - ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s extended call status reporting in primary port...", + ctx->enable ? "enabling" : "disabling"); mm_base_modem_at_command_full (MM_BASE_MODEM (self), ctx->primary, ctx->ucallstat_command, @@ -994,8 +988,8 @@ voice_unsolicited_events_context_step (GTask *task) case VOICE_UNSOLICITED_EVENTS_STEP_UCALLSTAT_SECONDARY: if (ctx->secondary) { - mm_dbg ("%s extended call status reporting in secondary port...", - ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s extended call status reporting in secondary port...", + ctx->enable ? "enabling" : "disabling"); mm_base_modem_at_command_full (MM_BASE_MODEM (self), ctx->secondary, ctx->ucallstat_command, @@ -1012,8 +1006,8 @@ voice_unsolicited_events_context_step (GTask *task) case VOICE_UNSOLICITED_EVENTS_STEP_UDTMFD_PRIMARY: if ((self->priv->udtmfd_support == FEATURE_SUPPORTED) && (ctx->primary)) { - mm_dbg ("%s DTMF detection and reporting in primary port...", - ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s DTMF detection and reporting in primary port...", + ctx->enable ? "enabling" : "disabling"); mm_base_modem_at_command_full (MM_BASE_MODEM (self), ctx->primary, ctx->udtmfd_command, @@ -1030,8 +1024,8 @@ voice_unsolicited_events_context_step (GTask *task) case VOICE_UNSOLICITED_EVENTS_STEP_UDTMFD_SECONDARY: if ((self->priv->udtmfd_support == FEATURE_SUPPORTED) && (ctx->secondary)) { - mm_dbg ("%s DTMF detection and reporting in secondary port...", - ctx->enable ? "Enabling" : "Disabling"); + mm_obj_dbg (self, "%s DTMF detection and reporting in secondary port...", + ctx->enable ? "enabling" : "disabling"); mm_base_modem_at_command_full (MM_BASE_MODEM (self), ctx->secondary, ctx->udtmfd_command, @@ -1103,7 +1097,7 @@ voice_enable_unsolicited_events_ready (MMBroadbandModemUblox *self, GError *error = NULL; if (!common_voice_enable_disable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't enable u-blox-specific voice unsolicited events: %s", error->message); + mm_obj_warn (self, "Couldn't enable u-blox-specific voice unsolicited events: %s", error->message); g_error_free (error); } @@ -1182,7 +1176,7 @@ voice_disable_unsolicited_events_ready (MMBroadbandModemUblox *self, GError *error = NULL; if (!common_voice_enable_disable_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't disable u-blox-specific voice unsolicited events: %s", error->message); + mm_obj_warn (self, "Couldn't disable u-blox-specific voice unsolicited events: %s", error->message); g_error_free (error); } @@ -1230,14 +1224,14 @@ ucallstat_received (MMPortSerialAt *port, guint aux; if (!mm_get_uint_from_match_info (match_info, 1, &aux)) { - mm_warn ("couldn't parse call index from +UCALLSTAT"); + mm_obj_warn (self, "couldn't parse call index from +UCALLSTAT"); return; } call_info.index = aux; if (!mm_get_uint_from_match_info (match_info, 2, &aux) || (aux >= G_N_ELEMENTS (ublox_call_state))) { - mm_warn ("couldn't parse call state from +UCALLSTAT"); + mm_obj_warn (self, "couldn't parse call state from +UCALLSTAT"); return; } call_info.state = ublox_call_state[aux]; @@ -1269,13 +1263,12 @@ udtmfd_received (MMPortSerialAt *port, GMatchInfo *match_info, MMBroadbandModemUblox *self) { - gchar *dtmf; + g_autofree gchar *dtmf = NULL; dtmf = g_match_info_fetch (match_info, 1); - mm_dbg ("received DTMF: %s", dtmf); + mm_obj_dbg (self, "received DTMF: %s", dtmf); /* call index unknown */ mm_iface_modem_voice_received_dtmf (MM_IFACE_MODEM_VOICE (self), 0, dtmf); - g_free (dtmf); } static void @@ -1333,7 +1326,7 @@ parent_voice_cleanup_unsolicited_events_ready (MMIfaceModemVoice *self, GError *error = NULL; if (!iface_modem_voice_parent->cleanup_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't cleanup parent voice unsolicited events: %s", error->message); + mm_obj_warn (self, "Couldn't cleanup parent voice unsolicited events: %s", error->message); g_error_free (error); } @@ -1379,7 +1372,7 @@ parent_voice_setup_unsolicited_events_ready (MMIfaceModemVoice *self, GError *error = NULL; if (!iface_modem_voice_parent->setup_unsolicited_events_finish (self, res, &error)) { - mm_warn ("Couldn't setup parent voice unsolicited events: %s", error->message); + mm_obj_warn (self, "Couldn't setup parent voice unsolicited events: %s", error->message); g_error_free (error); } @@ -1497,20 +1490,17 @@ typedef enum { } CreateBearerStep; typedef struct { - MMBroadbandModemUblox *self; - CreateBearerStep step; - MMBearerProperties *properties; - MMBaseBearer *bearer; - gboolean has_net; + CreateBearerStep step; + MMBearerProperties *properties; + MMBaseBearer *bearer; + gboolean has_net; } CreateBearerContext; static void create_bearer_context_free (CreateBearerContext *ctx) { - if (ctx->bearer) - g_object_unref (ctx->bearer); + g_clear_object (&ctx->bearer); g_object_unref (ctx->properties); - g_object_unref (ctx->self); g_slice_free (CreateBearerContext, ctx); } @@ -1529,10 +1519,12 @@ broadband_bearer_new_ready (GObject *source, GAsyncResult *res, GTask *task) { - CreateBearerContext *ctx; - GError *error = NULL; + MMBroadbandModemUblox *self; + CreateBearerContext *ctx; + GError *error = NULL; - ctx = (CreateBearerContext *) g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); g_assert (!ctx->bearer); ctx->bearer = mm_broadband_bearer_new_finish (res, &error); @@ -1542,7 +1534,7 @@ broadband_bearer_new_ready (GObject *source, return; } - mm_dbg ("u-blox: new generic broadband bearer created at DBus path '%s'", mm_base_bearer_get_path (ctx->bearer)); + mm_obj_dbg (self, "new generic broadband bearer created at DBus path '%s'", mm_base_bearer_get_path (ctx->bearer)); ctx->step++; create_bearer_step (task); } @@ -1552,10 +1544,12 @@ broadband_bearer_ublox_new_ready (GObject *source, GAsyncResult *res, GTask *task) { - CreateBearerContext *ctx; - GError *error = NULL; + MMBroadbandModemUblox *self; + CreateBearerContext *ctx; + GError *error = NULL; - ctx = (CreateBearerContext *) g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); g_assert (!ctx->bearer); ctx->bearer = mm_broadband_bearer_ublox_new_finish (res, &error); @@ -1565,74 +1559,76 @@ broadband_bearer_ublox_new_ready (GObject *source, return; } - mm_dbg ("u-blox: new u-blox broadband bearer created at DBus path '%s'", mm_base_bearer_get_path (ctx->bearer)); + mm_obj_dbg (self, "new u-blox broadband bearer created at DBus path '%s'", mm_base_bearer_get_path (ctx->bearer)); ctx->step++; create_bearer_step (task); } static void -mode_check_ready (MMBaseModem *self, +mode_check_ready (MMBaseModem *_self, GAsyncResult *res, GTask *task) { - const gchar *response; - GError *error = NULL; - CreateBearerContext *ctx; + MMBroadbandModemUblox *self = MM_BROADBAND_MODEM_UBLOX (_self); + const gchar *response; + GError *error = NULL; + CreateBearerContext *ctx; - ctx = (CreateBearerContext *) g_task_get_task_data (task); + ctx = g_task_get_task_data (task); - response = mm_base_modem_at_command_finish (self, res, &error); + response = mm_base_modem_at_command_finish (_self, res, &error); if (!response) { - mm_dbg ("u-blox: couldn't load current networking mode: %s", error->message); + mm_obj_dbg (self, "couldn't load current networking mode: %s", error->message); g_error_free (error); - } else if (!mm_ublox_parse_ubmconf_response (response, &ctx->self->priv->mode, &error)) { - mm_dbg ("u-blox: couldn't parse current networking mode response '%s': %s", response, error->message); + } else if (!mm_ublox_parse_ubmconf_response (response, &self->priv->mode, &error)) { + mm_obj_dbg (self, "couldn't parse current networking mode response '%s': %s", response, error->message); g_error_free (error); } else { - g_assert (ctx->self->priv->mode != MM_UBLOX_NETWORKING_MODE_UNKNOWN); - mm_dbg ("u-blox: networking mode loaded: %s", mm_ublox_networking_mode_get_string (ctx->self->priv->mode)); + g_assert (self->priv->mode != MM_UBLOX_NETWORKING_MODE_UNKNOWN); + mm_obj_dbg (self, "networking mode loaded: %s", mm_ublox_networking_mode_get_string (self->priv->mode)); } /* If checking networking mode isn't supported, we'll fallback to * assume the device is in router mode, which is the mode asking for * less connection setup rules from our side (just request DHCP). */ - if (ctx->self->priv->mode == MM_UBLOX_NETWORKING_MODE_UNKNOWN && ctx->has_net) { - mm_dbg ("u-blox: fallback to default networking mode: router"); - ctx->self->priv->mode = MM_UBLOX_NETWORKING_MODE_ROUTER; + if (self->priv->mode == MM_UBLOX_NETWORKING_MODE_UNKNOWN && ctx->has_net) { + mm_obj_dbg (self, "fallback to default networking mode: router"); + self->priv->mode = MM_UBLOX_NETWORKING_MODE_ROUTER; } - ctx->self->priv->mode_checked = TRUE; + self->priv->mode_checked = TRUE; ctx->step++; create_bearer_step (task); } static void -profile_check_ready (MMBaseModem *self, +profile_check_ready (MMBaseModem *_self, GAsyncResult *res, GTask *task) { - const gchar *response; - GError *error = NULL; - CreateBearerContext *ctx; + MMBroadbandModemUblox *self = MM_BROADBAND_MODEM_UBLOX (_self); + const gchar *response; + GError *error = NULL; + CreateBearerContext *ctx; - ctx = (CreateBearerContext *) g_task_get_task_data (task); + ctx = g_task_get_task_data (task); - response = mm_base_modem_at_command_finish (self, res, &error); + response = mm_base_modem_at_command_finish (_self, res, &error); if (!response) { - mm_dbg ("u-blox: couldn't load current usb profile: %s", error->message); + mm_obj_dbg (self, "couldn't load current usb profile: %s", error->message); g_error_free (error); - } else if (!mm_ublox_parse_uusbconf_response (response, &ctx->self->priv->profile, &error)) { - mm_dbg ("u-blox: couldn't parse current usb profile response '%s': %s", response, error->message); + } else if (!mm_ublox_parse_uusbconf_response (response, &self->priv->profile, &error)) { + mm_obj_dbg (self, "couldn't parse current usb profile response '%s': %s", response, error->message); g_error_free (error); } else { - g_assert (ctx->self->priv->profile != MM_UBLOX_USB_PROFILE_UNKNOWN); - mm_dbg ("u-blox: usb profile loaded: %s", mm_ublox_usb_profile_get_string (ctx->self->priv->profile)); + g_assert (self->priv->profile != MM_UBLOX_USB_PROFILE_UNKNOWN); + mm_obj_dbg (self, "usb profile loaded: %s", mm_ublox_usb_profile_get_string (self->priv->profile)); } /* Assume the operation has been performed, even if it may have failed */ - ctx->self->priv->profile_checked = TRUE; + self->priv->profile_checked = TRUE; ctx->step++; create_bearer_step (task); @@ -1641,19 +1637,22 @@ profile_check_ready (MMBaseModem *self, static void create_bearer_step (GTask *task) { - CreateBearerContext *ctx; + MMBroadbandModemUblox *self; + CreateBearerContext *ctx; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); - ctx = (CreateBearerContext *) g_task_get_task_data (task); switch (ctx->step) { case CREATE_BEARER_STEP_FIRST: ctx->step++; /* fall through */ case CREATE_BEARER_STEP_CHECK_PROFILE: - if (!ctx->self->priv->profile_checked) { - mm_dbg ("u-blox: checking current USB profile..."); + if (!self->priv->profile_checked) { + mm_obj_dbg (self, "checking current USB profile..."); mm_base_modem_at_command ( - MM_BASE_MODEM (ctx->self), + MM_BASE_MODEM (self), "+UUSBCONF?", 3, FALSE, @@ -1665,10 +1664,10 @@ create_bearer_step (GTask *task) /* fall through */ case CREATE_BEARER_STEP_CHECK_MODE: - if (!ctx->self->priv->mode_checked) { - mm_dbg ("u-blox: checking current networking mode..."); + if (!self->priv->mode_checked) { + mm_obj_dbg (self, "checking current networking mode..."); mm_base_modem_at_command ( - MM_BASE_MODEM (ctx->self), + MM_BASE_MODEM (self), "+UBMCONF?", 3, FALSE, @@ -1682,16 +1681,16 @@ create_bearer_step (GTask *task) case CREATE_BEARER_STEP_CREATE_BEARER: /* If we have a net interface, we'll create a u-blox bearer, unless for * any reason we have the back-compatible profile selected. */ - if ((ctx->self->priv->profile != MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE) && ctx->has_net) { + if ((self->priv->profile != MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE) && ctx->has_net) { /* whenever there is a net port, we should have loaded a valid networking mode */ - g_assert (ctx->self->priv->mode != MM_UBLOX_NETWORKING_MODE_UNKNOWN); - mm_dbg ("u-blox: creating u-blox broadband bearer (%s profile, %s mode)...", - mm_ublox_usb_profile_get_string (ctx->self->priv->profile), - mm_ublox_networking_mode_get_string (ctx->self->priv->mode)); + g_assert (self->priv->mode != MM_UBLOX_NETWORKING_MODE_UNKNOWN); + mm_obj_dbg (self, "creating u-blox broadband bearer (%s profile, %s mode)...", + mm_ublox_usb_profile_get_string (self->priv->profile), + mm_ublox_networking_mode_get_string (self->priv->mode)); mm_broadband_bearer_ublox_new ( - MM_BROADBAND_MODEM (ctx->self), - ctx->self->priv->profile, - ctx->self->priv->mode, + MM_BROADBAND_MODEM (self), + self->priv->profile, + self->priv->mode, ctx->properties, NULL, /* cancellable */ (GAsyncReadyCallback) broadband_bearer_ublox_new_ready, @@ -1701,8 +1700,8 @@ create_bearer_step (GTask *task) /* If usb profile is back-compatible already, or if there is no NET port * available, create default generic bearer */ - mm_dbg ("u-blox: creating generic broadband bearer..."); - mm_broadband_bearer_new (MM_BROADBAND_MODEM (ctx->self), + mm_obj_dbg (self, "creating generic broadband bearer..."); + mm_broadband_bearer_new (MM_BROADBAND_MODEM (self), ctx->properties, NULL, /* cancellable */ (GAsyncReadyCallback) broadband_bearer_new_ready, @@ -1733,7 +1732,6 @@ modem_create_bearer (MMIfaceModem *self, ctx = g_slice_new0 (CreateBearerContext); ctx->step = CREATE_BEARER_STEP_FIRST; - ctx->self = g_object_ref (self); ctx->properties = g_object_ref (properties); /* Flag whether this modem has exposed a network interface */ diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c index fde9c962..fe1719c3 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.c +++ b/plugins/ublox/mm-modem-helpers-ublox.c @@ -365,6 +365,7 @@ static const MMModemMode ublox_combinations[] = { GArray * mm_ublox_parse_urat_test_response (const gchar *response, + gpointer log_object, GError **error) { GArray *combinations = NULL; @@ -415,7 +416,7 @@ mm_ublox_parse_urat_test_response (const gchar *response, selected_value = g_array_index (selected, guint, i); if (selected_value >= G_N_ELEMENTS (ublox_combinations)) { - mm_warn ("Unexpected AcT value: %u", selected_value); + mm_obj_warn (log_object, "unexpected AcT value: %u", selected_value); continue; } @@ -435,12 +436,12 @@ mm_ublox_parse_urat_test_response (const gchar *response, preferred_value = g_array_index (preferred, guint, j); if (preferred_value >= G_N_ELEMENTS (ublox_combinations)) { - mm_warn ("Unexpected AcT preferred value: %u", preferred_value); + mm_obj_warn (log_object, "unexpected AcT preferred value: %u", preferred_value); continue; } combination.preferred = ublox_combinations[preferred_value]; if (mm_count_bits_set (combination.preferred) != 1) { - mm_warn ("AcT preferred value should be a single AcT: %u", preferred_value); + mm_obj_warn (log_object, "AcT preferred value should be a single AcT: %u", preferred_value); continue; } if (!(combination.allowed & combination.preferred)) @@ -1023,6 +1024,7 @@ mm_ublox_filter_supported_modes (const gchar *model, GArray * mm_ublox_get_supported_bands (const gchar *model, + gpointer log_object, GError **error) { MMModemMode mode; @@ -1034,13 +1036,13 @@ mm_ublox_get_supported_bands (const gchar *model, for (i = 0; i < G_N_ELEMENTS (band_configuration); i++) { if (g_str_has_prefix (model, band_configuration[i].model)) { - mm_dbg("Found Model (Supported Bands): %s", band_configuration[i].model); + mm_obj_dbg (log_object, "known supported bands found for model: %s", band_configuration[i].model); break; } } if (i == G_N_ELEMENTS (band_configuration)) { - mm_warn ("Unknown model name given: %s", model); + mm_obj_warn (log_object, "unknown model name given when looking for supported bands: %s", model); return NULL; } @@ -1175,19 +1177,22 @@ static void append_bands (GArray *bands, guint ubandsel_value, MMModemMode mode, - const gchar *model) + const gchar *model, + gpointer log_object) { guint i, j, k, x; MMModemBand band; /* Find Modem Model Index in band_configuration */ for (i = 0; i < G_N_ELEMENTS (band_configuration); i++) { - if (g_str_has_prefix (model, band_configuration[i].model)) + if (g_str_has_prefix (model, band_configuration[i].model)) { + mm_obj_dbg (log_object, "known bands found for model: %s", band_configuration[i].model); break; + } } if (i == G_N_ELEMENTS (band_configuration)) { - mm_warn ("Unknown Modem Model given: %s", model); + mm_obj_warn (log_object, "unknown model name given when looking for bands: %s", model); return; } @@ -1242,6 +1247,7 @@ append_bands (GArray *bands, GArray * mm_ublox_parse_ubandsel_response (const gchar *response, const gchar *model, + gpointer log_object, GError **error) { GArray *array_values = NULL; @@ -1270,7 +1276,7 @@ mm_ublox_parse_ubandsel_response (const gchar *response, mode = supported_modes_per_model (model); array = g_array_new (FALSE, FALSE, sizeof (MMModemBand)); for (i = 0; i < array_values->len; i++) - append_bands (array, g_array_index (array_values, guint, i), mode, model); + append_bands (array, g_array_index (array_values, guint, i), mode, model, log_object); if (!array->len) { inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, @@ -1591,7 +1597,8 @@ mm_ublox_parse_uact_response (const gchar *response, static GArray * parse_bands_from_string (const gchar *str, - const gchar *group) + const gchar *group, + gpointer log_object) { GArray *bands = NULL; GError *inner_error = NULL; @@ -1603,12 +1610,12 @@ parse_bands_from_string (const gchar *str, bands = uact_num_array_to_band_array (nums); tmpstr = mm_common_build_bands_string ((MMModemBand *)(bands->data), bands->len); - mm_dbg ("modem reports support for %s bands: %s", group, tmpstr); + mm_obj_dbg (log_object, "modem reports support for %s bands: %s", group, tmpstr); g_free (tmpstr); g_array_unref (nums); } else if (inner_error) { - mm_warn ("couldn't parse list of supported %s bands: %s", group, inner_error->message); + mm_obj_warn (log_object, "couldn't parse list of supported %s bands: %s", group, inner_error->message); g_clear_error (&inner_error); } @@ -1617,6 +1624,7 @@ parse_bands_from_string (const gchar *str, gboolean mm_ublox_parse_uact_test (const gchar *response, + gpointer log_object, GArray **bands2g_out, GArray **bands3g_out, GArray **bands4g_out, @@ -1669,9 +1677,9 @@ mm_ublox_parse_uact_test (const gchar *response, goto out; } - bands2g = parse_bands_from_string (bands2g_str, "2G"); - bands3g = parse_bands_from_string (bands3g_str, "3G"); - bands4g = parse_bands_from_string (bands4g_str, "4G"); + bands2g = parse_bands_from_string (bands2g_str, "2G", log_object); + bands3g = parse_bands_from_string (bands3g_str, "3G", log_object); + bands4g = parse_bands_from_string (bands4g_str, "4G", log_object); if (!bands2g->len && !bands3g->len && !bands4g->len) { inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, @@ -1745,6 +1753,7 @@ mm_ublox_build_uact_set_command (GArray *bands, gboolean mm_ublox_parse_urat_read_response (const gchar *response, + gpointer log_object, MMModemMode *out_allowed, MMModemMode *out_preferred, GError **error) @@ -1783,7 +1792,7 @@ mm_ublox_parse_urat_read_response (const gchar *response, } allowed = ublox_combinations[value]; allowed_str = mm_modem_mode_build_string_from_mask (allowed); - mm_dbg ("current allowed modes retrieved: %s", allowed_str); + mm_obj_dbg (log_object, "current allowed modes retrieved: %s", allowed_str); /* Preferred item is optional */ if (mm_get_uint_from_match_info (match_info, 2, &value)) { @@ -1794,7 +1803,7 @@ mm_ublox_parse_urat_read_response (const gchar *response, } preferred = ublox_combinations[value]; preferred_str = mm_modem_mode_build_string_from_mask (preferred); - mm_dbg ("current preferred modes retrieved: %s", preferred_str); + mm_obj_dbg (log_object, "current preferred modes retrieved: %s", preferred_str); if (mm_count_bits_set (preferred) != 1) { inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "AcT preferred value should be a single AcT: %s", preferred_str); @@ -1884,6 +1893,7 @@ mm_ublox_build_urat_set_command (MMModemMode allowed, MMUbloxBearerAllowedAuth mm_ublox_parse_uauthreq_test (const char *response, + gpointer log_object, GError **error) { MMUbloxBearerAllowedAuth mask = MM_UBLOX_BEARER_ALLOWED_AUTH_UNKNOWN; @@ -1931,7 +1941,7 @@ mm_ublox_parse_uauthreq_test (const char *response, mask |= MM_UBLOX_BEARER_ALLOWED_AUTH_AUTO; break; default: - mm_warn ("Unexpected +UAUTHREQ value: %u", val); + mm_obj_warn (log_object, "unexpected +UAUTHREQ value: %u", val); break; } } diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h index 0b01b3df..06bba003 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.h +++ b/plugins/ublox/mm-modem-helpers-ublox.h @@ -101,6 +101,7 @@ gboolean mm_ublox_parse_cfun_response (const gchar *response, /* URAT=? response parser */ GArray *mm_ublox_parse_urat_test_response (const gchar *response, + gpointer log_object, GError **error); /*****************************************************************************/ @@ -122,6 +123,7 @@ GArray *mm_ublox_filter_supported_modes (const gchar *model, /* Model-based supported bands loading */ GArray *mm_ublox_get_supported_bands (const gchar *model, + gpointer log_object, GError **error); /*****************************************************************************/ @@ -129,6 +131,7 @@ GArray *mm_ublox_get_supported_bands (const gchar *model, GArray *mm_ublox_parse_ubandsel_response (const gchar *response, const gchar *model, + gpointer log_object, GError **error); /*****************************************************************************/ @@ -148,6 +151,7 @@ GArray *mm_ublox_parse_uact_response (const gchar *response, /* UACT=? test parser */ gboolean mm_ublox_parse_uact_test (const gchar *response, + gpointer log_object, GArray **bands_2g, GArray **bands_3g, GArray **bands_4g, @@ -168,6 +172,7 @@ MMModemMode mm_ublox_get_modem_mode_any (const GArray *combinations); /* URAT? response parser */ gboolean mm_ublox_parse_urat_read_response (const gchar *response, + gpointer log_object, MMModemMode *out_allowed, MMModemMode *out_preferred, GError **error); @@ -191,6 +196,7 @@ typedef enum { /*< underscore_name=mm_ublox_bearer_allowed_auth >*/ } MMUbloxBearerAllowedAuth; MMUbloxBearerAllowedAuth mm_ublox_parse_uauthreq_test (const char *response, + gpointer log_object, GError **error); /*****************************************************************************/ diff --git a/plugins/ublox/mm-plugin-ublox.c b/plugins/ublox/mm-plugin-ublox.c index 6a0d140b..39d3ded1 100644 --- a/plugins/ublox/mm-plugin-ublox.c +++ b/plugins/ublox/mm-plugin-ublox.c @@ -19,7 +19,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-serial-parsers.h" #include "mm-broadband-modem-ublox.h" #include "mm-plugin-ublox.h" @@ -88,9 +88,7 @@ ready_timeout (GTask *task) mm_port_serial_at_add_unsolicited_msg_handler (ctx->port, ctx->ready_regex, NULL, NULL, NULL); - mm_dbg ("(%s/%s) timed out waiting for READY unsolicited message", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (probe, "timed out waiting for READY unsolicited message"); /* not an error really, we didn't probe anything yet, that's all */ g_task_return_boolean (task, TRUE); @@ -113,9 +111,7 @@ ready_received (MMPortSerialAt *port, g_source_remove (ctx->timeout_id); ctx->timeout_id = 0; - mm_dbg ("(%s/%s) READY received: port is AT", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (probe, "received READY: port is AT"); /* Flag as an AT port right away */ mm_port_probe_set_result_at (probe, TRUE); @@ -133,9 +129,7 @@ wait_for_ready (GTask *task) ctx = g_task_get_task_data (task); probe = g_task_get_source_object (task); - mm_dbg ("(%s/%s) waiting for READY unsolicited message...", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (probe, "waiting for READY unsolicited message..."); /* Configure a regex on the TTY, so that we stop the custom init * as soon as +READY URC is received */ @@ -145,10 +139,7 @@ wait_for_ready (GTask *task) task, NULL); - mm_dbg ("(%s/%s) waiting %d seconds for init timeout", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe), - ctx->wait_timeout_secs); + mm_obj_dbg (probe, "waiting %d seconds for init timeout", ctx->wait_timeout_secs); /* Otherwise, let the custom init timeout in some seconds. */ ctx->timeout_id = g_timeout_add_seconds (ctx->wait_timeout_secs, (GSourceFunc) ready_timeout, task); @@ -160,7 +151,7 @@ quick_at_ready (MMPortSerialAt *port, GTask *task) { MMPortProbe *probe; - GError *error = NULL; + g_autoptr(GError) error = NULL; probe = g_task_get_source_object (task); @@ -169,28 +160,21 @@ quick_at_ready (MMPortSerialAt *port, /* On a timeout error, wait for READY URC */ if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) { wait_for_ready (task); - goto out; + return; } /* On an unknown error, make it fatal */ if (!mm_serial_parser_v1_is_known_error (error)) { - mm_warn ("(%s/%s) custom port initialization logic failed: %s", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe), - error->message); - goto out_complete; + mm_obj_warn (probe, "custom port initialization logic failed: %s", error->message); + goto out; } } - mm_dbg ("(%s/%s) port is AT", - mm_port_probe_get_port_subsys (probe), - mm_port_probe_get_port_name (probe)); + mm_obj_dbg (probe, "port is AT"); mm_port_probe_set_result_at (probe, TRUE); -out_complete: +out: g_task_return_boolean (task, TRUE); g_object_unref (task); -out: - g_clear_error (&error); } static void diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c index 0aa20f2b..b2999ee8 100644 --- a/plugins/ublox/tests/test-modem-helpers-ublox.c +++ b/plugins/ublox/tests/test-modem-helpers-ublox.c @@ -290,7 +290,7 @@ compare_combinations (const gchar *response, GError *error = NULL; guint i; - combinations = mm_ublox_parse_urat_test_response (response, &error); + combinations = mm_ublox_parse_urat_test_response (response, NULL, &error); g_assert_no_error (error); g_assert (combinations); @@ -461,7 +461,7 @@ test_urat_read_response (void) GError *error = NULL; gboolean success; - success = mm_ublox_parse_urat_read_response (urat_tests[i].response, + success = mm_ublox_parse_urat_read_response (urat_tests[i].response, NULL, &allowed, &preferred, &error); g_assert_no_error (error); g_assert (success); @@ -498,7 +498,7 @@ common_validate_ubandsel_response (const gchar *str, GError *error = NULL; GArray *bands; - bands = mm_ublox_parse_ubandsel_response (str, model, &error); + bands = mm_ublox_parse_ubandsel_response (str, model, NULL, &error); g_assert_no_error (error); g_assert (bands); @@ -701,7 +701,7 @@ common_validate_uact_test (const gchar *str, GArray *bands_3g = NULL; GArray *bands_4g = NULL; - result = mm_ublox_parse_uact_test (str, &bands_2g, &bands_3g, &bands_4g, &error); + result = mm_ublox_parse_uact_test (str, NULL, &bands_2g, &bands_3g, &bands_4g, &error); g_assert_no_error (error); g_assert (result); @@ -858,7 +858,7 @@ common_validate_uauthreq_test (const gchar *str, GError *error = NULL; MMUbloxBearerAllowedAuth allowed_auths; - allowed_auths = mm_ublox_parse_uauthreq_test (str, &error); + allowed_auths = mm_ublox_parse_uauthreq_test (str, NULL, &error); g_assert_no_error (error); g_assert_cmpuint (allowed_auths, ==, expected_allowed_auths); } From c891595e3f447c04eda7a14c00d63ea7d957ebea Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 07:54:46 +0200 Subject: [PATCH 124/675] via: port to use object logging --- plugins/via/mm-broadband-modem-via.c | 8 ++++---- plugins/via/mm-plugin-via.c | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/via/mm-broadband-modem-via.c b/plugins/via/mm-broadband-modem-via.c index 6e2cfe61..24ea6d00 100644 --- a/plugins/via/mm-broadband-modem-via.c +++ b/plugins/via/mm-broadband-modem-via.c @@ -24,7 +24,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-errors-types.h" #include "mm-base-modem-at.h" @@ -199,7 +199,7 @@ sysinfo_ready (MMBaseModem *self, /* Try to parse the results */ g_regex_match (r, response, 0, &match_info); if (g_match_info_get_match_count (match_info) < 6) { - mm_warn ("Via: failed to parse ^SYSINFO response: '%s'", response); + mm_obj_warn (self, "failed to parse ^SYSINFO response: '%s'", response); goto out; } @@ -232,7 +232,7 @@ sysinfo_ready (MMBaseModem *self, } } else { /* Say we're registered to something even though sysmode parsing failed */ - mm_dbg ("SYSMODE parsing failed: assuming registered at least in CDMA1x"); + mm_obj_dbg (self, "SYSMODE parsing failed: assuming registered at least in CDMA1x"); results->detailed_cdma1x_state = reg_state; } @@ -282,7 +282,7 @@ handle_evdo_quality_change (MMPortSerialAt *port, if (mm_get_uint_from_match_info (match_info, 1, &quality)) { quality = MM_CLAMP_HIGH (quality, 100); - mm_dbg ("EVDO signal quality: %u", quality); + mm_obj_dbg (self, "EVDO signal quality: %u", quality); mm_iface_modem_update_signal_quality (MM_IFACE_MODEM (self), quality); } } diff --git a/plugins/via/mm-plugin-via.c b/plugins/via/mm-plugin-via.c index 2e9e7049..8951af87 100644 --- a/plugins/via/mm-plugin-via.c +++ b/plugins/via/mm-plugin-via.c @@ -27,7 +27,6 @@ #include "mm-broadband-modem-via.h" #include "mm-plugin-via.h" -#include "mm-log.h" G_DEFINE_TYPE (MMPluginVia, mm_plugin_via, MM_TYPE_PLUGIN) From ab47b565731296ba76d18d17c0c2ccc9d029de52 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 07:56:51 +0200 Subject: [PATCH 125/675] wavecom: port to use object logging --- plugins/wavecom/mm-broadband-modem-wavecom.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/plugins/wavecom/mm-broadband-modem-wavecom.c b/plugins/wavecom/mm-broadband-modem-wavecom.c index 500d8895..83620558 100644 --- a/plugins/wavecom/mm-broadband-modem-wavecom.c +++ b/plugins/wavecom/mm-broadband-modem-wavecom.c @@ -27,7 +27,7 @@ #include #include "ModemManager.h" -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-serial-parsers.h" #include "mm-modem-helpers.h" #include "mm-iface-modem.h" @@ -341,7 +341,7 @@ current_ms_class_ready (MMBaseModem *self, if (strncmp (response, WAVECOM_MS_CLASS_A_IDSTR, strlen (WAVECOM_MS_CLASS_A_IDSTR)) == 0) { - mm_dbg ("Modem configured as a Class A mobile station"); + mm_obj_dbg (self, "configured as a Class A mobile station"); /* For 3G devices, query WWSM status */ mm_base_modem_at_command (self, "+WWSM?", @@ -358,19 +358,19 @@ current_ms_class_ready (MMBaseModem *self, if (strncmp (response, WAVECOM_MS_CLASS_B_IDSTR, strlen (WAVECOM_MS_CLASS_B_IDSTR)) == 0) { - mm_dbg ("Modem configured as a Class B mobile station"); + mm_obj_dbg (self, "configured as a Class B mobile station"); result.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_CS); result.preferred = MM_MODEM_MODE_2G; } else if (strncmp (response, WAVECOM_MS_CLASS_CG_IDSTR, strlen (WAVECOM_MS_CLASS_CG_IDSTR)) == 0) { - mm_dbg ("Modem configured as a Class CG mobile station"); + mm_obj_dbg (self, "configured as a Class CG mobile station"); result.allowed = MM_MODEM_MODE_2G; result.preferred = MM_MODEM_MODE_NONE; } else if (strncmp (response, WAVECOM_MS_CLASS_CC_IDSTR, strlen (WAVECOM_MS_CLASS_CC_IDSTR)) == 0) { - mm_dbg ("Modem configured as a Class CC mobile station"); + mm_obj_dbg (self, "configured as a Class CC mobile station"); result.allowed = MM_MODEM_MODE_CS; result.preferred = MM_MODEM_MODE_NONE; } @@ -812,7 +812,6 @@ set_bands_3g (GTask *task, return; } - mm_dbg ("Setting new bands to use: '%s'", bands_string); cmd = g_strdup_printf ("+WMBS=\"%u\",1", wavecom_band); mm_base_modem_at_command (MM_BASE_MODEM (self), cmd, @@ -885,7 +884,6 @@ set_bands_2g (GTask *task, return; } - mm_dbg ("Setting new bands to use: '%s'", bands_string); cmd = g_strdup_printf ("+WMBS=%c,1", wavecom_band); mm_base_modem_at_command (MM_BASE_MODEM (self), cmd, @@ -1090,7 +1088,7 @@ cops_ready (MMBaseModem *self, return; } - mm_dbg ("Device is already in automatic registration mode, not requesting it again"); + mm_obj_dbg (self, "device is already in automatic registration mode, not requesting it again"); out: if (error) @@ -1181,8 +1179,8 @@ modem_power_up (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_warn ("Not in full functionality status, power-up command is needed. " - "Note that it may reboot the modem."); + mm_obj_warn (self, "not in full functionality status, power-up command is needed"); + mm_obj_warn (self, "the device maybe rebooted"); /* Try to go to full functionality mode without rebooting the system. * Works well if we previously switched off the power with CFUN=4 @@ -1258,7 +1256,7 @@ setup_ports (MMBroadbandModem *self) MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_wavecom_parent_class)->setup_ports (self); /* Set 9600 baudrate by default in the AT port */ - mm_dbg ("Baudrate will be set to 9600 bps..."); + mm_obj_dbg (self, "baudrate will be set to 9600 bps..."); primary = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); if (!primary) return; From 9c9e531130e3a6cad4fcdf30c90d345a98cfe1b2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 08:00:03 +0200 Subject: [PATCH 126/675] x22x: port to use object logging --- plugins/x22x/mm-broadband-modem-x22x.c | 1 - plugins/x22x/mm-plugin-x22x.c | 24 ++++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/plugins/x22x/mm-broadband-modem-x22x.c b/plugins/x22x/mm-broadband-modem-x22x.c index a86b7a57..dcd1addb 100644 --- a/plugins/x22x/mm-broadband-modem-x22x.c +++ b/plugins/x22x/mm-broadband-modem-x22x.c @@ -300,7 +300,6 @@ load_access_technologies (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - mm_dbg ("loading access technology (x22x)..."); mm_base_modem_at_command (MM_BASE_MODEM (self), "+SSND?", 3, diff --git a/plugins/x22x/mm-plugin-x22x.c b/plugins/x22x/mm-plugin-x22x.c index 795d30a7..4ec03a71 100644 --- a/plugins/x22x/mm-plugin-x22x.c +++ b/plugins/x22x/mm-plugin-x22x.c @@ -21,7 +21,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-plugin-x22x.h" #include "mm-broadband-modem-x22x.h" @@ -62,12 +62,15 @@ static void x22x_custom_init_step (GTask *task); static void gmr_ready (MMPortSerialAt *port, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { + MMPortProbe *probe; const gchar *p; const gchar *response; - GError *error = NULL; + GError *error = NULL; + + probe = g_task_get_source_object (task); response = mm_port_serial_at_command_finish (port, res, &error); if (error) { @@ -90,7 +93,7 @@ gmr_ready (MMPortSerialAt *port, MM_CORE_ERROR_UNSUPPORTED, "Not supported with the X22X plugin"); } else { - mm_dbg ("(X22X) device is supported by this plugin"); + mm_obj_dbg (probe, "(X22X) device is supported by this plugin"); g_task_return_boolean (task, TRUE); } g_object_unref (task); @@ -99,16 +102,17 @@ gmr_ready (MMPortSerialAt *port, static void x22x_custom_init_step (GTask *task) { + MMPortProbe *probe; X22xCustomInitContext *ctx; - GCancellable *cancellable; + GCancellable *cancellable; - ctx = g_task_get_task_data (task); + probe = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); cancellable = g_task_get_cancellable (task); /* If cancelled, end */ if (g_cancellable_is_cancelled (cancellable)) { - mm_dbg ("(X22X) no need to keep on running custom init in (%s)", - mm_port_get_device (MM_PORT (ctx->port))); + mm_obj_dbg (probe, "(X22X) no need to keep on running custom init"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -190,7 +194,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered X22X modem found..."); + mm_obj_dbg (self, "QMI-powered X22X modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), From 35554aaeed42ddb9ecfad8d71f2e527485c10dda Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 09:38:59 +0200 Subject: [PATCH 127/675] xmm: port to use object logging --- plugins/xmm/mm-broadband-modem-mbim-xmm.c | 1 - plugins/xmm/mm-broadband-modem-xmm.c | 1 - plugins/xmm/mm-modem-helpers-xmm.c | 23 +++++++------- plugins/xmm/mm-shared-xmm.c | 37 ++++++++++++----------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/plugins/xmm/mm-broadband-modem-mbim-xmm.c b/plugins/xmm/mm-broadband-modem-mbim-xmm.c index 1aa8b7ba..781d7e4f 100644 --- a/plugins/xmm/mm-broadband-modem-mbim-xmm.c +++ b/plugins/xmm/mm-broadband-modem-mbim-xmm.c @@ -22,7 +22,6 @@ #include #include "ModemManager.h" -#include "mm-log.h" #include "mm-iface-modem.h" #include "mm-iface-modem-location.h" #include "mm-broadband-modem-mbim-xmm.h" diff --git a/plugins/xmm/mm-broadband-modem-xmm.c b/plugins/xmm/mm-broadband-modem-xmm.c index ab322162..35103d8b 100644 --- a/plugins/xmm/mm-broadband-modem-xmm.c +++ b/plugins/xmm/mm-broadband-modem-xmm.c @@ -22,7 +22,6 @@ #include #include "ModemManager.h" -#include "mm-log.h" #include "mm-iface-modem.h" #include "mm-iface-modem-location.h" #include "mm-broadband-modem-xmm.h" diff --git a/plugins/xmm/mm-modem-helpers-xmm.c b/plugins/xmm/mm-modem-helpers-xmm.c index 7c283dba..9b3933d2 100644 --- a/plugins/xmm/mm-modem-helpers-xmm.c +++ b/plugins/xmm/mm-modem-helpers-xmm.c @@ -172,7 +172,7 @@ static const MMModemMode xmm_modes[] = { gboolean mm_xmm_parse_xact_test_response (const gchar *response, - gpointer logger, + gpointer log_object, GArray **modes_out, GArray **bands_out, GError **error) @@ -232,7 +232,7 @@ mm_xmm_parse_xact_test_response (const gchar *response, supported_value = g_array_index (supported, guint, i); if (supported_value >= G_N_ELEMENTS (xmm_modes)) { - mm_warn ("Unexpected AcT supported value: %u", supported_value); + mm_obj_warn (log_object, "unexpected AcT supported value: %u", supported_value); continue; } @@ -252,12 +252,12 @@ mm_xmm_parse_xact_test_response (const gchar *response, preferred_value = g_array_index (preferred, guint, j); if (preferred_value >= G_N_ELEMENTS (xmm_modes)) { - mm_warn ("Unexpected AcT preferred value: %u", preferred_value); + mm_obj_warn (log_object, "unexpected AcT preferred value: %u", preferred_value); continue; } combination.preferred = xmm_modes[preferred_value]; if (mm_count_bits_set (combination.preferred) != 1) { - mm_warn ("AcT preferred value should be a single AcT: %u", preferred_value); + mm_obj_warn (log_object, "AcT preferred value should be a single AcT: %u", preferred_value); continue; } if (!(combination.allowed & combination.preferred)) @@ -284,7 +284,7 @@ mm_xmm_parse_xact_test_response (const gchar *response, guint num; if (!mm_get_uint_from_str (split[i], &num)) { - mm_warn ("Unexpected band value: %s", split[i]); + mm_obj_warn (log_object, "unexpected band value: %s", split[i]); continue; } @@ -293,7 +293,7 @@ mm_xmm_parse_xact_test_response (const gchar *response, band = xact_num_to_band (num); if (band == MM_MODEM_BAND_UNKNOWN) { - mm_warn ("Unsupported band value: %s", split[i]); + mm_obj_warn (log_object, "unsupported band value: %s", split[i]); continue; } @@ -319,7 +319,7 @@ mm_xmm_parse_xact_test_response (const gchar *response, all_modes = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 1); g_array_append_val (all_modes, all); - filtered = mm_filter_supported_modes (all_modes, modes, logger); + filtered = mm_filter_supported_modes (all_modes, modes, log_object); if (!filtered || filtered->len == 0) { inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Empty supported mode list after frequency band filtering"); @@ -697,8 +697,9 @@ mm_xmm_parse_xcesq_query_response (const gchar *response, } static gboolean -rssnr_level_to_rssnr (gint rssnr_level, - gdouble *out_rssnr) +rssnr_level_to_rssnr (gint rssnr_level, + gpointer log_object, + gdouble *out_rssnr) { if (rssnr_level <= 100 && rssnr_level >= -100) { @@ -707,7 +708,7 @@ rssnr_level_to_rssnr (gint rssnr_level, } if (rssnr_level != 255) - mm_warn ("unexpected RSSNR level: %u", rssnr_level); + mm_obj_warn (log_object, "unexpected RSSNR level: %u", rssnr_level); return FALSE; } @@ -786,7 +787,7 @@ mm_xmm_xcesq_response_to_signal_info (const gchar *response, } /* LTE RSSNR */ - if (rssnr_level_to_rssnr (rssnr_level, &rssnr)) { + if (rssnr_level_to_rssnr (rssnr_level, log_object, &rssnr)) { if (!lte) lte = mm_signal_new (); mm_signal_set_snr (lte, rssnr); diff --git a/plugins/xmm/mm-shared-xmm.c b/plugins/xmm/mm-shared-xmm.c index d447fec9..60457589 100644 --- a/plugins/xmm/mm-shared-xmm.c +++ b/plugins/xmm/mm-shared-xmm.c @@ -22,7 +22,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-iface-modem.h" #include "mm-iface-modem-signal.h" #include "mm-iface-modem-location.h" @@ -420,7 +420,8 @@ xact_set_bands_ready (MMBaseModem *self, } static gchar * -validate_and_build_command_set_current_bands (const GArray *bands_array, +validate_and_build_command_set_current_bands (MMSharedXmm *self, + const GArray *bands_array, const GArray *supported_modes, MMModemMode allowed_modes, GError **error) @@ -445,11 +446,10 @@ validate_and_build_command_set_current_bands (const GArray *bands_array, */ unapplied = mm_xmm_get_modem_mode_any (supported_modes) & ~(allowed_modes); if (unapplied != MM_MODEM_MODE_NONE) { - gchar *str; + g_autofree gchar *str = NULL; str = mm_modem_mode_build_string_from_mask (unapplied); - mm_warn ("Automatic band selection not applied to non-current modes %s", str); - g_free (str); + mm_obj_warn (self, "automatic band selection not applied to non-current modes %s", str); } /* Nothing else to validate, go build the command right away */ @@ -550,7 +550,8 @@ mm_shared_xmm_set_current_bands (MMIfaceModem *self, goto out; } - command = validate_and_build_command_set_current_bands (bands_array, + command = validate_and_build_command_set_current_bands (MM_SHARED_XMM (self), + bands_array, priv->supported_modes, priv->allowed_modes, &error); @@ -840,28 +841,28 @@ xlcslsr_test_ready (MMBaseModem *self, &loc_response_type_nmea_supported, &gnss_type_gps_glonass_supported, &error)) { - mm_dbg ("XLCSLSR based GPS control unsupported: %s", error->message); + mm_obj_dbg (self, "XLCSLSR based GPS control unsupported: %s", error->message); g_clear_error (&error); } else if (!transport_protocol_invalid_supported || !standalone_position_mode_supported || !loc_response_type_nmea_supported || !gnss_type_gps_glonass_supported) { - mm_dbg ("XLCSLSR based GPS control unsupported: protocol invalid %s, standalone %s, nmea %s, gps/glonass %s", - transport_protocol_invalid_supported ? "supported" : "unsupported", - standalone_position_mode_supported ? "supported" : "unsupported", - loc_response_type_nmea_supported ? "supported" : "unsupported", - gnss_type_gps_glonass_supported ? "supported" : "unsupported"); + mm_obj_dbg (self, "XLCSLSR based GPS control unsupported: protocol invalid %s, standalone %s, nmea %s, gps/glonass %s", + transport_protocol_invalid_supported ? "supported" : "unsupported", + standalone_position_mode_supported ? "supported" : "unsupported", + loc_response_type_nmea_supported ? "supported" : "unsupported", + gnss_type_gps_glonass_supported ? "supported" : "unsupported"); } else { - mm_dbg ("XLCSLSR based GPS control supported"); + mm_obj_dbg (self, "XLCSLSR based GPS control supported"); priv->supported_sources |= (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW); if (transport_protocol_supl_supported && ms_assisted_based_position_mode_supported) { - mm_dbg ("XLCSLSR based A-GPS control supported"); + mm_obj_dbg (self, "XLCSLSR based A-GPS control supported"); priv->supported_sources |= (MM_MODEM_LOCATION_SOURCE_AGPS_MSA | MM_MODEM_LOCATION_SOURCE_AGPS_MSB); } else { - mm_dbg ("XLCSLSR based A-GPS control unsupported: protocol supl %s, ms assisted/based %s", - transport_protocol_supl_supported ? "supported" : "unsupported", - ms_assisted_based_position_mode_supported ? "supported" : "unsupported"); + mm_obj_dbg (self, "XLCSLSR based A-GPS control unsupported: protocol supl %s, ms assisted/based %s", + transport_protocol_supl_supported ? "supported" : "unsupported", + ms_assisted_based_position_mode_supported ? "supported" : "unsupported"); } sources |= priv->supported_sources; @@ -903,7 +904,7 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self, /* If parent already supports GPS sources, we won't do anything else */ if (sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { - mm_dbg ("No need to run XLCSLSR based location gathering"); + mm_obj_dbg (self, "no need to run XLCSLSR based location gathering"); g_task_return_int (task, sources); g_object_unref (task); return; From 4508c11796fef8505891d47408de0e01c669003e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 09:40:25 +0200 Subject: [PATCH 128/675] zte: port to use object logging --- plugins/zte/mm-broadband-modem-zte-icera.c | 1 - plugins/zte/mm-broadband-modem-zte.c | 2 -- plugins/zte/mm-plugin-zte.c | 8 ++++---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/zte/mm-broadband-modem-zte-icera.c b/plugins/zte/mm-broadband-modem-zte-icera.c index fe8448e5..c0befa5b 100644 --- a/plugins/zte/mm-broadband-modem-zte-icera.c +++ b/plugins/zte/mm-broadband-modem-zte-icera.c @@ -29,7 +29,6 @@ #include "mm-common-zte.h" #include "mm-broadband-modem-zte-icera.h" #include "mm-modem-helpers.h" -#include "mm-log.h" static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface); diff --git a/plugins/zte/mm-broadband-modem-zte.c b/plugins/zte/mm-broadband-modem-zte.c index a3c81a66..64549cd8 100644 --- a/plugins/zte/mm-broadband-modem-zte.c +++ b/plugins/zte/mm-broadband-modem-zte.c @@ -24,7 +24,6 @@ #include #include "ModemManager.h" -#include "mm-log.h" #include "mm-errors-types.h" #include "mm-modem-helpers.h" #include "mm-base-modem-at.h" @@ -70,7 +69,6 @@ load_unlock_retries_ready (MMBaseModem *self, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - mm_dbg ("Couldn't query unlock retries: '%s'", error->message); g_task_return_error (task, error); g_object_unref (task); return; diff --git a/plugins/zte/mm-plugin-zte.c b/plugins/zte/mm-plugin-zte.c index 7b0849f1..ee5fdc74 100644 --- a/plugins/zte/mm-plugin-zte.c +++ b/plugins/zte/mm-plugin-zte.c @@ -21,7 +21,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-object.h" #include "mm-plugin-zte.h" #include "mm-broadband-modem-zte.h" #include "mm-broadband-modem-zte-icera.h" @@ -70,7 +70,7 @@ create_modem (MMPlugin *self, { #if defined WITH_QMI if (mm_port_probe_list_has_qmi_port (probes)) { - mm_dbg ("QMI-powered ZTE modem found..."); + mm_obj_dbg (self, "QMI-powered ZTE modem found..."); return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, drivers, mm_plugin_get_name (self), @@ -81,7 +81,7 @@ create_modem (MMPlugin *self, #if defined WITH_MBIM if (mm_port_probe_list_has_mbim_port (probes)) { - mm_dbg ("MBIM-powered ZTE modem found..."); + mm_obj_dbg (self, "MBIM-powered ZTE modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, drivers, mm_plugin_get_name (self), @@ -126,7 +126,7 @@ grab_port (MMPlugin *self, } if (mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_ZTE_ICERA_DHCP")) { - mm_dbg ("ZTE: Icera-based modem will use DHCP"); + mm_obj_dbg (self, "ZTE: Icera-based modem will use DHCP"); g_object_set (modem, MM_BROADBAND_MODEM_ICERA_DEFAULT_IP_METHOD, MM_BEARER_IP_METHOD_DHCP, NULL); From f1e930d574c712b75bf5772d3ae128b72b327a38 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 10:11:50 +0200 Subject: [PATCH 129/675] core: consolidate logging format in main daemon logic --- src/main.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 7a6b4b16..13b7cecb 100644 --- a/src/main.c +++ b/src/main.c @@ -43,7 +43,7 @@ static MMBaseManager *manager; static gboolean quit_cb (gpointer user_data) { - mm_info ("Caught signal, shutting down..."); + mm_info ("caught signal, shutting down..."); if (manager) g_object_set (manager, MM_BASE_MANAGER_CONNECTION, NULL, NULL); @@ -60,14 +60,14 @@ quit_cb (gpointer user_data) static void sleeping_cb (MMSleepMonitor *sleep_monitor) { - mm_dbg ("Removing devices... (sleeping)"); + mm_dbg ("removing devices... (sleeping)"); mm_base_manager_shutdown (manager, FALSE); } static void resuming_cb (MMSleepMonitor *sleep_monitor) { - mm_dbg ("Re-scanning (resuming)"); + mm_dbg ("re-scanning (resuming)"); mm_base_manager_start (manager, FALSE); } @@ -80,7 +80,7 @@ bus_acquired_cb (GDBusConnection *connection, { GError *error = NULL; - mm_dbg ("Bus acquired, creating manager..."); + mm_dbg ("bus acquired, creating manager..."); /* Create Manager object */ g_assert (!manager); @@ -92,7 +92,7 @@ bus_acquired_cb (GDBusConnection *connection, mm_context_get_test_enable (), &error); if (!manager) { - mm_warn ("Could not create manager: %s", error->message); + mm_warn ("could not create manager: %s", error->message); g_error_free (error); g_main_loop_quit (loop); return; @@ -104,7 +104,7 @@ name_acquired_cb (GDBusConnection *connection, const gchar *name, gpointer user_data) { - mm_dbg ("Service name '%s' was acquired", name); + mm_dbg ("service name '%s' was acquired", name); /* Launch automatic scan for devices */ g_assert (manager); @@ -119,10 +119,9 @@ name_lost_cb (GDBusConnection *connection, /* Note that we're not allowing replacement, so once the name acquired, the * process won't lose it. */ if (!name) - mm_warn ("Could not get the system bus. Make sure " - "the message bus daemon is running!"); + mm_warn ("could not get the system bus; make sure the message bus daemon is running!"); else - mm_warn ("Could not acquire the '%s' service name", name); + mm_warn ("could not acquire the '%s' service name", name); if (manager) g_object_set (manager, MM_BASE_MANAGER_CONNECTION, NULL, NULL); @@ -156,8 +155,8 @@ int main (int argc, char *argv[]) { GMainLoop *inner; - GError *err = NULL; - guint name_id; + GError *error = NULL; + guint name_id; /* Setup application context */ mm_context_init (argc, argv); @@ -167,9 +166,9 @@ main (int argc, char *argv[]) mm_context_get_log_journal (), mm_context_get_log_timestamps (), mm_context_get_log_relative_timestamps (), - &err)) { - g_warning ("Failed to set up logging: %s", err->message); - g_error_free (err); + &error)) { + g_warning ("failed to set up logging: %s", error->message); + g_error_free (error); exit (1); } @@ -228,8 +227,7 @@ main (int argc, char *argv[]) } if (mm_base_manager_num_modems (manager)) - mm_warn ("Disabling modems took too long, " - "shutting down with '%u' modems around", + mm_warn ("disabling modems took too long, shutting down with %u modems around", mm_base_manager_num_modems (manager)); g_object_unref (manager); From e956bac47b5a822a836381ec8dbb34041a8f41f4 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 15:13:53 +0200 Subject: [PATCH 130/675] log: common logging method definition for all testers and helpers --- .../tests/test-modem-helpers-cinterion.c | 23 +--------- .../huawei/tests/test-modem-helpers-huawei.c | 22 +-------- .../icera/tests/test-modem-helpers-icera.c | 23 +--------- .../tests/test-modem-helpers-linktop.c | 23 +--------- plugins/mbm/tests/test-modem-helpers-mbm.c | 23 +--------- .../sierra/tests/test-modem-helpers-sierra.c | 23 +--------- .../tests/test-modem-helpers-simtech.c | 23 +--------- .../telit/tests/test-mm-modem-helpers-telit.c | 23 +--------- plugins/tests/test-keyfiles.c | 23 +--------- plugins/tests/test-udev-rules.c | 23 +--------- .../tests/test-mm-modem-helpers-thuraya.c | 23 +--------- .../ublox/tests/test-modem-helpers-ublox.c | 23 +--------- plugins/xmm/tests/test-modem-helpers-xmm.c | 23 +--------- src/Makefile.am | 1 + src/mm-log-test.h | 45 +++++++++++++++++++ src/mm-log.c | 10 ++--- src/mm-log.h | 10 ++--- src/tests/test-at-serial-port.c | 23 +--------- src/tests/test-charsets.c | 23 +--------- src/tests/test-error-helpers.c | 21 --------- src/tests/test-modem-helpers-qmi.c | 23 +--------- src/tests/test-modem-helpers.c | 23 +--------- src/tests/test-qcdm-serial-port.c | 23 +--------- src/tests/test-sms-part-3gpp.c | 23 +--------- src/tests/test-sms-part-cdma.c | 23 +--------- src/tests/test-udev-rules.c | 23 +--------- test/mmrules.c | 23 +--------- test/mmsmspdu.c | 23 +--------- test/mmtty.c | 23 +--------- 29 files changed, 80 insertions(+), 558 deletions(-) create mode 100644 src/mm-log-test.h diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c index 88e0f74c..0baeec30 100644 --- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c +++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c @@ -21,7 +21,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-cinterion.h" @@ -858,27 +858,6 @@ test_ctzu_urc_full (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/huawei/tests/test-modem-helpers-huawei.c b/plugins/huawei/tests/test-modem-helpers-huawei.c index 18ac85a5..1aa50c9e 100644 --- a/plugins/huawei/tests/test-modem-helpers-huawei.c +++ b/plugins/huawei/tests/test-modem-helpers-huawei.c @@ -22,6 +22,7 @@ #define _LIBMM_INSIDE_MM #include +#include "mm-log-test.h" #include "mm-log-object.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-huawei.h" @@ -1248,27 +1249,6 @@ test_hcsq (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/icera/tests/test-modem-helpers-icera.c b/plugins/icera/tests/test-modem-helpers-icera.c index ef9d62cc..518e9afd 100644 --- a/plugins/icera/tests/test-modem-helpers-icera.c +++ b/plugins/icera/tests/test-modem-helpers-icera.c @@ -24,7 +24,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-icera.h" @@ -175,27 +175,6 @@ test_ipdpaddr (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/linktop/tests/test-modem-helpers-linktop.c b/plugins/linktop/tests/test-modem-helpers-linktop.c index 396abaae..07aa8378 100644 --- a/plugins/linktop/tests/test-modem-helpers-linktop.c +++ b/plugins/linktop/tests/test-modem-helpers-linktop.c @@ -21,7 +21,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-linktop.h" @@ -59,27 +59,6 @@ test_cfun_query_current_modes (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/mbm/tests/test-modem-helpers-mbm.c b/plugins/mbm/tests/test-modem-helpers-mbm.c index da33522c..4169140a 100644 --- a/plugins/mbm/tests/test-modem-helpers-mbm.c +++ b/plugins/mbm/tests/test-modem-helpers-mbm.c @@ -24,7 +24,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-mbm.h" @@ -253,27 +253,6 @@ test_cfun_query_current_modes (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/sierra/tests/test-modem-helpers-sierra.c b/plugins/sierra/tests/test-modem-helpers-sierra.c index ad25ec9b..b0c66496 100644 --- a/plugins/sierra/tests/test-modem-helpers-sierra.c +++ b/plugins/sierra/tests/test-modem-helpers-sierra.c @@ -22,7 +22,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-sierra.h" @@ -115,27 +115,6 @@ test_scact_read_response_multiple (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/simtech/tests/test-modem-helpers-simtech.c b/plugins/simtech/tests/test-modem-helpers-simtech.c index f1109534..d5d774f2 100644 --- a/plugins/simtech/tests/test-modem-helpers-simtech.c +++ b/plugins/simtech/tests/test-modem-helpers-simtech.c @@ -21,7 +21,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-simtech.h" @@ -317,27 +317,6 @@ test_rxdtmf_urc_one_cr (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/telit/tests/test-mm-modem-helpers-telit.c b/plugins/telit/tests/test-mm-modem-helpers-telit.c index b6083816..251abd1e 100644 --- a/plugins/telit/tests/test-mm-modem-helpers-telit.c +++ b/plugins/telit/tests/test-mm-modem-helpers-telit.c @@ -23,7 +23,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-telit.h" @@ -572,27 +572,6 @@ test_telit_parse_qss_query (void) /******************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/tests/test-keyfiles.c b/plugins/tests/test-keyfiles.c index 173893be..d528cac9 100644 --- a/plugins/tests/test-keyfiles.c +++ b/plugins/tests/test-keyfiles.c @@ -23,7 +23,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" /************************************************************/ @@ -64,27 +64,6 @@ test_foxconn_t77w968 (void) /************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/tests/test-udev-rules.c b/plugins/tests/test-udev-rules.c index e12f07ac..36cc4120 100644 --- a/plugins/tests/test-udev-rules.c +++ b/plugins/tests/test-udev-rules.c @@ -25,7 +25,7 @@ #include #include "mm-kernel-device-generic-rules.h" -#include "mm-log.h" +#include "mm-log-test.h" /************************************************************/ @@ -162,27 +162,6 @@ test_fibocom (void) /************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c index c3c76f09..bdc073d0 100644 --- a/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c +++ b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c @@ -24,7 +24,7 @@ #include "mm-modem-helpers.h" #include "mm-modem-helpers-thuraya.h" -#include "mm-log.h" +#include "mm-log-test.h" /*****************************************************************************/ /* Test CPMS response */ @@ -87,27 +87,6 @@ test_cpms_response_thuraya (void *f, gpointer d) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - #define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (GTestFixtureFunc) t, NULL) int main (int argc, char **argv) diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c index b2999ee8..2d662877 100644 --- a/plugins/ublox/tests/test-modem-helpers-ublox.c +++ b/plugins/ublox/tests/test-modem-helpers-ublox.c @@ -22,7 +22,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-ublox.h" @@ -979,27 +979,6 @@ test_ugcntrd_response (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/plugins/xmm/tests/test-modem-helpers-xmm.c b/plugins/xmm/tests/test-modem-helpers-xmm.c index 39aa8ccc..e40ffcab 100644 --- a/plugins/xmm/tests/test-modem-helpers-xmm.c +++ b/plugins/xmm/tests/test-modem-helpers-xmm.c @@ -22,7 +22,7 @@ #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-modem-helpers.h" #include "mm-modem-helpers-xmm.h" @@ -754,27 +754,6 @@ test_xlcsslp_queries (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/src/Makefile.am b/src/Makefile.am index cb50d2b8..e80c10aa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -101,6 +101,7 @@ libhelpers_la_SOURCES = \ mm-log-object.c \ mm-log.c \ mm-log.h \ + mm-log-test.h \ mm-error-helpers.c \ mm-error-helpers.h \ mm-modem-helpers.c \ diff --git a/src/mm-log-test.h b/src/mm-log-test.h new file mode 100644 index 00000000..056de53b --- /dev/null +++ b/src/mm-log-test.h @@ -0,0 +1,45 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2020 Aleksander Morgado + */ + +#ifndef MM_LOG_TEST_H +#define MM_LOG_TEST_H + +#include +#include "mm-log.h" + +/* This is a common logging method to be used by all test applications */ + +void +_mm_log (gpointer obj, + const gchar *loc, + const gchar *func, + guint32 level, + const gchar *fmt, + ...) +{ + va_list args; + gchar *msg; + + if (!g_test_verbose ()) + return; + + va_start (args, fmt); + msg = g_strdup_vprintf (fmt, args); + va_end (args); + g_print ("%s\n", msg); + g_free (msg); +} + +#endif /* MM_LOG_TEST_H */ diff --git a/src/mm-log.c b/src/mm-log.c index f15ce5c9..339e7955 100644 --- a/src/mm-log.c +++ b/src/mm-log.c @@ -202,11 +202,11 @@ log_backend_systemd_journal (const char *loc, #endif void -_mm_log (gpointer obj, - const char *loc, - const char *func, - MMLogLevel level, - const char *fmt, +_mm_log (gpointer obj, + const gchar *loc, + const gchar *func, + MMLogLevel level, + const gchar *fmt, ...) { va_list args; diff --git a/src/mm-log.h b/src/mm-log.h index 934b41c2..0145c9aa 100644 --- a/src/mm-log.h +++ b/src/mm-log.h @@ -37,11 +37,11 @@ typedef enum { #define mm_info(...) mm_obj_info (NULL, ## __VA_ARGS__ ) #define mm_dbg(...) mm_obj_dbg (NULL, ## __VA_ARGS__ ) -void _mm_log (gpointer obj, - const char *loc, - const char *func, - MMLogLevel level, - const char *fmt, +void _mm_log (gpointer obj, + const gchar *loc, + const gchar *func, + MMLogLevel level, + const gchar *fmt, ...) __attribute__((__format__ (__printf__, 5, 6))); gboolean mm_log_set_level (const char *level, GError **error); diff --git a/src/tests/test-at-serial-port.c b/src/tests/test-at-serial-port.c index 2d57d30e..2147df4d 100644 --- a/src/tests/test-at-serial-port.c +++ b/src/tests/test-at-serial-port.c @@ -18,7 +18,7 @@ #include #include "mm-port-serial-at.h" -#include "mm-log.h" +#include "mm-log-test.h" typedef struct { const gchar *original; @@ -64,27 +64,6 @@ at_serial_echo_removal (void) } } -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c index b8a92575..5c9e1875 100644 --- a/src/tests/test-charsets.c +++ b/src/tests/test-charsets.c @@ -18,7 +18,7 @@ #include #include "mm-modem-helpers.h" -#include "mm-log.h" +#include "mm-log-test.h" static void common_test_gsm7 (const gchar *in_utf8) @@ -408,27 +408,6 @@ test_charset_can_covert_to (void) } } -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/src/tests/test-error-helpers.c b/src/tests/test-error-helpers.c index ae2b8626..ddff9a0d 100644 --- a/src/tests/test-error-helpers.c +++ b/src/tests/test-error-helpers.c @@ -52,27 +52,6 @@ TEST_ERROR_HELPER (MESSAGE_ERROR, message_error, MessageError) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/src/tests/test-modem-helpers-qmi.c b/src/tests/test-modem-helpers-qmi.c index e1f6af64..fbd6cdba 100644 --- a/src/tests/test-modem-helpers-qmi.c +++ b/src/tests/test-modem-helpers-qmi.c @@ -21,7 +21,7 @@ #include "mm-enums-types.h" #include "mm-modem-helpers-qmi.h" -#include "mm-log.h" +#include "mm-log-test.h" static void test_capabilities_expected (MMQmiCapabilitiesContext *ctx, @@ -309,27 +309,6 @@ test_gobi3k_cdma (void) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 3a4fdd63..653bc5e9 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -22,7 +22,7 @@ #define _LIBMM_INSIDE_MM #include #include "mm-modem-helpers.h" -#include "mm-log.h" +#include "mm-log-test.h" #define g_assert_cmpfloat_tolerance(val1, val2, tolerance) \ g_assert_cmpfloat (fabs (val1 - val2), <, tolerance) @@ -4424,27 +4424,6 @@ test_bcd_to_string (void *f, gpointer d) /*****************************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - #define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (GTestFixtureFunc) t, NULL) int main (int argc, char **argv) diff --git a/src/tests/test-qcdm-serial-port.c b/src/tests/test-qcdm-serial-port.c index db20f9aa..0b14282c 100644 --- a/src/tests/test-qcdm-serial-port.c +++ b/src/tests/test-qcdm-serial-port.c @@ -34,7 +34,7 @@ #include "libqcdm/src/utils.h" #include "libqcdm/src/com.h" #include "libqcdm/src/errors.h" -#include "mm-log.h" +#include "mm-log-test.h" typedef struct { int master; @@ -437,27 +437,6 @@ test_pty_cleanup (TestData *d) } } -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - typedef void (*TCFunc) (TestData *, gconstpointer); #define TESTCASE_PTY(s, t) g_test_add (s, TestData, NULL, (TCFunc)test_pty_create, (TCFunc)t, (TCFunc)test_pty_cleanup); diff --git a/src/tests/test-sms-part-3gpp.c b/src/tests/test-sms-part-3gpp.c index 9889a4e9..c3d59d87 100644 --- a/src/tests/test-sms-part-3gpp.c +++ b/src/tests/test-sms-part-3gpp.c @@ -24,7 +24,7 @@ #include #include "mm-sms-part-3gpp.h" -#include "mm-log.h" +#include "mm-log-test.h" /********************* PDU PARSER TESTS *********************/ @@ -841,27 +841,6 @@ test_text_split_two_pdu_ucs2 (void) /************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/src/tests/test-sms-part-cdma.c b/src/tests/test-sms-part-cdma.c index 7bb2bf65..af01b5f5 100644 --- a/src/tests/test-sms-part-cdma.c +++ b/src/tests/test-sms-part-cdma.c @@ -23,7 +23,7 @@ #include #include "mm-sms-part-cdma.h" -#include "mm-log.h" +#include "mm-log-test.h" /********************* PDU PARSER TESTS *********************/ @@ -502,27 +502,6 @@ test_create_pdu_text_unicode_encoding (void) /************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/src/tests/test-udev-rules.c b/src/tests/test-udev-rules.c index cc594918..cdc962e0 100644 --- a/src/tests/test-udev-rules.c +++ b/src/tests/test-udev-rules.c @@ -23,7 +23,7 @@ #include #include "mm-kernel-device-generic-rules.h" -#include "mm-log.h" +#include "mm-log-test.h" /************************************************************/ @@ -43,27 +43,6 @@ test_load_cleanup_core (void) /************************************************************/ -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!g_test_verbose ()) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - int main (int argc, char **argv) { setlocale (LC_ALL, ""); diff --git a/test/mmrules.c b/test/mmrules.c index 29b32fba..3538f44d 100644 --- a/test/mmrules.c +++ b/test/mmrules.c @@ -23,7 +23,7 @@ #include #include -#include +#include #include #define PROGRAM_NAME "mmrules" @@ -50,27 +50,6 @@ static GOptionEntry main_entries[] = { { NULL } }; -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!verbose_flag) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - static void print_version_and_exit (void) { diff --git a/test/mmsmspdu.c b/test/mmsmspdu.c index ef27074c..3a56ffc5 100644 --- a/test/mmsmspdu.c +++ b/test/mmsmspdu.c @@ -26,7 +26,7 @@ #include #define _LIBMM_INSIDE_MM #include -#include "mm-log.h" +#include "mm-log-test.h" #include "mm-sms-part-3gpp.h" #define PROGRAM_NAME "mmsmspdu" @@ -163,27 +163,6 @@ show_part_info (MMSmsPart *part) } } -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!verbose_flag) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - static void print_version_and_exit (void) { diff --git a/test/mmtty.c b/test/mmtty.c index f7852cd4..28df6285 100644 --- a/test/mmtty.c +++ b/test/mmtty.c @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -83,27 +83,6 @@ signals_handler (int signum) } } -void -_mm_log (gpointer obj, - const char *loc, - const char *func, - guint32 level, - const char *fmt, - ...) -{ - va_list args; - gchar *msg; - - if (!verbose_flag) - return; - - va_start (args, fmt); - msg = g_strdup_vprintf (fmt, args); - va_end (args); - g_print ("%s\n", msg); - g_free (msg); -} - static void print_version_and_exit (void) { From 997e2cefb8d72ced4d8ad96382d40482ec58ccdd Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 16:07:32 +0200 Subject: [PATCH 131/675] log: define per-module logging for shared utils and plugins --- plugins/Makefile.am | 331 +++++++++++++++++++++++++++++++++----------- src/mm-log-test.h | 1 + src/mm-log.c | 3 + src/mm-log.h | 15 +- 4 files changed, 263 insertions(+), 87 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index b158bb57..15ba237d 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -128,6 +128,9 @@ libhelpers_icera_la_SOURCES = \ icera/mm-modem-helpers-icera.c \ icera/mm-modem-helpers-icera.h \ $(NULL) +libhelpers_icera_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"shared-icera\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-icera test_modem_helpers_icera_SOURCES = \ @@ -150,7 +153,10 @@ libmm_shared_icera_la_SOURCES = \ icera/mm-broadband-bearer-icera.h \ icera/mm-broadband-bearer-icera.c \ $(NULL) -libmm_shared_icera_la_CPPFLAGS = $(SHARED_COMMON_COMPILER_FLAGS) +libmm_shared_icera_la_CPPFLAGS = \ + $(SHARED_COMMON_COMPILER_FLAGS) + -DMM_MODULE_NAME=\"shared-icera\" \ + $(NULL) libmm_shared_icera_la_LDFLAGS = $(SHARED_COMMON_LINKER_FLAGS) libmm_shared_icera_la_LIBADD = \ $(builddir)/libhelpers-icera.la \ @@ -171,6 +177,9 @@ libhelpers_sierra_la_SOURCES = \ sierra/mm-modem-helpers-sierra.c \ sierra/mm-modem-helpers-sierra.h \ $(NULL) +libhelpers_sierra_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"shared-sierra\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-sierra test_modem_helpers_sierra_SOURCES = \ @@ -197,7 +206,10 @@ libmm_shared_sierra_la_SOURCES = \ sierra/mm-broadband-modem-sierra.c \ sierra/mm-broadband-modem-sierra.h \ $(NULL) -libmm_shared_sierra_la_CPPFLAGS = $(SHARED_COMMON_COMPILER_FLAGS) +libmm_shared_sierra_la_CPPFLAGS = \ + $(SHARED_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"shared-sierra\" \ + $(NULL) libmm_shared_sierra_la_LDFLAGS = $(SHARED_COMMON_LINKER_FLAGS) libmm_shared_sierra_la_LIBADD = \ $(builddir)/libhelpers-sierra.la \ @@ -241,7 +253,10 @@ libmm_shared_novatel_la_SOURCES = \ novatel/mm-broadband-modem-novatel.c \ novatel/mm-broadband-modem-novatel.h \ $(NULL) -libmm_shared_novatel_la_CPPFLAGS = $(SHARED_COMMON_COMPILER_FLAGS) +libmm_shared_novatel_la_CPPFLAGS = \ + $(SHARED_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"shared-novatel\" \ + $(NULL) libmm_shared_novatel_la_LDFLAGS = $(SHARED_COMMON_LINKER_FLAGS) NOVATEL_COMMON_COMPILER_FLAGS = -I$(top_srcdir)/plugins/novatel @@ -259,6 +274,9 @@ libhelpers_xmm_la_SOURCES = \ xmm/mm-modem-helpers-xmm.c \ xmm/mm-modem-helpers-xmm.h \ $(NULL) +libhelpers_xmm_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"shared-xmm\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-xmm test_modem_helpers_xmm_SOURCES = \ @@ -289,7 +307,10 @@ libmm_shared_xmm_la_SOURCES += \ $(NULL) endif -libmm_shared_xmm_la_CPPFLAGS = $(SHARED_COMMON_COMPILER_FLAGS) +libmm_shared_xmm_la_CPPFLAGS = \ + $(SHARED_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"shared-xmm\" \ + $(NULL) libmm_shared_xmm_la_LDFLAGS = $(SHARED_COMMON_LINKER_FLAGS) libmm_shared_xmm_la_LIBADD = \ $(builddir)/libhelpers-xmm.la \ @@ -340,6 +361,7 @@ libhelpers_telit_la_SOURCES = \ telit/mm-modem-helpers-telit.h \ $(NULL) libhelpers_telit_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"shared-telit\" \ -I$(top_srcdir)/plugins/telit \ -I$(top_builddir)/plugins/telit \ $(NULL) @@ -383,6 +405,7 @@ libmm_shared_telit_la_CPPFLAGS = \ -I$(top_srcdir)/plugins/telit \ -I$(top_builddir)/plugins/telit \ $(SHARED_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"shared-telit\" \ $(NULL) libmm_shared_telit_la_LDFLAGS = $(SHARED_COMMON_LINKER_FLAGS) libmm_shared_telit_la_LIBADD = \ @@ -409,7 +432,10 @@ libmm_shared_foxconn_la_SOURCES = \ foxconn/mm-broadband-modem-foxconn-t77w968.c \ foxconn/mm-broadband-modem-foxconn-t77w968.h \ $(NULL) -libmm_shared_foxconn_la_CPPFLAGS = $(SHARED_COMMON_COMPILER_FLAGS) +libmm_shared_foxconn_la_CPPFLAGS = \ + $(SHARED_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"shared-foxconn\" \ + $(NULL) libmm_shared_foxconn_la_LDFLAGS = $(SHARED_COMMON_LINKER_FLAGS) FOXCONN_COMMON_COMPILER_FLAGS = -I$(top_srcdir)/plugins/foxconn @@ -427,7 +453,10 @@ libmm_plugin_generic_la_SOURCES = \ generic/mm-plugin-generic.c \ generic/mm-plugin-generic.h \ $(NULL) -libmm_plugin_generic_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) +libmm_plugin_generic_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"generic\" \ + $(NULL) libmm_plugin_generic_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) noinst_PROGRAMS += test-service-generic @@ -451,6 +480,9 @@ libhelpers_altair_lte_la_SOURCES = \ altair/mm-modem-helpers-altair-lte.c \ altair/mm-modem-helpers-altair-lte.h \ $(NULL) +libhelpers_altair_lte_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"altair-lte\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-altair-lte test_modem_helpers_altair_lte_SOURCES = \ @@ -474,9 +506,12 @@ libmm_plugin_altair_lte_la_SOURCES = \ altair/mm-broadband-bearer-altair-lte.c \ altair/mm-broadband-bearer-altair-lte.h \ $(NULL) -libmm_plugin_altair_lte_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_altair_lte_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -libmm_plugin_altair_lte_la_LIBADD = $(builddir)/libhelpers-altair-lte.la +libmm_plugin_altair_lte_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"altair-lte\" \ + $(NULL) +libmm_plugin_altair_lte_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_altair_lte_la_LIBADD = $(builddir)/libhelpers-altair-lte.la endif @@ -493,8 +528,11 @@ libmm_plugin_anydata_la_SOURCES = \ anydata/mm-broadband-modem-anydata.h \ anydata/mm-broadband-modem-anydata.c \ $(NULL) -libmm_plugin_anydata_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_anydata_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_anydata_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"anydata\" \ + $(NULL) +libmm_plugin_anydata_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -509,6 +547,9 @@ libhelpers_cinterion_la_SOURCES = \ cinterion/mm-modem-helpers-cinterion.c \ cinterion/mm-modem-helpers-cinterion.h \ $(NULL) +libhelpers_cinterion_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"cinterion\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-cinterion test_modem_helpers_cinterion_SOURCES = \ @@ -540,9 +581,12 @@ libmm_plugin_cinterion_la_SOURCES += \ cinterion/mm-broadband-modem-qmi-cinterion.h \ $(NULL) endif -libmm_plugin_cinterion_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_cinterion_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -libmm_plugin_cinterion_la_LIBADD = $(builddir)/libhelpers-cinterion.la +libmm_plugin_cinterion_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"cinterion\" \ + $(NULL) +libmm_plugin_cinterion_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_cinterion_la_LIBADD = $(builddir)/libhelpers-cinterion.la dist_udevrules_DATA += cinterion/77-mm-cinterion-port-types.rules @@ -569,6 +613,7 @@ libmm_plugin_dell_la_CPPFLAGS = \ $(TELIT_COMMON_COMPILER_FLAGS) \ $(XMM_COMMON_COMPILER_FLAGS) \ $(FOXCONN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"dell\" \ $(NULL) libmm_plugin_dell_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) @@ -591,8 +636,11 @@ libmm_plugin_dlink_la_SOURCES = \ dlink/mm-plugin-dlink.c \ dlink/mm-plugin-dlink.h \ $(NULL) -libmm_plugin_dlink_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_dlink_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_dlink_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"d-link\" \ + $(NULL) +libmm_plugin_dlink_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += dlink/77-mm-dlink-port-types.rules @@ -611,8 +659,12 @@ libmm_plugin_fibocom_la_SOURCES = \ fibocom/mm-plugin-fibocom.c \ fibocom/mm-plugin-fibocom.h \ $(NULL) -libmm_plugin_fibocom_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(XMM_COMMON_COMPILER_FLAGS) -libmm_plugin_fibocom_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_fibocom_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(XMM_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"fibocom\" \ + $(NULL) +libmm_plugin_fibocom_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += fibocom/77-mm-fibocom-port-types.rules @@ -631,8 +683,12 @@ libmm_plugin_foxconn_la_SOURCES = \ foxconn/mm-plugin-foxconn.c \ foxconn/mm-plugin-foxconn.h \ $(NULL) -libmm_plugin_foxconn_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(FOXCONN_COMMON_COMPILER_FLAGS) -libmm_plugin_foxconn_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_foxconn_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(FOXCONN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"foxconn\" \ + $(NULL) +libmm_plugin_foxconn_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += foxconn/77-mm-foxconn-port-types.rules @@ -656,8 +712,11 @@ libmm_plugin_haier_la_SOURCES = \ haier/mm-plugin-haier.c \ haier/mm-plugin-haier.h \ $(NULL) -libmm_plugin_haier_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_haier_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_haier_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"haier\" \ + $(NULL) +libmm_plugin_haier_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += haier/77-mm-haier-port-types.rules @@ -676,6 +735,9 @@ libhelpers_huawei_la_SOURCES = \ huawei/mm-modem-helpers-huawei.c \ huawei/mm-modem-helpers-huawei.h \ $(NULL) +libhelpers_huawei_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"huawei\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-huawei test_modem_helpers_huawei_SOURCES = \ @@ -701,9 +763,12 @@ libmm_plugin_huawei_la_SOURCES = \ huawei/mm-broadband-bearer-huawei.c \ huawei/mm-broadband-bearer-huawei.h \ $(NULL) -libmm_plugin_huawei_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_huawei_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -libmm_plugin_huawei_la_LIBADD = $(builddir)/libhelpers-huawei.la +libmm_plugin_huawei_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"huawei\" \ + $(NULL) +libmm_plugin_huawei_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_huawei_la_LIBADD = $(builddir)/libhelpers-huawei.la dist_udevrules_DATA += huawei/77-mm-huawei-net-port-types.rules @@ -728,8 +793,11 @@ libmm_plugin_iridium_la_SOURCES = \ iridium/mm-sim-iridium.c \ iridium/mm-sim-iridium.h \ $(NULL) -libmm_plugin_iridium_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_iridium_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_iridium_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"iridium\" \ + $(NULL) +libmm_plugin_iridium_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -744,6 +812,9 @@ libhelpers_linktop_la_SOURCES = \ linktop/mm-modem-helpers-linktop.c \ linktop/mm-modem-helpers-linktop.h \ $(NULL) +libhelpers_linktop_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"linktop\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-linktop test_modem_helpers_linktop_SOURCES = \ @@ -765,9 +836,12 @@ libmm_plugin_linktop_la_SOURCES = \ linktop/mm-broadband-modem-linktop.h \ linktop/mm-broadband-modem-linktop.c \ $(NULL) -libmm_plugin_linktop_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_linktop_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -libmm_plugin_linktop_la_LIBADD = $(builddir)/libhelpers-linktop.la +libmm_plugin_linktop_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"linktop\" \ + $(NULL) +libmm_plugin_linktop_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_linktop_la_LIBADD = $(builddir)/libhelpers-linktop.la endif @@ -784,8 +858,11 @@ libmm_plugin_longcheer_la_SOURCES = \ longcheer/mm-broadband-modem-longcheer.h \ longcheer/mm-broadband-modem-longcheer.c \ $(NULL) -libmm_plugin_longcheer_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_longcheer_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_longcheer_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"longcheer\" \ + $(NULL) +libmm_plugin_longcheer_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += longcheer/77-mm-longcheer-port-types.rules @@ -804,6 +881,9 @@ libhelpers_mbm_la_SOURCES = \ mbm/mm-modem-helpers-mbm.c \ mbm/mm-modem-helpers-mbm.h \ $(NULL) +libhelpers_mbm_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"ericsson-mbm\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-mbm test_modem_helpers_mbm_SOURCES = \ @@ -829,9 +909,12 @@ libmm_plugin_ericsson_mbm_la_SOURCES = \ mbm/mm-plugin-mbm.c \ mbm/mm-plugin-mbm.h \ $(NULL) -libmm_plugin_ericsson_mbm_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_ericsson_mbm_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -libmm_plugin_ericsson_mbm_la_LIBADD = $(builddir)/libhelpers-mbm.la +libmm_plugin_ericsson_mbm_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"ericsson-mbm\" \ + $(NULL) +libmm_plugin_ericsson_mbm_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_ericsson_mbm_la_LIBADD = $(builddir)/libhelpers-mbm.la dist_udevrules_DATA += mbm/77-mm-ericsson-mbm.rules @@ -852,8 +935,11 @@ libmm_plugin_motorola_la_SOURCES = \ motorola/mm-broadband-modem-motorola.c \ motorola/mm-broadband-modem-motorola.h \ $(NULL) -libmm_plugin_motorola_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_motorola_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_motorola_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"motorola\" \ + $(NULL) +libmm_plugin_motorola_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -870,8 +956,11 @@ libmm_plugin_mtk_la_SOURCES = \ mtk/mm-broadband-modem-mtk.h \ mtk/mm-broadband-modem-mtk.c \ $(NULL) -libmm_plugin_mtk_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_mtk_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_mtk_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"mtk\" \ + $(NULL) +libmm_plugin_mtk_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += mtk/77-mm-mtk-port-types.rules @@ -894,8 +983,10 @@ libmm_plugin_nokia_la_SOURCES = \ nokia/mm-broadband-modem-nokia.c \ nokia/mm-broadband-modem-nokia.h \ $(NULL) -libmm_plugin_nokia_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_nokia_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_nokia_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"nokia\" \ + $(NULL) +libmm_plugin_nokia_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -910,8 +1001,12 @@ libmm_plugin_nokia_icera_la_SOURCES = \ nokia/mm-plugin-nokia-icera.c \ nokia/mm-plugin-nokia-icera.h \ $(NULL) -libmm_plugin_nokia_icera_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(ICERA_COMMON_COMPILER_FLAGS) -libmm_plugin_nokia_icera_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_nokia_icera_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(ICERA_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"nokia-icera\" \ + $(NULL) +libmm_plugin_nokia_icera_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += nokia/77-mm-nokia-port-types.rules @@ -930,8 +1025,12 @@ libmm_plugin_novatel_la_SOURCES = \ novatel/mm-plugin-novatel.c \ novatel/mm-plugin-novatel.h \ $(NULL) -libmm_plugin_novatel_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(NOVATEL_COMMON_COMPILER_FLAGS) -libmm_plugin_novatel_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_novatel_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(NOVATEL_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"novatel\" \ + $(NULL) +libmm_plugin_novatel_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -952,8 +1051,11 @@ libmm_plugin_novatel_lte_la_SOURCES = \ novatel/mm-sim-novatel-lte.c \ novatel/mm-sim-novatel-lte.h \ $(NULL) -libmm_plugin_novatel_lte_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_novatel_lte_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_novatel_lte_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"novatel-lte\" \ + $(NULL) +libmm_plugin_novatel_lte_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -968,8 +1070,12 @@ libmm_plugin_option_la_SOURCES = \ option/mm-plugin-option.c \ option/mm-plugin-option.h \ $(NULL) -libmm_plugin_option_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(OPTION_COMMON_COMPILER_FLAGS) -libmm_plugin_option_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_option_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(OPTION_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"option\" \ + $(NULL) +libmm_plugin_option_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -988,8 +1094,12 @@ libmm_plugin_option_hso_la_SOURCES = \ option/mm-broadband-modem-hso.c \ option/mm-broadband-modem-hso.h \ $(NULL) -libmm_plugin_option_hso_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(OPTION_COMMON_COMPILER_FLAGS) -libmm_plugin_option_hso_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_option_hso_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(OPTION_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"option-hso\" \ + $(NULL) +libmm_plugin_option_hso_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -1008,8 +1118,11 @@ libmm_plugin_pantech_la_SOURCES = \ pantech/mm-broadband-modem-pantech.c \ pantech/mm-broadband-modem-pantech.h \ $(NULL) -libmm_plugin_pantech_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_pantech_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_pantech_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"pantech\" \ + $(NULL) +libmm_plugin_pantech_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -1036,8 +1149,11 @@ libmm_plugin_quectel_la_SOURCES += \ quectel/mm-broadband-modem-qmi-quectel.h \ $(NULL) endif -libmm_plugin_quectel_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_quectel_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_quectel_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"quectel\" \ + $(NULL) +libmm_plugin_quectel_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -1054,7 +1170,11 @@ libmm_plugin_samsung_la_SOURCES = \ samsung/mm-broadband-modem-samsung.c \ samsung/mm-broadband-modem-samsung.h \ $(NULL) -libmm_plugin_samsung_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(ICERA_COMMON_COMPILER_FLAGS) +libmm_plugin_samsung_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(ICERA_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"samsumg\" \ + $(NULL) libmm_plugin_samsung_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -1072,8 +1192,13 @@ libmm_plugin_sierra_legacy_la_SOURCES = \ sierra/mm-broadband-modem-sierra-icera.c \ sierra/mm-broadband-modem-sierra-icera.h \ $(NULL) -libmm_plugin_sierra_legacy_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(ICERA_COMMON_COMPILER_FLAGS) $(SIERRA_COMMON_COMPILER_FLAGS) -libmm_plugin_sierra_legacy_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_sierra_legacy_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(ICERA_COMMON_COMPILER_FLAGS) \ + $(SIERRA_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"sierra-legacy\" \ + $(NULL) +libmm_plugin_sierra_legacy_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -1090,8 +1215,11 @@ libmm_plugin_sierra_la_SOURCES = \ sierra/mm-plugin-sierra.c \ sierra/mm-plugin-sierra.h \ $(NULL) -libmm_plugin_sierra_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_sierra_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_sierra_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"sierra\" \ + $(NULL) +libmm_plugin_sierra_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -1106,6 +1234,9 @@ libhelpers_simtech_la_SOURCES = \ simtech/mm-modem-helpers-simtech.c \ simtech/mm-modem-helpers-simtech.h \ $(NULL) +libhelpers_simtech_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"simtech\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-simtech test_modem_helpers_simtech_SOURCES = \ @@ -1135,9 +1266,12 @@ libmm_plugin_simtech_la_SOURCES += \ simtech/mm-broadband-modem-qmi-simtech.h \ $(NULL) endif -libmm_plugin_simtech_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_simtech_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -libmm_plugin_simtech_la_LIBADD = $(builddir)/libhelpers-simtech.la +libmm_plugin_simtech_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"simtech\" \ + $(NULL) +libmm_plugin_simtech_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_simtech_la_LIBADD = $(builddir)/libhelpers-simtech.la dist_udevrules_DATA += simtech/77-mm-simtech-port-types.rules @@ -1156,8 +1290,12 @@ libmm_plugin_telit_la_SOURCES = \ telit/mm-plugin-telit.c \ telit/mm-plugin-telit.h \ $(NULL) -libmm_plugin_telit_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(TELIT_COMMON_COMPILER_FLAGS) -libmm_plugin_telit_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_telit_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(TELIT_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"telit\" \ + $(NULL) +libmm_plugin_telit_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += telit/77-mm-telit-port-types.rules @@ -1176,6 +1314,9 @@ libhelpers_thuraya_la_SOURCES = \ thuraya/mm-modem-helpers-thuraya.c \ thuraya/mm-modem-helpers-thuraya.h \ $(NULL) +libhelpers_thuraya_la_CPPFLAGS = \ + -DMM_MODULE_NAME=\"thuraya\" \ + $(NULL) noinst_PROGRAMS += test-modem-helpers-thuraya test_modem_helpers_thuraya_SOURCES = \ @@ -1198,9 +1339,12 @@ libmm_plugin_thuraya_la_SOURCES = \ thuraya/mm-broadband-modem-thuraya.c \ thuraya/mm-broadband-modem-thuraya.h \ $(NULL) -libmm_plugin_thuraya_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_thuraya_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -libmm_plugin_thuraya_la_LIBADD = $(builddir)/libhelpers-thuraya.la +libmm_plugin_thuraya_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"thuraya\" \ + $(NULL) +libmm_plugin_thuraya_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_thuraya_la_LIBADD = $(builddir)/libhelpers-thuraya.la endif @@ -1215,8 +1359,11 @@ libmm_plugin_tplink_la_SOURCES = \ tplink/mm-plugin-tplink.c \ tplink/mm-plugin-tplink.h \ $(NULL) -libmm_plugin_tplink_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_tplink_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_tplink_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"tp-link\" \ + $(NULL) +libmm_plugin_tplink_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += tplink/77-mm-tplink-port-types.rules @@ -1272,7 +1419,10 @@ libhelpers_ublox_la_SOURCES = \ nodist_libhelpers_ublox_la_SOURCES = $(UBLOX_ENUMS_GENERATED) -libhelpers_ublox_la_CPPFLAGS = $(PLUGIN_UBLOX_COMPILER_FLAGS) +libhelpers_ublox_la_CPPFLAGS = \ + $(PLUGIN_UBLOX_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"u-blox\" \ + $(NULL) BUILT_SOURCES += $(UBLOX_ENUMS_GENERATED) CLEANFILES += $(UBLOX_ENUMS_GENERATED) @@ -1303,9 +1453,13 @@ libmm_plugin_ublox_la_SOURCES = \ ublox/mm-sim-ublox.c \ ublox/mm-sim-ublox.h \ $(NULL) -libmm_plugin_ublox_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(PLUGIN_UBLOX_COMPILER_FLAGS) -libmm_plugin_ublox_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -libmm_plugin_ublox_la_LIBADD = $(builddir)/libhelpers-ublox.la +libmm_plugin_ublox_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(PLUGIN_UBLOX_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"u-blox\" \ + $(NULL) +libmm_plugin_ublox_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_ublox_la_LIBADD = $(builddir)/libhelpers-ublox.la endif @@ -1322,8 +1476,11 @@ libmm_plugin_via_la_SOURCES = \ via/mm-broadband-modem-via.c \ via/mm-broadband-modem-via.h \ $(NULL) -libmm_plugin_via_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_via_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_via_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"via\" \ + $(NULL) +libmm_plugin_via_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -1340,8 +1497,11 @@ libmm_plugin_wavecom_la_SOURCES = \ wavecom/mm-broadband-modem-wavecom.c \ wavecom/mm-broadband-modem-wavecom.h \ $(NULL) -libmm_plugin_wavecom_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_wavecom_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_wavecom_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"wavecom\" \ + $(NULL) +libmm_plugin_wavecom_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif @@ -1358,8 +1518,11 @@ libmm_plugin_x22x_la_SOURCES = \ x22x/mm-broadband-modem-x22x.h \ x22x/mm-broadband-modem-x22x.c \ $(NULL) -libmm_plugin_x22x_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -libmm_plugin_x22x_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_x22x_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"x22x\" \ + $(NULL) +libmm_plugin_x22x_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += x22x/77-mm-x22x-port-types.rules @@ -1384,8 +1547,12 @@ libmm_plugin_zte_la_SOURCES = \ zte/mm-broadband-modem-zte-icera.h \ zte/mm-broadband-modem-zte-icera.c \ $(NULL) -libmm_plugin_zte_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) $(ICERA_COMMON_COMPILER_FLAGS) -libmm_plugin_zte_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +libmm_plugin_zte_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(ICERA_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"zte\" \ + $(NULL) +libmm_plugin_zte_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += zte/77-mm-zte-port-types.rules diff --git a/src/mm-log-test.h b/src/mm-log-test.h index 056de53b..22493d6d 100644 --- a/src/mm-log-test.h +++ b/src/mm-log-test.h @@ -23,6 +23,7 @@ void _mm_log (gpointer obj, + const gchar *module, const gchar *loc, const gchar *func, guint32 level, diff --git a/src/mm-log.c b/src/mm-log.c index 339e7955..658e0c12 100644 --- a/src/mm-log.c +++ b/src/mm-log.c @@ -203,6 +203,7 @@ log_backend_systemd_journal (const char *loc, void _mm_log (gpointer obj, + const gchar *module, const gchar *loc, const gchar *func, MMLogLevel level, @@ -248,6 +249,8 @@ _mm_log (gpointer obj, if (obj) g_string_append_printf (msgbuf, "[%s] ", mm_log_object_get_id (MM_LOG_OBJECT (obj))); + if (module) + g_string_append_printf (msgbuf, "(%s) ", module); va_start (args, fmt); g_string_append_vprintf (msgbuf, fmt, args); diff --git a/src/mm-log.h b/src/mm-log.h index 0145c9aa..d33cef9f 100644 --- a/src/mm-log.h +++ b/src/mm-log.h @@ -27,10 +27,14 @@ typedef enum { MM_LOG_LEVEL_DEBUG = 0x00000008 } MMLogLevel; -#define mm_obj_err(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_ERR, ## __VA_ARGS__ ) -#define mm_obj_warn(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_WARN, ## __VA_ARGS__ ) -#define mm_obj_info(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_INFO, ## __VA_ARGS__ ) -#define mm_obj_dbg(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_DEBUG, ## __VA_ARGS__ ) +#if !defined MM_MODULE_NAME +# define MM_MODULE_NAME (const gchar *)NULL +#endif + +#define mm_obj_err(obj, ...) _mm_log (obj, MM_MODULE_NAME, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_ERR, ## __VA_ARGS__ ) +#define mm_obj_warn(obj, ...) _mm_log (obj, MM_MODULE_NAME, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_WARN, ## __VA_ARGS__ ) +#define mm_obj_info(obj, ...) _mm_log (obj, MM_MODULE_NAME, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_INFO, ## __VA_ARGS__ ) +#define mm_obj_dbg(obj, ...) _mm_log (obj, MM_MODULE_NAME, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_DEBUG, ## __VA_ARGS__ ) #define mm_err(...) mm_obj_err (NULL, ## __VA_ARGS__ ) #define mm_warn(...) mm_obj_warn (NULL, ## __VA_ARGS__ ) @@ -38,11 +42,12 @@ typedef enum { #define mm_dbg(...) mm_obj_dbg (NULL, ## __VA_ARGS__ ) void _mm_log (gpointer obj, + const gchar *module, const gchar *loc, const gchar *func, MMLogLevel level, const gchar *fmt, - ...) __attribute__((__format__ (__printf__, 5, 6))); + ...) __attribute__((__format__ (__printf__, 6, 7))); gboolean mm_log_set_level (const char *level, GError **error); From 8722215f7e6ceb00c692fc94c1915ad2671ca1ae Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 16:07:58 +0200 Subject: [PATCH 132/675] plugins: use logging module name as plugin name --- plugins/altair/mm-plugin-altair-lte.c | 2 +- plugins/anydata/mm-plugin-anydata.c | 2 +- plugins/cinterion/mm-plugin-cinterion.c | 2 +- plugins/dell/mm-plugin-dell.c | 2 +- plugins/dlink/mm-plugin-dlink.c | 2 +- plugins/fibocom/mm-plugin-fibocom.c | 2 +- plugins/foxconn/mm-plugin-foxconn.c | 2 +- plugins/haier/mm-plugin-haier.c | 2 +- plugins/huawei/mm-plugin-huawei.c | 2 +- plugins/iridium/mm-plugin-iridium.c | 2 +- plugins/linktop/mm-plugin-linktop.c | 2 +- plugins/longcheer/mm-plugin-longcheer.c | 2 +- plugins/mbm/mm-plugin-mbm.c | 2 +- plugins/motorola/mm-plugin-motorola.c | 2 +- plugins/mtk/mm-plugin-mtk.c | 2 +- plugins/nokia/mm-plugin-nokia-icera.c | 2 +- plugins/nokia/mm-plugin-nokia.c | 2 +- plugins/novatel/mm-plugin-novatel-lte.c | 2 +- plugins/novatel/mm-plugin-novatel.c | 2 +- plugins/option/mm-plugin-hso.c | 2 +- plugins/option/mm-plugin-option.c | 2 +- plugins/pantech/mm-plugin-pantech.c | 2 +- plugins/quectel/mm-plugin-quectel.c | 2 +- plugins/samsung/mm-plugin-samsung.c | 2 +- plugins/sierra/mm-plugin-sierra-legacy.c | 2 +- plugins/sierra/mm-plugin-sierra.c | 2 +- plugins/simtech/mm-plugin-simtech.c | 2 +- plugins/telit/mm-plugin-telit.c | 2 +- plugins/thuraya/mm-plugin-thuraya.c | 8 ++++---- plugins/tplink/mm-plugin-tplink.c | 2 +- plugins/ublox/mm-plugin-ublox.c | 2 +- plugins/via/mm-plugin-via.c | 2 +- plugins/wavecom/mm-plugin-wavecom.c | 2 +- plugins/x22x/mm-plugin-x22x.c | 2 +- plugins/zte/mm-plugin-zte.c | 2 +- 35 files changed, 38 insertions(+), 38 deletions(-) diff --git a/plugins/altair/mm-plugin-altair-lte.c b/plugins/altair/mm-plugin-altair-lte.c index 7f6a7c0b..054a600f 100644 --- a/plugins/altair/mm-plugin-altair-lte.c +++ b/plugins/altair/mm-plugin-altair-lte.c @@ -77,7 +77,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_ALTAIR_LTE, - MM_PLUGIN_NAME, "Altair LTE", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_PRODUCT_IDS, products, MM_PLUGIN_CUSTOM_AT_PROBE, custom_at_probe, diff --git a/plugins/anydata/mm-plugin-anydata.c b/plugins/anydata/mm-plugin-anydata.c index 62039022..cc118963 100644 --- a/plugins/anydata/mm-plugin-anydata.c +++ b/plugins/anydata/mm-plugin-anydata.c @@ -73,7 +73,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_ANYDATA, - MM_PLUGIN_NAME, "AnyDATA", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/cinterion/mm-plugin-cinterion.c b/plugins/cinterion/mm-plugin-cinterion.c index 30c0f481..5fdd48b5 100644 --- a/plugins/cinterion/mm-plugin-cinterion.c +++ b/plugins/cinterion/mm-plugin-cinterion.c @@ -176,7 +176,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_CINTERION, - MM_PLUGIN_NAME, "Cinterion", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_STRINGS, vendor_strings, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, diff --git a/plugins/dell/mm-plugin-dell.c b/plugins/dell/mm-plugin-dell.c index 1d383ede..cc0d803b 100644 --- a/plugins/dell/mm-plugin-dell.c +++ b/plugins/dell/mm-plugin-dell.c @@ -500,7 +500,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_DELL, - MM_PLUGIN_NAME, "Dell", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendors, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/dlink/mm-plugin-dlink.c b/plugins/dlink/mm-plugin-dlink.c index d891ee88..46c96088 100644 --- a/plugins/dlink/mm-plugin-dlink.c +++ b/plugins/dlink/mm-plugin-dlink.c @@ -72,7 +72,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_DLINK, - MM_PLUGIN_NAME, "D-Link", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/fibocom/mm-plugin-fibocom.c b/plugins/fibocom/mm-plugin-fibocom.c index 8447ab60..7916b536 100644 --- a/plugins/fibocom/mm-plugin-fibocom.c +++ b/plugins/fibocom/mm-plugin-fibocom.c @@ -92,7 +92,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_FIBOCOM, - MM_PLUGIN_NAME, "Fibocom", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_DRIVERS, drivers, diff --git a/plugins/foxconn/mm-plugin-foxconn.c b/plugins/foxconn/mm-plugin-foxconn.c index 5a2c6120..1ad0681b 100644 --- a/plugins/foxconn/mm-plugin-foxconn.c +++ b/plugins/foxconn/mm-plugin-foxconn.c @@ -103,7 +103,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_FOXCONN, - MM_PLUGIN_NAME, "Foxconn", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendors, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/haier/mm-plugin-haier.c b/plugins/haier/mm-plugin-haier.c index 27f67dcf..0c11aeb6 100644 --- a/plugins/haier/mm-plugin-haier.c +++ b/plugins/haier/mm-plugin-haier.c @@ -54,7 +54,7 @@ mm_plugin_create (void) static const guint16 vendor_ids[] = { 0x201e, 0 }; return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_HAIER, - MM_PLUGIN_NAME, "Haier", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/huawei/mm-plugin-huawei.c b/plugins/huawei/mm-plugin-huawei.c index 2f6febfa..ea87c7e6 100644 --- a/plugins/huawei/mm-plugin-huawei.c +++ b/plugins/huawei/mm-plugin-huawei.c @@ -599,7 +599,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_HUAWEI, - MM_PLUGIN_NAME, "Huawei", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/iridium/mm-plugin-iridium.c b/plugins/iridium/mm-plugin-iridium.c index 1ae8a3f9..582d86a3 100644 --- a/plugins/iridium/mm-plugin-iridium.c +++ b/plugins/iridium/mm-plugin-iridium.c @@ -65,7 +65,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_IRIDIUM, - MM_PLUGIN_NAME, "Iridium", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_STRINGS, vendor_strings, MM_PLUGIN_ALLOWED_PRODUCT_STRINGS, product_strings, diff --git a/plugins/linktop/mm-plugin-linktop.c b/plugins/linktop/mm-plugin-linktop.c index 771f335f..d4b0bdc9 100644 --- a/plugins/linktop/mm-plugin-linktop.c +++ b/plugins/linktop/mm-plugin-linktop.c @@ -57,7 +57,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_LINKTOP, - MM_PLUGIN_NAME, "Linktop", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/longcheer/mm-plugin-longcheer.c b/plugins/longcheer/mm-plugin-longcheer.c index e2d4230e..74f6ae7a 100644 --- a/plugins/longcheer/mm-plugin-longcheer.c +++ b/plugins/longcheer/mm-plugin-longcheer.c @@ -219,7 +219,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_LONGCHEER, - MM_PLUGIN_NAME, "Longcheer", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/mbm/mm-plugin-mbm.c b/plugins/mbm/mm-plugin-mbm.c index b27cbf64..cae41d85 100644 --- a/plugins/mbm/mm-plugin-mbm.c +++ b/plugins/mbm/mm-plugin-mbm.c @@ -78,7 +78,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_MBM, - MM_PLUGIN_NAME, "Ericsson MBM", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_UDEV_TAGS, udev_tags, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/motorola/mm-plugin-motorola.c b/plugins/motorola/mm-plugin-motorola.c index 68c8d483..368e898b 100644 --- a/plugins/motorola/mm-plugin-motorola.c +++ b/plugins/motorola/mm-plugin-motorola.c @@ -62,7 +62,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_MOTOROLA, - MM_PLUGIN_NAME, "Motorola", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_PRODUCT_IDS, product_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/mtk/mm-plugin-mtk.c b/plugins/mtk/mm-plugin-mtk.c index 6adfa845..5a4ea1c1 100644 --- a/plugins/mtk/mm-plugin-mtk.c +++ b/plugins/mtk/mm-plugin-mtk.c @@ -60,7 +60,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_MTK, - MM_PLUGIN_NAME, "MTK", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_UDEV_TAGS, udev_tags, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/nokia/mm-plugin-nokia-icera.c b/plugins/nokia/mm-plugin-nokia-icera.c index 1d0af832..f8cbc432 100644 --- a/plugins/nokia/mm-plugin-nokia-icera.c +++ b/plugins/nokia/mm-plugin-nokia-icera.c @@ -66,7 +66,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_NOKIA_ICERA, - MM_PLUGIN_NAME, "Nokia (Icera)", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_CUSTOM_AT_PROBE, custom_at_probe, diff --git a/plugins/nokia/mm-plugin-nokia.c b/plugins/nokia/mm-plugin-nokia.c index 03c44c68..29b8c8ff 100644 --- a/plugins/nokia/mm-plugin-nokia.c +++ b/plugins/nokia/mm-plugin-nokia.c @@ -68,7 +68,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_NOKIA, - MM_PLUGIN_NAME, "Nokia", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_VENDOR_STRINGS, vendor_strings, diff --git a/plugins/novatel/mm-plugin-novatel-lte.c b/plugins/novatel/mm-plugin-novatel-lte.c index e9bf9c35..18aac32c 100644 --- a/plugins/novatel/mm-plugin-novatel-lte.c +++ b/plugins/novatel/mm-plugin-novatel-lte.c @@ -59,7 +59,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_NOVATEL_LTE, - MM_PLUGIN_NAME, "Novatel LTE", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_PRODUCT_IDS, products, MM_PLUGIN_ALLOWED_SINGLE_AT, TRUE, diff --git a/plugins/novatel/mm-plugin-novatel.c b/plugins/novatel/mm-plugin-novatel.c index 91662f7c..f90a8788 100644 --- a/plugins/novatel/mm-plugin-novatel.c +++ b/plugins/novatel/mm-plugin-novatel.c @@ -87,7 +87,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_NOVATEL, - MM_PLUGIN_NAME, "Novatel", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendors, MM_PLUGIN_FORBIDDEN_PRODUCT_IDS, forbidden_products, diff --git a/plugins/option/mm-plugin-hso.c b/plugins/option/mm-plugin-hso.c index 3fce21df..dbc41c11 100644 --- a/plugins/option/mm-plugin-hso.c +++ b/plugins/option/mm-plugin-hso.c @@ -176,7 +176,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_HSO, - MM_PLUGIN_NAME, "Option High-Speed", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_DRIVERS, drivers, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/option/mm-plugin-option.c b/plugins/option/mm-plugin-option.c index 93965370..3ba183ec 100644 --- a/plugins/option/mm-plugin-option.c +++ b/plugins/option/mm-plugin-option.c @@ -97,7 +97,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_OPTION, - MM_PLUGIN_NAME, "Option", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_DRIVERS, drivers, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, diff --git a/plugins/pantech/mm-plugin-pantech.c b/plugins/pantech/mm-plugin-pantech.c index 4ba7b1e1..5301ea94 100644 --- a/plugins/pantech/mm-plugin-pantech.c +++ b/plugins/pantech/mm-plugin-pantech.c @@ -135,7 +135,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_PANTECH, - MM_PLUGIN_NAME, "Pantech", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/quectel/mm-plugin-quectel.c b/plugins/quectel/mm-plugin-quectel.c index bca81f32..12e4612e 100644 --- a/plugins/quectel/mm-plugin-quectel.c +++ b/plugins/quectel/mm-plugin-quectel.c @@ -72,7 +72,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_QUECTEL, - MM_PLUGIN_NAME, "Quectel", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_VENDOR_STRINGS, vendor_strings, diff --git a/plugins/samsung/mm-plugin-samsung.c b/plugins/samsung/mm-plugin-samsung.c index 2b634a6e..18b0b9d3 100644 --- a/plugins/samsung/mm-plugin-samsung.c +++ b/plugins/samsung/mm-plugin-samsung.c @@ -60,7 +60,7 @@ mm_plugin_create (void) { 0, 0 } }; return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_SAMSUNG, - MM_PLUGIN_NAME, "Samsung", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_PRODUCT_IDS, products, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/sierra/mm-plugin-sierra-legacy.c b/plugins/sierra/mm-plugin-sierra-legacy.c index d7d7a03e..ebbca1b0 100644 --- a/plugins/sierra/mm-plugin-sierra-legacy.c +++ b/plugins/sierra/mm-plugin-sierra-legacy.c @@ -72,7 +72,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_SIERRA_LEGACY, - MM_PLUGIN_NAME, "Sierra (legacy)", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_DRIVERS, drivers, MM_PLUGIN_FORBIDDEN_DRIVERS, forbidden_drivers, diff --git a/plugins/sierra/mm-plugin-sierra.c b/plugins/sierra/mm-plugin-sierra.c index 99871a4a..6622c5e1 100644 --- a/plugins/sierra/mm-plugin-sierra.c +++ b/plugins/sierra/mm-plugin-sierra.c @@ -91,7 +91,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_SIERRA, - MM_PLUGIN_NAME, "Sierra", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_DRIVERS, drivers, diff --git a/plugins/simtech/mm-plugin-simtech.c b/plugins/simtech/mm-plugin-simtech.c index 9940573b..48daa842 100644 --- a/plugins/simtech/mm-plugin-simtech.c +++ b/plugins/simtech/mm-plugin-simtech.c @@ -74,7 +74,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_SIMTECH, - MM_PLUGIN_NAME, "SimTech", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/telit/mm-plugin-telit.c b/plugins/telit/mm-plugin-telit.c index 926ce977..aa6f52ab 100644 --- a/plugins/telit/mm-plugin-telit.c +++ b/plugins/telit/mm-plugin-telit.c @@ -99,7 +99,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_TELIT, - MM_PLUGIN_NAME, "Telit", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_VENDOR_STRINGS, vendor_strings, diff --git a/plugins/thuraya/mm-plugin-thuraya.c b/plugins/thuraya/mm-plugin-thuraya.c index 9db3d61e..64e1b452 100644 --- a/plugins/thuraya/mm-plugin-thuraya.c +++ b/plugins/thuraya/mm-plugin-thuraya.c @@ -63,10 +63,10 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_THURAYA, - MM_PLUGIN_NAME, "Thuraya", - MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, - MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, - MM_PLUGIN_ALLOWED_AT, TRUE, + MM_PLUGIN_NAME, MM_MODULE_NAME, + MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, + MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, + MM_PLUGIN_ALLOWED_AT, TRUE, NULL)); } diff --git a/plugins/tplink/mm-plugin-tplink.c b/plugins/tplink/mm-plugin-tplink.c index 93fde158..da70d0f9 100644 --- a/plugins/tplink/mm-plugin-tplink.c +++ b/plugins/tplink/mm-plugin-tplink.c @@ -72,7 +72,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_TPLINK, - MM_PLUGIN_NAME, "TP-Link", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/ublox/mm-plugin-ublox.c b/plugins/ublox/mm-plugin-ublox.c index 39d3ded1..569054b9 100644 --- a/plugins/ublox/mm-plugin-ublox.c +++ b/plugins/ublox/mm-plugin-ublox.c @@ -240,7 +240,7 @@ mm_plugin_create (void) }; return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_UBLOX, - MM_PLUGIN_NAME, "u-blox", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_VENDOR_STRINGS, vendor_strings, diff --git a/plugins/via/mm-plugin-via.c b/plugins/via/mm-plugin-via.c index 8951af87..f12c6508 100644 --- a/plugins/via/mm-plugin-via.c +++ b/plugins/via/mm-plugin-via.c @@ -61,7 +61,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_VIA, - MM_PLUGIN_NAME, "Via CBP7", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_PRODUCT_STRINGS, product_strings, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/wavecom/mm-plugin-wavecom.c b/plugins/wavecom/mm-plugin-wavecom.c index 8ed217bd..22b1ba4c 100644 --- a/plugins/wavecom/mm-plugin-wavecom.c +++ b/plugins/wavecom/mm-plugin-wavecom.c @@ -65,7 +65,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_WAVECOM, - MM_PLUGIN_NAME, "Wavecom", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_FORBIDDEN_DRIVERS, forbidden_drivers, diff --git a/plugins/x22x/mm-plugin-x22x.c b/plugins/x22x/mm-plugin-x22x.c index 4ec03a71..248d5fd9 100644 --- a/plugins/x22x/mm-plugin-x22x.c +++ b/plugins/x22x/mm-plugin-x22x.c @@ -230,7 +230,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_X22X, - MM_PLUGIN_NAME, "X22X", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, diff --git a/plugins/zte/mm-plugin-zte.c b/plugins/zte/mm-plugin-zte.c index ee5fdc74..f2d6e003 100644 --- a/plugins/zte/mm-plugin-zte.c +++ b/plugins/zte/mm-plugin-zte.c @@ -149,7 +149,7 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_ZTE, - MM_PLUGIN_NAME, "ZTE", + MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_CUSTOM_AT_PROBE, custom_at_probe, From 4b058872a092fa85413fa905c37a6a1510a7a056 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 16:14:00 +0200 Subject: [PATCH 133/675] plugins: don't add plugin name in log message explicitly --- plugins/altair/mm-broadband-modem-altair-lte.c | 2 +- .../cinterion/mm-broadband-bearer-cinterion.c | 16 ++++++++-------- plugins/huawei/mm-broadband-modem-huawei.c | 4 ++-- plugins/huawei/mm-plugin-huawei.c | 14 +++++++------- plugins/longcheer/mm-plugin-longcheer.c | 6 +++--- plugins/novatel/mm-broadband-modem-novatel.c | 6 +++--- plugins/novatel/mm-common-novatel.c | 8 ++++---- plugins/sierra/mm-common-sierra.c | 6 +++--- plugins/ublox/mm-broadband-bearer-ublox.c | 4 ++-- plugins/zte/mm-plugin-zte.c | 2 +- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/plugins/altair/mm-broadband-modem-altair-lte.c b/plugins/altair/mm-broadband-modem-altair-lte.c index 5fafd94e..c2965e8d 100644 --- a/plugins/altair/mm-broadband-modem-altair-lte.c +++ b/plugins/altair/mm-broadband-modem-altair-lte.c @@ -708,7 +708,7 @@ altair_statcm_changed (MMPortSerialAt *port, mm_get_int_from_match_info (match_info, 1, &pdn_event); - mm_obj_dbg (self, "altair PDN event detected: %d", pdn_event); + mm_obj_dbg (self, "PDN event detected: %d", pdn_event); /* Currently we only care about bearer disconnection */ diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index 2f895efb..e1a06135 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -402,7 +402,7 @@ dial_3gpp_context_step (GTask *task) command = build_auth_string (self, mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)), ctx->cid); if (command) { - mm_obj_dbg (self, "cinterion dial step %u/%u: authenticating...", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); + mm_obj_dbg (self, "dial step %u/%u: authenticating...", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); /* Send SGAUTH write, if User & Pass are provided. * advance to next state by callback */ mm_base_modem_at_command_full (ctx->modem, @@ -418,14 +418,14 @@ dial_3gpp_context_step (GTask *task) return; } - mm_obj_dbg (self, "cinterion dial step %u/%u: authentication not required", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); + mm_obj_dbg (self, "dial step %u/%u: authentication not required", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); ctx->step++; } /* fall through */ case DIAL_3GPP_CONTEXT_STEP_START_SWWAN: { gchar *command; - mm_obj_dbg (self, "cinterion dial step %u/%u: starting SWWAN interface %u connection...", + mm_obj_dbg (self, "dial step %u/%u: starting SWWAN interface %u connection...", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); command = g_strdup_printf ("^SWWAN=1,%u,%u", ctx->cid, @@ -444,7 +444,7 @@ dial_3gpp_context_step (GTask *task) } case DIAL_3GPP_CONTEXT_STEP_VALIDATE_CONNECTION: - mm_obj_dbg (self, "cinterion dial step %u/%u: checking SWWAN interface %u status...", + mm_obj_dbg (self, "dial step %u/%u: checking SWWAN interface %u status...", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); load_connection_status_by_cid (ctx->self, ctx->cid, @@ -453,7 +453,7 @@ dial_3gpp_context_step (GTask *task) return; case DIAL_3GPP_CONTEXT_STEP_LAST: - mm_obj_dbg (self, "cinterion dial step %u/%u: finished", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); + mm_obj_dbg (self, "dial step %u/%u: finished", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); g_task_return_pointer (task, g_object_ref (ctx->data), g_object_unref); g_object_unref (task); return; @@ -625,7 +625,7 @@ disconnect_3gpp_context_step (GTask *task) command = g_strdup_printf ("^SWWAN=0,%u,%u", ctx->cid, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); - mm_obj_dbg (self, "cinterion disconnect step %u/%u: disconnecting PDP CID %u...", + mm_obj_dbg (self, "disconnect step %u/%u: disconnecting PDP CID %u...", ctx->step, DISCONNECT_3GPP_CONTEXT_STEP_LAST, ctx->cid); mm_base_modem_at_command_full (ctx->modem, ctx->primary, @@ -641,7 +641,7 @@ disconnect_3gpp_context_step (GTask *task) } case DISCONNECT_3GPP_CONTEXT_STEP_CONNECTION_STATUS: - mm_obj_dbg (self, "cinterion disconnect step %u/%u: checking SWWAN interface %u status...", + mm_obj_dbg (self, "disconnect step %u/%u: checking SWWAN interface %u status...", ctx->step, DISCONNECT_3GPP_CONTEXT_STEP_LAST, usb_interface_configs[ctx->usb_interface_config_index].swwan_index); load_connection_status_by_cid (MM_BROADBAND_BEARER_CINTERION (ctx->self), @@ -651,7 +651,7 @@ disconnect_3gpp_context_step (GTask *task) return; case DISCONNECT_3GPP_CONTEXT_STEP_LAST: - mm_obj_dbg (self, "cinterion disconnect step %u/%u: finished", + mm_obj_dbg (self, "disconnect step %u/%u: finished", ctx->step, DISCONNECT_3GPP_CONTEXT_STEP_LAST); g_task_return_boolean (task, TRUE); g_object_unref (task); diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index e6f45750..bf009f29 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2890,7 +2890,7 @@ cvoice_check_ready (MMBaseModem *_self, &self->priv->audio_bits, &error)) { self->priv->cvoice_support = FEATURE_NOT_SUPPORTED; - mm_obj_dbg (self, "Huawei-specific CVOICE is unsupported: %s", error->message); + mm_obj_dbg (self, "CVOICE is unsupported: %s", error->message); g_clear_error (&error); /* Now check generic support */ @@ -2900,7 +2900,7 @@ cvoice_check_ready (MMBaseModem *_self, return; } - mm_obj_dbg (self, "Huawei-specific CVOICE is supported"); + mm_obj_dbg (self, "CVOICE is supported"); self->priv->cvoice_support = FEATURE_SUPPORTED; g_task_return_boolean (task, TRUE); g_object_unref (task); diff --git a/plugins/huawei/mm-plugin-huawei.c b/plugins/huawei/mm-plugin-huawei.c index ea87c7e6..b9118ece 100644 --- a/plugins/huawei/mm-plugin-huawei.c +++ b/plugins/huawei/mm-plugin-huawei.c @@ -152,7 +152,7 @@ getportmode_ready (MMPortSerialAt *port, MMDevice *device; guint n_cached_port_modes = 0; - mm_obj_dbg (probe, "(Huawei) port mode layout retrieved"); + mm_obj_dbg (probe, "port mode layout retrieved"); /* Results are cached in the parent device object */ device = mm_port_probe_peek_device (probe); @@ -200,10 +200,10 @@ curc_ready (MMPortSerialAt *port, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) goto out; - mm_obj_dbg (probe, "(Huawei) couldn't turn off unsolicited messages in secondary ports: %s", error->message); + mm_obj_dbg (probe, "couldn't turn off unsolicited messages in secondary ports: %s", error->message); } - mm_obj_dbg (probe, "(Huawei) unsolicited messages in secondary ports turned off"); + mm_obj_dbg (probe, "unsolicited messages in secondary ports turned off"); ctx->curc_done = TRUE; @@ -245,9 +245,9 @@ try_next_usbif (MMPortProbe *probe, if (closest == G_MAXUINT) { /* No more ttys to try! Just return something */ closest = 0; - mm_obj_dbg (probe, "(Huawei) no more ports to run initial probing"); + mm_obj_dbg (probe, "no more ports to run initial probing"); } else - mm_obj_dbg (probe, "(Huawei) will try initial probing with interface '%d' instead", closest); + mm_obj_dbg (probe, "will try initial probing with interface '%d' instead", closest); fi_ctx->first_usbif = closest; } @@ -265,7 +265,7 @@ huawei_custom_init_step (GTask *task) /* If cancelled, end */ if (g_task_return_error_if_cancelled (task)) { - mm_obj_dbg (probe, "(Huawei) no need to keep on running custom init"); + mm_obj_dbg (probe, "no need to keep on running custom init"); g_object_unref (task); return; } @@ -571,7 +571,7 @@ grab_port (MMPlugin *self, gchar *str; str = mm_port_serial_at_flag_build_string_from_mask (pflags); - mm_obj_dbg (self, "(%s/%s) huawei port will have AT flags '%s'", + mm_obj_dbg (self, "(%s/%s) port will have AT flags '%s'", mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_name (probe), str); diff --git a/plugins/longcheer/mm-plugin-longcheer.c b/plugins/longcheer/mm-plugin-longcheer.c index 74f6ae7a..4331d21b 100644 --- a/plugins/longcheer/mm-plugin-longcheer.c +++ b/plugins/longcheer/mm-plugin-longcheer.c @@ -69,7 +69,7 @@ gmr_ready (MMPortSerialAt *port, response = mm_port_serial_at_command_finish (port, res, NULL); if (!response) { - mm_obj_dbg (probe, "(Longcheer) retrying custom init step..."); + mm_obj_dbg (probe, "retrying custom init step..."); longcheer_custom_init_step (task); return; } @@ -88,7 +88,7 @@ gmr_ready (MMPortSerialAt *port, MM_CORE_ERROR_UNSUPPORTED, "X200 cannot be supported with the Longcheer plugin"); } else { - mm_obj_dbg (probe, "(Longcheer) device is not a X200"); + mm_obj_dbg (probe, "device is not a X200"); g_task_return_boolean (task, TRUE); } g_object_unref (task); @@ -107,7 +107,7 @@ longcheer_custom_init_step (GTask *task) /* If cancelled, end */ if (g_cancellable_is_cancelled (cancellable)) { - mm_obj_dbg (probe, "(Longcheer) no need to keep on running custom init"); + mm_obj_dbg (probe, "no need to keep on running custom init"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; diff --git a/plugins/novatel/mm-broadband-modem-novatel.c b/plugins/novatel/mm-broadband-modem-novatel.c index 086ea637..aeec7873 100644 --- a/plugins/novatel/mm-broadband-modem-novatel.c +++ b/plugins/novatel/mm-broadband-modem-novatel.c @@ -553,15 +553,15 @@ modem_load_access_technologies_finish (MMIfaceModem *self, ctx = g_task_get_task_data (G_TASK (res)); if (ctx->act & MM_IFACE_MODEM_CDMA_ALL_EVDO_ACCESS_TECHNOLOGIES_MASK) { if (ctx->hdr_revision == QCDM_HDR_REV_0) { - mm_obj_dbg (self, "novatel modem snapshot EVDO revision: 0"); + mm_obj_dbg (self, "modem snapshot EVDO revision: 0"); ctx->act &= ~MM_IFACE_MODEM_CDMA_ALL_EVDO_ACCESS_TECHNOLOGIES_MASK; ctx->act |= MM_MODEM_ACCESS_TECHNOLOGY_EVDO0; } else if (ctx->hdr_revision == QCDM_HDR_REV_A) { - mm_obj_dbg (self, "novatel modem snapshot EVDO revision: A"); + mm_obj_dbg (self, "modem snapshot EVDO revision: A"); ctx->act &= ~MM_IFACE_MODEM_CDMA_ALL_EVDO_ACCESS_TECHNOLOGIES_MASK; ctx->act |= MM_MODEM_ACCESS_TECHNOLOGY_EVDOA; } else - mm_obj_dbg (self, "novatel modem snapshot EVDO revision: %d (unknown)", ctx->hdr_revision); + mm_obj_dbg (self, "modem snapshot EVDO revision: %d (unknown)", ctx->hdr_revision); } *access_technologies = ctx->act; diff --git a/plugins/novatel/mm-common-novatel.c b/plugins/novatel/mm-common-novatel.c index 0a444418..b6b0e272 100644 --- a/plugins/novatel/mm-common-novatel.c +++ b/plugins/novatel/mm-common-novatel.c @@ -59,7 +59,7 @@ nwdmat_ready (MMPortSerialAt *port, return; } - mm_obj_dbg (probe, "(Novatel) Error flipping secondary ports to AT mode: %s", error->message); + mm_obj_dbg (probe, "error flipping secondary ports to AT mode: %s", error->message); } /* Finish custom_init */ @@ -85,14 +85,14 @@ custom_init_step (GTask *task) /* If cancelled, end */ if (g_task_return_error_if_cancelled (task)) { - mm_obj_dbg (probe, "(Novatel) no need to keep on running custom init"); + mm_obj_dbg (probe, "no need to keep on running custom init"); g_object_unref (task); return; } /* If device has a QMI port, don't run $NWDMAT */ if (mm_port_probe_list_has_qmi_port (mm_device_peek_port_probe_list (mm_port_probe_peek_device (probe)))) { - mm_obj_dbg (probe, "(Novatel) no need to run custom init: device has QMI port"); + mm_obj_dbg (probe, "no need to run custom init: device has QMI port"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -118,7 +118,7 @@ custom_init_step (GTask *task) } /* Finish custom_init */ - mm_obj_dbg (probe, "(Novatel) couldn't flip secondary port to AT: all retries consumed"); + mm_obj_dbg (probe, "couldn't flip secondary port to AT: all retries consumed"); g_task_return_boolean (task, TRUE); g_object_unref (task); } diff --git a/plugins/sierra/mm-common-sierra.c b/plugins/sierra/mm-common-sierra.c index 8a89a166..f366050b 100644 --- a/plugins/sierra/mm-common-sierra.c +++ b/plugins/sierra/mm-common-sierra.c @@ -160,7 +160,7 @@ gcap_ready (MMPortSerialAt *port, * on the APP1 port or not. */ if (getenv ("MM_SIERRA_APP1_PPP_OK")) { - mm_obj_dbg (probe, "(Sierra) APP1 PPP OK '%s'", response); + mm_obj_dbg (probe, "APP1 PPP OK '%s'", response); g_object_set_data (G_OBJECT (probe), TAG_SIERRA_APP1_PPP_OK, GUINT_TO_POINTER (TRUE)); } } else if (strstr (response, "APP2") || @@ -193,14 +193,14 @@ sierra_custom_init_step (GTask *task) /* If cancelled, end */ if (g_cancellable_is_cancelled (cancellable)) { - mm_obj_dbg (probe, "(Sierra) no need to keep on running custom init"); + mm_obj_dbg (probe, "no need to keep on running custom init"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; } if (ctx->retries == 0) { - mm_obj_dbg (probe, "(Sierra) couldn't get port type hints"); + mm_obj_dbg (probe, "couldn't get port type hints"); g_task_return_boolean (task, TRUE); g_object_unref (task); return; diff --git a/plugins/ublox/mm-broadband-bearer-ublox.c b/plugins/ublox/mm-broadband-bearer-ublox.c index a453396d..1e2ea4d5 100644 --- a/plugins/ublox/mm-broadband-bearer-ublox.c +++ b/plugins/ublox/mm-broadband-bearer-ublox.c @@ -417,7 +417,7 @@ test_cedata_ready (MMBaseModem *modem, self->priv->cedata = FEATURE_SUPPORTED; else self->priv->cedata = FEATURE_UNSUPPORTED; - mm_obj_dbg (self, "u-blox: +UCEDATA command%s available", + mm_obj_dbg (self, "+UCEDATA command%s available", (self->priv->cedata == FEATURE_SUPPORTED) ? "" : " not"); activate_3gpp (task); @@ -439,7 +439,7 @@ test_cedata (GTask *task) return; } - mm_obj_dbg (self, "u-blox: checking availability of +UCEDATA command..."); + mm_obj_dbg (self, "checking availability of +UCEDATA command..."); mm_base_modem_at_command (MM_BASE_MODEM (ctx->modem), "+UCEDATA=?", 3, diff --git a/plugins/zte/mm-plugin-zte.c b/plugins/zte/mm-plugin-zte.c index f2d6e003..195ff56f 100644 --- a/plugins/zte/mm-plugin-zte.c +++ b/plugins/zte/mm-plugin-zte.c @@ -126,7 +126,7 @@ grab_port (MMPlugin *self, } if (mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_ZTE_ICERA_DHCP")) { - mm_obj_dbg (self, "ZTE: Icera-based modem will use DHCP"); + mm_obj_dbg (self, "icera-based modem will use DHCP"); g_object_set (modem, MM_BROADBAND_MODEM_ICERA_DEFAULT_IP_METHOD, MM_BEARER_IP_METHOD_DHCP, NULL); From 93e4c8625beb1dab16dd2ae23b6d09587200fea8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 16:22:52 +0200 Subject: [PATCH 134/675] plugin: don't match generic plugin by name --- plugins/generic/mm-plugin-generic.c | 3 ++- plugins/generic/tests/test-service-generic.c | 2 +- src/mm-plugin-manager.c | 21 ++++++++-------- src/mm-plugin.c | 25 +++++++++++++++++++- src/mm-plugin.h | 3 ++- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/plugins/generic/mm-plugin-generic.c b/plugins/generic/mm-plugin-generic.c index 242ddf42..c2e3a07e 100644 --- a/plugins/generic/mm-plugin-generic.c +++ b/plugins/generic/mm-plugin-generic.c @@ -95,7 +95,8 @@ mm_plugin_create (void) return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_GENERIC, - MM_PLUGIN_NAME, MM_PLUGIN_GENERIC_NAME, + MM_PLUGIN_NAME, MM_MODULE_NAME, + MM_PLUGIN_IS_GENERIC, TRUE, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_AT, TRUE, MM_PLUGIN_ALLOWED_QCDM, TRUE, diff --git a/plugins/generic/tests/test-service-generic.c b/plugins/generic/tests/test-service-generic.c index ea29e9e9..d7bc4e01 100644 --- a/plugins/generic/tests/test-service-generic.c +++ b/plugins/generic/tests/test-service-generic.c @@ -51,7 +51,7 @@ test_enable_disable (TestFixture *fixture) /* Set the test profile */ test_fixture_set_profile (fixture, "test-enable-disable", - "Generic", + "generic", (const gchar *const *)ports); /* Wait and get the modem object */ diff --git a/src/mm-plugin-manager.c b/src/mm-plugin-manager.c index d00b65e3..9ee4edae 100644 --- a/src/mm-plugin-manager.c +++ b/src/mm-plugin-manager.c @@ -363,7 +363,7 @@ port_context_set_suggestion (PortContext *port_context, return; /* The GENERIC plugin is NEVER suggested to others */ - if (g_str_equal (mm_plugin_get_name (suggested_plugin), MM_PLUGIN_GENERIC_NAME)) + if (mm_plugin_is_generic (suggested_plugin)) return; /* If the plugin has MM_PLUGIN_FORBIDDEN_ICERA set, we do *not* suggest @@ -974,10 +974,10 @@ device_context_set_best_plugin (DeviceContext *device_context, * one and now we're reporting a more specific one, use the new one. */ if (!device_context->best_plugin || - (g_str_equal (mm_plugin_get_name (device_context->best_plugin), MM_PLUGIN_GENERIC_NAME) && + (mm_plugin_is_generic (device_context->best_plugin) && device_context->best_plugin != best_plugin)) { /* Only log best plugin if it's not the generic one */ - if (!g_str_equal (mm_plugin_get_name (best_plugin), MM_PLUGIN_GENERIC_NAME)) + if (!mm_plugin_is_generic (best_plugin)) mm_obj_dbg (self, "task %s: found best plugin: %s", port_context->name, mm_plugin_get_name (best_plugin)); /* Store and suggest this plugin also to other port probes */ @@ -1170,10 +1170,8 @@ device_context_run_port_context (DeviceContext *device_context, /* If we got one already set in the device context, it will be the first one, * unless it is the generic plugin */ - if (device_context->best_plugin && - !g_str_equal (mm_plugin_get_name (device_context->best_plugin), MM_PLUGIN_GENERIC_NAME)) { + if (device_context->best_plugin && !mm_plugin_is_generic (device_context->best_plugin)) suggested = device_context->best_plugin; - } port_context_run (self, port_context, @@ -1805,11 +1803,12 @@ load_plugins (MMPluginManager *self, if (!plugin) continue; - if (g_str_equal (mm_plugin_get_name (plugin), MM_PLUGIN_GENERIC_NAME)) - /* Generic plugin */ - self->priv->generic = plugin; - else - /* Vendor specific plugin */ + if (mm_plugin_is_generic (plugin)) { + if (self->priv->generic) + mm_obj_warn (self, "cannot register more than one generic plugin"); + else + self->priv->generic = plugin; + } else self->priv->plugins = g_list_append (self->priv->plugins, plugin); /* Register plugin whitelist rules in filter, if any */ diff --git a/src/mm-plugin.c b/src/mm-plugin.c index 6849218d..4f3ec18d 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -64,8 +64,9 @@ static const gchar *virtual_port[] = {"smd0", NULL}; struct _MMPluginPrivate { - gchar *name; + gchar *name; GHashTable *tasks; + gboolean is_generic; /* Pre-probing filters */ gchar **subsystems; @@ -107,6 +108,7 @@ struct _MMPluginPrivate { enum { PROP_0, PROP_NAME, + PROP_IS_GENERIC, PROP_ALLOWED_SUBSYSTEMS, PROP_ALLOWED_DRIVERS, PROP_FORBIDDEN_DRIVERS, @@ -156,6 +158,12 @@ mm_plugin_get_allowed_product_ids (MMPlugin *self) return self->priv->product_ids; } +gboolean +mm_plugin_is_generic (MMPlugin *self) +{ + return self->priv->is_generic; +} + /*****************************************************************************/ static gboolean @@ -1110,6 +1118,10 @@ set_property (GObject *object, /* Construct only */ self->priv->name = g_value_dup_string (value); break; + case PROP_IS_GENERIC: + /* Construct only */ + self->priv->is_generic = g_value_get_boolean (value); + break; case PROP_ALLOWED_SUBSYSTEMS: /* Construct only */ self->priv->subsystems = g_value_dup_boxed (value); @@ -1232,6 +1244,9 @@ get_property (GObject *object, case PROP_NAME: g_value_set_string (value, self->priv->name); break; + case PROP_IS_GENERIC: + g_value_set_boolean (value, self->priv->is_generic); + break; case PROP_ALLOWED_SUBSYSTEMS: g_value_set_boxed (value, self->priv->subsystems); break; @@ -1369,6 +1384,14 @@ mm_plugin_class_init (MMPluginClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property + (object_class, PROP_IS_GENERIC, + g_param_spec_boolean (MM_PLUGIN_IS_GENERIC, + "Generic", + "Whether the plugin is the generic one", + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_ALLOWED_SUBSYSTEMS, g_param_spec_boxed (MM_PLUGIN_ALLOWED_SUBSYSTEMS, diff --git a/src/mm-plugin.h b/src/mm-plugin.h index 926840bf..fe0469c1 100644 --- a/src/mm-plugin.h +++ b/src/mm-plugin.h @@ -27,7 +27,6 @@ #include "mm-device.h" #include "mm-kernel-device.h" -#define MM_PLUGIN_GENERIC_NAME "Generic" #define MM_PLUGIN_MAJOR_VERSION 4 #define MM_PLUGIN_MINOR_VERSION 0 @@ -48,6 +47,7 @@ #define MM_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN, MMPluginClass)) #define MM_PLUGIN_NAME "name" +#define MM_PLUGIN_IS_GENERIC "is-generic" #define MM_PLUGIN_ALLOWED_SUBSYSTEMS "allowed-subsystems" #define MM_PLUGIN_ALLOWED_DRIVERS "allowed-drivers" #define MM_PLUGIN_FORBIDDEN_DRIVERS "forbidden-drivers" @@ -127,6 +127,7 @@ GType mm_plugin_get_type (void); const gchar *mm_plugin_get_name (MMPlugin *self); const gchar **mm_plugin_get_allowed_udev_tags (MMPlugin *self); const mm_uint16_pair *mm_plugin_get_allowed_product_ids (MMPlugin *self); +gboolean mm_plugin_is_generic (MMPlugin *self); /* This method will run all pre-probing filters, to see if we can discard this * plugin from the probing logic as soon as possible. */ From 382b059c1eea8108b5dfb38d70f2a03118a566b7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Apr 2020 16:25:35 +0200 Subject: [PATCH 135/675] po: update source code lines --- po/cs.po | 4 ++-- po/da.po | 4 ++-- po/de.po | 4 ++-- po/fr.po | 4 ++-- po/fur.po | 4 ++-- po/hu.po | 4 ++-- po/id.po | 4 ++-- po/it.po | 4 ++-- po/lt.po | 4 ++-- po/pl.po | 4 ++-- po/pt_BR.po | 4 ++-- po/ru.po | 4 ++-- po/sk.po | 4 ++-- po/sv.po | 4 ++-- po/tr.po | 4 ++-- po/uk.po | 8 ++++---- po/zh_CN.po | 4 ++-- 17 files changed, 36 insertions(+), 36 deletions(-) diff --git a/po/cs.po b/po/cs.po index 568e43ff..205d21f1 100644 --- a/po/cs.po +++ b/po/cs.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2017-10-21 15:32+0200\n" "Last-Translator: Marek Černocký \n" "Language-Team: čeština \n" @@ -114,6 +114,6 @@ msgstr "" "Systémová zásada brání v dotázání na firmware nebo brání v jeho správě na " "tomto zařízení." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "Správa modemů potřebuje resetovat zařízení" diff --git a/po/da.po b/po/da.po index 9473d0af..dc89d559 100644 --- a/po/da.po +++ b/po/da.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2019-02-10 16:46+0200\n" "Last-Translator: scootergrisen\n" "Language-Team: Danish\n" @@ -107,6 +107,6 @@ msgid "System policy prevents querying or managing this device's firmware." msgstr "" "Systempolitikken forhindrer forespørgsel og håndtering af enhedens firmware." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager har brug for at nulstille enhederne" diff --git a/po/de.po b/po/de.po index 7e0281f9..4f8661e3 100644 --- a/po/de.po +++ b/po/de.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2014-01-06 21:23+0100\n" "Last-Translator: Mario Blättermann \n" "Language-Team: German \n" @@ -115,6 +115,6 @@ msgstr "" "Die Systemrichtlinien verhindern die Abfrage oder Verwaltung der Firmware " "dieses Gerätes." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "" diff --git a/po/fr.po b/po/fr.po index c86ecd1d..928a7953 100644 --- a/po/fr.po +++ b/po/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2018-08-18 16:17+0200\n" "Last-Translator: Claude Paroz \n" "Language-Team: French \n" @@ -111,6 +111,6 @@ msgstr "" "La politique système empêche l’interrogation et la gestion du matériel de ce " "périphérique." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager a besoin de réinitialiser les périphériques" diff --git a/po/fur.po b/po/fur.po index 536e482d..4b59615c 100644 --- a/po/fur.po +++ b/po/fur.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2018-03-25 17:20+0200\n" "Last-Translator: Fabio Tomat \n" "Language-Team: Friulian \n" @@ -114,6 +114,6 @@ msgstr "" "La politiche dal sisteme e impedìs di interogâ o gjestî il firmware di chest " "dispositîf." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager al à bisugne di ristabilî/azerâ i dispositîfs" diff --git a/po/hu.po b/po/hu.po index 6b204c23..a07a5bde 100644 --- a/po/hu.po +++ b/po/hu.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: modemmanager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2017-09-26 22:02+0000\n" "Last-Translator: Gabor Kelemen \n" "Language-Team: Hungarian \n" @@ -110,6 +110,6 @@ msgstr "" "A rendszer lekérdezése és használata lehetővé a firmware lekérdezését és " "kezelését az eszközön." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "A Modemkezelőnek alapállapotba kell állítania eszközöket" diff --git a/po/id.po b/po/id.po index b0d09784..afa8b651 100644 --- a/po/id.po +++ b/po/id.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2020-04-01 08:24+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2020-03-31 18:14+0700\n" "Last-Translator: Andika Triwidada \n" "Language-Team: Indonesian \n" @@ -105,6 +105,6 @@ msgstr "Kuiri dan kelola firmware pada suatu peranti data seluler" msgid "System policy prevents querying or managing this device's firmware." msgstr "Kebijakan sistem mencegah kuiri atau pengelolaan firmware peranti ini." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager perlu mereset peranti" diff --git a/po/it.po b/po/it.po index 91abf4a4..66555934 100644 --- a/po/it.po +++ b/po/it.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2020-03-10 20:15+0100\n" "Last-Translator: Milo Casagrande \n" "Language-Team: Italian \n" @@ -112,6 +112,6 @@ msgstr "" "La politica di sistema impedisce di interrogare o gestire il firmware di " "questo dispositivo." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager deve reimpostare i dispositivi" diff --git a/po/lt.po b/po/lt.po index d238b025..303cd50a 100644 --- a/po/lt.po +++ b/po/lt.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2019-04-13 22:08+0300\n" "Last-Translator: \n" "Language-Team: \n" @@ -116,6 +116,6 @@ msgstr "" "Sistemos politika neleidžia užklausti ar tvarkyti šio įrenginio programinę " "aparatinę įrangą." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager turi atstatyti įrenginius" diff --git a/po/pl.po b/po/pl.po index 928c3783..63849e55 100644 --- a/po/pl.po +++ b/po/pl.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-26 03:26+0000\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2019-09-28 15:02+0200\n" "Last-Translator: Piotr Drąg \n" "Language-Team: Polish \n" @@ -113,6 +113,6 @@ msgstr "" "Ustawienia systemu uniemożliwiają odpytywanie lub zarządzanie " "oprogramowaniem sprzętowym tego urządzenia." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "Usługa ModemManager musi ponownie uruchomić urządzenia" diff --git a/po/pt_BR.po b/po/pt_BR.po index 944a37f1..487d7e26 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-11-27 09:33+0100\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2019-11-25 00:17-0300\n" "Last-Translator: Rafael Fontenelle \n" "Language-Team: Brazilian Portuguese \n" @@ -109,6 +109,6 @@ msgstr "" "A política de sistema impede de consultar ou gerenciar o firmware do " "dispositivo." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "O ModemManager precisa reiniciar os dispositivos" diff --git a/po/ru.po b/po/ru.po index 8c0174d3..ef98b678 100644 --- a/po/ru.po +++ b/po/ru.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2020-04-05 09:45+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2020-04-04 21:26+0300\n" "Last-Translator: Артемий Судаков \n" "Language-Team: Russian \n" @@ -112,6 +112,6 @@ msgstr "" "Системная политика не позволяет запрашивать или управлять прошивкой этого " "устройства." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager'у необходимо перезагрузить устройства" diff --git a/po/sk.po b/po/sk.po index a8e342f7..c5534ca8 100644 --- a/po/sk.po +++ b/po/sk.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2017-09-16 08:51+0200\n" "Last-Translator: Dušan Kazik \n" "Language-Team: Slovak \n" @@ -114,6 +114,6 @@ msgstr "" "Politika systému zabraňuje požadovaniu, alebo správe firmvéru tohto " "zariadenia." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "Služba ModemManager vyžaduje obnovenie zariadení" diff --git a/po/sv.po b/po/sv.po index c6f0fcfb..059c998c 100644 --- a/po/sv.po +++ b/po/sv.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2017-12-04 20:28+0100\n" "Last-Translator: Josef Andersson \n" "Language-Team: Swedish \n" @@ -111,6 +111,6 @@ msgstr "" "En systempolicy förhindrar att fråga och hantera denna enhets fasta " "programvara." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager behöver starta om enheter" diff --git a/po/tr.po b/po/tr.po index fd341234..737f6d62 100644 --- a/po/tr.po +++ b/po/tr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-11-11 10:01+0100\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2019-11-10 09:05+0300\n" "Last-Translator: Emin Tufan Çetin \n" "Language-Team: Türkçe \n" @@ -108,6 +108,6 @@ msgstr "" "Sistem ilkesi bu aygıtın donanım yazılımını sorgulamayı veya yönetmeyi " "engelliyor." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager'in aygıtları sıfırlaması gerekiyor" diff --git a/po/uk.po b/po/uk.po index 0be8149f..ba2d9e04 100644 --- a/po/uk.po +++ b/po/uk.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Modem Manager\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-11-11 10:09+0100\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2019-11-10 14:35+0200\n" "Last-Translator: Yuri Chornoivan \n" "Language-Team: Ukrainian \n" @@ -15,8 +15,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " -"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Generator: Lokalize 19.11.70\n" #: data/org.freedesktop.ModemManager1.policy.in.in:13 @@ -114,6 +114,6 @@ msgstr "" "Правила системи перешкоджають опитуванню або керування мікропрограмою цього " "пристрою." -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "ModemManager потребує відновлення початкового стану пристроїв" diff --git a/po/zh_CN.po b/po/zh_CN.po index 1b576a24..2e939f90 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: ModemManager master\n" "Report-Msgid-Bugs-To: modemmanager-devel@lists.freedesktop.org\n" -"POT-Creation-Date: 2019-09-25 12:48+0200\n" +"POT-Creation-Date: 2020-04-08 16:23+0200\n" "PO-Revision-Date: 2019-05-03 00:10+0800\n" "Last-Translator: 王滋涵 \n" "Language-Team: Chinese (China) \n" @@ -97,6 +97,6 @@ msgstr "在移动宽带设备上查询和管理固件" msgid "System policy prevents querying or managing this device's firmware." msgstr "系统策略禁止在移动宽带设备上查询和管理固件。" -#: src/mm-sleep-monitor.c:114 +#: src/mm-sleep-monitor.c:125 msgid "ModemManager needs to reset devices" msgstr "调制解调器管理器需要重置设备" From 6de13631745f35391f895628cc17ca03526ed0cc Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 09:36:06 +0200 Subject: [PATCH 136/675] api,modem: improve capabilities related documentation And remove the unused mm_common_build_capability_combinations_any() method in the common non-public library code. --- .../org.freedesktop.ModemManager1.Modem.xml | 26 ++++++++++++++----- libmm-glib/mm-common-helpers.c | 11 -------- libmm-glib/mm-common-helpers.h | 1 - 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.xml b/introspection/org.freedesktop.ModemManager1.Modem.xml index eb4debd8..a67197d2 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.xml @@ -146,7 +146,12 @@ SetCurrentCapabilities: @capabilities: Bitmask of MMModemCapability values, to specify the capabilities to use. - Set the capabilities of the device. A restart of the modem may be required. + Set the capabilities of the device. + + The given bitmask should be supported by the modem, as specified in the + #org.freedesktop.ModemManager1.Modem.Modem:SupportedCapabilities property. + + This command may power-cycle the device. --> @@ -230,12 +235,16 @@ SupportedCapabilities: List of MMModemCapability - values, specifying the combinations of generic family of access + bitmasks, specifying the combinations of generic family of access technologies the modem supports. - If the modem doesn't allow changing the current capabilities, a single entry with - MM_MODEM_CAPABILITY_ANY - will be given. + If the modem doesn't allow changing the current capabilities, the + list will report one single entry with the same bitmask as in + #org.freedesktop.ModemManager1.Modem.Modem:CurrentCapabilities. + + Only multimode devices implementing both 3GPP (GSM/UMTS/LTE/5GNR) and + 3GPP2 (CDMA/EVDO) specs will report more than one combination of + capabilities. --> @@ -243,8 +252,11 @@ CurrentCapabilities: Bitmask of MMModemCapability - values, specifying the generic family of access technologies the modem - currently supports without a firmware reload or reinitialization. + values, specifying the currently used generic family of access + technologies. + + This bitmask will be one of the ones listed in + #org.freedesktop.ModemManager1.Modem.Modem:SupportedCapabilities. --> diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 484771b3..5bdb6df4 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -538,17 +538,6 @@ mm_common_build_capability_combinations_none (void) return g_variant_builder_end (&builder); } -GVariant * -mm_common_build_capability_combinations_any (void) -{ - GVariantBuilder builder; - - g_variant_builder_init (&builder, G_VARIANT_TYPE ("au")); - g_variant_builder_add_value (&builder, - g_variant_new_uint32 (MM_MODEM_CAPABILITY_ANY)); - return g_variant_builder_end (&builder); -} - void mm_common_get_bands_from_string (const gchar *str, MMModemBand **bands, diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h index e910d8c0..be9f2bb8 100644 --- a/libmm-glib/mm-common-helpers.h +++ b/libmm-glib/mm-common-helpers.h @@ -126,7 +126,6 @@ MMModemCapability *mm_common_capability_combinations_variant_to_array (GVariant GVariant *mm_common_capability_combinations_array_to_variant (const MMModemCapability *capabilities, guint n_capabilities); GVariant *mm_common_capability_combinations_garray_to_variant (GArray *array); -GVariant *mm_common_build_capability_combinations_any (void); GVariant *mm_common_build_capability_combinations_none (void); GArray *mm_common_oma_pending_network_initiated_sessions_variant_to_garray (GVariant *variant); From 839e2ec7ab51132ab01530bef4bf894692b239a3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 7 Apr 2020 09:38:51 +0200 Subject: [PATCH 137/675] api,modem: reword the properties argument explanation in CreateBearer() --- introspection/org.freedesktop.ModemManager1.Modem.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.xml b/introspection/org.freedesktop.ModemManager1.Modem.xml index a67197d2..474f1293 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.xml @@ -55,7 +55,7 @@ From 956dc8a704fce4ca5687cc7f43eaf7e9d703e699 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Apr 2020 07:10:52 +0200 Subject: [PATCH 140/675] api,3gpp: fix InitialEpsBearerSettings documentation --- .../org.freedesktop.ModemManager1.Modem.Modem3gpp.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.Modem3gpp.xml b/introspection/org.freedesktop.ModemManager1.Modem.Modem3gpp.xml index 205f7e21..e741ae91 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.Modem3gpp.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.Modem3gpp.xml @@ -237,8 +237,9 @@ The network may decide to use different settings during the actual device attach procedure, e.g. if the device is roaming or no explicit settings were requested, - so the properties shown in the #org.freedesktop.ModemManager1.Modem.Modem3gpp.InitialEpsBearer:InitialEpsBearer - may be totally different. + so the values shown in the + #org.freedesktop.ModemManager1.Modem.Modem3gpp:InitialEpsBearer + bearer object may be totally different. This is a read-only property, updating these settings should be done using the SetInitialEpsBearerSettings() From 6f82ea3732278ca25f367aab3e1cef2ef865f52f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Apr 2020 07:34:39 +0200 Subject: [PATCH 141/675] log: force using the object logging API Unless the generic API is explicitly allowed, as in the main.c source file. --- src/main.c | 3 ++- src/mm-log.h | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 13b7cecb..9963c7cc 100644 --- a/src/main.c +++ b/src/main.c @@ -26,8 +26,9 @@ #include "ModemManager.h" -#include "mm-base-manager.h" +#define MM_LOG_NO_OBJECT #include "mm-log.h" +#include "mm-base-manager.h" #include "mm-context.h" #if defined WITH_SYSTEMD_SUSPEND_RESUME diff --git a/src/mm-log.h b/src/mm-log.h index d33cef9f..d0b5c607 100644 --- a/src/mm-log.h +++ b/src/mm-log.h @@ -36,10 +36,14 @@ typedef enum { #define mm_obj_info(obj, ...) _mm_log (obj, MM_MODULE_NAME, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_INFO, ## __VA_ARGS__ ) #define mm_obj_dbg(obj, ...) _mm_log (obj, MM_MODULE_NAME, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_DEBUG, ## __VA_ARGS__ ) -#define mm_err(...) mm_obj_err (NULL, ## __VA_ARGS__ ) -#define mm_warn(...) mm_obj_warn (NULL, ## __VA_ARGS__ ) -#define mm_info(...) mm_obj_info (NULL, ## __VA_ARGS__ ) -#define mm_dbg(...) mm_obj_dbg (NULL, ## __VA_ARGS__ ) +/* only allow using non-object logging API if explicitly requested + * (e.g. in the main daemon source) */ +#if defined MM_LOG_NO_OBJECT +# define mm_err(...) mm_obj_err (NULL, ## __VA_ARGS__ ) +# define mm_warn(...) mm_obj_warn (NULL, ## __VA_ARGS__ ) +# define mm_info(...) mm_obj_info (NULL, ## __VA_ARGS__ ) +# define mm_dbg(...) mm_obj_dbg (NULL, ## __VA_ARGS__ ) +#endif void _mm_log (gpointer obj, const gchar *module, From cc99ab562b2f47f48f5ed9e5afa0c23a4a5c32cd Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 05:45:13 +0100 Subject: [PATCH 142/675] cli: consolidate logic to process user provided object lookup info The user may specify DBus objects in several ways, e.g. with full object paths, just with the object numeric ids, or in some other cases with the full device UID. Setup one single method to process this info for all object types, so that it's also easier to add new lookup methods for all at the same time. --- cli/mmcli-common.c | 338 +++++++++++++++++---------------------------- cli/mmcli-common.h | 20 +-- 2 files changed, 134 insertions(+), 224 deletions(-) diff --git a/cli/mmcli-common.c b/cli/mmcli-common.c index 10a1fb75..784dafe2 100644 --- a/cli/mmcli-common.c +++ b/cli/mmcli-common.c @@ -110,6 +110,68 @@ mmcli_get_manager_sync (GDBusConnection *connection) return manager; } +/******************************************************************************/ +/* Common to all objects */ + +static void +get_object_lookup_info (const gchar *str, + const gchar *object_type, + const gchar *object_prefix, + gchar **object_path, + gchar **modem_uid) +{ + gboolean all_numeric; + guint i; + + /* Empty string not allowed */ + if (!str || !str[0]) { + g_printerr ("error: no %s was specified\n", object_type); + exit (EXIT_FAILURE); + } + + /* User string may come in three ways: + * a) full DBus path + * b) object index + * c) modem UID (for modem or SIM lookup only) + */ + + *object_path = NULL; + if (modem_uid) + *modem_uid = NULL; + + /* If match the DBus prefix, we have a DBus object path */ + if (g_str_has_prefix (str, object_prefix)) { + g_debug ("Assuming '%s' is the full %s path", str, object_type); + *object_path = g_strdup (str); + return; + } + + /* If all numeric, we have the object index */ + all_numeric = TRUE; + for (i = 0; str[i]; i++) { + if (!g_ascii_isdigit (str[i])) { + all_numeric = FALSE; + break; + } + } + if (all_numeric) { + g_debug ("Assuming '%s' is the %s index", str, object_type); + *object_path = g_strdup_printf ("%s/%s", object_prefix, str); + return; + } + + /* Otherwise we have the UID */ + if (modem_uid) { + g_debug ("Assuming '%s' is the modem UID", str); + *modem_uid = g_strdup (str); + return; + } + + /* If UID is not a valid input for the object type, error out */ + g_printerr ("error: invalid %s string specified: '%s'\n", object_type, str); + exit (EXIT_FAILURE); +} + /******************************************************************************/ /* Modem */ @@ -146,10 +208,7 @@ find_modem (MMManager *manager, g_list_free_full (modems, g_object_unref); if (!found) { - if (modem_path) - g_printerr ("error: couldn't find modem at '%s'\n", modem_path); - else if (modem_uid) - g_printerr ("error: couldn't find modem identified by uid '%s'\n", modem_uid); + g_printerr ("error: couldn't find modem\n"); exit (EXIT_FAILURE); } @@ -217,57 +276,9 @@ get_manager_ready (GDBusConnection *connection, g_object_unref (task); } -static void -get_modem_path_or_uid (const gchar *str, - gchar **modem_path, - gchar **modem_uid) -{ - gboolean all_numeric; - guint i; - - /* We must have a given modem specified */ - if (!str || !str[0]) { - g_printerr ("error: no modem was specified\n"); - exit (EXIT_FAILURE); - } - - /* Modem path may come in three ways: - * a) full DBus path - * b) modem index - * c) uid - */ - - *modem_path = NULL; - *modem_uid = NULL; - - /* If we have DBus prefix, we have the modem DBus path */ - if (g_str_has_prefix (str, MM_DBUS_MODEM_PREFIX)) { - g_debug ("Assuming '%s' is the full modem path", str); - *modem_path = g_strdup (str); - return; - } - - /* If all numeric, we have the modem index */ - all_numeric = TRUE; - for (i = 0; str[i]; i++) { - if (!g_ascii_isdigit (str[i])) { - all_numeric = FALSE; - break; - } - } - if (all_numeric) { - g_debug ("Assuming '%s' is the modem index", str); - *modem_path = g_strdup_printf (MM_DBUS_MODEM_PREFIX "/%s", str); - return; - } - - /* Otherwise we have the UID */ - *modem_uid = g_strdup (str); -} - void mmcli_get_modem (GDBusConnection *connection, - const gchar *modem_str, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -278,7 +289,8 @@ mmcli_get_modem (GDBusConnection *connection, task = g_task_new (connection, cancellable, callback, user_data); ctx = g_new0 (GetModemContext, 1); - get_modem_path_or_uid (modem_str, &ctx->modem_path, &ctx->modem_uid); + get_object_lookup_info (str, "modem", MM_DBUS_MODEM_PREFIX, + &ctx->modem_path, &ctx->modem_uid); g_assert (ctx->modem_path || ctx->modem_uid); g_task_set_task_data (task, ctx, (GDestroyNotify) get_modem_context_free); @@ -290,7 +302,7 @@ mmcli_get_modem (GDBusConnection *connection, MMObject * mmcli_get_modem_sync (GDBusConnection *connection, - const gchar *modem_str, + const gchar *str, MMManager **o_manager) { MMManager *manager; @@ -299,7 +311,8 @@ mmcli_get_modem_sync (GDBusConnection *connection, gchar *modem_uid = NULL; manager = mmcli_get_manager_sync (connection); - get_modem_path_or_uid (modem_str, &modem_path, &modem_uid); + get_object_lookup_info (str, "modem", MM_DBUS_MODEM_PREFIX, + &modem_path, &modem_uid); g_assert (modem_path || modem_uid); found = find_modem (manager, modem_path, modem_uid); @@ -552,37 +565,9 @@ get_bearer_manager_ready (GDBusConnection *connection, look_for_bearer_in_modem (task); } -static gchar * -get_bearer_path (const gchar *path_or_index) -{ - gchar *bearer_path; - - /* We must have a given bearer specified */ - if (!path_or_index) { - g_printerr ("error: no bearer was specified\n"); - exit (EXIT_FAILURE); - } - - /* Bearer path may come in two ways: full DBus path or just bearer index. - * If it is a bearer index, we'll need to generate the DBus path ourselves */ - if (g_str_has_prefix (path_or_index, MM_DBUS_BEARER_PREFIX)) { - g_debug ("Assuming '%s' is the full bearer path", path_or_index); - bearer_path = g_strdup (path_or_index); - } else if (g_ascii_isdigit (path_or_index[0])) { - g_debug ("Assuming '%s' is the bearer index", path_or_index); - bearer_path = g_strdup_printf (MM_DBUS_BEARER_PREFIX "/%s", path_or_index); - } else { - g_printerr ("error: invalid path or index string specified: '%s'\n", - path_or_index); - exit (EXIT_FAILURE); - } - - return bearer_path; -} - void mmcli_get_bearer (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -593,7 +578,9 @@ mmcli_get_bearer (GDBusConnection *connection, task = g_task_new (connection, cancellable, callback, user_data); ctx = g_new0 (GetBearerContext, 1); - ctx->bearer_path = get_bearer_path (path_or_index); + get_object_lookup_info (str, "bearer", MM_DBUS_BEARER_PREFIX, + &ctx->bearer_path, NULL); + g_assert (ctx->bearer_path); g_task_set_task_data (task, ctx, (GDestroyNotify) get_bearer_context_free); mmcli_get_manager (connection, @@ -604,7 +591,7 @@ mmcli_get_bearer (GDBusConnection *connection, MMBearer * mmcli_get_bearer_sync (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, MMManager **o_manager, MMObject **o_object) { @@ -612,9 +599,11 @@ mmcli_get_bearer_sync (GDBusConnection *connection, GList *modems; GList *l; MMBearer *found = NULL; - gchar *bearer_path; + gchar *bearer_path = NULL; - bearer_path = get_bearer_path (path_or_index); + get_object_lookup_info (str, "bearer", MM_DBUS_BEARER_PREFIX, + &bearer_path, NULL); + g_assert (bearer_path); manager = mmcli_get_manager_sync (connection); modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); @@ -695,7 +684,7 @@ mmcli_get_bearer_sync (GDBusConnection *connection, typedef struct { gchar *sim_path; - gchar *sim_maybe_uid; + gchar *modem_uid; MMManager *manager; MMObject *current; } GetSimContext; @@ -722,7 +711,7 @@ get_sim_context_free (GetSimContext *ctx) g_object_unref (ctx->current); if (ctx->manager) g_object_unref (ctx->manager); - g_free (ctx->sim_maybe_uid); + g_free (ctx->modem_uid); g_free (ctx->sim_path); g_free (ctx); } @@ -760,7 +749,7 @@ get_sim_ready (MMModem *modem, sim = mm_modem_get_sim_finish (modem, res, &error); if (error) { - g_printerr ("error: couldn't get sim '%s' at '%s': '%s'\n", + g_printerr ("error: couldn't get SIM '%s' at '%s': '%s'\n", ctx->sim_path, mm_modem_get_path (modem), error->message); @@ -791,7 +780,7 @@ get_sim_manager_ready (GDBusConnection *connection, modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (ctx->manager)); if (!modems) { - g_printerr ("error: couldn't find sim at '%s': 'no modems found'\n", + g_printerr ("error: couldn't find SIM at '%s': 'no modems found'\n", ctx->sim_path); exit (EXIT_FAILURE); } @@ -802,14 +791,18 @@ get_sim_manager_ready (GDBusConnection *connection, object = MM_OBJECT (l->data); modem = mm_object_get_modem (object); - if (!ctx->sim_path) { - if (g_str_equal (ctx->sim_maybe_uid, mm_modem_get_device (modem))) + + /* check if modem UID matches */ + if (ctx->modem_uid) { + if (g_str_equal (ctx->modem_uid, mm_modem_get_device (modem))) { + g_assert (!ctx->sim_path); ctx->sim_path = g_strdup (mm_modem_get_sim_path (modem)); - else { + } else { g_object_unref (modem); continue; } } + if (g_str_equal (ctx->sim_path, mm_modem_get_sim_path (modem))) { ctx->current = g_object_ref (object); mm_modem_get_sim (modem, @@ -821,46 +814,15 @@ get_sim_manager_ready (GDBusConnection *connection, } g_list_free_full (modems, g_object_unref); - if (!ctx->sim_path) { - g_printerr ("error: invalid index string specified: '%s'\n", - ctx->sim_maybe_uid); - exit (EXIT_FAILURE); - } - if (!ctx->current) { - g_printerr ("error: couldn't find sim at '%s'\n", - ctx->sim_path); + g_printerr ("error: couldn't find SIM\n"); exit (EXIT_FAILURE); } } -static gchar * -get_sim_path (const gchar *path_or_index) -{ - gchar *sim_path = NULL; - - /* We must have a given sim specified */ - if (!path_or_index) { - g_printerr ("error: no sim was specified\n"); - exit (EXIT_FAILURE); - } - - /* Sim path may come in two ways: full DBus path or just sim index. - * If it is a sim index, we'll need to generate the DBus path ourselves */ - if (g_str_has_prefix (path_or_index, MM_DBUS_SIM_PREFIX)) { - g_debug ("Assuming '%s' is the full SIM path", path_or_index); - sim_path = g_strdup (path_or_index); - } else if (g_ascii_isdigit (path_or_index[0])) { - g_debug ("Assuming '%s' is the SIM index", path_or_index); - sim_path = g_strdup_printf (MM_DBUS_SIM_PREFIX "/%s", path_or_index); - } - - return sim_path; -} - void mmcli_get_sim (GDBusConnection *connection, - const gchar *path_or_index_or_uid, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -871,8 +833,9 @@ mmcli_get_sim (GDBusConnection *connection, task = g_task_new (connection, cancellable, callback, user_data); ctx = g_new0 (GetSimContext, 1); - ctx->sim_path = get_sim_path (path_or_index_or_uid); - ctx->sim_maybe_uid = g_strdup (path_or_index_or_uid); + get_object_lookup_info (str, "SIM", MM_DBUS_SIM_PREFIX, + &ctx->sim_path, &ctx->modem_uid); + g_assert (ctx->sim_path || ctx->modem_uid); g_task_set_task_data (task, ctx, (GDestroyNotify) get_sim_context_free); mmcli_get_manager (connection, @@ -883,7 +846,7 @@ mmcli_get_sim (GDBusConnection *connection, MMSim * mmcli_get_sim_sync (GDBusConnection *connection, - const gchar *path_or_index_or_uid, + const gchar *str, MMManager **o_manager, MMObject **o_object) { @@ -891,14 +854,17 @@ mmcli_get_sim_sync (GDBusConnection *connection, GList *modems; GList *l; MMSim *found = NULL; - gchar *sim_path; + gchar *sim_path = NULL; + gchar *modem_uid = NULL; - sim_path = get_sim_path (path_or_index_or_uid); + get_object_lookup_info (str, "SIM", MM_DBUS_SIM_PREFIX, + &sim_path, &modem_uid); + g_assert (sim_path || modem_uid); manager = mmcli_get_manager_sync (connection); modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); if (!modems) { - g_printerr ("error: couldn't find sim at '%s': 'no modems found'\n", + g_printerr ("error: couldn't find SIM at '%s': 'no modems found'\n", sim_path); exit (EXIT_FAILURE); } @@ -911,10 +877,12 @@ mmcli_get_sim_sync (GDBusConnection *connection, object = MM_OBJECT (l->data); modem = mm_object_get_modem (object); - if (!sim_path) { - if (g_str_equal (path_or_index_or_uid, mm_modem_get_device (modem))) + /* check if modem UID matches */ + if (modem_uid) { + if (g_str_equal (modem_uid, mm_modem_get_device (modem))) { + g_assert (!sim_path); sim_path = g_strdup (mm_modem_get_sim_path (modem)); - else { + } else { g_object_unref (modem); continue; } @@ -923,7 +891,7 @@ mmcli_get_sim_sync (GDBusConnection *connection, if (g_str_equal (sim_path, mm_modem_get_sim_path (modem))) { found = mm_modem_get_sim_sync (modem, NULL, &error); if (error) { - g_printerr ("error: couldn't get sim '%s' in modem '%s': '%s'\n", + g_printerr ("error: couldn't get SIM '%s' in modem '%s': '%s'\n", sim_path, mm_modem_get_path (modem), error->message); @@ -937,14 +905,8 @@ mmcli_get_sim_sync (GDBusConnection *connection, g_object_unref (modem); } - if (!sim_path) { - g_printerr ("error: invalid index string specified: '%s'\n", - path_or_index_or_uid); - exit (EXIT_FAILURE); - } - if (!found) { - g_printerr ("error: couldn't find sim at '%s'\n", sim_path); + g_printerr ("error: couldn't find SIM\n"); exit (EXIT_FAILURE); } @@ -1027,7 +989,7 @@ find_sms_in_list (GList *list, MMSms *sms = MM_SMS (l->data); if (g_str_equal (mm_sms_get_path (sms), sms_path)) { - g_debug ("Sms found at '%s'\n", sms_path); + g_debug ("SMS found at '%s'\n", sms_path); return g_object_ref (sms); } } @@ -1129,37 +1091,9 @@ get_sms_manager_ready (GDBusConnection *connection, look_for_sms_in_modem (task); } -static gchar * -get_sms_path (const gchar *path_or_index) -{ - gchar *sms_path; - - /* We must have a given sms specified */ - if (!path_or_index) { - g_printerr ("error: no SMS was specified\n"); - exit (EXIT_FAILURE); - } - - /* Sms path may come in two ways: full DBus path or just sms index. - * If it is a sms index, we'll need to generate the DBus path ourselves */ - if (g_str_has_prefix (path_or_index, MM_DBUS_SMS_PREFIX)) { - g_debug ("Assuming '%s' is the full SMS path", path_or_index); - sms_path = g_strdup (path_or_index); - } else if (g_ascii_isdigit (path_or_index[0])) { - g_debug ("Assuming '%s' is the SMS index", path_or_index); - sms_path = g_strdup_printf (MM_DBUS_SMS_PREFIX "/%s", path_or_index); - } else { - g_printerr ("error: invalid path or index string specified: '%s'\n", - path_or_index); - exit (EXIT_FAILURE); - } - - return sms_path; -} - void mmcli_get_sms (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -1170,7 +1104,8 @@ mmcli_get_sms (GDBusConnection *connection, task = g_task_new (connection, cancellable, callback, user_data); ctx = g_new0 (GetSmsContext, 1); - ctx->sms_path = get_sms_path (path_or_index); + get_object_lookup_info (str, "SMS", MM_DBUS_SMS_PREFIX, + &ctx->sms_path, NULL); g_task_set_task_data (task, ctx, (GDestroyNotify) get_sms_context_free); mmcli_get_manager (connection, @@ -1181,7 +1116,7 @@ mmcli_get_sms (GDBusConnection *connection, MMSms * mmcli_get_sms_sync (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, MMManager **o_manager, MMObject **o_object) { @@ -1189,14 +1124,15 @@ mmcli_get_sms_sync (GDBusConnection *connection, GList *modems; GList *l; MMSms *found = NULL; - gchar *sms_path; + gchar *sms_path = NULL; - sms_path = get_sms_path (path_or_index); + get_object_lookup_info (str, "SMS", MM_DBUS_SMS_PREFIX, + &sms_path, NULL); manager = mmcli_get_manager_sync (connection); modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); if (!modems) { - g_printerr ("error: couldn't find sms at '%s': 'no modems found'\n", + g_printerr ("error: couldn't find SMS at '%s': 'no modems found'\n", sms_path); exit (EXIT_FAILURE); } @@ -1418,37 +1354,9 @@ get_call_manager_ready (GDBusConnection *connection, look_for_call_in_modem (task); } -static gchar * -get_call_path (const gchar *path_or_index) -{ - gchar *call_path; - - /* We must have a given call specified */ - if (!path_or_index) { - g_printerr ("error: no call was specified\n"); - exit (EXIT_FAILURE); - } - - /* Call path may come in two ways: full DBus path or just call index. - * If it is a call index, we'll need to generate the DBus path ourselves */ - if (g_str_has_prefix (path_or_index, MM_DBUS_CALL_PREFIX)) { - g_debug ("Assuming '%s' is the full call path", path_or_index); - call_path = g_strdup (path_or_index); - } else if (g_ascii_isdigit (path_or_index[0])) { - g_debug ("Assuming '%s' is the call index", path_or_index); - call_path = g_strdup_printf (MM_DBUS_CALL_PREFIX "/%s", path_or_index); - } else { - g_printerr ("error: invalid path or index string specified: '%s'\n", - path_or_index); - exit (EXIT_FAILURE); - } - - return call_path; -} - void mmcli_get_call (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -1459,7 +1367,8 @@ mmcli_get_call (GDBusConnection *connection, task = g_task_new (connection, cancellable, callback, user_data); ctx = g_new0 (GetCallContext, 1); - ctx->call_path = get_call_path (path_or_index); + get_object_lookup_info (str, "call", MM_DBUS_CALL_PREFIX, + &ctx->call_path, NULL); g_task_set_task_data (task, ctx, (GDestroyNotify) get_call_context_free); mmcli_get_manager (connection, @@ -1470,7 +1379,7 @@ mmcli_get_call (GDBusConnection *connection, MMCall * mmcli_get_call_sync (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, MMManager **o_manager, MMObject **o_object) { @@ -1478,9 +1387,10 @@ mmcli_get_call_sync (GDBusConnection *connection, GList *modems; GList *l; MMCall *found = NULL; - gchar *call_path; + gchar *call_path = NULL; - call_path = get_call_path (path_or_index); + get_object_lookup_info (str, "call", MM_DBUS_CALL_PREFIX, + &call_path, NULL); manager = mmcli_get_manager_sync (connection); modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); diff --git a/cli/mmcli-common.h b/cli/mmcli-common.h index e3d96c0c..237ebb55 100644 --- a/cli/mmcli-common.h +++ b/cli/mmcli-common.h @@ -34,18 +34,18 @@ MMManager *mmcli_get_manager_finish (GAsyncResult *res); MMManager *mmcli_get_manager_sync (GDBusConnection *connection); void mmcli_get_modem (GDBusConnection *connection, - const gchar *modem_str, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); MMObject *mmcli_get_modem_finish (GAsyncResult *res, MMManager **o_manager); MMObject *mmcli_get_modem_sync (GDBusConnection *connection, - const gchar *modem_str, + const gchar *str, MMManager **o_manager); void mmcli_get_bearer (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -53,12 +53,12 @@ MMBearer *mmcli_get_bearer_finish (GAsyncResult *res, MMManager **manager, MMObject **object); MMBearer *mmcli_get_bearer_sync (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, MMManager **manager, MMObject **object); void mmcli_get_sim (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -66,12 +66,12 @@ MMSim *mmcli_get_sim_finish (GAsyncResult *res, MMManager **manager, MMObject **object); MMSim *mmcli_get_sim_sync (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, MMManager **manager, MMObject **object); void mmcli_get_sms (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -79,12 +79,12 @@ MMSms *mmcli_get_sms_finish (GAsyncResult *res, MMManager **manager, MMObject **object); MMSms *mmcli_get_sms_sync (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, MMManager **manager, MMObject **object); void mmcli_get_call (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -92,7 +92,7 @@ MMCall *mmcli_get_call_finish (GAsyncResult *res, MMManager **manager, MMObject **object); MMCall *mmcli_get_call_sync (GDBusConnection *connection, - const gchar *path_or_index, + const gchar *str, MMManager **manager, MMObject **object); From d72a9df041bd25df6f6acb28eed5cbb044a89c51 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 06:05:51 +0100 Subject: [PATCH 143/675] cli: allow looking up for first available modem or SIM When a system only has one single modem, it's convenient to just look for the first available modem or SIM object, instead of needing to provide the full path or the exact index number. This improvement allows users to use the "any" keyword, or any of its substrings (e.g. "an" or even "a") to match the first available object of the requested type. E.g.: $ mmcli -m a -------------------------------- General | dbus path: /org/freedesktop/ModemManager1/Modem/0 | device id: 1a48f1180f1fb0166d91f7b139d027136b59ba63 -------------------------------- Hardware | manufacturer: Sierra Wireless Inc. | model: Sierra Wireless EM7345 4G LTE ... Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/issues/196 --- cli/mmcli-common.c | 87 +++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/cli/mmcli-common.c b/cli/mmcli-common.c index 784dafe2..c072d220 100644 --- a/cli/mmcli-common.c +++ b/cli/mmcli-common.c @@ -113,12 +113,15 @@ mmcli_get_manager_sync (GDBusConnection *connection) /******************************************************************************/ /* Common to all objects */ +#define ANY_OBJECT_STR "any" + static void get_object_lookup_info (const gchar *str, const gchar *object_type, const gchar *object_prefix, gchar **object_path, - gchar **modem_uid) + gchar **modem_uid, + gboolean *find_any) { gboolean all_numeric; guint i; @@ -129,15 +132,18 @@ get_object_lookup_info (const gchar *str, exit (EXIT_FAILURE); } - /* User string may come in three ways: + /* User string may come in four ways: * a) full DBus path * b) object index * c) modem UID (for modem or SIM lookup only) + * d) "any" string (for modem or SIM lookup only) */ *object_path = NULL; if (modem_uid) *modem_uid = NULL; + if (find_any) + *find_any = FALSE; /* If match the DBus prefix, we have a DBus object path */ if (g_str_has_prefix (str, object_prefix)) { @@ -160,6 +166,14 @@ get_object_lookup_info (const gchar *str, return; } + /* If it matches the lookup keyword or any of its substrings, we have + * to look for the first available object */ + if ((find_any) && (g_ascii_strncasecmp (str, ANY_OBJECT_STR, strlen (str)) == 0)) { + g_debug ("Will look for first available %s", object_type); + *find_any = TRUE; + return; + } + /* Otherwise we have the UID */ if (modem_uid) { g_debug ("Assuming '%s' is the modem UID", str); @@ -178,15 +192,13 @@ get_object_lookup_info (const gchar *str, static MMObject * find_modem (MMManager *manager, const gchar *modem_path, - const gchar *modem_uid) + const gchar *modem_uid, + gboolean modem_any) { GList *modems; GList *l; MMObject *found = NULL; - g_assert (modem_path || modem_uid); - g_assert (!(modem_path && modem_uid)); - modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); for (l = modems; l; l = g_list_next (l)) { MMObject *obj; @@ -195,12 +207,9 @@ find_modem (MMManager *manager, obj = MM_OBJECT (l->data); modem = MM_MODEM (mm_object_get_modem (obj)); - if (modem_path && g_str_equal (mm_object_get_path (obj), modem_path)) { - found = g_object_ref (obj); - break; - } - - if (modem_uid && g_str_equal (mm_modem_get_device (modem), modem_uid)) { + if (modem_any || + (modem_path && g_str_equal (mm_object_get_path (obj), modem_path)) || + (modem_uid && g_str_equal (mm_modem_get_device (modem), modem_uid))) { found = g_object_ref (obj); break; } @@ -218,8 +227,9 @@ find_modem (MMManager *manager, } typedef struct { - gchar *modem_path; - gchar *modem_uid; + gchar *modem_path; + gchar *modem_uid; + gboolean modem_any; } GetModemContext; typedef struct { @@ -271,7 +281,7 @@ get_manager_ready (GDBusConnection *connection, results = g_new (GetModemResults, 1); results->manager = mmcli_get_manager_finish (res); - results->object = find_modem (results->manager, ctx->modem_path, ctx->modem_uid); + results->object = find_modem (results->manager, ctx->modem_path, ctx->modem_uid, ctx->modem_any); g_task_return_pointer (task, results, (GDestroyNotify)get_modem_results_free); g_object_unref (task); } @@ -290,8 +300,8 @@ mmcli_get_modem (GDBusConnection *connection, ctx = g_new0 (GetModemContext, 1); get_object_lookup_info (str, "modem", MM_DBUS_MODEM_PREFIX, - &ctx->modem_path, &ctx->modem_uid); - g_assert (ctx->modem_path || ctx->modem_uid); + &ctx->modem_path, &ctx->modem_uid, &ctx->modem_any); + g_assert (!!ctx->modem_path + !!ctx->modem_uid + ctx->modem_any == 1); g_task_set_task_data (task, ctx, (GDestroyNotify) get_modem_context_free); mmcli_get_manager (connection, @@ -309,12 +319,13 @@ mmcli_get_modem_sync (GDBusConnection *connection, MMObject *found; gchar *modem_path = NULL; gchar *modem_uid = NULL; + gboolean modem_any = FALSE; manager = mmcli_get_manager_sync (connection); get_object_lookup_info (str, "modem", MM_DBUS_MODEM_PREFIX, - &modem_path, &modem_uid); - g_assert (modem_path || modem_uid); - found = find_modem (manager, modem_path, modem_uid); + &modem_path, &modem_uid, &modem_any); + g_assert (!!modem_path + !!modem_uid + modem_any == 1); + found = find_modem (manager, modem_path, modem_uid, modem_any); if (o_manager) *o_manager = manager; @@ -579,7 +590,7 @@ mmcli_get_bearer (GDBusConnection *connection, ctx = g_new0 (GetBearerContext, 1); get_object_lookup_info (str, "bearer", MM_DBUS_BEARER_PREFIX, - &ctx->bearer_path, NULL); + &ctx->bearer_path, NULL, NULL); g_assert (ctx->bearer_path); g_task_set_task_data (task, ctx, (GDestroyNotify) get_bearer_context_free); @@ -602,7 +613,7 @@ mmcli_get_bearer_sync (GDBusConnection *connection, gchar *bearer_path = NULL; get_object_lookup_info (str, "bearer", MM_DBUS_BEARER_PREFIX, - &bearer_path, NULL); + &bearer_path, NULL, NULL); g_assert (bearer_path); manager = mmcli_get_manager_sync (connection); @@ -685,6 +696,7 @@ mmcli_get_bearer_sync (GDBusConnection *connection, typedef struct { gchar *sim_path; gchar *modem_uid; + gboolean sim_any; MMManager *manager; MMObject *current; } GetSimContext; @@ -792,8 +804,13 @@ get_sim_manager_ready (GDBusConnection *connection, object = MM_OBJECT (l->data); modem = mm_object_get_modem (object); + /* check if we can match the first object found */ + if (ctx->sim_any) { + g_assert (!ctx->sim_path); + ctx->sim_path = g_strdup (mm_modem_get_sim_path (modem)); + } /* check if modem UID matches */ - if (ctx->modem_uid) { + else if (ctx->modem_uid) { if (g_str_equal (ctx->modem_uid, mm_modem_get_device (modem))) { g_assert (!ctx->sim_path); ctx->sim_path = g_strdup (mm_modem_get_sim_path (modem)); @@ -834,8 +851,8 @@ mmcli_get_sim (GDBusConnection *connection, ctx = g_new0 (GetSimContext, 1); get_object_lookup_info (str, "SIM", MM_DBUS_SIM_PREFIX, - &ctx->sim_path, &ctx->modem_uid); - g_assert (ctx->sim_path || ctx->modem_uid); + &ctx->sim_path, &ctx->modem_uid, &ctx->sim_any); + g_assert (!!ctx->sim_path + !!ctx->modem_uid + ctx->sim_any == 1); g_task_set_task_data (task, ctx, (GDestroyNotify) get_sim_context_free); mmcli_get_manager (connection, @@ -856,10 +873,11 @@ mmcli_get_sim_sync (GDBusConnection *connection, MMSim *found = NULL; gchar *sim_path = NULL; gchar *modem_uid = NULL; + gboolean sim_any = FALSE; get_object_lookup_info (str, "SIM", MM_DBUS_SIM_PREFIX, - &sim_path, &modem_uid); - g_assert (sim_path || modem_uid); + &sim_path, &modem_uid, &sim_any); + g_assert (!!sim_path + !!modem_uid + sim_any == 1); manager = mmcli_get_manager_sync (connection); modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); @@ -877,8 +895,13 @@ mmcli_get_sim_sync (GDBusConnection *connection, object = MM_OBJECT (l->data); modem = mm_object_get_modem (object); + /* check if we can match the first object found */ + if (sim_any) { + g_assert (!sim_path); + sim_path = g_strdup (mm_modem_get_sim_path (modem)); + } /* check if modem UID matches */ - if (modem_uid) { + else if (modem_uid) { if (g_str_equal (modem_uid, mm_modem_get_device (modem))) { g_assert (!sim_path); sim_path = g_strdup (mm_modem_get_sim_path (modem)); @@ -1105,7 +1128,7 @@ mmcli_get_sms (GDBusConnection *connection, ctx = g_new0 (GetSmsContext, 1); get_object_lookup_info (str, "SMS", MM_DBUS_SMS_PREFIX, - &ctx->sms_path, NULL); + &ctx->sms_path, NULL, NULL); g_task_set_task_data (task, ctx, (GDestroyNotify) get_sms_context_free); mmcli_get_manager (connection, @@ -1127,7 +1150,7 @@ mmcli_get_sms_sync (GDBusConnection *connection, gchar *sms_path = NULL; get_object_lookup_info (str, "SMS", MM_DBUS_SMS_PREFIX, - &sms_path, NULL); + &sms_path, NULL, NULL); manager = mmcli_get_manager_sync (connection); modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); @@ -1368,7 +1391,7 @@ mmcli_get_call (GDBusConnection *connection, ctx = g_new0 (GetCallContext, 1); get_object_lookup_info (str, "call", MM_DBUS_CALL_PREFIX, - &ctx->call_path, NULL); + &ctx->call_path, NULL, NULL); g_task_set_task_data (task, ctx, (GDestroyNotify) get_call_context_free); mmcli_get_manager (connection, @@ -1390,7 +1413,7 @@ mmcli_get_call_sync (GDBusConnection *connection, gchar *call_path = NULL; get_object_lookup_info (str, "call", MM_DBUS_CALL_PREFIX, - &call_path, NULL); + &call_path, NULL, NULL); manager = mmcli_get_manager_sync (connection); modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); From 1a67db047e6d5473ed6327d58c25cdf96134df5f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 06:18:22 +0100 Subject: [PATCH 144/675] cli: improve --help output for --modem and --sim options Specify the full list of supported object lookup methods. --- cli/mmcli-common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/mmcli-common.c b/cli/mmcli-common.c index c072d220..59498caf 100644 --- a/cli/mmcli-common.c +++ b/cli/mmcli-common.c @@ -1498,16 +1498,16 @@ static gchar *call_str; static GOptionEntry entries[] = { { "modem", 'm', 0, G_OPTION_ARG_STRING, &modem_str, - "Specify modem by path or index. Shows modem information if no action specified.", - "[PATH|INDEX]" + "Specify modem by path, index, UID or 'any'. Shows modem information if no action specified.", + "[PATH|INDEX|UID|any]" }, { "bearer", 'b', 0, G_OPTION_ARG_STRING, &bearer_str, "Specify bearer by path or index. Shows bearer information if no action specified.", "[PATH|INDEX]" }, { "sim", 'i', 0, G_OPTION_ARG_STRING, &sim_str, - "Specify SIM card by path or index. Shows SIM card information if no action specified.", - "[PATH|INDEX]" + "Specify SIM card by path, index, UID or 'any'. Shows SIM card information if no action specified.", + "[PATH|INDEX|UID|any]" }, { "sms", 's', 0, G_OPTION_ARG_STRING, &sms_str, "Specify SMS by path or index. Shows SMS information if no action specified.", From e1cfe3b4ee47d94a0f63bb9dbe83e3415d15b664 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Apr 2020 14:35:31 +0200 Subject: [PATCH 145/675] api,cdma: fix small typo Reported by Malte Grosse. https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/202#note_460466 --- introspection/org.freedesktop.ModemManager1.Modem.ModemCdma.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.ModemCdma.xml b/introspection/org.freedesktop.ModemManager1.Modem.ModemCdma.xml index 6000f41a..5c27f3f9 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.ModemCdma.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.ModemCdma.xml @@ -112,7 +112,7 @@ ActivationStateChanged: @activation_state: Current activation state, given as a MMModemCdmaActivationState. @activation_error: Carrier-specific error code, given as a MMCdmaActivationError. - @status_changes: Properties that have changed as a result of this activation state chage, including "mdn" and "min". The dictionary may be empty if the changed properties are unknown. + @status_changes: Properties that have changed as a result of this activation state change, including "mdn" and "min". The dictionary may be empty if the changed properties are unknown. The device activation state changed. --> From 78266ac4895e34a02f4f66893d7ae867b38864b0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 07:02:57 +0100 Subject: [PATCH 146/675] iface-modem: simplify is_cdma_only() check The check needs to look for a matching single bit, so no need to make it too complex. --- src/mm-iface-modem.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index a8577493..32467efb 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -5576,10 +5576,7 @@ mm_iface_modem_is_3gpp_lte_only (MMIfaceModem *self) gboolean mm_iface_modem_is_cdma_only (MMIfaceModem *self) { - MMModemCapability capabilities; - - capabilities = mm_iface_modem_get_current_capabilities (self); - return (capabilities & MM_MODEM_CAPABILITY_CDMA_EVDO) && !((MM_MODEM_CAPABILITY_CDMA_EVDO ^ capabilities) & capabilities); + return (mm_iface_modem_get_current_capabilities (self) == MM_MODEM_CAPABILITY_CDMA_EVDO); } /*****************************************************************************/ From 0cd76bf1c411707b6ba1c4222d791e2115ef6840 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 06:34:53 +0100 Subject: [PATCH 147/675] api: deprecate MM_MODEM_CAPABILITY_LTE_ADVANCED It's not used anywhere. --- cli/mmcli-modem.c | 2 +- docs/reference/api/ModemManager-sections.txt | 2 ++ include/ModemManager-compat.h | 17 +++++++++++++++++ include/ModemManager-enums.h | 3 +-- libmm-glib/mm-modem-3gpp.c | 2 +- src/mm-iface-modem.c | 4 ++-- src/mm-modem-helpers-qmi.c | 2 -- src/mm-modem-helpers.h | 6 +----- 8 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index 88774b64..a25de316 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -407,7 +407,7 @@ print_modem_info (void) pco_list = mm_modem_3gpp_get_pco (ctx->modem_3gpp); initial_eps_bearer_path = mm_modem_3gpp_get_initial_eps_bearer_path (ctx->modem_3gpp); - if (mm_modem_get_current_capabilities (ctx->modem) & (MM_MODEM_CAPABILITY_LTE | MM_MODEM_CAPABILITY_LTE_ADVANCED)) { + if (mm_modem_get_current_capabilities (ctx->modem) & (MM_MODEM_CAPABILITY_LTE)) { MMBearerProperties *initial_eps_bearer_properties; initial_eps_bearer_properties = mm_modem_3gpp_peek_initial_eps_bearer_settings (ctx->modem_3gpp); diff --git a/docs/reference/api/ModemManager-sections.txt b/docs/reference/api/ModemManager-sections.txt index f1d6b270..e63ce121 100644 --- a/docs/reference/api/ModemManager-sections.txt +++ b/docs/reference/api/ModemManager-sections.txt @@ -140,9 +140,11 @@ MM_MODEM_BAND_CDMA_BC17_US_FLO_2500 MM_MODEM_BAND_CDMA_BC18_US_PS_700 MM_MODEM_BAND_CDMA_BC19_US_LOWER_700 MM_MODEM_LOCATION_SOURCE_AGPS +MM_MODEM_CAPABILITY_LTE_ADVANCED MMModemBandDeprecated MMModemLocationSourceDeprecated +MMModemCapabilityDeprecated MM_DEPRECATED diff --git a/include/ModemManager-compat.h b/include/ModemManager-compat.h index e1458400..5aaaddf9 100644 --- a/include/ModemManager-compat.h +++ b/include/ModemManager-compat.h @@ -709,6 +709,23 @@ typedef int MMModemLocationSourceDeprecated; */ #define MM_MODEM_LOCATION_SOURCE_AGPS ((MMModemLocationSourceDeprecated)MM_MODEM_LOCATION_SOURCE_AGPS_MSA) +/* The following type exists just so that we can get deprecation warnings */ +MM_DEPRECATED +typedef int MMModemCapabilityDeprecated; + +/** + * MM_MODEM_CAPABILITY_LTE_ADVANCED: + * + * Modem has LTE Advanced data capability. + * + * This value is deprecated because it is not used anywhere. LTE Advanced + * capable devices are reported as LTE capable. + * + * Since: 1.0 + * Deprecated: 1.14.0. + */ +#define MM_MODEM_CAPABILITY_LTE_ADVANCED ((MMModemCapabilityDeprecated)(1 << 4)) + #endif /* MM_DISABLE_DEPRECATED */ #endif /* _MODEMMANAGER_COMPAT_H_ */ diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h index bf068bdc..6d99aa50 100644 --- a/include/ModemManager-enums.h +++ b/include/ModemManager-enums.h @@ -36,7 +36,6 @@ * @MM_MODEM_CAPABILITY_CDMA_EVDO: Modem supports at least one of CDMA 1xRTT, EVDO revision 0, EVDO revision A, or EVDO revision B. * @MM_MODEM_CAPABILITY_GSM_UMTS: Modem supports at least one of GSM, GPRS, EDGE, UMTS, HSDPA, HSUPA, or HSPA+ packet switched data capability. * @MM_MODEM_CAPABILITY_LTE: Modem has LTE data capability. - * @MM_MODEM_CAPABILITY_LTE_ADVANCED: Modem has LTE Advanced data capability. * @MM_MODEM_CAPABILITY_IRIDIUM: Modem has Iridium capabilities. * @MM_MODEM_CAPABILITY_ANY: Mask specifying all capabilities. * @@ -51,7 +50,7 @@ typedef enum { /*< underscore_name=mm_modem_capability >*/ MM_MODEM_CAPABILITY_CDMA_EVDO = 1 << 1, MM_MODEM_CAPABILITY_GSM_UMTS = 1 << 2, MM_MODEM_CAPABILITY_LTE = 1 << 3, - MM_MODEM_CAPABILITY_LTE_ADVANCED = 1 << 4, + /* MM_MODEM_CAPABILITY_LTE_ADVANCED = 1 << 4 */ MM_MODEM_CAPABILITY_IRIDIUM = 1 << 5, MM_MODEM_CAPABILITY_ANY = 0xFFFFFFFF } MMModemCapability; diff --git a/libmm-glib/mm-modem-3gpp.c b/libmm-glib/mm-modem-3gpp.c index 7170acdb..97d8fafe 100644 --- a/libmm-glib/mm-modem-3gpp.c +++ b/libmm-glib/mm-modem-3gpp.c @@ -38,7 +38,7 @@ * properties of the 3GPP interface. * * The 3GPP interface is exposed whenever a modem has any of the 3GPP - * capabilities (%MM_MODEM_CAPABILITY_GSM_UMTS, %MM_MODEM_CAPABILITY_LTE or %MM_MODEM_CAPABILITY_LTE_ADVANCED). + * capabilities (%MM_MODEM_CAPABILITY_GSM_UMTS or %MM_MODEM_CAPABILITY_LTE). */ G_DEFINE_TYPE (MMModem3gpp, mm_modem_3gpp, MM_GDBUS_TYPE_MODEM3GPP_PROXY) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 32467efb..9671e396 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -5546,7 +5546,7 @@ mm_iface_modem_is_3gpp (MMIfaceModem *self) gboolean mm_iface_modem_is_3gpp_lte (MMIfaceModem *self) { - return (mm_iface_modem_get_current_capabilities (self) & MM_MODEM_CAPABILITY_3GPP_LTE); + return (mm_iface_modem_get_current_capabilities (self) & MM_MODEM_CAPABILITY_LTE); } gboolean @@ -5570,7 +5570,7 @@ mm_iface_modem_is_3gpp_lte_only (MMIfaceModem *self) MMModemCapability capabilities; capabilities = mm_iface_modem_get_current_capabilities (self); - return (capabilities & MM_MODEM_CAPABILITY_3GPP_LTE) && !((MM_MODEM_CAPABILITY_3GPP_LTE ^ capabilities) & capabilities); + return (capabilities & MM_MODEM_CAPABILITY_LTE) && !((MM_MODEM_CAPABILITY_LTE ^ capabilities) & capabilities); } gboolean diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 90a25996..531c5849 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1029,8 +1029,6 @@ mm_modem_capability_from_qmi_rat_mode_preference (QmiNasRatModePreference qmi) if (qmi & QMI_NAS_RAT_MODE_PREFERENCE_LTE) caps |= MM_MODEM_CAPABILITY_LTE; - /* FIXME: LTE Advanced? */ - return caps; } diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 3ad03ef8..4adaee2a 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -39,13 +39,9 @@ /* Common utilities */ /*****************************************************************************/ -#define MM_MODEM_CAPABILITY_3GPP_LTE \ - (MM_MODEM_CAPABILITY_LTE | \ - MM_MODEM_CAPABILITY_LTE_ADVANCED) - #define MM_MODEM_CAPABILITY_3GPP \ (MM_MODEM_CAPABILITY_GSM_UMTS | \ - MM_MODEM_CAPABILITY_3GPP_LTE) + MM_MODEM_CAPABILITY_LTE) gchar *mm_strip_quotes (gchar *str); const gchar *mm_strip_tag (const gchar *str, From bf771be7fac874a26f35afebd1fad27af64eaae7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 25 Mar 2020 18:14:52 +0100 Subject: [PATCH 148/675] build: require libqmi 1.25.4 for full 5G enum support --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 57495032..9f21f98f 100644 --- a/configure.ac +++ b/configure.ac @@ -391,7 +391,7 @@ dnl----------------------------------------------------------------------------- dnl QMI support (enabled by default) dnl -LIBQMI_VERSION=1.25.1 +LIBQMI_VERSION=1.25.4 AC_ARG_WITH(qmi, AS_HELP_STRING([--without-qmi], [Build without QMI support]), [], [with_qmi=yes]) AM_CONDITIONAL(WITH_QMI, test "x$with_qmi" = "xyes") From 7354dc928f389d090dfa5c3599ed199f232c2fde Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 06:36:36 +0100 Subject: [PATCH 149/675] api: new 5GNR capability --- include/ModemManager-enums.h | 4 +++- libmm-glib/mm-modem-3gpp.c | 3 ++- src/mm-iface-modem.c | 8 +++----- src/mm-modem-helpers-qmi.c | 13 ++++++++++++- src/mm-modem-helpers.h | 3 ++- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h index 6d99aa50..e7a82b18 100644 --- a/include/ModemManager-enums.h +++ b/include/ModemManager-enums.h @@ -37,6 +37,7 @@ * @MM_MODEM_CAPABILITY_GSM_UMTS: Modem supports at least one of GSM, GPRS, EDGE, UMTS, HSDPA, HSUPA, or HSPA+ packet switched data capability. * @MM_MODEM_CAPABILITY_LTE: Modem has LTE data capability. * @MM_MODEM_CAPABILITY_IRIDIUM: Modem has Iridium capabilities. + * @MM_MODEM_CAPABILITY_5GNR: Modem has 5GNR capabilities. Since 1.14. * @MM_MODEM_CAPABILITY_ANY: Mask specifying all capabilities. * * Flags describing one or more of the general access technology families that a @@ -50,8 +51,9 @@ typedef enum { /*< underscore_name=mm_modem_capability >*/ MM_MODEM_CAPABILITY_CDMA_EVDO = 1 << 1, MM_MODEM_CAPABILITY_GSM_UMTS = 1 << 2, MM_MODEM_CAPABILITY_LTE = 1 << 3, - /* MM_MODEM_CAPABILITY_LTE_ADVANCED = 1 << 4 */ + /* MM_MODEM_CAPABILITY_LTE_ADVANCED deprecated */ MM_MODEM_CAPABILITY_IRIDIUM = 1 << 5, + MM_MODEM_CAPABILITY_5GNR = 1 << 6, MM_MODEM_CAPABILITY_ANY = 0xFFFFFFFF } MMModemCapability; diff --git a/libmm-glib/mm-modem-3gpp.c b/libmm-glib/mm-modem-3gpp.c index 97d8fafe..1cfb419d 100644 --- a/libmm-glib/mm-modem-3gpp.c +++ b/libmm-glib/mm-modem-3gpp.c @@ -38,7 +38,8 @@ * properties of the 3GPP interface. * * The 3GPP interface is exposed whenever a modem has any of the 3GPP - * capabilities (%MM_MODEM_CAPABILITY_GSM_UMTS or %MM_MODEM_CAPABILITY_LTE). + * capabilities (%MM_MODEM_CAPABILITY_GSM_UMTS, %MM_MODEM_CAPABILITY_LTE + * or %MM_MODEM_CAPABILITY_5GNR). */ G_DEFINE_TYPE (MMModem3gpp, mm_modem_3gpp, MM_GDBUS_TYPE_MODEM3GPP_PROXY) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 9671e396..c9f5c174 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -4220,8 +4220,7 @@ current_capabilities_internal_load_unlock_required_ready (MMIfaceModem *self, mm_obj_dbg (self, "multimode device without SIM, no 3GPP capabilities"); caps = mm_gdbus_modem_get_current_capabilities (ctx->skeleton); - caps &= ~MM_MODEM_CAPABILITY_GSM_UMTS; - caps &= ~MM_MODEM_CAPABILITY_LTE; + caps &= ~MM_MODEM_CAPABILITY_3GPP; /* CDMA-EVDO must still be around */ g_assert (caps & MM_MODEM_CAPABILITY_CDMA_EVDO); @@ -4283,8 +4282,7 @@ load_current_capabilities_ready (MMIfaceModem *self, /* If the device is a multimode device (3GPP+3GPP2) check whether we have a * SIM or not. */ - if (caps & MM_MODEM_CAPABILITY_CDMA_EVDO && - (caps & MM_MODEM_CAPABILITY_GSM_UMTS || caps & MM_MODEM_CAPABILITY_LTE)) { + if ((caps & MM_MODEM_CAPABILITY_CDMA_EVDO) && (caps & MM_MODEM_CAPABILITY_3GPP)) { mm_obj_dbg (self, "checking if multimode device has a SIM..."); internal_load_unlock_required ( self, @@ -5570,7 +5568,7 @@ mm_iface_modem_is_3gpp_lte_only (MMIfaceModem *self) MMModemCapability capabilities; capabilities = mm_iface_modem_get_current_capabilities (self); - return (capabilities & MM_MODEM_CAPABILITY_LTE) && !((MM_MODEM_CAPABILITY_LTE ^ capabilities) & capabilities); + return ((capabilities & MM_MODEM_CAPABILITY_LTE) && !((MM_MODEM_CAPABILITY_LTE ^ capabilities) & capabilities)); } gboolean diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 531c5849..d735c0d4 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1029,6 +1029,9 @@ mm_modem_capability_from_qmi_rat_mode_preference (QmiNasRatModePreference qmi) if (qmi & QMI_NAS_RAT_MODE_PREFERENCE_LTE) caps |= MM_MODEM_CAPABILITY_LTE; + if (qmi & QMI_NAS_RAT_MODE_PREFERENCE_5GNR) + caps |= MM_MODEM_CAPABILITY_5GNR; + return caps; } @@ -1050,6 +1053,9 @@ mm_modem_capability_to_qmi_rat_mode_preference (MMModemCapability caps) if (caps & MM_MODEM_CAPABILITY_LTE) qmi |= QMI_NAS_RAT_MODE_PREFERENCE_LTE; + if (caps & MM_MODEM_CAPABILITY_5GNR) + qmi |= QMI_NAS_RAT_MODE_PREFERENCE_5GNR; + return qmi; } @@ -1063,6 +1069,11 @@ mm_modem_capability_to_qmi_acquisition_order_preference (MMModemCapability caps) array = g_array_new (FALSE, FALSE, sizeof (QmiNasRadioInterface)); + if (caps & MM_MODEM_CAPABILITY_5GNR) { + value = QMI_NAS_RADIO_INTERFACE_5GNR; + g_array_append_val (array, value); + } + if (caps & MM_MODEM_CAPABILITY_LTE) { value = QMI_NAS_RADIO_INTERFACE_LTE; g_array_append_val (array, value); @@ -1166,7 +1177,7 @@ mm_modem_capability_from_qmi_radio_technology_preference (QmiNasRadioTechnologyP if (qmi & QMI_NAS_RADIO_TECHNOLOGY_PREFERENCE_LTE) caps |= MM_MODEM_CAPABILITY_LTE; - /* FIXME: LTE Advanced? */ + /* NOTE: no 5GNR defined in Technology Preference */ return caps; } diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 4adaee2a..cf60e425 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -41,7 +41,8 @@ #define MM_MODEM_CAPABILITY_3GPP \ (MM_MODEM_CAPABILITY_GSM_UMTS | \ - MM_MODEM_CAPABILITY_LTE) + MM_MODEM_CAPABILITY_LTE | \ + MM_MODEM_CAPABILITY_5GNR) gchar *mm_strip_quotes (gchar *str); const gchar *mm_strip_tag (const gchar *str, From 5db3fa88e92129b723e645c8bece1e620d2a6349 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 07:19:56 +0100 Subject: [PATCH 150/675] api: new 5G mode --- include/ModemManager-enums.h | 2 ++ src/mm-iface-modem.c | 16 ++++++++++++++ src/mm-iface-modem.h | 2 ++ src/mm-modem-helpers-qmi.c | 15 +++++++++++++ src/mm-modem-helpers.c | 41 ++++++++++++++++++++++++++---------- 5 files changed, 65 insertions(+), 11 deletions(-) diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h index e7a82b18..2ce8c40a 100644 --- a/include/ModemManager-enums.h +++ b/include/ModemManager-enums.h @@ -243,6 +243,7 @@ typedef enum { /*< underscore_name=mm_modem_access_technology >*/ * @MM_MODEM_MODE_2G: GPRS, EDGE. * @MM_MODEM_MODE_3G: UMTS, HSxPA. * @MM_MODEM_MODE_4G: LTE. + * @MM_MODEM_MODE_5G: 5GNR. Since 1.14. * @MM_MODEM_MODE_ANY: Any mode can be used (only this value allowed for POTS modems). * * Bitfield to indicate which access modes are supported, allowed or @@ -256,6 +257,7 @@ typedef enum { /*< underscore_name=mm_modem_mode >*/ MM_MODEM_MODE_2G = 1 << 1, MM_MODEM_MODE_3G = 1 << 2, MM_MODEM_MODE_4G = 1 << 3, + MM_MODEM_MODE_5G = 1 << 4, MM_MODEM_MODE_ANY = 0xFFFFFFFF } MMModemMode; diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index c9f5c174..a39fd001 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -5515,6 +5515,22 @@ mm_iface_modem_is_4g_only (MMIfaceModem *self) FALSE); } +gboolean +mm_iface_modem_is_5g (MMIfaceModem *self) +{ + return find_supported_mode (self, MM_MODEM_MODE_5G, NULL); +} + +gboolean +mm_iface_modem_is_5g_only (MMIfaceModem *self) +{ + gboolean only; + + return (find_supported_mode (self, MM_MODEM_MODE_5G, &only) ? + only : + FALSE); +} + /*****************************************************************************/ MMModemCapability diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index 4cb68608..13be87ad 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -402,6 +402,8 @@ gboolean mm_iface_modem_is_3g (MMIfaceModem *self); gboolean mm_iface_modem_is_3g_only (MMIfaceModem *self); gboolean mm_iface_modem_is_4g (MMIfaceModem *self); gboolean mm_iface_modem_is_4g_only (MMIfaceModem *self); +gboolean mm_iface_modem_is_5g (MMIfaceModem *self); +gboolean mm_iface_modem_is_5g_only (MMIfaceModem *self); /* Helpers to query properties */ const gchar *mm_iface_modem_get_model (MMIfaceModem *self); diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index d735c0d4..1ac3bd3f 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -975,6 +975,9 @@ mm_modem_mode_from_qmi_rat_mode_preference (QmiNasRatModePreference qmi) if (qmi & QMI_NAS_RAT_MODE_PREFERENCE_LTE) mode |= MM_MODEM_MODE_4G; + if (qmi & QMI_NAS_RAT_MODE_PREFERENCE_5GNR) + mode |= MM_MODEM_MODE_5G; + return mode; } @@ -1002,6 +1005,9 @@ mm_modem_mode_to_qmi_rat_mode_preference (MMModemMode mode, if (mode & MM_MODEM_MODE_4G) pref |= QMI_NAS_RAT_MODE_PREFERENCE_LTE; + + if (mode & MM_MODEM_MODE_5G) + pref |= QMI_NAS_RAT_MODE_PREFERENCE_5GNR; } return pref; @@ -1107,6 +1113,14 @@ mm_modem_mode_to_qmi_acquisition_order_preference (MMModemMode allowed, array = g_array_new (FALSE, FALSE, sizeof (QmiNasRadioInterface)); + if (allowed & MM_MODEM_MODE_5G) { + value = QMI_NAS_RADIO_INTERFACE_5GNR; + if (preferred == MM_MODEM_MODE_5G) + g_array_prepend_val (array, value); + else + g_array_append_val (array, value); + } + if (allowed & MM_MODEM_MODE_4G) { value = QMI_NAS_RADIO_INTERFACE_LTE; if (preferred == MM_MODEM_MODE_4G) @@ -1300,6 +1314,7 @@ mm_modem_mode_to_qmi_gsm_wcdma_acquisition_order_preference (MMModemMode mode, return QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_AUTOMATIC; case MM_MODEM_MODE_CS: case MM_MODEM_MODE_4G: + case MM_MODEM_MODE_5G: case MM_MODEM_MODE_ANY: default: break; diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index e12a26b7..940ca40a 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1047,22 +1047,38 @@ typedef struct { MMModemMode mode; } Ws46Mode; -/* 3GPP TS 27.007 r14, section 5.9: select wireless network +WS46 */ +/* 3GPP TS 27.007 v16.3.0, section 5.9: select wireless network +WS46 */ static const Ws46Mode ws46_modes[] = { /* GSM Digital Cellular Systems (GERAN only) */ { 12, MM_MODEM_MODE_2G }, /* UTRAN only */ { 22, MM_MODEM_MODE_3G }, /* 3GPP Systems (GERAN, UTRAN and E-UTRAN) */ - { 25, MM_MODEM_MODE_ANY }, + { 25, MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G }, /* E-UTRAN only */ { 28, MM_MODEM_MODE_4G }, /* GERAN and UTRAN */ { 29, MM_MODEM_MODE_2G | MM_MODEM_MODE_3G }, /* GERAN and E-UTRAN */ { 30, MM_MODEM_MODE_2G | MM_MODEM_MODE_4G }, - /* UERAN and E-UTRAN */ + /* UTRAN and E-UTRAN */ { 31, MM_MODEM_MODE_3G | MM_MODEM_MODE_4G }, + /* GERAN, UTRAN, E-UTRAN and NG-RAN */ + { 35, MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G | MM_MODEM_MODE_5G }, + /* NG-RAN only */ + { 36, MM_MODEM_MODE_5G }, + /* E-UTRAN and NG-RAN */ + { 37, MM_MODEM_MODE_4G | MM_MODEM_MODE_5G }, + /* UTRAN, E-UTRAN and NG-RAN */ + { 38, MM_MODEM_MODE_3G | MM_MODEM_MODE_4G | MM_MODEM_MODE_5G }, + /* GERAN, E-UTRAN and NG-RAN */ + { 39, MM_MODEM_MODE_2G | MM_MODEM_MODE_4G | MM_MODEM_MODE_5G }, + /* UTRAN and NG-RAN */ + { 40, MM_MODEM_MODE_3G | MM_MODEM_MODE_5G }, + /* GERAN, UTRAN and NG-RAN */ + { 41, MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_5G }, + /* GERAN and NG-RAN */ + { 42, MM_MODEM_MODE_2G | MM_MODEM_MODE_5G }, }; GArray * @@ -1078,6 +1094,7 @@ mm_3gpp_parse_ws46_test_response (const gchar *response, guint val; guint i; guint j; + gboolean supported_5g = FALSE; gboolean supported_4g = FALSE; gboolean supported_3g = FALSE; gboolean supported_2g = FALSE; @@ -1109,14 +1126,14 @@ mm_3gpp_parse_ws46_test_response (const gchar *response, for (j = 0; j < G_N_ELEMENTS (ws46_modes); j++) { if (ws46_modes[j].ws46 == val) { - if (val != 25) { - if (ws46_modes[j].mode & MM_MODEM_MODE_4G) - supported_4g = TRUE; - if (ws46_modes[j].mode & MM_MODEM_MODE_3G) - supported_3g = TRUE; - if (ws46_modes[j].mode & MM_MODEM_MODE_2G) - supported_2g = TRUE; - } + if (ws46_modes[j].mode & MM_MODEM_MODE_5G) + supported_5g = TRUE; + if (ws46_modes[j].mode & MM_MODEM_MODE_4G) + supported_4g = TRUE; + if (ws46_modes[j].mode & MM_MODEM_MODE_3G) + supported_3g = TRUE; + if (ws46_modes[j].mode & MM_MODEM_MODE_2G) + supported_2g = TRUE; g_array_append_val (modes, ws46_modes[j].mode); break; } @@ -1145,6 +1162,8 @@ mm_3gpp_parse_ws46_test_response (const gchar *response, *mode |= MM_MODEM_MODE_3G; if (supported_4g) *mode |= MM_MODEM_MODE_4G; + if (supported_5g) + *mode |= MM_MODEM_MODE_5G; if (*mode == 0) { inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "No way to fixup the ANY value"); From f912de357439174b1bc08f509052d053cefa2f29 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 07:29:46 +0100 Subject: [PATCH 151/675] broadband-modem: support 5G in +WS46 to capabilities conversion --- src/mm-broadband-modem.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index deb3aa15..4f473b17 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -501,6 +501,10 @@ current_capabilities_ws46_test_ready (MMBaseModem *self, const gchar *response; GArray *modes; guint i; + gboolean is_2g = FALSE; + gboolean is_3g = FALSE; + gboolean is_4g = FALSE; + gboolean is_5g = FALSE; ctx = g_task_get_task_data (task); @@ -513,27 +517,37 @@ current_capabilities_ws46_test_ready (MMBaseModem *self, if (!modes) goto out; - /* Add LTE caps if any of the reported modes supports 4G */ + /* Process list of modes to gather supported ones */ for (i = 0; i < modes->len; i++) { - if (g_array_index (modes, MMModemMode, i) & MM_MODEM_MODE_4G) { - ctx->caps |= MM_MODEM_CAPABILITY_LTE; - break; - } - } + if (g_array_index (modes, MMModemMode, i) & MM_MODEM_MODE_2G) + is_2g = TRUE; + if (g_array_index (modes, MMModemMode, i) & MM_MODEM_MODE_3G) + is_3g = TRUE; + if (g_array_index (modes, MMModemMode, i) & MM_MODEM_MODE_4G) + is_4g = TRUE; + if (g_array_index (modes, MMModemMode, i) & MM_MODEM_MODE_5G) + is_5g = TRUE; + } + + /* Add capabilities from modes */ + if (is_2g || is_3g) + ctx->caps |= MM_MODEM_CAPABILITY_GSM_UMTS; + if (is_4g) + ctx->caps |= MM_MODEM_CAPABILITY_LTE; + if (is_5g) + ctx->caps |= MM_MODEM_CAPABILITY_5GNR; /* The +CGSM capability is saying that the modem is a 3GPP modem, but that * doesn't necessarily mean it's a GSM/UMTS modem, it could be a LTE-only - * device. We did add the GSM_UMTS capability when +CGSM was found, so now - * we'll check if the device only reports 4G-only mode, and remove the - * capability if so. + * or 5GNR-only device. We did add the GSM_UMTS capability when +CGSM was + * found, so now we'll check if the device only reports 4G or 5G modes, and + * remove the capability if so. * * Note that we don't change the default +CGSM -> GSM/UMTS logic, we just * fix it up. */ - if ((modes->len == 1) && (g_array_index (modes, MMModemMode, 0) == MM_MODEM_MODE_4G)) { - g_assert (ctx->caps & MM_MODEM_CAPABILITY_LTE); + if ((is_4g || is_5g) && !is_2g && !is_3g) ctx->caps &= ~MM_MODEM_CAPABILITY_GSM_UMTS; - } g_array_unref (modes); From 1cfd5daf9b67c3394e0541d72210128461282d09 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 07:31:39 +0100 Subject: [PATCH 152/675] api: new 5GNR access technology --- include/ModemManager-enums.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h index 2ce8c40a..47d2ccca 100644 --- a/include/ModemManager-enums.h +++ b/include/ModemManager-enums.h @@ -209,6 +209,7 @@ typedef enum { /*< underscore_name=mm_modem_state_change_reason >*/ * @MM_MODEM_ACCESS_TECHNOLOGY_EVDOA: CDMA2000 EVDO revision A. * @MM_MODEM_ACCESS_TECHNOLOGY_EVDOB: CDMA2000 EVDO revision B. * @MM_MODEM_ACCESS_TECHNOLOGY_LTE: LTE (ETSI 27.007: "E-UTRAN") + * @MM_MODEM_ACCESS_TECHNOLOGY_5GNR: 5GNR (ETSI 27.007: "NG-RAN"). Since 1.14. * @MM_MODEM_ACCESS_TECHNOLOGY_ANY: Mask specifying all access technologies. * * Describes various access technologies that a device uses when registered with @@ -233,6 +234,7 @@ typedef enum { /*< underscore_name=mm_modem_access_technology >*/ MM_MODEM_ACCESS_TECHNOLOGY_EVDOA = 1 << 12, MM_MODEM_ACCESS_TECHNOLOGY_EVDOB = 1 << 13, MM_MODEM_ACCESS_TECHNOLOGY_LTE = 1 << 14, + MM_MODEM_ACCESS_TECHNOLOGY_5GNR = 1 << 15, MM_MODEM_ACCESS_TECHNOLOGY_ANY = 0xFFFFFFFF, } MMModemAccessTechnology; From 9144a9fa344856c484e3354eafc41c11e4a0c4a2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 07:34:15 +0100 Subject: [PATCH 153/675] helpers-qmi: support 5G capabilities and modes --- src/mm-modem-helpers-qmi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 1ac3bd3f..8c99d512 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -42,6 +42,7 @@ mm_modem_capability_from_qmi_radio_interface (QmiDmsRadioInterface network, case QMI_DMS_RADIO_INTERFACE_LTE: return MM_MODEM_CAPABILITY_LTE; case QMI_DMS_RADIO_INTERFACE_5GNR: + return MM_MODEM_CAPABILITY_5GNR; default: mm_obj_warn (log_object, "unhandled QMI radio interface '%u'", (guint)network); return MM_MODEM_CAPABILITY_NONE; @@ -66,6 +67,7 @@ mm_modem_mode_from_qmi_radio_interface (QmiDmsRadioInterface network, case QMI_DMS_RADIO_INTERFACE_LTE: return MM_MODEM_MODE_4G; case QMI_DMS_RADIO_INTERFACE_5GNR: + return MM_MODEM_MODE_5G; default: mm_obj_warn (log_object, "unhandled QMI radio interface '%u'", (guint)network); return MM_MODEM_MODE_NONE; @@ -793,6 +795,7 @@ mm_modem_access_technology_from_qmi_radio_interface (QmiNasRadioInterface interf case QMI_NAS_RADIO_INTERFACE_LTE: return MM_MODEM_ACCESS_TECHNOLOGY_LTE; case QMI_NAS_RADIO_INTERFACE_5GNR: + return MM_MODEM_ACCESS_TECHNOLOGY_5GNR; case QMI_NAS_RADIO_INTERFACE_UNKNOWN: case QMI_NAS_RADIO_INTERFACE_TD_SCDMA: case QMI_NAS_RADIO_INTERFACE_AMPS: @@ -890,6 +893,7 @@ mm_modem_mode_from_qmi_nas_radio_interface (QmiNasRadioInterface iface) case QMI_NAS_RADIO_INTERFACE_LTE: return MM_MODEM_MODE_4G; case QMI_NAS_RADIO_INTERFACE_5GNR: + return MM_MODEM_MODE_5G; case QMI_NAS_RADIO_INTERFACE_NONE: case QMI_NAS_RADIO_INTERFACE_AMPS: case QMI_NAS_RADIO_INTERFACE_TD_SCDMA: From 05301f23a1f3fdacb3a024b38d48d0129305daf0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 07:58:23 +0100 Subject: [PATCH 154/675] iface-modem-3gpp: new 5GS network support --- .../altair/mm-broadband-modem-altair-lte.c | 20 ++- src/mm-broadband-modem-mbim.c | 7 +- src/mm-broadband-modem-qmi.c | 13 +- src/mm-broadband-modem.c | 53 +++--- src/mm-iface-modem-3gpp.c | 158 +++++++++++------- src/mm-iface-modem-3gpp.h | 12 +- src/mm-iface-modem.c | 25 ++- 7 files changed, 183 insertions(+), 105 deletions(-) diff --git a/plugins/altair/mm-broadband-modem-altair-lte.c b/plugins/altair/mm-broadband-modem-altair-lte.c index c2965e8d..54702172 100644 --- a/plugins/altair/mm-broadband-modem-altair-lte.c +++ b/plugins/altair/mm-broadband-modem-altair-lte.c @@ -504,12 +504,13 @@ run_registration_checks_ready (MMIfaceModem3gpp *self, } static void -modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, - gboolean cs_supported, - gboolean ps_supported, - gboolean eps_supported, - GAsyncReadyCallback callback, - gpointer user_data) +modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, + gboolean is_cs_supported, + gboolean is_ps_supported, + gboolean is_eps_supported, + gboolean is_5gs_supported, + GAsyncReadyCallback callback, + gpointer user_data) { GTask *task; @@ -517,9 +518,10 @@ modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, g_assert (iface_modem_3gpp_parent->run_registration_checks); iface_modem_3gpp_parent->run_registration_checks (self, - cs_supported, - ps_supported, - eps_supported, + is_cs_supported, + is_ps_supported, + is_eps_supported, + is_5gs_supported, (GAsyncReadyCallback) run_registration_checks_ready, task); } diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index d834beb0..3a55f058 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4066,9 +4066,10 @@ register_state_query_ready (MbimDevice *device, static void modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, - gboolean cs_supported, - gboolean ps_supported, - gboolean eps_supported, + gboolean is_cs_supported, + gboolean is_ps_supported, + gboolean is_eps_supported, + gboolean is_5gs_supported, GAsyncReadyCallback callback, gpointer user_data) { diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index ec85c1c7..30d1113b 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -3311,12 +3311,13 @@ get_system_info_ready (QmiClientNas *client, #endif /* WITH_NEWEST_QMI_COMMANDS */ static void -modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, - gboolean cs_supported, - gboolean ps_supported, - gboolean eps_supported, - GAsyncReadyCallback callback, - gpointer user_data) +modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, + gboolean is_cs_supported, + gboolean is_ps_supported, + gboolean is_eps_supported, + gboolean is_5gs_supported, + GAsyncReadyCallback callback, + gpointer user_data) { GTask *task; QmiClient *client = NULL; diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 4f473b17..a485349f 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -106,6 +106,7 @@ enum { PROP_MODEM_3GPP_CS_NETWORK_SUPPORTED, PROP_MODEM_3GPP_PS_NETWORK_SUPPORTED, PROP_MODEM_3GPP_EPS_NETWORK_SUPPORTED, + PROP_MODEM_3GPP_5GS_NETWORK_SUPPORTED, PROP_MODEM_3GPP_IGNORED_FACILITY_LOCKS, PROP_MODEM_3GPP_INITIAL_EPS_BEARER, PROP_MODEM_CDMA_CDMA1X_REGISTRATION_STATE, @@ -179,6 +180,7 @@ struct _MMBroadbandModemPrivate { gboolean modem_3gpp_cs_network_supported; gboolean modem_3gpp_ps_network_supported; gboolean modem_3gpp_eps_network_supported; + gboolean modem_3gpp_5gs_network_supported; /* Implementation helpers */ GPtrArray *modem_3gpp_registration_regex; MMModem3gppFacility modem_3gpp_ignored_facility_locks; @@ -4860,9 +4862,9 @@ modem_3gpp_register_in_network (MMIfaceModem3gpp *self, /* Registration checks (3GPP interface) */ typedef struct { - gboolean cs_supported; - gboolean ps_supported; - gboolean eps_supported; + gboolean is_cs_supported; + gboolean is_ps_supported; + gboolean is_eps_supported; gboolean run_cs; gboolean run_ps; gboolean run_eps; @@ -5100,10 +5102,10 @@ run_registration_checks_context_step (GTask *task) } /* If all run checks returned errors we fail */ - if ((ctx->cs_supported || ctx->ps_supported || ctx->eps_supported) && - (!ctx->cs_supported || ctx->cs_error) && - (!ctx->ps_supported || ctx->ps_error) && - (!ctx->eps_supported || ctx->eps_error)) { + if ((ctx->is_cs_supported || ctx->is_ps_supported || ctx->is_eps_supported) && + (!ctx->is_cs_supported || ctx->cs_error) && + (!ctx->is_ps_supported || ctx->ps_error) && + (!ctx->is_eps_supported || ctx->eps_error)) { /* Prefer the EPS, and then PS error if any */ if (ctx->eps_error) { g_propagate_error (&error, ctx->eps_error); @@ -5126,23 +5128,25 @@ run_registration_checks_context_step (GTask *task) } static void -modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, - gboolean cs_supported, - gboolean ps_supported, - gboolean eps_supported, - GAsyncReadyCallback callback, - gpointer user_data) +modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, + gboolean is_cs_supported, + gboolean is_ps_supported, + gboolean is_eps_supported, + gboolean is_5gs_supported, + GAsyncReadyCallback callback, + gpointer user_data) { RunRegistrationChecksContext *ctx; GTask *task; ctx = g_new0 (RunRegistrationChecksContext, 1); - ctx->cs_supported = cs_supported; - ctx->ps_supported = ps_supported; - ctx->eps_supported = eps_supported; - ctx->run_cs = cs_supported; - ctx->run_ps = ps_supported; - ctx->run_eps = eps_supported; + ctx->is_cs_supported = is_cs_supported; + ctx->is_ps_supported = is_ps_supported; + ctx->is_eps_supported = is_eps_supported; + ctx->run_cs = is_cs_supported; + ctx->run_ps = is_ps_supported; + ctx->run_eps = is_eps_supported; + /* TODO: 5gs */ task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, ctx, (GDestroyNotify)run_registration_checks_context_free); @@ -11915,6 +11919,9 @@ set_property (GObject *object, case PROP_MODEM_3GPP_EPS_NETWORK_SUPPORTED: self->priv->modem_3gpp_eps_network_supported = g_value_get_boolean (value); break; + case PROP_MODEM_3GPP_5GS_NETWORK_SUPPORTED: + self->priv->modem_3gpp_5gs_network_supported = g_value_get_boolean (value); + break; case PROP_MODEM_3GPP_IGNORED_FACILITY_LOCKS: self->priv->modem_3gpp_ignored_facility_locks = g_value_get_flags (value); break; @@ -12051,6 +12058,9 @@ get_property (GObject *object, case PROP_MODEM_3GPP_EPS_NETWORK_SUPPORTED: g_value_set_boolean (value, self->priv->modem_3gpp_eps_network_supported); break; + case PROP_MODEM_3GPP_5GS_NETWORK_SUPPORTED: + g_value_set_boolean (value, self->priv->modem_3gpp_5gs_network_supported); + break; case PROP_MODEM_3GPP_IGNORED_FACILITY_LOCKS: g_value_set_flags (value, self->priv->modem_3gpp_ignored_facility_locks); break; @@ -12131,6 +12141,7 @@ mm_broadband_modem_init (MMBroadbandModem *self) self->priv->modem_3gpp_cs_network_supported = TRUE; self->priv->modem_3gpp_ps_network_supported = TRUE; self->priv->modem_3gpp_eps_network_supported = FALSE; + self->priv->modem_3gpp_5gs_network_supported = FALSE; self->priv->modem_3gpp_ignored_facility_locks = MM_MODEM_3GPP_FACILITY_NONE; self->priv->modem_cdma_cdma1x_registration_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; self->priv->modem_cdma_evdo_registration_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN; @@ -12618,6 +12629,10 @@ mm_broadband_modem_class_init (MMBroadbandModemClass *klass) PROP_MODEM_3GPP_EPS_NETWORK_SUPPORTED, MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED); + g_object_class_override_property (object_class, + PROP_MODEM_3GPP_5GS_NETWORK_SUPPORTED, + MM_IFACE_MODEM_3GPP_5GS_NETWORK_SUPPORTED); + g_object_class_override_property (object_class, PROP_MODEM_3GPP_IGNORED_FACILITY_LOCKS, MM_IFACE_MODEM_3GPP_IGNORED_FACILITY_LOCKS); diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index cbd989f6..f3779c95 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -38,9 +38,10 @@ static GQuark private_quark; typedef struct { /* Registration state */ - MMModem3gppRegistrationState cs; - MMModem3gppRegistrationState ps; - MMModem3gppRegistrationState eps; + MMModem3gppRegistrationState state_cs; + MMModem3gppRegistrationState state_ps; + MMModem3gppRegistrationState state_eps; + MMModem3gppRegistrationState state_5gs; gboolean manual_registration; gchar *manual_registration_operator_id; GCancellable *pending_registration_cancellable; @@ -74,9 +75,10 @@ get_private (MMIfaceModem3gpp *self) priv = g_object_get_qdata (G_OBJECT (self), private_quark); if (!priv) { priv = g_slice_new0 (Private); - priv->cs = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; - priv->ps = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; - priv->eps = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; + priv->state_cs = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; + priv->state_ps = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; + priv->state_eps = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; + priv->state_5gs = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; g_object_set_qdata_full (G_OBJECT (self), private_quark, priv, (GDestroyNotify)private_free); } @@ -140,50 +142,59 @@ get_consolidated_reg_state (MMIfaceModem3gpp *self) * So here we prefer the +CREG response, but if we never got a successful * +CREG response, we'll take +CGREG instead. */ - if (priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || - priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { - consolidated = priv->cs; + if (priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || + priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { + consolidated = priv->state_cs; goto out; } - if (priv->ps == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || - priv->ps == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { - consolidated = priv->ps; + if (priv->state_ps == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || + priv->state_ps == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { + consolidated = priv->state_ps; goto out; } - if (priv->eps == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || - priv->eps == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { - consolidated = priv->eps; + if (priv->state_eps == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || + priv->state_eps == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { + consolidated = priv->state_eps; + goto out; + } + if (priv->state_5gs == MM_MODEM_3GPP_REGISTRATION_STATE_HOME || + priv->state_5gs == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING) { + consolidated = priv->state_5gs; goto out; } /* Searching? */ - if (priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING || - priv->ps == MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING || - priv->eps == MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING) { + if (priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING || + priv->state_ps == MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING || + priv->state_eps == MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING || + priv->state_5gs == MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING) { consolidated = MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING; goto out; } /* If at least one state is DENIED and the others are UNKNOWN or IDLE, use DENIED */ - if ((priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_DENIED || - priv->ps == MM_MODEM_3GPP_REGISTRATION_STATE_DENIED || - priv->eps == MM_MODEM_3GPP_REGISTRATION_STATE_DENIED) && - REG_STATE_IS_UNKNOWN_IDLE_DENIED (priv->cs) && - REG_STATE_IS_UNKNOWN_IDLE_DENIED (priv->ps) && - REG_STATE_IS_UNKNOWN_IDLE_DENIED (priv->eps)) { + if ((priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_DENIED || + priv->state_ps == MM_MODEM_3GPP_REGISTRATION_STATE_DENIED || + priv->state_eps == MM_MODEM_3GPP_REGISTRATION_STATE_DENIED || + priv->state_5gs == MM_MODEM_3GPP_REGISTRATION_STATE_DENIED) && + REG_STATE_IS_UNKNOWN_IDLE_DENIED (priv->state_cs) && + REG_STATE_IS_UNKNOWN_IDLE_DENIED (priv->state_ps) && + REG_STATE_IS_UNKNOWN_IDLE_DENIED (priv->state_eps) && + REG_STATE_IS_UNKNOWN_IDLE_DENIED (priv->state_5gs)) { consolidated = MM_MODEM_3GPP_REGISTRATION_STATE_DENIED; goto out; } /* Emergency services? */ - if (priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY || - priv->ps == MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY || - priv->eps == MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY) { + if (priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY || + priv->state_ps == MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY || + priv->state_eps == MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY || + priv->state_5gs == MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY) { consolidated = MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY; goto out; } - /* Support for additional registration states reported when on LTE. + /* Support for additional registration states reported when on LTE/5GNR. * * For example, we may see the modem registered in LTE (EPS==HOME), and we * may get "SMS only" reported for CS. @@ -195,29 +206,31 @@ get_consolidated_reg_state (MMIfaceModem3gpp *self) * We also warn in that case, because ideally we should always report the * LTE registration state first, not this one. */ - if (priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY || - priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_SMS_ONLY || - priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_HOME_CSFB_NOT_PREFERRED || - priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_CSFB_NOT_PREFERRED) { + if (priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY || + priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_SMS_ONLY || + priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_HOME_CSFB_NOT_PREFERRED || + priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_CSFB_NOT_PREFERRED) { mm_obj_warn (self, "3GPP CSFB registration state is consolidated: %s", - mm_modem_3gpp_registration_state_get_string (priv->cs)); - consolidated = priv->cs; + mm_modem_3gpp_registration_state_get_string (priv->state_cs)); + consolidated = priv->state_cs; goto out; } /* Idle? */ - if (priv->cs == MM_MODEM_3GPP_REGISTRATION_STATE_IDLE || - priv->ps == MM_MODEM_3GPP_REGISTRATION_STATE_IDLE || - priv->eps == MM_MODEM_3GPP_REGISTRATION_STATE_IDLE) { + if (priv->state_cs == MM_MODEM_3GPP_REGISTRATION_STATE_IDLE || + priv->state_ps == MM_MODEM_3GPP_REGISTRATION_STATE_IDLE || + priv->state_eps == MM_MODEM_3GPP_REGISTRATION_STATE_IDLE || + priv->state_5gs == MM_MODEM_3GPP_REGISTRATION_STATE_IDLE) { consolidated = MM_MODEM_3GPP_REGISTRATION_STATE_IDLE; goto out; } out: - mm_obj_dbg (self, "building consolidated registration state: cs '%s', ps '%s', eps '%s' --> '%s'", - mm_modem_3gpp_registration_state_get_string (priv->cs), - mm_modem_3gpp_registration_state_get_string (priv->ps), - mm_modem_3gpp_registration_state_get_string (priv->eps), + mm_obj_dbg (self, "building consolidated registration state: cs '%s', ps '%s', eps '%s', 5gs '%s' --> '%s'", + mm_modem_3gpp_registration_state_get_string (priv->state_cs), + mm_modem_3gpp_registration_state_get_string (priv->state_ps), + mm_modem_3gpp_registration_state_get_string (priv->state_eps), + mm_modem_3gpp_registration_state_get_string (priv->state_5gs), mm_modem_3gpp_registration_state_get_string (consolidated)); return consolidated; @@ -1141,27 +1154,31 @@ mm_iface_modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, GAsyncReadyCallback callback, gpointer user_data) { - gboolean cs_supported = FALSE; - gboolean ps_supported = FALSE; - gboolean eps_supported = FALSE; + gboolean is_cs_supported = FALSE; + gboolean is_ps_supported = FALSE; + gboolean is_eps_supported = FALSE; + gboolean is_5gs_supported = FALSE; g_assert (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->run_registration_checks != NULL); g_object_get (self, - MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED, &cs_supported, - MM_IFACE_MODEM_3GPP_PS_NETWORK_SUPPORTED, &ps_supported, - MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED, &eps_supported, + MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED, &is_cs_supported, + MM_IFACE_MODEM_3GPP_PS_NETWORK_SUPPORTED, &is_ps_supported, + MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED, &is_eps_supported, + MM_IFACE_MODEM_3GPP_5GS_NETWORK_SUPPORTED, &is_5gs_supported, NULL); - mm_obj_dbg (self, "running registration checks (CS: '%s', PS: '%s', EPS: '%s')", - cs_supported ? "yes" : "no", - ps_supported ? "yes" : "no", - eps_supported ? "yes" : "no"); + mm_obj_dbg (self, "running registration checks (CS: '%s', PS: '%s', EPS: '%s', 5GS: '%s')", + is_cs_supported ? "yes" : "no", + is_ps_supported ? "yes" : "no", + is_eps_supported ? "yes" : "no", + is_5gs_supported ? "yes" : "no"); MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->run_registration_checks (self, - cs_supported, - ps_supported, - eps_supported, + is_cs_supported, + is_ps_supported, + is_eps_supported, + is_5gs_supported, callback, user_data); } @@ -1531,7 +1548,7 @@ mm_iface_modem_3gpp_update_cs_registration_state (MMIfaceModem3gpp * return; priv = get_private (self); - priv->cs = state; + priv->state_cs = state; update_registration_state (self, get_consolidated_reg_state (self), TRUE); } @@ -1550,7 +1567,7 @@ mm_iface_modem_3gpp_update_ps_registration_state (MMIfaceModem3gpp * return; priv = get_private (self); - priv->ps = state; + priv->state_ps = state; update_registration_state (self, get_consolidated_reg_state (self), TRUE); } @@ -1569,7 +1586,26 @@ mm_iface_modem_3gpp_update_eps_registration_state (MMIfaceModem3gpp return; priv = get_private (self); - priv->eps = state; + priv->state_eps = state; + update_registration_state (self, get_consolidated_reg_state (self), TRUE); +} + +void +mm_iface_modem_3gpp_update_5gs_registration_state (MMIfaceModem3gpp *self, + MMModem3gppRegistrationState state) +{ + Private *priv; + gboolean supported = FALSE; + + g_object_get (self, + MM_IFACE_MODEM_3GPP_5GS_NETWORK_SUPPORTED, &supported, + NULL); + + if (!supported) + return; + + priv = get_private (self); + priv->state_5gs = state; update_registration_state (self, get_consolidated_reg_state (self), TRUE); } @@ -2627,6 +2663,14 @@ iface_modem_3gpp_init (gpointer g_iface) FALSE, G_PARAM_READWRITE)); + g_object_interface_install_property + (g_iface, + g_param_spec_boolean (MM_IFACE_MODEM_3GPP_5GS_NETWORK_SUPPORTED, + "5GS network supported", + "Whether the modem works in the 5GS network", + FALSE, + G_PARAM_READWRITE)); + g_object_interface_install_property (g_iface, g_param_spec_flags (MM_IFACE_MODEM_3GPP_IGNORED_FACILITY_LOCKS, diff --git a/src/mm-iface-modem-3gpp.h b/src/mm-iface-modem-3gpp.h index 91976fdc..7f3e9cb9 100644 --- a/src/mm-iface-modem-3gpp.h +++ b/src/mm-iface-modem-3gpp.h @@ -34,6 +34,7 @@ #define MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED "iface-modem-3gpp-cs-network-supported" #define MM_IFACE_MODEM_3GPP_PS_NETWORK_SUPPORTED "iface-modem-3gpp-ps-network-supported" #define MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED "iface-modem-3gpp-eps-network-supported" +#define MM_IFACE_MODEM_3GPP_5GS_NETWORK_SUPPORTED "iface-modem-3gpp-5gs-network-supported" #define MM_IFACE_MODEM_3GPP_IGNORED_FACILITY_LOCKS "iface-modem-3gpp-ignored-facility-locks" #define MM_IFACE_MODEM_3GPP_INITIAL_EPS_BEARER "iface-modem-3gpp-initial-eps-bearer" @@ -167,13 +168,14 @@ struct _MMIfaceModem3gpp { MMBaseBearer * (*create_initial_eps_bearer) (MMIfaceModem3gpp *self, MMBearerProperties *properties); - /* Run CS/PS/EPS registration state checks.. + /* Run CS/PS/EPS/5GS registration state checks.. * Note that no registration state is returned, implementations should call * mm_iface_modem_3gpp_update_registration_state(). */ void (* run_registration_checks) (MMIfaceModem3gpp *self, - gboolean cs_supported, - gboolean ps_supported, - gboolean eps_supported, + gboolean is_cs_supported, + gboolean is_ps_supported, + gboolean is_eps_supported, + gboolean is_5gs_supported, GAsyncReadyCallback callback, gpointer user_data); gboolean (*run_registration_checks_finish) (MMIfaceModem3gpp *self, @@ -274,6 +276,8 @@ void mm_iface_modem_3gpp_update_ps_registration_state (MMIfaceModem3gpp *self, MMModem3gppRegistrationState state); void mm_iface_modem_3gpp_update_eps_registration_state (MMIfaceModem3gpp *self, MMModem3gppRegistrationState state); +void mm_iface_modem_3gpp_update_5gs_registration_state (MMIfaceModem3gpp *self, + MMModem3gppRegistrationState state); void mm_iface_modem_3gpp_update_subscription_state (MMIfaceModem3gpp *self, MMModem3gppSubscriptionState state); void mm_iface_modem_3gpp_update_access_technologies (MMIfaceModem3gpp *self, diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index a39fd001..eaab6c17 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -4256,24 +4256,35 @@ load_current_capabilities_ready (MMIfaceModem *self, return; } - /* If LTE capability is reported, enable EPS network registration checks */ + /* By default CS/PS/CDMA1X/EVDO network registration checks are the only + * ones enabled, so fix them up based on capabilities, enabling EPS or 5GS + * checks if required, and disabling CS/PS/CDMA1X/EVDO if required. */ if (caps & MM_MODEM_CAPABILITY_LTE) { mm_obj_dbg (self, "setting EPS network as supported"); g_object_set (G_OBJECT (self), MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED, TRUE, NULL); } - - /* If LTE capability is the only one reported, disable all other network registration checks */ - if (caps == MM_MODEM_CAPABILITY_LTE) { - mm_obj_dbg (self, "setting CS/PS/CDMA1x/EVDO networks as unsupported"); + if (caps & MM_MODEM_CAPABILITY_5GNR) { + mm_obj_dbg (self, "setting 5GS network as supported"); + g_object_set (G_OBJECT (self), + MM_IFACE_MODEM_3GPP_5GS_NETWORK_SUPPORTED, TRUE, + NULL); + } + if (!(caps & MM_MODEM_CAPABILITY_CDMA_EVDO)) { + mm_obj_dbg (self, "setting CDMA1x/EVDO networks as unsupported"); g_object_set (G_OBJECT (self), - MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED, FALSE, - MM_IFACE_MODEM_3GPP_PS_NETWORK_SUPPORTED, FALSE, MM_IFACE_MODEM_CDMA_CDMA1X_NETWORK_SUPPORTED, FALSE, MM_IFACE_MODEM_CDMA_EVDO_NETWORK_SUPPORTED, FALSE, NULL); } + if (!(caps & MM_MODEM_CAPABILITY_GSM_UMTS)) { + mm_obj_dbg (self, "setting CS/PS networks as unsupported"); + g_object_set (G_OBJECT (self), + MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED, FALSE, + MM_IFACE_MODEM_3GPP_PS_NETWORK_SUPPORTED, FALSE, + NULL); + } /* Update current caps right away, even if we may fix them during the * multimode device check. No big deal in updating them twice, as we're not From f31182c08d3801489510cb40cca11f82868d1989 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 08:07:18 +0100 Subject: [PATCH 155/675] iface-modem-3gpp: don't fixup CS network support This is already done by the modem interface as soon as current capabilities are loaded. --- src/mm-iface-modem-3gpp.c | 9 --------- src/mm-iface-modem.c | 9 --------- src/mm-iface-modem.h | 1 - 3 files changed, 19 deletions(-) diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index f3779c95..662052fb 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -2579,15 +2579,6 @@ mm_iface_modem_3gpp_initialize (MMIfaceModem3gpp *self, g_object_set (self, MM_IFACE_MODEM_3GPP_DBUS_SKELETON, skeleton, NULL); - - /* If the modem is *only* LTE, we assume that CS network is not - * supported */ - if (mm_iface_modem_is_3gpp_lte_only (MM_IFACE_MODEM (self))) { - mm_obj_dbg (self, "LTE-only device, assuming CS network is not supported"); - g_object_set (self, - MM_IFACE_MODEM_3GPP_CS_NETWORK_SUPPORTED, FALSE, - NULL); - } } ctx = g_new0 (InitializationContext, 1); diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index eaab6c17..14e64ec3 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -5589,15 +5589,6 @@ mm_iface_modem_is_3gpp_only (MMIfaceModem *self) return (capabilities & MM_MODEM_CAPABILITY_3GPP) && !((MM_MODEM_CAPABILITY_3GPP ^ capabilities) & capabilities); } -gboolean -mm_iface_modem_is_3gpp_lte_only (MMIfaceModem *self) -{ - MMModemCapability capabilities; - - capabilities = mm_iface_modem_get_current_capabilities (self); - return ((capabilities & MM_MODEM_CAPABILITY_LTE) && !((MM_MODEM_CAPABILITY_LTE ^ capabilities) & capabilities)); -} - gboolean mm_iface_modem_is_cdma_only (MMIfaceModem *self) { diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index 13be87ad..541d6f6b 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -391,7 +391,6 @@ MMModemCapability mm_iface_modem_get_current_capabilities (MMIfaceModem *self); gboolean mm_iface_modem_is_3gpp (MMIfaceModem *self); gboolean mm_iface_modem_is_3gpp_only (MMIfaceModem *self); gboolean mm_iface_modem_is_3gpp_lte (MMIfaceModem *self); -gboolean mm_iface_modem_is_3gpp_lte_only (MMIfaceModem *self); gboolean mm_iface_modem_is_cdma (MMIfaceModem *self); gboolean mm_iface_modem_is_cdma_only (MMIfaceModem *self); From 44ace9642cd8a2a80c65655a6d543c69169b2a06 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 23 Mar 2020 10:42:39 +0100 Subject: [PATCH 156/675] modem-helpers: improved +WS46 mode '25' handling The mode '25' means different things on LTE-capable and non-LTE-capable devices, so improve the logic to clarify that. --- src/mm-modem-helpers.c | 43 +++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 940ca40a..5ecbfe12 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1039,7 +1039,9 @@ mm_3gpp_cds_regex_get (void) * NOTE: ignore WS46 prefix or it will break Cinterion handling. * * For the specific case of '25', we will check if any other mode supports - * 4G, and if there is none, we'll remove 4G caps from it. + * 4G, and if there is none, we'll remove 4G caps from it. This is needed + * because pre-LTE modems used '25' to report GERAN+URAN instead of the + * new '29' value since LTE modems are around. */ typedef struct { @@ -1054,7 +1056,7 @@ static const Ws46Mode ws46_modes[] = { /* UTRAN only */ { 22, MM_MODEM_MODE_3G }, /* 3GPP Systems (GERAN, UTRAN and E-UTRAN) */ - { 25, MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G }, + { 25, MM_MODEM_MODE_ANY }, /* E-UTRAN only */ { 28, MM_MODEM_MODE_4G }, /* GERAN and UTRAN */ @@ -1098,6 +1100,8 @@ mm_3gpp_parse_ws46_test_response (const gchar *response, gboolean supported_4g = FALSE; gboolean supported_3g = FALSE; gboolean supported_2g = FALSE; + gboolean supported_mode_25 = FALSE; + gboolean supported_mode_29 = FALSE; r = g_regex_new ("(?:\\+WS46:)?\\s*\\((.*)\\)(?:\\r\\n)?", 0, 0, NULL); g_assert (r != NULL); @@ -1126,15 +1130,21 @@ mm_3gpp_parse_ws46_test_response (const gchar *response, for (j = 0; j < G_N_ELEMENTS (ws46_modes); j++) { if (ws46_modes[j].ws46 == val) { - if (ws46_modes[j].mode & MM_MODEM_MODE_5G) - supported_5g = TRUE; - if (ws46_modes[j].mode & MM_MODEM_MODE_4G) - supported_4g = TRUE; - if (ws46_modes[j].mode & MM_MODEM_MODE_3G) - supported_3g = TRUE; - if (ws46_modes[j].mode & MM_MODEM_MODE_2G) - supported_2g = TRUE; - g_array_append_val (modes, ws46_modes[j].mode); + if (val == 25) + supported_mode_25 = TRUE; + else { + if (val == 29) + supported_mode_29 = TRUE; + if (ws46_modes[j].mode & MM_MODEM_MODE_5G) + supported_5g = TRUE; + if (ws46_modes[j].mode & MM_MODEM_MODE_4G) + supported_4g = TRUE; + if (ws46_modes[j].mode & MM_MODEM_MODE_3G) + supported_3g = TRUE; + if (ws46_modes[j].mode & MM_MODEM_MODE_2G) + supported_2g = TRUE; + g_array_append_val (modes, ws46_modes[j].mode); + } break; } } @@ -1143,6 +1153,17 @@ mm_3gpp_parse_ws46_test_response (const gchar *response, g_warning ("Unknown +WS46 mode reported: %u", val); } + if (supported_mode_25) { + MMModemMode mode_25; + + mode_25 = MM_MODEM_MODE_2G | MM_MODEM_MODE_3G; + if (supported_4g) { + mode_25 |= MM_MODEM_MODE_4G; + g_array_append_val (modes, mode_25); + } else if (!supported_mode_29) + g_array_append_val (modes, mode_25); + } + if (modes->len == 0) { inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "No valid modes reported"); g_clear_pointer (&modes, g_array_unref); From 539562af0181f12343f6ebe2e3ffd44c5efb2fce Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 06:17:34 +0100 Subject: [PATCH 157/675] libmm-glib,helpers: skip quotes when reading numbers from match infos Useful when the regex applied to the parseable strings don't have an special ignore rule for the quotes. --- libmm-glib/mm-common-helpers.c | 39 ++++++++-------------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 5bdb6df4..cdb9115c 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1356,17 +1356,10 @@ mm_get_int_from_match_info (GMatchInfo *match_info, guint32 match_index, gint *out) { - gchar *s; - gboolean ret; + g_autofree gchar *s = NULL; - s = g_match_info_fetch (match_info, match_index); - if (!s) - return FALSE; - - ret = mm_get_int_from_str (s, out); - g_free (s); - - return ret; + s = mm_get_string_unquoted_from_match_info (match_info, match_index); + return (s ? mm_get_int_from_str (s, out) : FALSE); } gboolean @@ -1492,17 +1485,10 @@ mm_get_u64_from_match_info (GMatchInfo *match_info, guint32 match_index, guint64 *out) { - gchar *s; - gboolean ret; - - s = g_match_info_fetch (match_info, match_index); - if (!s) - return FALSE; + g_autofree gchar *s = NULL; - ret = mm_get_u64_from_str (s, out); - g_free (s); - - return ret; + s = mm_get_string_unquoted_from_match_info (match_info, match_index); + return (s ? mm_get_u64_from_str (s, out) : FALSE); } gboolean @@ -1549,17 +1535,10 @@ mm_get_double_from_match_info (GMatchInfo *match_info, guint32 match_index, gdouble *out) { - gchar *s; - gboolean ret; - - s = g_match_info_fetch (match_info, match_index); - if (!s) - return FALSE; - - ret = mm_get_double_from_str (s, out); - g_free (s); + g_autofree gchar *s = NULL; - return ret; + s = mm_get_string_unquoted_from_match_info (match_info, match_index); + return (s ? mm_get_double_from_str (s, out) : FALSE); } gchar * From 1c7304eb718a76dc679b1c08d3e5f0a5cf2d7a2d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 06:22:34 +0100 Subject: [PATCH 158/675] libmm-glib,helpers: allow reading hex strings from match info --- libmm-glib/mm-common-helpers.c | 25 +++++++++++++++++++++++++ libmm-glib/mm-common-helpers.h | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index cdb9115c..8e0fc601 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1491,6 +1491,31 @@ mm_get_u64_from_match_info (GMatchInfo *match_info, return (s ? mm_get_u64_from_str (s, out) : FALSE); } +gboolean +mm_get_uint_from_hex_match_info (GMatchInfo *match_info, + guint32 match_index, + guint *out) +{ + guint64 num; + + if (!mm_get_u64_from_hex_match_info (match_info, match_index, &num) || num > G_MAXUINT) + return FALSE; + + *out = (guint)num; + return TRUE; +} + +gboolean +mm_get_u64_from_hex_match_info (GMatchInfo *match_info, + guint32 match_index, + guint64 *out) +{ + g_autofree gchar *s = NULL; + + s = mm_get_string_unquoted_from_match_info (match_info, match_index); + return (s ? mm_get_u64_from_hex_str (s, out) : FALSE); +} + gboolean mm_get_double_from_str (const gchar *str, gdouble *out) diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h index be9f2bb8..65d0e70a 100644 --- a/libmm-glib/mm-common-helpers.h +++ b/libmm-glib/mm-common-helpers.h @@ -164,6 +164,12 @@ gboolean mm_get_uint_from_match_info (GMatchInfo *match_info, gboolean mm_get_u64_from_match_info (GMatchInfo *match_info, guint32 match_index, guint64 *out); +gboolean mm_get_uint_from_hex_match_info (GMatchInfo *match_info, + guint32 match_index, + guint *out); +gboolean mm_get_u64_from_hex_match_info (GMatchInfo *match_info, + guint32 match_index, + guint64 *out); gboolean mm_get_double_from_str (const gchar *str, gdouble *out); gboolean mm_get_double_from_match_info (GMatchInfo *match_info, From 68917f502e60a73bd1904bf6bf98b65354a55251 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 07:01:36 +0100 Subject: [PATCH 159/675] api: new 'attached RLOS' registration state Reporting the state when the UE attaches to access restricted local operator services. --- include/ModemManager-enums.h | 2 ++ src/mm-base-bearer.c | 1 + src/mm-modem-helpers.c | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h index 47d2ccca..9377ba0f 100644 --- a/include/ModemManager-enums.h +++ b/include/ModemManager-enums.h @@ -1193,6 +1193,7 @@ typedef enum { /*< underscore_name=mm_modem_cdma_rm_protocol >*/ * @MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY: Emergency services only. Since 1.8. * @MM_MODEM_3GPP_REGISTRATION_STATE_HOME_CSFB_NOT_PREFERRED: Registered for "CSFB not preferred", home network (applicable only when on LTE). Since 1.8. * @MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_CSFB_NOT_PREFERRED: Registered for "CSFB not preferred", roaming network (applicable only when on LTE). Since 1.8. + * @MM_MODEM_3GPP_REGISTRATION_STATE_ATTACHED_RLOS: Attached for access to Restricted Local Operator Services (applicable only when on LTE). Since 1.14. * * GSM registration code as defined in 3GPP TS 27.007. * @@ -1210,6 +1211,7 @@ typedef enum { /*< underscore_name=mm_modem_3gpp_registration_state >*/ MM_MODEM_3GPP_REGISTRATION_STATE_EMERGENCY_ONLY = 8, MM_MODEM_3GPP_REGISTRATION_STATE_HOME_CSFB_NOT_PREFERRED = 9, MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_CSFB_NOT_PREFERRED = 10, + MM_MODEM_3GPP_REGISTRATION_STATE_ATTACHED_RLOS = 11, } MMModem3gppRegistrationState; /** diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c index c74eccff..461c4058 100644 --- a/src/mm-base-bearer.c +++ b/src/mm-base-bearer.c @@ -480,6 +480,7 @@ modem_3gpp_registration_state_changed (MMIfaceModem3gpp *modem, case MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY: case MM_MODEM_3GPP_REGISTRATION_STATE_HOME_CSFB_NOT_PREFERRED: case MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING: + case MM_MODEM_3GPP_REGISTRATION_STATE_ATTACHED_RLOS: self->priv->reason_3gpp = CONNECTION_FORBIDDEN_REASON_NONE; break; case MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING: diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 5ecbfe12..e6dbd74c 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -2096,8 +2096,8 @@ mm_3gpp_parse_creg_response (GMatchInfo *info, return FALSE; } - /* 'roaming (csfb not preferred)' is the last valid state */ - if (stat > MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING_CSFB_NOT_PREFERRED) { + /* 'attached RLOS' is the last valid state */ + if (stat > MM_MODEM_3GPP_REGISTRATION_STATE_ATTACHED_RLOS) { mm_obj_warn (log_object, "unknown registration state value '%lu'", stat); stat = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; } From 7eee214b8e6e61db92d564b2757099620d4eccbf Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 07:05:56 +0100 Subject: [PATCH 160/675] helpers: add additional AcT values from 27.007 --- src/mm-modem-helpers.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index e6dbd74c..24690b7b 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1234,7 +1234,8 @@ get_mm_access_tech_from_etsi_access_tech (guint act) { /* See ETSI TS 27.007 */ switch (act) { - case 0: + case 0: /* GSM */ + case 8: /* EC-GSM-IoT (A/Gb mode) */ return MM_MODEM_ACCESS_TECHNOLOGY_GSM; case 1: return MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT; @@ -1248,8 +1249,15 @@ get_mm_access_tech_from_etsi_access_tech (guint act) return MM_MODEM_ACCESS_TECHNOLOGY_HSUPA; case 6: return MM_MODEM_ACCESS_TECHNOLOGY_HSPA; - case 7: + case 7: /* E-UTRAN */ + case 9: /* E-UTRAN (NB-S1) */ + case 10: /* E-UTRA connected to a 5GCN */ return MM_MODEM_ACCESS_TECHNOLOGY_LTE; + case 11: /* NR connected to a 5G CN */ + case 12: /* NG-RAN */ + return MM_MODEM_ACCESS_TECHNOLOGY_5GNR; + case 13: /* E-UTRA-NR dual connectivity */ + return (MM_MODEM_ACCESS_TECHNOLOGY_5GNR | MM_MODEM_ACCESS_TECHNOLOGY_LTE); default: return MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; } From ccb45a8941f2b96a06c032a6d009b6b74c23b3a3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 07:10:45 +0100 Subject: [PATCH 161/675] libmm-glib,helpers: ignore all leading whitespaces when parsing numbers --- libmm-glib/mm-common-helpers.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 8e0fc601..d2c54a1c 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1322,7 +1322,14 @@ mm_get_int_from_str (const gchar *str, glong num; guint eol = 0; - if (!str || !str[0]) + if (!str) + return FALSE; + + /* ignore all leading whitespaces */ + while (str[0] == ' ') + str++; + + if (!str[0]) return FALSE; for (num = 0; str[num]; num++) { @@ -1382,7 +1389,14 @@ mm_get_u64_from_str (const gchar *str, guint64 num; guint eol = 0; - if (!str || !str[0]) + if (!str) + return FALSE; + + /* ignore all leading whitespaces */ + while (str[0] == ' ') + str++; + + if (!str[0]) return FALSE; for (num = 0; str[num]; num++) { @@ -1434,6 +1448,10 @@ mm_get_u64_from_hex_str (const gchar *str, if (!str) return FALSE; + /* ignore all leading whitespaces */ + while (str[0] == ' ') + str++; + if (g_str_has_prefix (str, "0x")) str = &str[2]; From 40b36a25cad1d43a46dc0bdf8acb88189fbfbb53 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 14:32:43 +0100 Subject: [PATCH 162/675] test,modem-helpers: remove obsolete comments in u-blox CREG tests We already support "SMS only" registration state. --- src/tests/test-modem-helpers.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 653bc5e9..60f0a287 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1324,7 +1324,6 @@ test_creg2_ublox_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const gchar *reply = "\r\n+CREG: 2,6,\"8B37\",\"0A265185\",7\r\n"; - /* NOTE: '6' means registered for "SMS only", home network; we just assume UNKNOWN in this case */ const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, FALSE }; test_creg_match ("Ublox Toby-L2 solicited while on LTE", TRUE, reply, data, &result); @@ -1335,7 +1334,6 @@ test_creg2_ublox_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const gchar *reply = "\r\n+CREG: 6,\"8B37\",\"0A265185\",7\r\n"; - /* NOTE: '6' means registered for "SMS only", home network; we just assume UNKNOWN in this case */ const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, FALSE }; test_creg_match ("Ublox Toby-L2 unsolicited while on LTE", FALSE, reply, data, &result); From 040eb3880cae208660ae9e35bde75f7cffd790a7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 07:36:01 +0100 Subject: [PATCH 163/675] helpers: use generic number parsing methods in CREG parser This fixes the s8500 wave unit test, which was incorrectly parsing the Act field reported as 'B' as "GSM" (strtol(B)=0) Also, given that the generic parsing methods are able to parse numbers from quoted strings, this change allows us to remove the Thuraya specific CREG matching that just took into consideration quoted strings. The Thuraya unit tests are also fixed up to provide proper testing of the logic. --- src/mm-modem-helpers.c | 93 ++++++++-------------------------- src/tests/test-modem-helpers.c | 14 ++--- 2 files changed, 28 insertions(+), 79 deletions(-) diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 24690b7b..15962d06 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -828,7 +828,6 @@ mm_flow_control_from_string (const gchar *str, /* +CREG: ,, (GSM 07.07 CREG=2 unsolicited) */ #define CREG3 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)" -#define CREG11 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*(\"[^\"\\s]*\")\\s*,\\s*(\"[^\"\\s]*\")" /* +CREG: ,,, (GSM 07.07 solicited and some CREG=2 unsolicited) */ #define CREG4 "\\+(CREG|CGREG|CEREG):\\s*([0-9]),\\s*([0-9])\\s*,\\s*([^,]*)\\s*,\\s*([^,\\s]*)" @@ -857,8 +856,10 @@ mm_flow_control_from_string (const gchar *str, GPtrArray * mm_3gpp_creg_regex_get (gboolean solicited) { - GPtrArray *array = g_ptr_array_sized_new (13); - GRegex *regex; + GPtrArray *array; + GRegex *regex; + + array = g_ptr_array_sized_new (12); /* #1 */ if (solicited) @@ -940,14 +941,6 @@ mm_3gpp_creg_regex_get (gboolean solicited) g_assert (regex); g_ptr_array_add (array, regex); - /* #11 */ - if (solicited) - regex = g_regex_new (CREG11 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG11 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - /* CEREG #1 */ if (solicited) regex = g_regex_new (CEREG1 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); @@ -1946,35 +1939,6 @@ mm_3gpp_parse_cgact_read_response (const gchar *reply, /*************************************************************************/ -static gulong -parse_uint (gchar *str, - gint base, - gulong nmin, - gulong nmax, - gboolean *valid) -{ - gulong ret = 0; - gchar *endquote; - - *valid = FALSE; - if (!str) - return 0; - - /* Strip quotes */ - if (str[0] == '"') - str++; - endquote = strchr (str, '"'); - if (endquote) - *endquote = '\0'; - - if (strlen (str)) { - ret = strtol (str, NULL, base); - if ((nmin == nmax) || (ret >= nmin && ret <= nmax)) - *valid = TRUE; - } - return *valid ? (guint) ret : 0; -} - static gboolean item_is_lac_not_stat (GMatchInfo *info, guint32 item) { @@ -2000,9 +1964,9 @@ mm_3gpp_parse_creg_response (GMatchInfo *info, gboolean *out_cereg, GError **error) { - gboolean success = FALSE, foo; gint n_matches, act = -1; - gulong stat = 0, lac = 0, ci = 0; + guint stat = 0; + guint64 lac = 0, ci = 0; guint istat = 0, ilac = 0, ici = 0, iact = 0; gchar *str; @@ -2094,10 +2058,7 @@ mm_3gpp_parse_creg_response (GMatchInfo *info, } /* Status */ - str = g_match_info_fetch (info, istat); - stat = parse_uint (str, 10, 0, G_MAXUINT, &success); - g_free (str); - if (!success) { + if (!mm_get_uint_from_match_info (info, istat, &stat)) { g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Could not parse the registration status response"); @@ -2106,43 +2067,31 @@ mm_3gpp_parse_creg_response (GMatchInfo *info, /* 'attached RLOS' is the last valid state */ if (stat > MM_MODEM_3GPP_REGISTRATION_STATE_ATTACHED_RLOS) { - mm_obj_warn (log_object, "unknown registration state value '%lu'", stat); + mm_obj_warn (log_object, "unknown registration state value '%u'", stat); stat = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; } - /* Location Area Code */ - if (ilac) { - /* FIXME: some phones apparently swap the LAC bytes (LG, SonyEricsson, - * Sagem). Need to handle that. - */ - str = g_match_info_fetch (info, ilac); - lac = parse_uint (str, 16, 1, 0xFFFF, &foo); - g_free (str); - } + /* Location Area Code/Tracking Area Code + * FIXME: some phones apparently swap the LAC bytes (LG, SonyEricsson, + * Sagem). Need to handle that. + */ + if (ilac) + mm_get_u64_from_hex_match_info (info, ilac, &lac); /* Cell ID */ - if (ici) { - str = g_match_info_fetch (info, ici); - ci = parse_uint (str, 16, 1, 0x0FFFFFFE, &foo); - g_free (str); - } + if (ici) + mm_get_u64_from_hex_match_info (info, ici, &ci); /* Access Technology */ - if (iact) { - str = g_match_info_fetch (info, iact); - act = (gint) parse_uint (str, 10, 0, 7, &foo); - g_free (str); - if (!foo) - act = -1; - } + if (iact) + mm_get_int_from_match_info (info, iact, &act); *out_reg_state = (MMModem3gppRegistrationState) stat; if (stat != MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN) { /* Don't fill in lac/ci/act if the device's state is unknown */ - *out_lac = lac; - *out_ci = ci; - - *out_act = get_mm_access_tech_from_etsi_access_tech (act); + *out_lac = (gulong)lac; + *out_ci = (gulong)ci; + *out_act = (act >= 0 ? get_mm_access_tech_from_etsi_access_tech (act) : MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN); } return TRUE; } diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 60f0a287..1a0d6078 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1435,7 +1435,7 @@ test_creg2_s8500_wave_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,1,000B,2816, B, C2816\r\n"; - const CregResult result = { 1, 0x000B, 0x2816, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 9, FALSE, FALSE }; + const CregResult result = { 1, 0x000B, 0x2816, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 9, FALSE, FALSE }; test_creg_match ("Samsung Wave S8500 CREG=2", FALSE, reply, data, &result); } @@ -1525,7 +1525,7 @@ test_cereg2_novatel_lte_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2,1, 1F00, 20 ,79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 13, FALSE, TRUE }; + const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 12, FALSE, TRUE }; test_creg_match ("Novatel LTE E362 CEREG=2", TRUE, reply, data, &result); } @@ -1535,7 +1535,7 @@ test_cereg2_novatel_lte_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 1F00, 20 ,79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 12, FALSE, TRUE }; + const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 11, FALSE, TRUE }; test_creg_match ("Novatel LTE E362 CEREG=2", FALSE, reply, data, &result); } @@ -1544,8 +1544,8 @@ static void test_cgreg2_thuraya_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; - const char *reply = "+CGREG: 1, \"0426\", \"F0,0F\""; - const CregResult result = { 1, 0x0426, 0x00F0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 11, TRUE, FALSE }; + const char *reply = "+CGREG: 2, 1, \"0426\", \"F00F\""; + const CregResult result = { 1, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE }; test_creg_match ("Thuraya solicited CREG=2", TRUE, reply, data, &result); } @@ -1554,8 +1554,8 @@ static void test_cgreg2_thuraya_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; - const char *reply = "\r\n+CGREG: 1, \"0426\", \"F0,0F\"\r\n"; - const CregResult result = { 1, 0x0426, 0x00F0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 11, TRUE, FALSE }; + const char *reply = "\r\n+CGREG: 1, \"0426\", \"F00F\"\r\n"; + const CregResult result = { 1, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, TRUE, FALSE }; test_creg_match ("Thuraya unsolicited CREG=2", FALSE, reply, data, &result); } From c78da3de7e6bdd82b53268614b997e5a4f3190f6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 07:38:00 +0100 Subject: [PATCH 164/675] broadband-modem: run +C5GREG state checks The generic CREG parser is improved to also allow parsing +C5GREG responses and URCs. --- src/mm-broadband-modem.c | 172 +++++++++++++++++++-------------- src/mm-modem-helpers.c | 83 +++++++++++----- src/mm-modem-helpers.h | 1 + src/tests/test-modem-helpers.c | 139 +++++++++++++++++--------- 4 files changed, 254 insertions(+), 141 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index a485349f..a56ae354 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -4578,6 +4578,7 @@ registration_state_changed (MMPortSerialAt *port, MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; gboolean cgreg = FALSE; gboolean cereg = FALSE; + gboolean c5greg = FALSE; GError *error = NULL; if (!mm_3gpp_parse_creg_response (match_info, @@ -4588,6 +4589,7 @@ registration_state_changed (MMPortSerialAt *port, &act, &cgreg, &cereg, + &c5greg, &error)) { mm_obj_warn (self, "error parsing unsolicited registration: %s", error && error->message ? error->message : "(unknown)"); @@ -4598,7 +4600,7 @@ registration_state_changed (MMPortSerialAt *port, /* Report new registration state and fix LAC/TAC. * According to 3GPP TS 27.007: * - If CREG reports 7 (LTE) then the field contains TAC - * - CEREG always reports TAC + * - CEREG/C5GREG always reports TAC */ if (cgreg) mm_iface_modem_3gpp_update_ps_registration_state (MM_IFACE_MODEM_3GPP (self), state); @@ -4606,6 +4608,10 @@ registration_state_changed (MMPortSerialAt *port, tac = lac; lac = 0; mm_iface_modem_3gpp_update_eps_registration_state (MM_IFACE_MODEM_3GPP (self), state); + } else if (c5greg) { + tac = lac; + lac = 0; + mm_iface_modem_3gpp_update_5gs_registration_state (MM_IFACE_MODEM_3GPP (self), state); } else { if (act == MM_MODEM_ACCESS_TECHNOLOGY_LTE) { tac = lac; @@ -4865,43 +4871,62 @@ typedef struct { gboolean is_cs_supported; gboolean is_ps_supported; gboolean is_eps_supported; + gboolean is_5gs_supported; gboolean run_cs; gboolean run_ps; gboolean run_eps; + gboolean run_5gs; gboolean running_cs; gboolean running_ps; gboolean running_eps; - GError *cs_error; - GError *ps_error; - GError *eps_error; + gboolean running_5gs; + GError *error_cs; + GError *error_ps; + GError *error_eps; + GError *error_5gs; } RunRegistrationChecksContext; static void run_registration_checks_context_free (RunRegistrationChecksContext *ctx) { - if (ctx->cs_error) - g_error_free (ctx->cs_error); - if (ctx->ps_error) - g_error_free (ctx->ps_error); - if (ctx->eps_error) - g_error_free (ctx->eps_error); + g_clear_error (&ctx->error_cs); + g_clear_error (&ctx->error_ps); + g_clear_error (&ctx->error_eps); + g_clear_error (&ctx->error_5gs); g_free (ctx); } static gboolean -modem_3gpp_run_registration_checks_finish (MMIfaceModem3gpp *self, - GAsyncResult *res, - GError **error) +modem_3gpp_run_registration_checks_finish (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } static void run_registration_checks_context_step (GTask *task); +static void +run_registration_checks_context_set_error (RunRegistrationChecksContext *ctx, + GError *error) +{ + g_assert (error != NULL); + if (ctx->running_cs) + ctx->error_cs = error; + else if (ctx->running_ps) + ctx->error_ps = error; + else if (ctx->running_eps) + ctx->error_eps = error; + else if (ctx->running_5gs) + ctx->error_5gs = error; + else + g_assert_not_reached (); +} + static void registration_status_check_ready (MMBroadbandModem *self, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { RunRegistrationChecksContext *ctx; const gchar *response; @@ -4909,31 +4934,23 @@ registration_status_check_ready (MMBroadbandModem *self, GMatchInfo *match_info = NULL; guint i; gboolean parsed; - gboolean cgreg; - gboolean cereg; - MMModem3gppRegistrationState state; - MMModemAccessTechnology act; - gulong lac; - gulong tac; - gulong cid; + gboolean cgreg = FALSE; + gboolean cereg = FALSE; + gboolean c5greg = FALSE; + MMModem3gppRegistrationState state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; + MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; + gulong lac = 0; + gulong tac = 0; + gulong cid = 0; ctx = g_task_get_task_data (task); /* Only one must be running */ - g_assert ((ctx->running_cs ? 1 : 0) + - (ctx->running_ps ? 1 : 0) + - (ctx->running_eps ? 1 : 0) == 1); + g_assert ((ctx->running_cs + ctx->running_ps + ctx->running_eps + ctx->running_5gs) == 1); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); if (!response) { - g_assert (error != NULL); - if (ctx->running_cs) - ctx->cs_error = error; - else if (ctx->running_ps) - ctx->ps_error = error; - else - ctx->eps_error = error; - + run_registration_checks_context_set_error (ctx, error); run_registration_checks_context_step (task); return; } @@ -4951,8 +4968,7 @@ registration_status_check_ready (MMBroadbandModem *self, for (i = 0; i < self->priv->modem_3gpp_registration_regex->len; i++) { - if (g_regex_match ((GRegex *)g_ptr_array_index ( - self->priv->modem_3gpp_registration_regex, i), + if (g_regex_match ((GRegex *)g_ptr_array_index (self->priv->modem_3gpp_registration_regex, i), response, 0, &match_info)) @@ -4966,24 +4982,11 @@ registration_status_check_ready (MMBroadbandModem *self, MM_CORE_ERROR_FAILED, "Unknown registration status response: '%s'", response); - if (ctx->running_cs) - ctx->cs_error = error; - else if (ctx->running_ps) - ctx->ps_error = error; - else - ctx->eps_error = error; - + run_registration_checks_context_set_error (ctx, error); run_registration_checks_context_step (task); return; } - cgreg = FALSE; - cereg = FALSE; - state = MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; - act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; - tac = 0; - lac = 0; - cid = 0; parsed = mm_3gpp_parse_creg_response (match_info, self, &state, @@ -4992,6 +4995,7 @@ registration_status_check_ready (MMBroadbandModem *self, &act, &cgreg, &cereg, + &c5greg, &error); g_match_info_free (match_info); @@ -5001,12 +5005,7 @@ registration_status_check_ready (MMBroadbandModem *self, MM_CORE_ERROR_FAILED, "Error parsing registration response: '%s'", response); - if (ctx->running_cs) - ctx->cs_error = error; - else if (ctx->running_ps) - ctx->ps_error = error; - else - ctx->eps_error = error; + run_registration_checks_context_set_error (ctx, error); run_registration_checks_context_step (task); return; } @@ -5021,6 +5020,8 @@ registration_status_check_ready (MMBroadbandModem *self, mm_obj_dbg (self, "got PS registration state when checking CS registration state"); else if (ctx->running_eps) mm_obj_dbg (self, "got PS registration state when checking EPS registration state"); + else if (ctx->running_5gs) + mm_obj_dbg (self, "got PS registration state when checking 5GS registration state"); mm_iface_modem_3gpp_update_ps_registration_state (MM_IFACE_MODEM_3GPP (self), state); } else if (cereg) { tac = lac; @@ -5029,7 +5030,19 @@ registration_status_check_ready (MMBroadbandModem *self, mm_obj_dbg (self, "got EPS registration state when checking CS registration state"); else if (ctx->running_ps) mm_obj_dbg (self, "got EPS registration state when checking PS registration state"); + else if (ctx->running_5gs) + mm_obj_dbg (self, "got EPS registration state when checking 5GS registration state"); mm_iface_modem_3gpp_update_eps_registration_state (MM_IFACE_MODEM_3GPP (self), state); + } else if (c5greg) { + tac = lac; + lac = 0; + if (ctx->running_cs) + mm_obj_dbg (self, "got 5GS registration state when checking CS registration state"); + else if (ctx->running_ps) + mm_obj_dbg (self, "got 5GS registration state when checking PS registration state"); + else if (ctx->running_eps) + mm_obj_dbg (self, "got 5GS registration state when checking EPS registration state"); + mm_iface_modem_3gpp_update_5gs_registration_state (MM_IFACE_MODEM_3GPP (self), state); } else { if (act == MM_MODEM_ACCESS_TECHNOLOGY_LTE) { tac = lac; @@ -5039,6 +5052,8 @@ registration_status_check_ready (MMBroadbandModem *self, mm_obj_dbg (self, "got CS registration state when checking PS registration state"); else if (ctx->running_eps) mm_obj_dbg (self, "got CS registration state when checking EPS registration state"); + else if (ctx->running_5gs) + mm_obj_dbg (self, "got CS registration state when checking 5GS registration state"); mm_iface_modem_3gpp_update_cs_registration_state (MM_IFACE_MODEM_3GPP (self), state); } @@ -5061,6 +5076,7 @@ run_registration_checks_context_step (GTask *task) ctx->running_cs = FALSE; ctx->running_ps = FALSE; ctx->running_eps = FALSE; + ctx->running_5gs = FALSE; if (ctx->run_cs) { ctx->running_cs = TRUE; @@ -5101,22 +5117,35 @@ run_registration_checks_context_step (GTask *task) return; } + if (ctx->run_5gs) { + ctx->running_5gs = TRUE; + ctx->run_5gs = FALSE; + /* Check current 5GS-registration state. */ + mm_base_modem_at_command (MM_BASE_MODEM (self), + "+C5GREG?", + 10, + FALSE, + (GAsyncReadyCallback)registration_status_check_ready, + task); + return; + } + /* If all run checks returned errors we fail */ - if ((ctx->is_cs_supported || ctx->is_ps_supported || ctx->is_eps_supported) && - (!ctx->is_cs_supported || ctx->cs_error) && - (!ctx->is_ps_supported || ctx->ps_error) && - (!ctx->is_eps_supported || ctx->eps_error)) { - /* Prefer the EPS, and then PS error if any */ - if (ctx->eps_error) { - g_propagate_error (&error, ctx->eps_error); - ctx->eps_error = NULL; - } else if (ctx->ps_error) { - g_propagate_error (&error, ctx->ps_error); - ctx->ps_error = NULL; - } else if (ctx->cs_error) { - g_propagate_error (&error, ctx->cs_error); - ctx->cs_error = NULL; - } else + if ((ctx->is_cs_supported || ctx->is_ps_supported || ctx->is_eps_supported || ctx->is_5gs_supported) && + (!ctx->is_cs_supported || ctx->error_cs) && + (!ctx->is_ps_supported || ctx->error_ps) && + (!ctx->is_eps_supported || ctx->error_eps) && + (!ctx->is_5gs_supported || ctx->error_5gs)) { + /* When reporting errors, prefer the 5GS, then EPS, then PS, then CS */ + if (ctx->error_5gs) + error = g_steal_pointer (&ctx->error_5gs); + else if (ctx->error_eps) + error = g_steal_pointer (&ctx->error_eps); + else if (ctx->error_ps) + error = g_steal_pointer (&ctx->error_ps); + else if (ctx->error_cs) + error = g_steal_pointer (&ctx->error_cs); + else g_assert_not_reached (); } @@ -5143,10 +5172,11 @@ modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, ctx->is_cs_supported = is_cs_supported; ctx->is_ps_supported = is_ps_supported; ctx->is_eps_supported = is_eps_supported; + ctx->is_5gs_supported = is_5gs_supported; ctx->run_cs = is_cs_supported; ctx->run_ps = is_ps_supported; ctx->run_eps = is_eps_supported; - /* TODO: 5gs */ + ctx->run_5gs = is_5gs_supported; task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, ctx, (GDestroyNotify)run_registration_checks_context_free); diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 15962d06..5ec38823 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -821,10 +821,10 @@ mm_flow_control_from_string (const gchar *str, /*************************************************************************/ /* +CREG: (GSM 07.07 CREG=1 unsolicited) */ -#define CREG1 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9])" +#define CREG1 "\\+(CREG|CGREG|CEREG|C5GREG):\\s*0*([0-9])" /* +CREG: , (GSM 07.07 CREG=1 solicited) */ -#define CREG2 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*0*([0-9])" +#define CREG2 "\\+(CREG|CGREG|CEREG|C5GREG):\\s*0*([0-9]),\\s*0*([0-9])" /* +CREG: ,, (GSM 07.07 CREG=2 unsolicited) */ #define CREG3 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)" @@ -853,13 +853,19 @@ mm_flow_control_from_string (const gchar *str, /* +CEREG: ,,,,, (ETSI 27.007 v8.6 CREG=2 solicited with RAC) */ #define CEREG2 "\\+(CEREG):\\s*0*([0-9]),\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*0*([0-9])" +/* +C5GREG: ,,,,, (ETSI 27.007 CREG=2 unsolicited) */ +#define C5GREG1 "\\+(C5GREG):\\s*([0-9]+)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([0-9]+)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)" + +/* +C5GREG: ,,,,,, (ETSI 27.007 solicited) */ +#define C5GREG2 "\\+(C5GREG):\\s*([0-9]+)\\s*,\\s*([0-9+])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([0-9]+)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)" + GPtrArray * mm_3gpp_creg_regex_get (gboolean solicited) { GPtrArray *array; GRegex *regex; - array = g_ptr_array_sized_new (12); + array = g_ptr_array_sized_new (14); /* #1 */ if (solicited) @@ -957,6 +963,22 @@ mm_3gpp_creg_regex_get (gboolean solicited) g_assert (regex); g_ptr_array_add (array, regex); + /* C5GREG #1 */ + if (solicited) + regex = g_regex_new (C5GREG1 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + else + regex = g_regex_new ("\\r\\n" C5GREG1 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + g_assert (regex); + g_ptr_array_add (array, regex); + + /* C5GREG #2 */ + if (solicited) + regex = g_regex_new (C5GREG2 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + else + regex = g_regex_new ("\\r\\n" C5GREG2 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + g_assert (regex); + g_ptr_array_add (array, regex); + return array; } @@ -1962,6 +1984,7 @@ mm_3gpp_parse_creg_response (GMatchInfo *info, MMModemAccessTechnology *out_act, gboolean *out_cgreg, gboolean *out_cereg, + gboolean *out_c5greg, GError **error) { gint n_matches, act = -1; @@ -1970,17 +1993,19 @@ mm_3gpp_parse_creg_response (GMatchInfo *info, guint istat = 0, ilac = 0, ici = 0, iact = 0; gchar *str; - g_return_val_if_fail (info != NULL, FALSE); - g_return_val_if_fail (out_reg_state != NULL, FALSE); - g_return_val_if_fail (out_lac != NULL, FALSE); - g_return_val_if_fail (out_ci != NULL, FALSE); - g_return_val_if_fail (out_act != NULL, FALSE); - g_return_val_if_fail (out_cgreg != NULL, FALSE); - g_return_val_if_fail (out_cereg != NULL, FALSE); + g_assert (info != NULL); + g_assert (out_reg_state != NULL); + g_assert (out_lac != NULL); + g_assert (out_ci != NULL); + g_assert (out_act != NULL); + g_assert (out_cgreg != NULL); + g_assert (out_cereg != NULL); + g_assert (out_c5greg != NULL); str = g_match_info_fetch (info, 1); *out_cgreg = (str && strstr (str, "CGREG")) ? TRUE : FALSE; *out_cereg = (str && strstr (str, "CEREG")) ? TRUE : FALSE; + *out_c5greg = (str && strstr (str, "C5GREG")) ? TRUE : FALSE; g_free (str); /* Normally the number of matches could be used to determine what each @@ -2025,37 +2050,49 @@ mm_3gpp_parse_creg_response (GMatchInfo *info, /* Check if the third item is the LAC to distinguish the two cases */ if (item_is_lac_not_stat (info, 3)) { istat = 2; - ilac = 3; + ilac = 3; } else { istat = 3; - ilac = 4; + ilac = 4; } - ici = 5; + ici = 5; iact = 6; } else { /* Check if the third item is the LAC to distinguish the two cases */ if (item_is_lac_not_stat (info, 3)) { istat = 2; - ilac = 3; - ici = 4; - iact = 5; + ilac = 3; + ici = 4; + iact = 5; } else { istat = 3; - ilac = 4; - ici = 5; - iact = 6; + ilac = 4; + ici = 5; + iact = 6; } } } else if (n_matches == 8) { /* CEREG=2 (solicited with RAC): +CEREG: ,,,,, + * C5GREG=2 (unsolicited): +C5GREG: ,,,,, */ if (*out_cereg) { istat = 3; - ilac = 4; - ici = 6; - iact = 7; + ilac = 4; + ici = 6; + iact = 7; + } else if (*out_c5greg) { + istat = 2; + ilac = 3; + ici = 4; + iact = 5; } - } + } else if (n_matches == 9) { + /* C5GREG=2 (solicited): +C5GREG: ,,,,,, */ + istat = 3; + ilac = 4; + ici = 5; + iact = 6; + } /* Status */ if (!mm_get_uint_from_match_info (info, istat, &stat)) { diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index cf60e425..c1a1b2c9 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -222,6 +222,7 @@ gboolean mm_3gpp_parse_creg_response (GMatchInfo *info, MMModemAccessTechnology *out_act, gboolean *out_cgreg, gboolean *out_cereg, + gboolean *out_c5greg, GError **error); /* AT+CMGF=? (SMS message format) response parser */ diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 1a0d6078..49cea874 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1094,6 +1094,7 @@ typedef struct { guint regex_num; gboolean cgreg; gboolean cereg; + gboolean c5greg; } CregResult; static void @@ -1109,7 +1110,7 @@ test_creg_match (const char *test, MMModemAccessTechnology access_tech = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; gulong lac = 0, ci = 0; GError *error = NULL; - gboolean success, cgreg = FALSE, cereg = FALSE; + gboolean success, cgreg = FALSE, cereg = FALSE, c5greg = FALSE; guint regex_num = 0; GPtrArray *array; @@ -1143,19 +1144,18 @@ test_creg_match (const char *test, g_assert (info != NULL); g_assert_cmpuint (regex_num, ==, result->regex_num); - success = mm_3gpp_parse_creg_response (info, NULL, &state, &lac, &ci, &access_tech, &cgreg, &cereg, &error); + success = mm_3gpp_parse_creg_response (info, NULL, &state, &lac, &ci, &access_tech, &cgreg, &cereg, &c5greg, &error); + g_match_info_free (info); g_assert (success); g_assert_no_error (error); g_assert_cmpuint (state, ==, result->state); - g_assert (lac == result->lac); - g_assert (ci == result->ci); - - g_debug (" access_tech (%d) == result->act (%d)", - access_tech, result->act); + g_assert_cmpuint (lac, ==, result->lac); + g_assert_cmpuint (ci, ==, result->ci); g_assert_cmpuint (access_tech, ==, result->act); g_assert_cmpuint (cgreg, ==, result->cgreg); g_assert_cmpuint (cereg, ==, result->cereg); + g_assert_cmpuint (c5greg, ==, result->c5greg); } static void @@ -1163,7 +1163,7 @@ test_creg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 1,3"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, FALSE }; + const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, FALSE, FALSE }; test_creg_match ("CREG=1", TRUE, reply, data, &result); } @@ -1173,7 +1173,7 @@ test_creg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 3\r\n"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, FALSE }; + const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, FALSE, FALSE }; test_creg_match ("CREG=1", FALSE, reply, data, &result); } @@ -1183,7 +1183,7 @@ test_creg2_mercury_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 0,1,84CD,00D30173"; - const CregResult result = { 1, 0x84cd, 0xd30173, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE }; + const CregResult result = { 1, 0x84cd, 0xd30173, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; test_creg_match ("Sierra Mercury CREG=2", TRUE, reply, data, &result); } @@ -1193,7 +1193,7 @@ test_creg2_mercury_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,84CD,00D30156\r\n"; - const CregResult result = { 1, 0x84cd, 0xd30156, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE }; + const CregResult result = { 1, 0x84cd, 0xd30156, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; test_creg_match ("Sierra Mercury CREG=2", FALSE, reply, data, &result); } @@ -1203,7 +1203,7 @@ test_creg2_sek850i_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,1,\"CE00\",\"01CEAD8F\""; - const CregResult result = { 1, 0xce00, 0x01cead8f, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE }; + const CregResult result = { 1, 0xce00, 0x01cead8f, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; test_creg_match ("Sony Ericsson K850i CREG=2", TRUE, reply, data, &result); } @@ -1213,7 +1213,7 @@ test_creg2_sek850i_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,\"CE00\",\"00005449\"\r\n"; - const CregResult result = { 1, 0xce00, 0x5449, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE }; + const CregResult result = { 1, 0xce00, 0x5449, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; test_creg_match ("Sony Ericsson K850i CREG=2", FALSE, reply, data, &result); } @@ -1223,7 +1223,7 @@ test_creg2_e160g_solicited_unregistered (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,0,00,0"; - const CregResult result = { 0, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE }; + const CregResult result = { 0, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; test_creg_match ("Huawei E160G unregistered CREG=2", TRUE, reply, data, &result); } @@ -1233,7 +1233,7 @@ test_creg2_e160g_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,1,8BE3,2BAF"; - const CregResult result = { 1, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE }; + const CregResult result = { 1, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; test_creg_match ("Huawei E160G CREG=2", TRUE, reply, data, &result); } @@ -1243,7 +1243,7 @@ test_creg2_e160g_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,8BE3,2BAF\r\n"; - const CregResult result = { 2, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE }; + const CregResult result = { 2, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; test_creg_match ("Huawei E160G CREG=2", FALSE, reply, data, &result); } @@ -1253,7 +1253,7 @@ test_creg2_tm506_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,1,\"8BE3\",\"00002BAF\""; - const CregResult result = { 1, 0x8BE3, 0x2BAF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE }; + const CregResult result = { 1, 0x8BE3, 0x2BAF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; /* Test leading zeros in the CI */ test_creg_match ("Sony Ericsson TM-506 CREG=2", TRUE, reply, data, &result); @@ -1264,7 +1264,7 @@ test_creg2_xu870_unsolicited_unregistered (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,,\r\n"; - const CregResult result = { 2, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE }; + const CregResult result = { 2, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; test_creg_match ("Novatel XU870 unregistered CREG=2", FALSE, reply, data, &result); } @@ -1274,7 +1274,7 @@ test_creg2_iridium_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG:002,001,\"18d8\",\"ffff\""; - const CregResult result = { 1, 0x18D8, 0xFFFF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE }; + const CregResult result = { 1, 0x18D8, 0xFFFF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE, FALSE }; test_creg_match ("Iridium, CREG=2", TRUE, reply, data, &result); } @@ -1284,7 +1284,7 @@ test_creg2_no_leading_zeros_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG:2,1,0001,0010"; - const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE }; + const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; test_creg_match ("solicited CREG=2 with no leading zeros in integer fields", TRUE, reply, data, &result); } @@ -1294,7 +1294,7 @@ test_creg2_leading_zeros_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG:002,001,\"0001\",\"0010\""; - const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE }; + const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE, FALSE }; test_creg_match ("solicited CREG=2 with leading zeros in integer fields", TRUE, reply, data, &result); } @@ -1304,7 +1304,7 @@ test_creg2_no_leading_zeros_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,0001,0010,0\r\n"; - const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 6, FALSE, FALSE }; + const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 6, FALSE, FALSE, FALSE }; test_creg_match ("unsolicited CREG=2 with no leading zeros in integer fields", FALSE, reply, data, &result); } @@ -1314,7 +1314,7 @@ test_creg2_leading_zeros_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 001,\"0001\",\"0010\",000\r\n"; - const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 7, FALSE, FALSE }; + const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 7, FALSE, FALSE, FALSE }; test_creg_match ("unsolicited CREG=2 with leading zeros in integer fields", FALSE, reply, data, &result); } @@ -1324,7 +1324,7 @@ test_creg2_ublox_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const gchar *reply = "\r\n+CREG: 2,6,\"8B37\",\"0A265185\",7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, FALSE, FALSE }; test_creg_match ("Ublox Toby-L2 solicited while on LTE", TRUE, reply, data, &result); } @@ -1334,7 +1334,7 @@ test_creg2_ublox_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const gchar *reply = "\r\n+CREG: 6,\"8B37\",\"0A265185\",7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, FALSE, FALSE }; test_creg_match ("Ublox Toby-L2 unsolicited while on LTE", FALSE, reply, data, &result); } @@ -1344,7 +1344,7 @@ test_cgreg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CGREG: 1,3"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, TRUE, FALSE }; + const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, TRUE, FALSE, FALSE }; test_creg_match ("CGREG=1", TRUE, reply, data, &result); } @@ -1354,7 +1354,7 @@ test_cgreg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 3\r\n"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, TRUE, FALSE }; + const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, TRUE, FALSE, FALSE }; test_creg_match ("CGREG=1", FALSE, reply, data, &result); } @@ -1364,7 +1364,7 @@ test_cgreg2_f3607gw_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CGREG: 2,1,\"8BE3\",\"00002B5D\",3"; - const CregResult result = { 1, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 8, TRUE, FALSE }; + const CregResult result = { 1, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 8, TRUE, FALSE, FALSE }; test_creg_match ("Ericsson F3607gw CGREG=2", TRUE, reply, data, &result); } @@ -1374,7 +1374,7 @@ test_cgreg2_f3607gw_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 1,\"8BE3\",\"00002B5D\",3\r\n"; - const CregResult result = { 1, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 6, TRUE, FALSE }; + const CregResult result = { 1, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 6, TRUE, FALSE, FALSE }; test_creg_match ("Ericsson F3607gw CGREG=2", FALSE, reply, data, &result); } @@ -1384,7 +1384,7 @@ test_creg2_md400_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,5,\"0502\",\"0404736D\"\r\n"; - const CregResult result = { 5, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE }; + const CregResult result = { 5, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; test_creg_match ("Sony-Ericsson MD400 CREG=2", FALSE, reply, data, &result); } @@ -1394,7 +1394,7 @@ test_cgreg2_md400_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 5,\"0502\",\"0404736D\",2\r\n"; - const CregResult result = { 5, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UMTS, 6, TRUE, FALSE }; + const CregResult result = { 5, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UMTS, 6, TRUE, FALSE, FALSE }; test_creg_match ("Sony-Ericsson MD400 CGREG=2", FALSE, reply, data, &result); } @@ -1404,7 +1404,7 @@ test_creg_cgreg_multi_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 5\r\n\r\n+CGREG: 0\r\n"; - const CregResult result = { 5, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, FALSE }; + const CregResult result = { 5, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, FALSE, FALSE }; test_creg_match ("Multi CREG/CGREG", FALSE, reply, data, &result); } @@ -1414,7 +1414,7 @@ test_creg_cgreg_multi2_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 0\r\n\r\n+CREG: 5\r\n"; - const CregResult result = { 0, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, TRUE, FALSE }; + const CregResult result = { 0, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, TRUE, FALSE, FALSE }; test_creg_match ("Multi CREG/CGREG #2", FALSE, reply, data, &result); } @@ -1424,7 +1424,7 @@ test_cgreg2_x220_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 2,1, 81ED, 1A9CEB\r\n"; - const CregResult result = { 1, 0x81ED, 0x1A9CEB, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE }; + const CregResult result = { 1, 0x81ED, 0x1A9CEB, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE, FALSE }; /* Tests random spaces in response */ test_creg_match ("Alcatel One-Touch X220D CGREG=2", FALSE, reply, data, &result); @@ -1435,7 +1435,7 @@ test_creg2_s8500_wave_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,1,000B,2816, B, C2816\r\n"; - const CregResult result = { 1, 0x000B, 0x2816, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 9, FALSE, FALSE }; + const CregResult result = { 1, 0x000B, 0x2816, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 9, FALSE, FALSE, FALSE }; test_creg_match ("Samsung Wave S8500 CREG=2", FALSE, reply, data, &result); } @@ -1445,7 +1445,7 @@ test_creg2_gobi_weird_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,1, 0 5, 2715\r\n"; - const CregResult result = { 1, 0x0000, 0x2715, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE }; + const CregResult result = { 1, 0x0000, 0x2715, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; test_creg_match ("Qualcomm Gobi 1000 CREG=2", TRUE, reply, data, &result); } @@ -1455,7 +1455,7 @@ test_cgreg2_unsolicited_with_rac (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 1,\"1422\",\"00000142\",3,\"00\"\r\n"; - const CregResult result = { 1, 0x1422, 0x0142, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 10, TRUE, FALSE }; + const CregResult result = { 1, 0x1422, 0x0142, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 10, TRUE, FALSE, FALSE }; test_creg_match ("CGREG=2 with RAC", FALSE, reply, data, &result); } @@ -1465,7 +1465,7 @@ test_cereg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CEREG: 1,3"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, TRUE }; + const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=1", TRUE, reply, data, &result); } @@ -1475,7 +1475,7 @@ test_cereg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 3\r\n"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, TRUE }; + const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=1", FALSE, reply, data, &result); } @@ -1485,7 +1485,7 @@ test_cereg2_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2,1, 1F00, 79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE }; + const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=2", TRUE, reply, data, &result); } @@ -1495,7 +1495,7 @@ test_cereg2_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 1F00, 79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE }; + const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=2", FALSE, reply, data, &result); } @@ -1505,7 +1505,7 @@ test_cereg2_altair_lte_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 2, 0001, 00000100, 7\r\n"; - const CregResult result = { 2, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE }; + const CregResult result = { 2, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE, FALSE }; test_creg_match ("Altair LTE CEREG=2", FALSE, reply, data, &result); } @@ -1515,7 +1515,7 @@ test_cereg2_altair_lte_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2, 0001, 00000100, 7\r\n"; - const CregResult result = { 2, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE }; + const CregResult result = { 2, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE, FALSE }; test_creg_match ("Altair LTE CEREG=2", FALSE, reply, data, &result); } @@ -1525,7 +1525,7 @@ test_cereg2_novatel_lte_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2,1, 1F00, 20 ,79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 12, FALSE, TRUE }; + const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 12, FALSE, TRUE, FALSE }; test_creg_match ("Novatel LTE E362 CEREG=2", TRUE, reply, data, &result); } @@ -1535,7 +1535,7 @@ test_cereg2_novatel_lte_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 1F00, 20 ,79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 11, FALSE, TRUE }; + const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 11, FALSE, TRUE, FALSE }; test_creg_match ("Novatel LTE E362 CEREG=2", FALSE, reply, data, &result); } @@ -1545,7 +1545,7 @@ test_cgreg2_thuraya_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CGREG: 2, 1, \"0426\", \"F00F\""; - const CregResult result = { 1, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE }; + const CregResult result = { 1, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE, FALSE }; test_creg_match ("Thuraya solicited CREG=2", TRUE, reply, data, &result); } @@ -1555,11 +1555,51 @@ test_cgreg2_thuraya_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 1, \"0426\", \"F00F\"\r\n"; - const CregResult result = { 1, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, TRUE, FALSE }; + const CregResult result = { 1, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, TRUE, FALSE, FALSE }; test_creg_match ("Thuraya unsolicited CREG=2", FALSE, reply, data, &result); } +static void +test_c5greg1_solicited (void *f, gpointer d) +{ + RegTestData *data = (RegTestData *) d; + const char *reply = "+C5GREG: 1,3"; + const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, FALSE, TRUE }; + + test_creg_match ("C5GREG=1", TRUE, reply, data, &result); +} + +static void +test_c5greg1_unsolicited (void *f, gpointer d) +{ + RegTestData *data = (RegTestData *) d; + const char *reply = "\r\n+C5GREG: 3\r\n"; + const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, FALSE, TRUE }; + + test_creg_match ("C5GREG=1", FALSE, reply, data, &result); +} + +static void +test_c5greg2_solicited (void *f, gpointer d) +{ + RegTestData *data = (RegTestData *) d; + const char *reply = "+C5GREG: 2,1,1F00,79D903,11,6,ABCDEF"; + const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 14, FALSE, FALSE, TRUE }; + + test_creg_match ("C5GREG=2", TRUE, reply, data, &result); +} + +static void +test_c5greg2_unsolicited (void *f, gpointer d) +{ + RegTestData *data = (RegTestData *) d; + const char *reply = "\r\n+C5GREG: 1,1F00,79D903,11,6,ABCDEF\r\n"; + const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 13, FALSE, FALSE, TRUE }; + + test_creg_match ("C5GREG=2", FALSE, reply, data, &result); +} + /*****************************************************************************/ /* Test CSCS responses */ @@ -4534,6 +4574,11 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test_cereg2_novatel_lte_solicited, reg_data)); g_test_suite_add (suite, TESTCASE (test_cereg2_novatel_lte_unsolicited, reg_data)); + g_test_suite_add (suite, TESTCASE (test_c5greg1_solicited, reg_data)); + g_test_suite_add (suite, TESTCASE (test_c5greg1_unsolicited, reg_data)); + g_test_suite_add (suite, TESTCASE (test_c5greg2_solicited, reg_data)); + g_test_suite_add (suite, TESTCASE (test_c5greg2_unsolicited, reg_data)); + g_test_suite_add (suite, TESTCASE (test_creg_cgreg_multi_unsolicited, reg_data)); g_test_suite_add (suite, TESTCASE (test_creg_cgreg_multi2_unsolicited, reg_data)); From 28b0e2b43917da0ebb3a69909321f6f06e704ede Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 14:16:45 +0100 Subject: [PATCH 165/675] modem-helpers: simplify logic to create array of GRegex Iterate over the list of available patterns, instead of adding them one by one. --- src/mm-modem-helpers.c | 196 +++++++++-------------------------------- 1 file changed, 44 insertions(+), 152 deletions(-) diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 5ec38823..869fd80e 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -820,165 +820,57 @@ mm_flow_control_from_string (const gchar *str, /*************************************************************************/ -/* +CREG: (GSM 07.07 CREG=1 unsolicited) */ -#define CREG1 "\\+(CREG|CGREG|CEREG|C5GREG):\\s*0*([0-9])" - -/* +CREG: , (GSM 07.07 CREG=1 solicited) */ -#define CREG2 "\\+(CREG|CGREG|CEREG|C5GREG):\\s*0*([0-9]),\\s*0*([0-9])" - -/* +CREG: ,, (GSM 07.07 CREG=2 unsolicited) */ -#define CREG3 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)" - -/* +CREG: ,,, (GSM 07.07 solicited and some CREG=2 unsolicited) */ -#define CREG4 "\\+(CREG|CGREG|CEREG):\\s*([0-9]),\\s*([0-9])\\s*,\\s*([^,]*)\\s*,\\s*([^,\\s]*)" -#define CREG5 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*0*([0-9])\\s*,\\s*(\"[^,]*\")\\s*,\\s*(\"[^,\\s]*\")" - -/* +CREG: ,,, (ETSI 27.007 CREG=2 unsolicited) */ -#define CREG6 "\\+(CREG|CGREG|CEREG):\\s*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([0-9])" -#define CREG7 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9])\\s*,\\s*(\"[^,\\s]*\")\\s*,\\s*(\"[^,\\s]*\")\\s*,\\s*0*([0-9])" - -/* +CREG: ,,,, (ETSI 27.007 solicited and some CREG=2 unsolicited) */ -#define CREG8 "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*0*([0-9])" - -/* +CREG: ,,,,, (Samsung Wave S8500) */ -/* '+CREG: 2,1,000B,2816, B, C2816OK' */ -#define CREG9 "\\+(CREG|CGREG):\\s*0*([0-9]),\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*[^,\\s]*" - -/* +CREG: ,,,, (ETSI 27.007 v9.20 CREG=2 unsolicited with RAC) */ -#define CREG10 "\\+(CREG|CGREG):\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*0*([0-9])\\s*,\\s*([^,\\s]*)" - -/* +CEREG: ,,,, (ETSI 27.007 v8.6 CREG=2 unsolicited with RAC) */ -#define CEREG1 "\\+(CEREG):\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*0*([0-9])" - -/* +CEREG: ,,,,, (ETSI 27.007 v8.6 CREG=2 solicited with RAC) */ -#define CEREG2 "\\+(CEREG):\\s*0*([0-9]),\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*0*([0-9])" - -/* +C5GREG: ,,,,, (ETSI 27.007 CREG=2 unsolicited) */ -#define C5GREG1 "\\+(C5GREG):\\s*([0-9]+)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([0-9]+)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)" - -/* +C5GREG: ,,,,,, (ETSI 27.007 solicited) */ -#define C5GREG2 "\\+(C5GREG):\\s*([0-9]+)\\s*,\\s*([0-9+])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([0-9]+)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)" +static const gchar *creg_regex[] = { + /* +CREG: (GSM 07.07 CREG=1 unsolicited) */ + [0] = "\\+(CREG|CGREG|CEREG|C5GREG):\\s*0*([0-9])", + /* +CREG: , (GSM 07.07 CREG=1 solicited) */ + [1] = "\\+(CREG|CGREG|CEREG|C5GREG):\\s*0*([0-9]),\\s*0*([0-9])", + /* +CREG: ,, (GSM 07.07 CREG=2 unsolicited) */ + [2] = "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)", + /* +CREG: ,,, (GSM 07.07 solicited and some CREG=2 unsolicited) */ + [3] = "\\+(CREG|CGREG|CEREG):\\s*([0-9]),\\s*([0-9])\\s*,\\s*([^,]*)\\s*,\\s*([^,\\s]*)", + [4] = "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*0*([0-9])\\s*,\\s*(\"[^,]*\")\\s*,\\s*(\"[^,\\s]*\")", + /* +CREG: ,,, (ETSI 27.007 CREG=2 unsolicited) */ + [5] = "\\+(CREG|CGREG|CEREG):\\s*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([0-9])", + [6] = "\\+(CREG|CGREG|CEREG):\\s*0*([0-9])\\s*,\\s*(\"[^,\\s]*\")\\s*,\\s*(\"[^,\\s]*\")\\s*,\\s*0*([0-9])", + /* +CREG: ,,,, (ETSI 27.007 solicited and some CREG=2 unsolicited) */ + [7] = "\\+(CREG|CGREG|CEREG):\\s*0*([0-9]),\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*0*([0-9])", + /* +CREG: ,,,,, (Samsung Wave S8500) */ + /* '+CREG: 2,1,000B,2816, B, C2816OK' */ + [8] = "\\+(CREG|CGREG):\\s*0*([0-9]),\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*[^,\\s]*", + /* +CREG: ,,,, (ETSI 27.007 v9.20 CREG=2 unsolicited with RAC) */ + [9] = "\\+(CREG|CGREG):\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*0*([0-9])\\s*,\\s*([^,\\s]*)", + /* +CEREG: ,,,, (ETSI 27.007 v8.6 CREG=2 unsolicited with RAC) */ + [10] = "\\+(CEREG):\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*0*([0-9])", + /* +CEREG: ,,,,, (ETSI 27.007 v8.6 CREG=2 solicited with RAC) */ + [11] = "\\+(CEREG):\\s*0*([0-9]),\\s*0*([0-9])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*0*([0-9])", + /* +C5GREG: ,,,,, (ETSI 27.007 CREG=2 unsolicited) */ + [12] = "\\+(C5GREG):\\s*([0-9]+)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([0-9]+)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)", + /* +C5GREG: ,,,,,, (ETSI 27.007 solicited) */ + [13] = "\\+(C5GREG):\\s*([0-9]+)\\s*,\\s*([0-9+])\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)\\s*,\\s*([0-9]+)\\s*,\\s*([^,\\s]*)\\s*,\\s*([^,\\s]*)", +}; GPtrArray * mm_3gpp_creg_regex_get (gboolean solicited) { GPtrArray *array; - GRegex *regex; - - array = g_ptr_array_sized_new (14); - - /* #1 */ - if (solicited) - regex = g_regex_new (CREG1 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG1 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* #2 */ - if (solicited) - regex = g_regex_new (CREG2 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG2 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* #3 */ - if (solicited) - regex = g_regex_new (CREG3 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG3 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* #4 */ - if (solicited) - regex = g_regex_new (CREG4 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG4 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* #5 */ - if (solicited) - regex = g_regex_new (CREG5 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG5 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* #6 */ - if (solicited) - regex = g_regex_new (CREG6 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG6 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* #7 */ - if (solicited) - regex = g_regex_new (CREG7 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG7 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* #8 */ - if (solicited) - regex = g_regex_new (CREG8 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG8 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* #9 */ - if (solicited) - regex = g_regex_new (CREG9 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG9 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* #10 */ - if (solicited) - regex = g_regex_new (CREG10 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CREG10 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* CEREG #1 */ - if (solicited) - regex = g_regex_new (CEREG1 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CEREG1 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* CEREG #2 */ - if (solicited) - regex = g_regex_new (CEREG2 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" CEREG2 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); - - /* C5GREG #1 */ - if (solicited) - regex = g_regex_new (C5GREG1 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" C5GREG1 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); + guint i; - /* C5GREG #2 */ - if (solicited) - regex = g_regex_new (C5GREG2 "$", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - else - regex = g_regex_new ("\\r\\n" C5GREG2 "\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - g_assert (regex); - g_ptr_array_add (array, regex); + array = g_ptr_array_sized_new (G_N_ELEMENTS (creg_regex)); + for (i = 0; i < G_N_ELEMENTS (creg_regex); i++) { + GRegex *regex; + g_autofree gchar *pattern = NULL; + if (solicited) { + pattern = g_strdup_printf ("%s$", creg_regex[i]); + regex = g_regex_new (pattern, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + } else { + pattern = g_strdup_printf ("\\r\\n%s\\r\\n", creg_regex[i]); + regex = g_regex_new (pattern, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + } + g_assert (regex); + g_ptr_array_add (array, regex); + } return array; } From 8aec9e3889706bc1677c65919297a1310eed5718 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 15:27:57 +0100 Subject: [PATCH 166/675] test,modem-helpers: use MMModem3gppRegistrationState values in tests --- src/tests/test-modem-helpers.c | 88 +++++++++++++++++----------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 49cea874..1f15e012 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1163,7 +1163,7 @@ test_creg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 1,3"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 2, FALSE, FALSE, FALSE }; test_creg_match ("CREG=1", TRUE, reply, data, &result); } @@ -1173,7 +1173,7 @@ test_creg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 3\r\n"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, FALSE, FALSE }; test_creg_match ("CREG=1", FALSE, reply, data, &result); } @@ -1182,8 +1182,8 @@ static void test_creg2_mercury_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; - const char *reply = "+CREG: 0,1,84CD,00D30173"; - const CregResult result = { 1, 0x84cd, 0xd30173, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; + const char *reply = "+CREG: 1,1,84CD,00D30173"; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x84cd, 0xd30173, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; test_creg_match ("Sierra Mercury CREG=2", TRUE, reply, data, &result); } @@ -1193,7 +1193,7 @@ test_creg2_mercury_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,84CD,00D30156\r\n"; - const CregResult result = { 1, 0x84cd, 0xd30156, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x84cd, 0xd30156, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; test_creg_match ("Sierra Mercury CREG=2", FALSE, reply, data, &result); } @@ -1203,7 +1203,7 @@ test_creg2_sek850i_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,1,\"CE00\",\"01CEAD8F\""; - const CregResult result = { 1, 0xce00, 0x01cead8f, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0xce00, 0x01cead8f, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; test_creg_match ("Sony Ericsson K850i CREG=2", TRUE, reply, data, &result); } @@ -1213,7 +1213,7 @@ test_creg2_sek850i_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,\"CE00\",\"00005449\"\r\n"; - const CregResult result = { 1, 0xce00, 0x5449, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0xce00, 0x5449, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; test_creg_match ("Sony Ericsson K850i CREG=2", FALSE, reply, data, &result); } @@ -1223,7 +1223,7 @@ test_creg2_e160g_solicited_unregistered (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,0,00,0"; - const CregResult result = { 0, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; test_creg_match ("Huawei E160G unregistered CREG=2", TRUE, reply, data, &result); } @@ -1233,7 +1233,7 @@ test_creg2_e160g_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,1,8BE3,2BAF"; - const CregResult result = { 1, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; test_creg_match ("Huawei E160G CREG=2", TRUE, reply, data, &result); } @@ -1242,8 +1242,8 @@ static void test_creg2_e160g_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; - const char *reply = "\r\n+CREG: 2,8BE3,2BAF\r\n"; - const CregResult result = { 2, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; + const char *reply = "\r\n+CREG: 1,8BE3,2BAF\r\n"; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; test_creg_match ("Huawei E160G CREG=2", FALSE, reply, data, &result); } @@ -1253,7 +1253,7 @@ test_creg2_tm506_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,1,\"8BE3\",\"00002BAF\""; - const CregResult result = { 1, 0x8BE3, 0x2BAF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8BE3, 0x2BAF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; /* Test leading zeros in the CI */ test_creg_match ("Sony Ericsson TM-506 CREG=2", TRUE, reply, data, &result); @@ -1264,7 +1264,7 @@ test_creg2_xu870_unsolicited_unregistered (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,,\r\n"; - const CregResult result = { 2, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; test_creg_match ("Novatel XU870 unregistered CREG=2", FALSE, reply, data, &result); } @@ -1274,7 +1274,7 @@ test_creg2_iridium_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG:002,001,\"18d8\",\"ffff\""; - const CregResult result = { 1, 0x18D8, 0xFFFF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x18D8, 0xFFFF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE, FALSE }; test_creg_match ("Iridium, CREG=2", TRUE, reply, data, &result); } @@ -1284,7 +1284,7 @@ test_creg2_no_leading_zeros_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG:2,1,0001,0010"; - const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; test_creg_match ("solicited CREG=2 with no leading zeros in integer fields", TRUE, reply, data, &result); } @@ -1294,7 +1294,7 @@ test_creg2_leading_zeros_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG:002,001,\"0001\",\"0010\""; - const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE, FALSE }; test_creg_match ("solicited CREG=2 with leading zeros in integer fields", TRUE, reply, data, &result); } @@ -1304,7 +1304,7 @@ test_creg2_no_leading_zeros_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,0001,0010,0\r\n"; - const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 6, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 6, FALSE, FALSE, FALSE }; test_creg_match ("unsolicited CREG=2 with no leading zeros in integer fields", FALSE, reply, data, &result); } @@ -1314,7 +1314,7 @@ test_creg2_leading_zeros_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 001,\"0001\",\"0010\",000\r\n"; - const CregResult result = { 1, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 7, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 7, FALSE, FALSE, FALSE }; test_creg_match ("unsolicited CREG=2 with leading zeros in integer fields", FALSE, reply, data, &result); } @@ -1344,7 +1344,7 @@ test_cgreg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CGREG: 1,3"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, TRUE, FALSE, FALSE }; test_creg_match ("CGREG=1", TRUE, reply, data, &result); } @@ -1354,7 +1354,7 @@ test_cgreg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 3\r\n"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, TRUE, FALSE, FALSE }; test_creg_match ("CGREG=1", FALSE, reply, data, &result); } @@ -1364,7 +1364,7 @@ test_cgreg2_f3607gw_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CGREG: 2,1,\"8BE3\",\"00002B5D\",3"; - const CregResult result = { 1, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 8, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 8, TRUE, FALSE, FALSE }; test_creg_match ("Ericsson F3607gw CGREG=2", TRUE, reply, data, &result); } @@ -1374,7 +1374,7 @@ test_cgreg2_f3607gw_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 1,\"8BE3\",\"00002B5D\",3\r\n"; - const CregResult result = { 1, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 6, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 6, TRUE, FALSE, FALSE }; test_creg_match ("Ericsson F3607gw CGREG=2", FALSE, reply, data, &result); } @@ -1384,7 +1384,7 @@ test_creg2_md400_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,5,\"0502\",\"0404736D\"\r\n"; - const CregResult result = { 5, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; test_creg_match ("Sony-Ericsson MD400 CREG=2", FALSE, reply, data, &result); } @@ -1394,7 +1394,7 @@ test_cgreg2_md400_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 5,\"0502\",\"0404736D\",2\r\n"; - const CregResult result = { 5, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UMTS, 6, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UMTS, 6, TRUE, FALSE, FALSE }; test_creg_match ("Sony-Ericsson MD400 CGREG=2", FALSE, reply, data, &result); } @@ -1404,7 +1404,7 @@ test_creg_cgreg_multi_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 5\r\n\r\n+CGREG: 0\r\n"; - const CregResult result = { 5, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, FALSE, FALSE }; test_creg_match ("Multi CREG/CGREG", FALSE, reply, data, &result); } @@ -1414,7 +1414,7 @@ test_creg_cgreg_multi2_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 0\r\n\r\n+CREG: 5\r\n"; - const CregResult result = { 0, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, TRUE, FALSE, FALSE }; test_creg_match ("Multi CREG/CGREG #2", FALSE, reply, data, &result); } @@ -1424,7 +1424,7 @@ test_cgreg2_x220_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 2,1, 81ED, 1A9CEB\r\n"; - const CregResult result = { 1, 0x81ED, 0x1A9CEB, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x81ED, 0x1A9CEB, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE, FALSE }; /* Tests random spaces in response */ test_creg_match ("Alcatel One-Touch X220D CGREG=2", FALSE, reply, data, &result); @@ -1435,7 +1435,7 @@ test_creg2_s8500_wave_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,1,000B,2816, B, C2816\r\n"; - const CregResult result = { 1, 0x000B, 0x2816, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 9, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x000B, 0x2816, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 9, FALSE, FALSE, FALSE }; test_creg_match ("Samsung Wave S8500 CREG=2", FALSE, reply, data, &result); } @@ -1445,7 +1445,7 @@ test_creg2_gobi_weird_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,1, 0 5, 2715\r\n"; - const CregResult result = { 1, 0x0000, 0x2715, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0000, 0x2715, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; test_creg_match ("Qualcomm Gobi 1000 CREG=2", TRUE, reply, data, &result); } @@ -1455,7 +1455,7 @@ test_cgreg2_unsolicited_with_rac (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 1,\"1422\",\"00000142\",3,\"00\"\r\n"; - const CregResult result = { 1, 0x1422, 0x0142, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 10, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1422, 0x0142, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 10, TRUE, FALSE, FALSE }; test_creg_match ("CGREG=2 with RAC", FALSE, reply, data, &result); } @@ -1465,7 +1465,7 @@ test_cereg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CEREG: 1,3"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=1", TRUE, reply, data, &result); } @@ -1475,7 +1475,7 @@ test_cereg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 3\r\n"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=1", FALSE, reply, data, &result); } @@ -1485,7 +1485,7 @@ test_cereg2_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2,1, 1F00, 79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=2", TRUE, reply, data, &result); } @@ -1495,7 +1495,7 @@ test_cereg2_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 1F00, 79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=2", FALSE, reply, data, &result); } @@ -1505,7 +1505,7 @@ test_cereg2_altair_lte_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 2, 0001, 00000100, 7\r\n"; - const CregResult result = { 2, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE, FALSE }; test_creg_match ("Altair LTE CEREG=2", FALSE, reply, data, &result); } @@ -1515,7 +1515,7 @@ test_cereg2_altair_lte_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2, 0001, 00000100, 7\r\n"; - const CregResult result = { 2, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE, FALSE }; test_creg_match ("Altair LTE CEREG=2", FALSE, reply, data, &result); } @@ -1525,7 +1525,7 @@ test_cereg2_novatel_lte_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2,1, 1F00, 20 ,79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 12, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 12, FALSE, TRUE, FALSE }; test_creg_match ("Novatel LTE E362 CEREG=2", TRUE, reply, data, &result); } @@ -1535,7 +1535,7 @@ test_cereg2_novatel_lte_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 1F00, 20 ,79D903 ,7\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 11, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 11, FALSE, TRUE, FALSE }; test_creg_match ("Novatel LTE E362 CEREG=2", FALSE, reply, data, &result); } @@ -1545,7 +1545,7 @@ test_cgreg2_thuraya_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CGREG: 2, 1, \"0426\", \"F00F\""; - const CregResult result = { 1, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE, FALSE }; test_creg_match ("Thuraya solicited CREG=2", TRUE, reply, data, &result); } @@ -1555,7 +1555,7 @@ test_cgreg2_thuraya_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 1, \"0426\", \"F00F\"\r\n"; - const CregResult result = { 1, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, TRUE, FALSE, FALSE }; test_creg_match ("Thuraya unsolicited CREG=2", FALSE, reply, data, &result); } @@ -1565,7 +1565,7 @@ test_c5greg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+C5GREG: 1,3"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, FALSE, TRUE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, FALSE, TRUE }; test_creg_match ("C5GREG=1", TRUE, reply, data, &result); } @@ -1575,7 +1575,7 @@ test_c5greg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+C5GREG: 3\r\n"; - const CregResult result = { 3, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, FALSE, TRUE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, FALSE, TRUE }; test_creg_match ("C5GREG=1", FALSE, reply, data, &result); } @@ -1585,7 +1585,7 @@ test_c5greg2_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+C5GREG: 2,1,1F00,79D903,11,6,ABCDEF"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 14, FALSE, FALSE, TRUE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 14, FALSE, FALSE, TRUE }; test_creg_match ("C5GREG=2", TRUE, reply, data, &result); } @@ -1595,7 +1595,7 @@ test_c5greg2_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+C5GREG: 1,1F00,79D903,11,6,ABCDEF\r\n"; - const CregResult result = { 1, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 13, FALSE, FALSE, TRUE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 13, FALSE, FALSE, TRUE }; test_creg_match ("C5GREG=2", FALSE, reply, data, &result); } From 426f69d64b0516407995c27cd567bbaca74ff487 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 15:33:31 +0100 Subject: [PATCH 167/675] tests,modem-helpers: regex number is index of an array, so starts at 0 --- src/tests/test-modem-helpers.c | 90 +++++++++++++++++----------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 1f15e012..78b3cd11 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1130,7 +1130,7 @@ test_creg_match (const char *test, if (g_regex_match (r, reply, 0, &info)) { g_debug (" matched with %d", i); - regex_num = i + 1; + regex_num = i; break; } g_match_info_free (info); @@ -1163,7 +1163,7 @@ test_creg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 1,3"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 2, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, FALSE, FALSE }; test_creg_match ("CREG=1", TRUE, reply, data, &result); } @@ -1173,7 +1173,7 @@ test_creg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 3\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, FALSE, FALSE, FALSE }; test_creg_match ("CREG=1", FALSE, reply, data, &result); } @@ -1183,7 +1183,7 @@ test_creg2_mercury_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 1,1,84CD,00D30173"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x84cd, 0xd30173, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x84cd, 0xd30173, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; test_creg_match ("Sierra Mercury CREG=2", TRUE, reply, data, &result); } @@ -1193,7 +1193,7 @@ test_creg2_mercury_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,84CD,00D30156\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x84cd, 0xd30156, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x84cd, 0xd30156, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 2, FALSE, FALSE, FALSE }; test_creg_match ("Sierra Mercury CREG=2", FALSE, reply, data, &result); } @@ -1203,7 +1203,7 @@ test_creg2_sek850i_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,1,\"CE00\",\"01CEAD8F\""; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0xce00, 0x01cead8f, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0xce00, 0x01cead8f, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; test_creg_match ("Sony Ericsson K850i CREG=2", TRUE, reply, data, &result); } @@ -1213,7 +1213,7 @@ test_creg2_sek850i_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,\"CE00\",\"00005449\"\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0xce00, 0x5449, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0xce00, 0x5449, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 2, FALSE, FALSE, FALSE }; test_creg_match ("Sony Ericsson K850i CREG=2", FALSE, reply, data, &result); } @@ -1223,7 +1223,7 @@ test_creg2_e160g_solicited_unregistered (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,0,00,0"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; test_creg_match ("Huawei E160G unregistered CREG=2", TRUE, reply, data, &result); } @@ -1233,7 +1233,7 @@ test_creg2_e160g_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,1,8BE3,2BAF"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; test_creg_match ("Huawei E160G CREG=2", TRUE, reply, data, &result); } @@ -1243,7 +1243,7 @@ test_creg2_e160g_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,8BE3,2BAF\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8be3, 0x2baf, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 2, FALSE, FALSE, FALSE }; test_creg_match ("Huawei E160G CREG=2", FALSE, reply, data, &result); } @@ -1253,7 +1253,7 @@ test_creg2_tm506_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG: 2,1,\"8BE3\",\"00002BAF\""; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8BE3, 0x2BAF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8BE3, 0x2BAF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; /* Test leading zeros in the CI */ test_creg_match ("Sony Ericsson TM-506 CREG=2", TRUE, reply, data, &result); @@ -1264,7 +1264,7 @@ test_creg2_xu870_unsolicited_unregistered (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,,\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 3, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 2, FALSE, FALSE, FALSE }; test_creg_match ("Novatel XU870 unregistered CREG=2", FALSE, reply, data, &result); } @@ -1274,7 +1274,7 @@ test_creg2_iridium_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG:002,001,\"18d8\",\"ffff\""; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x18D8, 0xFFFF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x18D8, 0xFFFF, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; test_creg_match ("Iridium, CREG=2", TRUE, reply, data, &result); } @@ -1284,7 +1284,7 @@ test_creg2_no_leading_zeros_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG:2,1,0001,0010"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; test_creg_match ("solicited CREG=2 with no leading zeros in integer fields", TRUE, reply, data, &result); } @@ -1294,7 +1294,7 @@ test_creg2_leading_zeros_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CREG:002,001,\"0001\",\"0010\""; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 5, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; test_creg_match ("solicited CREG=2 with leading zeros in integer fields", TRUE, reply, data, &result); } @@ -1304,7 +1304,7 @@ test_creg2_no_leading_zeros_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 1,0001,0010,0\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 6, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 5, FALSE, FALSE, FALSE }; test_creg_match ("unsolicited CREG=2 with no leading zeros in integer fields", FALSE, reply, data, &result); } @@ -1314,7 +1314,7 @@ test_creg2_leading_zeros_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 001,\"0001\",\"0010\",000\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 7, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0001, 0x0010, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 6, FALSE, FALSE, FALSE }; test_creg_match ("unsolicited CREG=2 with leading zeros in integer fields", FALSE, reply, data, &result); } @@ -1324,7 +1324,7 @@ test_creg2_ublox_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const gchar *reply = "\r\n+CREG: 2,6,\"8B37\",\"0A265185\",7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 7, FALSE, FALSE, FALSE }; test_creg_match ("Ublox Toby-L2 solicited while on LTE", TRUE, reply, data, &result); } @@ -1334,7 +1334,7 @@ test_creg2_ublox_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const gchar *reply = "\r\n+CREG: 6,\"8B37\",\"0A265185\",7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME_SMS_ONLY, 0x8B37, 0x0A265185, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 5, FALSE, FALSE, FALSE }; test_creg_match ("Ublox Toby-L2 unsolicited while on LTE", FALSE, reply, data, &result); } @@ -1344,7 +1344,7 @@ test_cgreg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CGREG: 1,3"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, TRUE, FALSE, FALSE }; test_creg_match ("CGREG=1", TRUE, reply, data, &result); } @@ -1354,7 +1354,7 @@ test_cgreg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 3\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, TRUE, FALSE, FALSE }; test_creg_match ("CGREG=1", FALSE, reply, data, &result); } @@ -1364,7 +1364,7 @@ test_cgreg2_f3607gw_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CGREG: 2,1,\"8BE3\",\"00002B5D\",3"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 8, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 7, TRUE, FALSE, FALSE }; test_creg_match ("Ericsson F3607gw CGREG=2", TRUE, reply, data, &result); } @@ -1374,7 +1374,7 @@ test_cgreg2_f3607gw_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 1,\"8BE3\",\"00002B5D\",3\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 6, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x8BE3, 0x2B5D, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 5, TRUE, FALSE, FALSE }; test_creg_match ("Ericsson F3607gw CGREG=2", FALSE, reply, data, &result); } @@ -1384,7 +1384,7 @@ test_creg2_md400_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,5,\"0502\",\"0404736D\"\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; test_creg_match ("Sony-Ericsson MD400 CREG=2", FALSE, reply, data, &result); } @@ -1394,7 +1394,7 @@ test_cgreg2_md400_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 5,\"0502\",\"0404736D\",2\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UMTS, 6, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, 0x0502, 0x0404736D, MM_MODEM_ACCESS_TECHNOLOGY_UMTS, 5, TRUE, FALSE, FALSE }; test_creg_match ("Sony-Ericsson MD400 CGREG=2", FALSE, reply, data, &result); } @@ -1404,7 +1404,7 @@ test_creg_cgreg_multi_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 5\r\n\r\n+CGREG: 0\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, FALSE, FALSE, FALSE }; test_creg_match ("Multi CREG/CGREG", FALSE, reply, data, &result); } @@ -1414,7 +1414,7 @@ test_creg_cgreg_multi2_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 0\r\n\r\n+CREG: 5\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_IDLE, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, TRUE, FALSE, FALSE }; test_creg_match ("Multi CREG/CGREG #2", FALSE, reply, data, &result); } @@ -1424,7 +1424,7 @@ test_cgreg2_x220_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 2,1, 81ED, 1A9CEB\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x81ED, 0x1A9CEB, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x81ED, 0x1A9CEB, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, TRUE, FALSE, FALSE }; /* Tests random spaces in response */ test_creg_match ("Alcatel One-Touch X220D CGREG=2", FALSE, reply, data, &result); @@ -1435,7 +1435,7 @@ test_creg2_s8500_wave_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,1,000B,2816, B, C2816\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x000B, 0x2816, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 9, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x000B, 0x2816, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 8, FALSE, FALSE, FALSE }; test_creg_match ("Samsung Wave S8500 CREG=2", FALSE, reply, data, &result); } @@ -1445,7 +1445,7 @@ test_creg2_gobi_weird_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CREG: 2,1, 0 5, 2715\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0000, 0x2715, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, FALSE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0000, 0x2715, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, FALSE, FALSE, FALSE }; test_creg_match ("Qualcomm Gobi 1000 CREG=2", TRUE, reply, data, &result); } @@ -1455,7 +1455,7 @@ test_cgreg2_unsolicited_with_rac (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 1,\"1422\",\"00000142\",3,\"00\"\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1422, 0x0142, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 10, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1422, 0x0142, MM_MODEM_ACCESS_TECHNOLOGY_EDGE, 9, TRUE, FALSE, FALSE }; test_creg_match ("CGREG=2 with RAC", FALSE, reply, data, &result); } @@ -1465,7 +1465,7 @@ test_cereg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CEREG: 1,3"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=1", TRUE, reply, data, &result); } @@ -1475,7 +1475,7 @@ test_cereg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 3\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=1", FALSE, reply, data, &result); } @@ -1485,7 +1485,7 @@ test_cereg2_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2,1, 1F00, 79D903 ,7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 7, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=2", TRUE, reply, data, &result); } @@ -1495,7 +1495,7 @@ test_cereg2_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 1F00, 79D903 ,7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 5, FALSE, TRUE, FALSE }; test_creg_match ("CEREG=2", FALSE, reply, data, &result); } @@ -1505,7 +1505,7 @@ test_cereg2_altair_lte_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 2, 0001, 00000100, 7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 8, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 7, FALSE, TRUE, FALSE }; test_creg_match ("Altair LTE CEREG=2", FALSE, reply, data, &result); } @@ -1515,7 +1515,7 @@ test_cereg2_altair_lte_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2, 0001, 00000100, 7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 6, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_SEARCHING, 0x0001, 0x00000100, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 5, FALSE, TRUE, FALSE }; test_creg_match ("Altair LTE CEREG=2", FALSE, reply, data, &result); } @@ -1525,7 +1525,7 @@ test_cereg2_novatel_lte_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 2,1, 1F00, 20 ,79D903 ,7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 12, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 11, FALSE, TRUE, FALSE }; test_creg_match ("Novatel LTE E362 CEREG=2", TRUE, reply, data, &result); } @@ -1535,7 +1535,7 @@ test_cereg2_novatel_lte_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CEREG: 1, 1F00, 20 ,79D903 ,7\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 11, FALSE, TRUE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 10, FALSE, TRUE, FALSE }; test_creg_match ("Novatel LTE E362 CEREG=2", FALSE, reply, data, &result); } @@ -1545,7 +1545,7 @@ test_cgreg2_thuraya_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+CGREG: 2, 1, \"0426\", \"F00F\""; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 4, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, TRUE, FALSE, FALSE }; test_creg_match ("Thuraya solicited CREG=2", TRUE, reply, data, &result); } @@ -1555,7 +1555,7 @@ test_cgreg2_thuraya_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+CGREG: 1, \"0426\", \"F00F\"\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 3, TRUE, FALSE, FALSE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x0426, 0xF00F, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 2, TRUE, FALSE, FALSE }; test_creg_match ("Thuraya unsolicited CREG=2", FALSE, reply, data, &result); } @@ -1565,7 +1565,7 @@ test_c5greg1_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+C5GREG: 1,3"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 2, FALSE, FALSE, TRUE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 1, FALSE, FALSE, TRUE }; test_creg_match ("C5GREG=1", TRUE, reply, data, &result); } @@ -1575,7 +1575,7 @@ test_c5greg1_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+C5GREG: 3\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN , 1, FALSE, FALSE, TRUE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_DENIED, 0, 0, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, FALSE, FALSE, TRUE }; test_creg_match ("C5GREG=1", FALSE, reply, data, &result); } @@ -1585,7 +1585,7 @@ test_c5greg2_solicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "+C5GREG: 2,1,1F00,79D903,11,6,ABCDEF"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 14, FALSE, FALSE, TRUE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 13, FALSE, FALSE, TRUE }; test_creg_match ("C5GREG=2", TRUE, reply, data, &result); } @@ -1595,7 +1595,7 @@ test_c5greg2_unsolicited (void *f, gpointer d) { RegTestData *data = (RegTestData *) d; const char *reply = "\r\n+C5GREG: 1,1F00,79D903,11,6,ABCDEF\r\n"; - const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 13, FALSE, FALSE, TRUE }; + const CregResult result = { MM_MODEM_3GPP_REGISTRATION_STATE_HOME, 0x1F00, 0x79D903, MM_MODEM_ACCESS_TECHNOLOGY_5GNR, 12, FALSE, FALSE, TRUE }; test_creg_match ("C5GREG=2", FALSE, reply, data, &result); } From 03f625aa3b190a82b8947bed46d4d67f0f3a2cc6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 16:10:25 +0100 Subject: [PATCH 168/675] fibocom: support QMI capable devices --- plugins/fibocom/mm-plugin-fibocom.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/fibocom/mm-plugin-fibocom.c b/plugins/fibocom/mm-plugin-fibocom.c index 7916b536..e2188561 100644 --- a/plugins/fibocom/mm-plugin-fibocom.c +++ b/plugins/fibocom/mm-plugin-fibocom.c @@ -10,7 +10,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2018 Aleksander Morgado + * Copyright (C) 2018-2020 Aleksander Morgado */ #include @@ -29,6 +29,10 @@ #include "mm-broadband-modem-mbim-xmm.h" #endif +#if defined WITH_QMI +#include "mm-broadband-modem-qmi.h" +#endif + G_DEFINE_TYPE (MMPluginFibocom, mm_plugin_fibocom, MM_TYPE_PLUGIN) MM_PLUGIN_DEFINE_MAJOR_VERSION @@ -64,6 +68,17 @@ create_modem (MMPlugin *self, } #endif +#if defined WITH_QMI + if (mm_port_probe_list_has_qmi_port (probes)) { + mm_obj_dbg (self, "QMI-powered Fibocom modem found..."); + return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); + } +#endif + if (mm_port_probe_list_is_xmm (probes)) { mm_obj_dbg (self, "XMM-based Fibocom modem found..."); return MM_BASE_MODEM (mm_broadband_modem_xmm_new (uid, @@ -88,7 +103,7 @@ mm_plugin_create (void) { static const gchar *subsystems[] = { "tty", "net", "usb", NULL }; static const guint16 vendor_ids[] = { 0x2cb7, 0 }; - static const gchar *drivers[] = { "cdc_mbim", NULL }; + static const gchar *drivers[] = { "cdc_mbim", "qmi_wwan", NULL }; return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_FIBOCOM, From 8eaffb654f1cc5c66bcccfd069e43834405c200f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 16:15:34 +0100 Subject: [PATCH 169/675] fibocom: add FM150 port type hints --- plugins/fibocom/77-mm-fibocom-port-types.rules | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/fibocom/77-mm-fibocom-port-types.rules b/plugins/fibocom/77-mm-fibocom-port-types.rules index 215f1d21..11917f41 100644 --- a/plugins/fibocom/77-mm-fibocom-port-types.rules +++ b/plugins/fibocom/77-mm-fibocom-port-types.rules @@ -13,4 +13,14 @@ SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInte # ttyACM2 (if #6): AT port ATTRS{idVendor}=="2cb7", ATTRS{idProduct}=="0007", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_IGNORE}="1" +# Fibocom FM150 +# ttyUSB0 (if #0): QCDM port +# ttyUSB1 (if #1): AT port +# ttyUSB2 (if #2): AT port +# ttyUSB2 (if #3): Ignore +ATTRS{idVendor}=="2cb7", ATTRS{idProduct}=="0104", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_QCDM}="1" +ATTRS{idVendor}=="2cb7", ATTRS{idProduct}=="0104", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +ATTRS{idVendor}=="2cb7", ATTRS{idProduct}=="0104", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +ATTRS{idVendor}=="2cb7", ATTRS{idProduct}=="0104", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_PORT_IGNORE}="1" + LABEL="mm_fibocom_port_types_end" From c9ee47dd8f49ff24ce4244afbd44473f03a78f9a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 25 Mar 2020 16:14:48 +0100 Subject: [PATCH 170/675] helpers-qmi: always log all queried capabilities when building current --- src/mm-modem-helpers-qmi.c | 41 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 8c99d512..d339f489 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1496,27 +1496,28 @@ mm_modem_capability_from_qmi_capabilities_context (MMQmiCapabilitiesContext *ctx /* If not a multimode device, we're done */ #define MULTIMODE (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO) if ((ctx->dms_capabilities & MULTIMODE) != MULTIMODE) - return ctx->dms_capabilities; - - /* We have a multimode CDMA/EVDO+GSM/UMTS device, check SSP and TP */ - - /* SSP logic to gather capabilities uses the Mode Preference TLV if available */ - if (ctx->nas_ssp_mode_preference_mask) - tmp = mm_modem_capability_from_qmi_rat_mode_preference (ctx->nas_ssp_mode_preference_mask); - /* If no value retrieved from SSP, check TP. We only process TP - * values if not 'auto' (0). */ - else if (ctx->nas_tp_mask != QMI_NAS_RADIO_TECHNOLOGY_PREFERENCE_AUTO) - tmp = mm_modem_capability_from_qmi_radio_technology_preference (ctx->nas_tp_mask); - - /* Final capabilities are the intersection between the Technology - * Preference or SSP and the device's capabilities. - * If the Technology Preference was "auto" or unknown we just fall back - * to the Get Capabilities response. - */ - if (tmp == MM_MODEM_CAPABILITY_NONE) tmp = ctx->dms_capabilities; - else - tmp &= ctx->dms_capabilities; + else { + /* We have a multimode CDMA/EVDO+GSM/UMTS device, check SSP and TP */ + + /* SSP logic to gather capabilities uses the Mode Preference TLV if available */ + if (ctx->nas_ssp_mode_preference_mask) + tmp = mm_modem_capability_from_qmi_rat_mode_preference (ctx->nas_ssp_mode_preference_mask); + /* If no value retrieved from SSP, check TP. We only process TP + * values if not 'auto' (0). */ + else if (ctx->nas_tp_mask != QMI_NAS_RADIO_TECHNOLOGY_PREFERENCE_AUTO) + tmp = mm_modem_capability_from_qmi_radio_technology_preference (ctx->nas_tp_mask); + + /* Final capabilities are the intersection between the Technology + * Preference or SSP and the device's capabilities. + * If the Technology Preference was "auto" or unknown we just fall back + * to the Get Capabilities response. + */ + if (tmp == MM_MODEM_CAPABILITY_NONE) + tmp = ctx->dms_capabilities; + else + tmp &= ctx->dms_capabilities; + } /* Log about the logic applied */ nas_ssp_mode_preference_str = qmi_nas_rat_mode_preference_build_string_from_mask (ctx->nas_ssp_mode_preference_mask); From 2293fbe6ba2991d16d663986933d112812f97703 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 25 Mar 2020 18:07:53 +0100 Subject: [PATCH 171/675] shared-qmi: include all possible 5G related combinations if SSP is supported --- src/mm-shared-qmi.c | 111 +++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 58 deletions(-) diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 982bfd0b..1b18719a 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -1557,73 +1557,68 @@ mm_shared_qmi_load_supported_modes (MMIfaceModem *self, return; } - combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMModemModeCombination), 5); + combinations = g_array_new (FALSE, FALSE, sizeof (MMModemModeCombination)); + +#define ADD_MODE_PREFERENCE(MODE1, MODE2, MODE3, MODE4) do { \ + mode.allowed = MODE1; \ + if (MODE2 != MM_MODEM_MODE_NONE) { \ + mode.allowed |= MODE2; \ + if (MODE3 != MM_MODEM_MODE_NONE) { \ + mode.allowed |= MODE3; \ + if (MODE4 != MM_MODEM_MODE_NONE) \ + mode.allowed |= MODE4; \ + } \ + if (priv->feature_nas_system_selection_preference != FEATURE_UNSUPPORTED) { \ + if (MODE3 != MM_MODEM_MODE_NONE) { \ + if (MODE4 != MM_MODEM_MODE_NONE) { \ + mode.preferred = MODE4; \ + g_array_append_val (combinations, mode); \ + } \ + mode.preferred = MODE3; \ + g_array_append_val (combinations, mode); \ + } \ + mode.preferred = MODE2; \ + g_array_append_val (combinations, mode); \ + mode.preferred = MODE1; \ + g_array_append_val (combinations, mode); \ + } else { \ + mode.preferred = MM_MODEM_MODE_NONE; \ + g_array_append_val (combinations, mode); \ + } \ + } else { \ + mode.allowed = MODE1; \ + mode.preferred = MM_MODEM_MODE_NONE; \ + g_array_append_val (combinations, mode); \ + } \ + } while (0) /* 2G-only, 3G-only */ - mode.allowed = MM_MODEM_MODE_2G; - mode.preferred = MM_MODEM_MODE_NONE; - g_array_append_val (combinations, mode); - mode.allowed = MM_MODEM_MODE_3G; - mode.preferred = MM_MODEM_MODE_NONE; - g_array_append_val (combinations, mode); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_2G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); /* 4G-only mode is not possible in multimode GSM/UMTS+CDMA/EVDO+LTE * devices. This configuration may be selected as "LTE only" capability * instead. */ - if (!priv->disable_4g_only_mode) { - mode.allowed = MM_MODEM_MODE_4G; - mode.preferred = MM_MODEM_MODE_NONE; - g_array_append_val (combinations, mode); - } + if (!priv->disable_4g_only_mode) + ADD_MODE_PREFERENCE (MM_MODEM_MODE_4G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); - /* 2G+3G */ - mode.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G); - if (priv->feature_nas_system_selection_preference != FEATURE_UNSUPPORTED) { - mode.preferred = MM_MODEM_MODE_3G; - g_array_append_val (combinations, mode); - mode.preferred = MM_MODEM_MODE_2G; - g_array_append_val (combinations, mode); - } else { - mode.preferred = MM_MODEM_MODE_NONE; - g_array_append_val (combinations, mode); - } + /* 2G, 3G, 4G combinations */ + ADD_MODE_PREFERENCE (MM_MODEM_MODE_2G, MM_MODEM_MODE_3G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_2G, MM_MODEM_MODE_4G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_3G, MM_MODEM_MODE_4G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_2G, MM_MODEM_MODE_3G, MM_MODEM_MODE_4G, MM_MODEM_MODE_NONE); - /* 2G+4G */ - mode.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_4G); + /* 5G related mode combinations are only supported when NAS SSP is supported, + * as there is no 5G support in NAS TP. */ if (priv->feature_nas_system_selection_preference != FEATURE_UNSUPPORTED) { - mode.preferred = MM_MODEM_MODE_4G; - g_array_append_val (combinations, mode); - mode.preferred = MM_MODEM_MODE_2G; - g_array_append_val (combinations, mode); - } else { - mode.preferred = MM_MODEM_MODE_NONE; - g_array_append_val (combinations, mode); - } - - /* 3G+4G */ - mode.allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_4G); - if (priv->feature_nas_system_selection_preference != FEATURE_UNSUPPORTED) { - mode.preferred = MM_MODEM_MODE_3G; - g_array_append_val (combinations, mode); - mode.preferred = MM_MODEM_MODE_4G; - g_array_append_val (combinations, mode); - } else { - mode.preferred = MM_MODEM_MODE_NONE; - g_array_append_val (combinations, mode); - } - - /* 2G+3G+4G */ - mode.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G); - if (priv->feature_nas_system_selection_preference != FEATURE_UNSUPPORTED) { - mode.preferred = MM_MODEM_MODE_4G; - g_array_append_val (combinations, mode); - mode.preferred = MM_MODEM_MODE_3G; - g_array_append_val (combinations, mode); - mode.preferred = MM_MODEM_MODE_2G; - g_array_append_val (combinations, mode); - } else { - mode.preferred = MM_MODEM_MODE_NONE; - g_array_append_val (combinations, mode); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_2G, MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_3G, MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_4G, MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_2G, MM_MODEM_MODE_3G, MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_2G, MM_MODEM_MODE_4G, MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_3G, MM_MODEM_MODE_4G, MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE); + ADD_MODE_PREFERENCE (MM_MODEM_MODE_2G, MM_MODEM_MODE_3G, MM_MODEM_MODE_4G, MM_MODEM_MODE_5G); } /* Filter out unsupported modes */ From 32e26230526dda8298b38db2b65e57dc635fbf9d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Apr 2020 07:48:21 +0200 Subject: [PATCH 172/675] iface-modem-3gpp: add 5GNR to full 3GPP act mask So that the logic looking for 3GPP related registration info works in the QMI modem object when selected network is reported as 'unknown' but still the radio interfaces list reports 5GNR. <<<<<< TLV: <<<<<< type = "Serving System" (0x01) <<<<<< length = 6 <<<<<< value = 01:02:01:00:01:0C <<<<<< translated = [ registration_state = 'registered' cs_attach_state = 'detached' ps_attach_state = 'attached' selected_network = 'unknown' radio_interfaces = '{ [0] = '5gnr '}' ] --- src/mm-broadband-modem-qmi.c | 2 +- src/mm-iface-modem-3gpp.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 30d1113b..99fa798f 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -2636,7 +2636,7 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, /* Only process 3GPP info. * Seen the case already where 'selected_network' gives UNKNOWN but we still - * have valid LTE info around. */ + * have valid LTE/5GNR info around. */ if (selected_network == QMI_NAS_NETWORK_TYPE_3GPP || (selected_network == QMI_NAS_NETWORK_TYPE_UNKNOWN && (mm_access_technologies & MM_IFACE_MODEM_3GPP_ALL_ACCESS_TECHNOLOGIES_MASK))) { diff --git a/src/mm-iface-modem-3gpp.h b/src/mm-iface-modem-3gpp.h index 7f3e9cb9..321fec7d 100644 --- a/src/mm-iface-modem-3gpp.h +++ b/src/mm-iface-modem-3gpp.h @@ -48,7 +48,8 @@ MM_MODEM_ACCESS_TECHNOLOGY_HSUPA | \ MM_MODEM_ACCESS_TECHNOLOGY_HSPA | \ MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS | \ - MM_MODEM_ACCESS_TECHNOLOGY_LTE) + MM_MODEM_ACCESS_TECHNOLOGY_LTE | \ + MM_MODEM_ACCESS_TECHNOLOGY_5GNR) typedef struct _MMIfaceModem3gpp MMIfaceModem3gpp; From a60beedcc590c9dc590e616676652eec2a3bc51b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Apr 2020 15:43:59 +0200 Subject: [PATCH 173/675] port-qmi: allow users to release clients when no longer needed --- src/mm-port-qmi.c | 52 ++++++++++++++++++++++++++++++++++++++++------- src/mm-port-qmi.h | 4 ++++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/mm-port-qmi.c b/src/mm-port-qmi.c index 98dd8c44..3f39bfc0 100644 --- a/src/mm-port-qmi.c +++ b/src/mm-port-qmi.c @@ -41,24 +41,38 @@ struct _MMPortQmiPrivate { /*****************************************************************************/ -QmiClient * -mm_port_qmi_peek_client (MMPortQmi *self, - QmiService service, - MMPortQmiFlag flag) +static QmiClient * +lookup_client (MMPortQmi *self, + QmiService service, + MMPortQmiFlag flag, + gboolean steal) { GList *l; for (l = self->priv->services; l; l = g_list_next (l)) { ServiceInfo *info = l->data; - if (info->service == service && - info->flag == flag) - return info->client; + if (info->service == service && info->flag == flag) { + QmiClient *found; + + found = info->client; + if (steal) + self->priv->services = g_list_delete_link (self->priv->services, l); + return found; + } } return NULL; } +QmiClient * +mm_port_qmi_peek_client (MMPortQmi *self, + QmiService service, + MMPortQmiFlag flag) +{ + return lookup_client (self, service, flag, FALSE); +} + QmiClient * mm_port_qmi_get_client (MMPortQmi *self, QmiService service, @@ -82,6 +96,30 @@ mm_port_qmi_peek_device (MMPortQmi *self) /*****************************************************************************/ +void +mm_port_qmi_release_client (MMPortQmi *self, + QmiService service, + MMPortQmiFlag flag) +{ + QmiClient *client; + + if (!self->priv->qmi_device) + return; + + client = lookup_client (self, service, flag, TRUE); + if (!client) + return; + + mm_obj_dbg (self, "explicitly releasing client for service '%s'...", qmi_service_get_string (service)); + qmi_device_release_client (self->priv->qmi_device, + client, + QMI_DEVICE_RELEASE_CLIENT_FLAGS_RELEASE_CID, + 3, NULL, NULL, NULL); + g_object_unref (client); +} + +/*****************************************************************************/ + typedef struct { ServiceInfo *info; } AllocateClientContext; diff --git a/src/mm-port-qmi.h b/src/mm-port-qmi.h index f8ea9eec..b4e8460c 100644 --- a/src/mm-port-qmi.h +++ b/src/mm-port-qmi.h @@ -80,6 +80,10 @@ gboolean mm_port_qmi_allocate_client_finish (MMPortQmi *self, GAsyncResult *res, GError **error); +void mm_port_qmi_release_client (MMPortQmi *self, + QmiService service, + MMPortQmiFlag flag); + QmiClient *mm_port_qmi_peek_client (MMPortQmi *self, QmiService service, MMPortQmiFlag flag); From 5313c25bd8ad4543f207da611551e42537ede208 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Apr 2020 15:44:15 +0200 Subject: [PATCH 174/675] broadband-modem-qmi: explicitly disable autoconnect during enable If the QMI device has autoconnect enabled, it will collide in one way or another with the ModemManager triggered connection sequence, usually because the user-requested settings are different to the autoconnected ones. So, detect whether autoconnect is enabled or not, and if it is, explicitly disable it. --- src/mm-broadband-modem-qmi.c | 177 +++++++++++++++++++++++++++++++---- 1 file changed, 160 insertions(+), 17 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 99fa798f..0349be6d 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -93,6 +93,10 @@ struct _MMBroadbandModemQmiPrivate { /* New devices may not support the legacy DMS UIM commands */ gboolean dms_uim_deprecated; + /* Whether autoconnect disabling needs to be checked up during + * the device enabling */ + gboolean autoconnect_checked; + /* 3GPP/CDMA registration helpers */ gchar *current_operator_id; gchar *current_operator_description; @@ -8393,39 +8397,178 @@ signal_load_values (MMIfaceModemSignal *self, /*****************************************************************************/ /* First enabling step */ +typedef struct { + MMPortQmi *qmi; + QmiClientWds *wds; +} EnablingStartedContext; + +static void +enabling_started_context_free (EnablingStartedContext *ctx) +{ + if (ctx->wds) { + mm_port_qmi_release_client (ctx->qmi, QMI_SERVICE_WDS, MM_PORT_QMI_FLAG_DEFAULT); + g_clear_object (&ctx->wds); + } + g_clear_object (&ctx->qmi); + g_slice_free (EnablingStartedContext, ctx); +} + static gboolean -enabling_started_finish (MMBroadbandModem *self, - GAsyncResult *res, - GError **error) +enabling_started_finish (MMBroadbandModem *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } static void -parent_enabling_started_ready (MMBroadbandModem *self, - GAsyncResult *res, - GTask *task) +wds_set_autoconnect_settings_ready (QmiClientWds *client, + GAsyncResult *res, + GTask *task) { - GError *error = NULL; + MMBroadbandModemQmi *self; + g_autoptr(GError) error = NULL; + g_autoptr(QmiMessageWdsSetAutoconnectSettingsOutput) output = NULL; - if (!MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_qmi_parent_class)->enabling_started_finish ( - self, - res, - &error)) { + self = g_task_get_source_object (task); + + output = qmi_client_wds_set_autoconnect_settings_finish (client, res, &error); + if (!output || !qmi_message_wds_set_autoconnect_settings_output_get_result (output, &error)) + mm_obj_warn (self, "failed disabling autoconnect: %s", error->message); + else + mm_obj_info (self, "autoconnect explicitly disabled"); + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +wds_get_autoconnect_settings_ready (QmiClientWds *client, + GAsyncResult *res, + GTask *task) +{ + MMBroadbandModemQmi *self; + QmiWdsAutoconnectSetting autoconnect_setting; + g_autoptr(GError) error = NULL; + g_autoptr(QmiMessageWdsSetAutoconnectSettingsInput) input = NULL; + g_autoptr(QmiMessageWdsGetAutoconnectSettingsOutput) output = NULL; + + self = g_task_get_source_object (task); + + output = qmi_client_wds_get_autoconnect_settings_finish (client, res, &error); + if (!output || + !qmi_message_wds_get_autoconnect_settings_output_get_result (output, &error) || + !qmi_message_wds_get_autoconnect_settings_output_get_status (output, &autoconnect_setting, &error)) { + mm_obj_warn (self, "failed checking whether autoconnect is disabled or not: %s", error->message); + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + + if (autoconnect_setting != QMI_WDS_AUTOCONNECT_SETTING_ENABLED) { + mm_obj_dbg (self, "autoconnect is already disabled"); + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + + mm_obj_dbg (self, "need to explicitly disable autoconnect"); + input = qmi_message_wds_set_autoconnect_settings_input_new (); + qmi_message_wds_set_autoconnect_settings_input_set_status (input, QMI_WDS_AUTOCONNECT_SETTING_DISABLED, NULL); + qmi_client_wds_set_autoconnect_settings (client, + input, + 10, + NULL, + (GAsyncReadyCallback) wds_set_autoconnect_settings_ready, + task); +} + +static void +enabling_wds_client_ready (MMPortQmi *qmi, + GAsyncResult *res, + GTask *task) +{ + MMBroadbandModemQmi *self; + EnablingStartedContext *ctx; + g_autoptr(GError) error = NULL; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + + if (!mm_port_qmi_allocate_client_finish (qmi, res, &error)) { + mm_obj_warn (self, "cannot check whether autoconnect is disabled or not: " + "couldn't allocate client for WDS service: %s", error->message); + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + + ctx->wds = QMI_CLIENT_WDS (mm_port_qmi_get_client (ctx->qmi, + QMI_SERVICE_WDS, + MM_PORT_QMI_FLAG_DEFAULT)); + + qmi_client_wds_get_autoconnect_settings (ctx->wds, + NULL, + 5, + NULL, + (GAsyncReadyCallback) wds_get_autoconnect_settings_ready, + task); +} + +static void +parent_enabling_started_ready (MMBroadbandModem *_self, + GAsyncResult *res, + GTask *task) +{ + MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); + EnablingStartedContext *ctx; + g_autoptr(GError) error = NULL; + + if (!MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_qmi_parent_class)->enabling_started_finish (_self, res, &error)) { /* Don't treat this as fatal. Parent enabling may fail if it cannot grab a primary * AT port, which isn't really an issue in QMI-based modems */ mm_obj_dbg (self, "couldn't start parent enabling: %s", error->message); - g_error_free (error); } - g_task_return_boolean (task, TRUE); - g_object_unref (task); + /* If the autoconnect check has already been done, we're finished */ + if (self->priv->autoconnect_checked) { + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + + /* The connection logic doesn't work properly when the device is already set + * to autoconnect, so automatically disable autoconnect ourselves. */ + mm_obj_dbg (self, "need to check whether autoconnect is disabled or not..."); + self->priv->autoconnect_checked = TRUE; + + /* Setup context */ + ctx = g_slice_new0 (EnablingStartedContext); + g_task_set_task_data (task, ctx, (GDestroyNotify)enabling_started_context_free); + + /* Keep a full port reference around */ + ctx->qmi = mm_base_modem_get_port_qmi (MM_BASE_MODEM (self)); + if (!ctx->qmi) { + mm_obj_warn (self, "cannot check whether autoconnect is disabled or not: couldn't peek QMI port"); + /* not fatal, just assume autoconnect is disabled */ + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + + /* By default there is no generic WDS client preallocated in the QMI port, + * so explicitly allocate one ourselves */ + mm_port_qmi_allocate_client (ctx->qmi, + QMI_SERVICE_WDS, + MM_PORT_QMI_FLAG_DEFAULT, + NULL, + (GAsyncReadyCallback)enabling_wds_client_ready, + task); } static void -enabling_started (MMBroadbandModem *self, - GAsyncReadyCallback callback, - gpointer user_data) +enabling_started (MMBroadbandModem *self, + GAsyncReadyCallback callback, + gpointer user_data) { GTask *task; From ff97a776315d9e61f793c7312edce1f7e833f04a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Apr 2020 08:24:00 +0200 Subject: [PATCH 175/675] broadband-modem-mbim: request operator reload explicitly If the modem switches from one roaming operator to a different roaming operator, the actual operator MCCMNC/description will change even if the registration state keeps on being the same (roaming). Detect that, and trigger operator info reloading explicitly. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/154 --- src/mm-broadband-modem-mbim.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 3a55f058..8954889b 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -2960,6 +2960,7 @@ update_registration_info (MMBroadbandModemMbim *self, gchar *operator_name_take) { MMModem3gppRegistrationState reg_state; + gboolean operator_updated = FALSE; reg_state = mm_modem_3gpp_registration_state_from_mbim_register_state (state); @@ -2969,6 +2970,7 @@ update_registration_info (MMBroadbandModemMbim *self, g_str_equal (self->priv->current_operator_id, operator_id_take)) { g_free (operator_id_take); } else { + operator_updated = TRUE; g_free (self->priv->current_operator_id); self->priv->current_operator_id = operator_id_take; } @@ -2977,10 +2979,13 @@ update_registration_info (MMBroadbandModemMbim *self, g_str_equal (self->priv->current_operator_name, operator_name_take)) { g_free (operator_name_take); } else { + operator_updated = TRUE; g_free (self->priv->current_operator_name); self->priv->current_operator_name = operator_name_take; } } else { + if (self->priv->current_operator_id || self->priv->current_operator_name) + operator_updated = TRUE; g_clear_pointer (&self->priv->current_operator_id, g_free); g_clear_pointer (&self->priv->current_operator_name, g_free); g_free (operator_id_take); @@ -2993,6 +2998,11 @@ update_registration_info (MMBroadbandModemMbim *self, self->priv->available_data_classes = available_data_classes; update_access_technologies (self); + + /* request to reload operator info explicitly, so that the new + * operator name and code is propagated to the DBus interface */ + if (operator_updated) + mm_iface_modem_3gpp_reload_current_registration_info (MM_IFACE_MODEM_3GPP (self), NULL, NULL); } static void From 4758e49d879c47a92cd76156f0f7ec7739ceb39f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Apr 2020 11:09:45 +0200 Subject: [PATCH 176/675] broadband-modem-qmi: request operator reload explicitly If the modem switches from one roaming operator to a different roaming operator, the actual operator MCCMNC/description will change even if the registration state keeps on being the same (roaming). Detect that, and trigger operator info reloading explicitly. --- src/mm-broadband-modem-qmi.c | 59 ++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 0349be6d..599ebd68 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -2604,6 +2604,7 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, MMModemAccessTechnology mm_access_technologies; MMModem3gppRegistrationState mm_cs_registration_state; MMModem3gppRegistrationState mm_ps_registration_state; + gboolean operator_updated = FALSE; if (response_output) qmi_message_nas_get_serving_system_output_get_serving_system ( @@ -2649,6 +2650,8 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, MMModem3gppRegistrationState reg_state_3gpp; mm_obj_dbg (self, "no 3GPP info given..."); + if (self->priv->current_operator_id || self->priv->current_operator_description) + operator_updated = TRUE; g_free (self->priv->current_operator_id); self->priv->current_operator_id = NULL; g_free (self->priv->current_operator_description); @@ -2663,6 +2666,10 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, mm_iface_modem_3gpp_update_ps_registration_state (MM_IFACE_MODEM_3GPP (self), reg_state_3gpp); mm_iface_modem_3gpp_update_access_technologies (MM_IFACE_MODEM_3GPP (self), MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN); mm_iface_modem_3gpp_update_location (MM_IFACE_MODEM_3GPP (self), 0, 0, 0); + /* request to reload operator info explicitly, so that the new + * operator name and code is propagated to the DBus interface */ + if (operator_updated) + mm_iface_modem_3gpp_reload_current_registration_info (MM_IFACE_MODEM_3GPP (self), NULL, NULL); return; } @@ -2702,23 +2709,28 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, &mnc, &description, NULL))) { + gchar *new_operator_id; + /* When we don't have information about leading PCS digit, guess best */ - g_free (self->priv->current_operator_id); if (mnc >= 100) - self->priv->current_operator_id = - g_strdup_printf ("%.3" G_GUINT16_FORMAT "%.3" G_GUINT16_FORMAT, - mcc, - mnc); + new_operator_id = g_strdup_printf ("%.3" G_GUINT16_FORMAT "%.3" G_GUINT16_FORMAT, mcc, mnc); else - self->priv->current_operator_id = - g_strdup_printf ("%.3" G_GUINT16_FORMAT "%.2" G_GUINT16_FORMAT, - mcc, - mnc); - - g_clear_pointer (&self->priv->current_operator_description, g_free); - /* Some Telit modems apparently sometimes report non-UTF8 characters */ - if (g_utf8_validate (description, -1, NULL)) - self->priv->current_operator_description = g_strdup (description); + new_operator_id = g_strdup_printf ("%.3" G_GUINT16_FORMAT "%.2" G_GUINT16_FORMAT, mcc, mnc); + + if (!self->priv->current_operator_id || !g_str_equal (self->priv->current_operator_id, new_operator_id)) { + operator_updated = TRUE; + g_free (self->priv->current_operator_id); + self->priv->current_operator_id = new_operator_id; + } else + g_free (new_operator_id); + + if (!self->priv->current_operator_description || !g_str_equal (self->priv->current_operator_description, description)) { + operator_updated = TRUE; + g_clear_pointer (&self->priv->current_operator_description, g_free); + /* Some Telit modems apparently sometimes report non-UTF8 characters */ + if (g_utf8_validate (description, -1, NULL)) + self->priv->current_operator_description = g_strdup (description); + } } /* If MNC comes with PCS digit, we must make sure the additional @@ -2738,11 +2750,15 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, &has_pcs_digit, NULL))) && has_pcs_digit) { - g_free (self->priv->current_operator_id); - self->priv->current_operator_id = - g_strdup_printf ("%.3" G_GUINT16_FORMAT "%.3" G_GUINT16_FORMAT, - mcc, - mnc); + gchar *new_operator_id; + + new_operator_id = g_strdup_printf ("%.3" G_GUINT16_FORMAT "%.3" G_GUINT16_FORMAT, mcc, mnc); + if (!self->priv->current_operator_id || !g_str_equal (self->priv->current_operator_id, new_operator_id)) { + operator_updated = TRUE; + g_free (self->priv->current_operator_id); + self->priv->current_operator_id = new_operator_id; + } else + g_free (new_operator_id); } /* Report new registration states */ @@ -2768,6 +2784,11 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, if (cid && (lac || tac)) mm_iface_modem_3gpp_update_location (MM_IFACE_MODEM_3GPP (self), lac, tac, cid); + /* request to reload operator info explicitly, so that the new + * operator name and code is propagated to the DBus interface */ + if (operator_updated) + mm_iface_modem_3gpp_reload_current_registration_info (MM_IFACE_MODEM_3GPP (self), NULL, NULL); + /* Note: don't update access technologies with the ones retrieved here; they * are not really the 'current' access technologies */ } From 9c0a937cf3ce311f8ed7992dc5b8abd38ffc3e08 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 9 Apr 2020 11:15:30 +0200 Subject: [PATCH 177/675] broadband-modem-qmi: since 1.24.6 all strings are valid UTF-8 --- src/mm-broadband-modem-qmi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 599ebd68..cf7ebf55 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -2726,10 +2726,8 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, if (!self->priv->current_operator_description || !g_str_equal (self->priv->current_operator_description, description)) { operator_updated = TRUE; - g_clear_pointer (&self->priv->current_operator_description, g_free); - /* Some Telit modems apparently sometimes report non-UTF8 characters */ - if (g_utf8_validate (description, -1, NULL)) - self->priv->current_operator_description = g_strdup (description); + g_free (self->priv->current_operator_description); + self->priv->current_operator_description = g_strdup (description); } } From 797f2a5a2e73d2be64b16c739d9b859ffd7938d0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 10 Apr 2020 10:47:53 +0200 Subject: [PATCH 178/675] api,doc: fix some property gtk-doc links --- introspection/org.freedesktop.ModemManager1.Modem.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.xml b/introspection/org.freedesktop.ModemManager1.Modem.xml index 474f1293..41dd192e 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.xml @@ -149,7 +149,7 @@ Set the capabilities of the device. The given bitmask should be supported by the modem, as specified in the - #org.freedesktop.ModemManager1.Modem.Modem:SupportedCapabilities property. + #org.freedesktop.ModemManager1.Modem:SupportedCapabilities property. This command may power-cycle the device. --> @@ -240,7 +240,7 @@ If the modem doesn't allow changing the current capabilities, the list will report one single entry with the same bitmask as in - #org.freedesktop.ModemManager1.Modem.Modem:CurrentCapabilities. + #org.freedesktop.ModemManager1.Modem:CurrentCapabilities. Only multimode devices implementing both 3GPP (GSM/UMTS/LTE/5GNR) and 3GPP2 (CDMA/EVDO) specs will report more than one combination of @@ -256,7 +256,7 @@ technologies. This bitmask will be one of the ones listed in - #org.freedesktop.ModemManager1.Modem.Modem:SupportedCapabilities. + #org.freedesktop.ModemManager1.Modem:SupportedCapabilities. --> From 868d0dbf3f01259887c2b5dc6d16eee28ab3ffb5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 10 Apr 2020 11:37:59 +0200 Subject: [PATCH 179/675] api,doc: fix missing Command() doc output in html --- introspection/org.freedesktop.ModemManager1.Modem.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.xml b/introspection/org.freedesktop.ModemManager1.Modem.xml index 41dd192e..4a9327b4 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.xml @@ -183,10 +183,10 @@ From f325ef59020b0acc33b6d05e96c8df7b58373715 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 27 Mar 2020 16:24:48 +0100 Subject: [PATCH 181/675] api,bearer: add 'attempts' and 'failed-attempts' statistics When we're reusing over and over the same bearer object, we can provide statistical information about the number of connection attempts that have been done and how many of them failed. --- cli/mmcli-bearer.c | 16 +++- cli/mmcli-output.c | 2 + cli/mmcli-output.h | 2 + .../libmm-glib/libmm-glib-sections.txt | 4 + .../org.freedesktop.ModemManager1.Bearer.xml | 36 +++++-- libmm-glib/mm-bearer-stats.c | 93 ++++++++++++++++++- libmm-glib/mm-bearer-stats.h | 16 ++-- src/mm-base-bearer.c | 32 ++++--- 8 files changed, 168 insertions(+), 33 deletions(-) diff --git a/cli/mmcli-bearer.c b/cli/mmcli-bearer.c index 279e568a..2dfdab35 100644 --- a/cli/mmcli-bearer.c +++ b/cli/mmcli-bearer.c @@ -248,6 +248,8 @@ print_bearer_info (MMBearer *bearer) gchar *duration = NULL; gchar *bytes_rx = NULL; gchar *bytes_tx = NULL; + gchar *attempts = NULL; + gchar *failed_attempts = NULL; if (stats) { guint64 val; @@ -261,11 +263,19 @@ print_bearer_info (MMBearer *bearer) val = mm_bearer_stats_get_tx_bytes (stats); if (val) bytes_tx = g_strdup_printf ("%" G_GUINT64_FORMAT, val); + val = mm_bearer_stats_get_attempts (stats); + if (val) + attempts = g_strdup_printf ("%" G_GUINT64_FORMAT, val); + val = mm_bearer_stats_get_failed_attempts (stats); + if (val) + failed_attempts = g_strdup_printf ("%" G_GUINT64_FORMAT, val); } - mmcli_output_string_take (MMC_F_BEARER_STATS_DURATION, duration); - mmcli_output_string_take (MMC_F_BEARER_STATS_BYTES_RX, bytes_rx); - mmcli_output_string_take (MMC_F_BEARER_STATS_BYTES_TX, bytes_tx); + mmcli_output_string_take (MMC_F_BEARER_STATS_DURATION, duration); + mmcli_output_string_take (MMC_F_BEARER_STATS_BYTES_RX, bytes_rx); + mmcli_output_string_take (MMC_F_BEARER_STATS_BYTES_TX, bytes_tx); + mmcli_output_string_take (MMC_F_BEARER_STATS_ATTEMPTS, attempts); + mmcli_output_string_take (MMC_F_BEARER_STATS_FAILED_ATTEMPTS, failed_attempts); } mmcli_output_dump (); diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c index 25877b0b..7418fc18 100644 --- a/cli/mmcli-output.c +++ b/cli/mmcli-output.c @@ -226,6 +226,8 @@ static FieldInfo field_infos[] = { [MMC_F_BEARER_STATS_DURATION] = { "bearer.stats.duration", "duration", MMC_S_BEARER_STATS, }, [MMC_F_BEARER_STATS_BYTES_RX] = { "bearer.stats.bytes-rx", "bytes rx", MMC_S_BEARER_STATS, }, [MMC_F_BEARER_STATS_BYTES_TX] = { "bearer.stats.bytes-tx", "bytes tx", MMC_S_BEARER_STATS, }, + [MMC_F_BEARER_STATS_ATTEMPTS] = { "bearer.stats.attempts", "attempts", MMC_S_BEARER_STATS, }, + [MMC_F_BEARER_STATS_FAILED_ATTEMPTS] = { "bearer.stats.failed-attempts", "attempts", MMC_S_BEARER_STATS, }, [MMC_F_CALL_GENERAL_DBUS_PATH] = { "call.dbus-path", "dbus path", MMC_S_CALL_GENERAL, }, [MMC_F_CALL_PROPERTIES_NUMBER] = { "call.properties.number", "number", MMC_S_CALL_PROPERTIES, }, [MMC_F_CALL_PROPERTIES_DIRECTION] = { "call.properties.direction", "direction", MMC_S_CALL_PROPERTIES, }, diff --git a/cli/mmcli-output.h b/cli/mmcli-output.h index bd7b317a..76ca2026 100644 --- a/cli/mmcli-output.h +++ b/cli/mmcli-output.h @@ -243,6 +243,8 @@ typedef enum { MMC_F_BEARER_STATS_DURATION, MMC_F_BEARER_STATS_BYTES_RX, MMC_F_BEARER_STATS_BYTES_TX, + MMC_F_BEARER_STATS_ATTEMPTS, + MMC_F_BEARER_STATS_FAILED_ATTEMPTS, MMC_F_CALL_GENERAL_DBUS_PATH, MMC_F_CALL_PROPERTIES_NUMBER, MMC_F_CALL_PROPERTIES_DIRECTION, diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 64bd2e02..83dd52f8 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -1128,6 +1128,8 @@ MMBearerStats mm_bearer_stats_get_duration mm_bearer_stats_get_rx_bytes mm_bearer_stats_get_tx_bytes +mm_bearer_stats_get_attempts +mm_bearer_stats_get_failed_attempts mm_bearer_stats_get_dictionary mm_bearer_stats_new @@ -1135,6 +1137,8 @@ mm_bearer_stats_new_from_dictionary mm_bearer_stats_set_duration mm_bearer_stats_set_rx_bytes mm_bearer_stats_set_tx_bytes +mm_bearer_stats_set_attempts +mm_bearer_stats_set_failed_attempts MMBearerStatsClass MMBearerStatsPrivate diff --git a/introspection/org.freedesktop.ModemManager1.Bearer.xml b/introspection/org.freedesktop.ModemManager1.Bearer.xml index e86ef00d..b82c9d36 100644 --- a/introspection/org.freedesktop.ModemManager1.Bearer.xml +++ b/introspection/org.freedesktop.ModemManager1.Bearer.xml @@ -244,28 +244,50 @@ diff --git a/libmm-glib/mm-bearer-stats.c b/libmm-glib/mm-bearer-stats.c index 42e63839..49bebc0b 100644 --- a/libmm-glib/mm-bearer-stats.c +++ b/libmm-glib/mm-bearer-stats.c @@ -38,6 +38,9 @@ G_DEFINE_TYPE (MMBearerStats, mm_bearer_stats, G_TYPE_OBJECT) #define PROPERTY_TX_BYTES "tx-bytes" #define PROPERTY_ATTEMPTS "attempts" #define PROPERTY_FAILED_ATTEMPTS "failed-attempts" +#define PROPERTY_TOTAL_DURATION "total-duration" +#define PROPERTY_TOTAL_RX_BYTES "total-rx-bytes" +#define PROPERTY_TOTAL_TX_BYTES "total-tx-bytes" struct _MMBearerStatsPrivate { guint duration; @@ -45,6 +48,9 @@ struct _MMBearerStatsPrivate { guint64 tx_bytes; guint attempts; guint failed_attempts; + guint total_duration; + guint64 total_rx_bytes; + guint64 total_tx_bytes; }; /*****************************************************************************/ @@ -209,6 +215,104 @@ mm_bearer_stats_set_failed_attempts (MMBearerStats *self, /*****************************************************************************/ +/** + * mm_bearer_stats_get_total_duration: + * @self: a #MMBearerStats. + * + * Gets the total duration of all the connections of this bearer. + * + * Returns: a #guint. + * + * Since: 1.14 + */ +guint +mm_bearer_stats_get_total_duration (MMBearerStats *self) +{ + g_return_val_if_fail (MM_IS_BEARER_STATS (self), 0); + + return self->priv->total_duration; +} + +/** + * mm_bearer_stats_set_total_duration: (skip) + */ +void +mm_bearer_stats_set_total_duration (MMBearerStats *self, + guint total_duration) +{ + g_return_if_fail (MM_IS_BEARER_STATS (self)); + + self->priv->total_duration = total_duration; +} + +/*****************************************************************************/ + +/** + * mm_bearer_stats_get_total_rx_bytes: + * @self: a #MMBearerStats. + * + * Gets the total number of bytes received without error during all the + * connections of this bearer. + * + * Returns: a #guint64. + * + * Since: 1.14 + */ +guint64 +mm_bearer_stats_get_total_rx_bytes (MMBearerStats *self) +{ + g_return_val_if_fail (MM_IS_BEARER_STATS (self), 0); + + return self->priv->total_rx_bytes; +} + +/** + * mm_bearer_stats_set_total_rx_bytes: (skip) + */ +void +mm_bearer_stats_set_total_rx_bytes (MMBearerStats *self, + guint64 total_bytes) +{ + g_return_if_fail (MM_IS_BEARER_STATS (self)); + + self->priv->total_rx_bytes = total_bytes; +} + +/*****************************************************************************/ + +/** + * mm_bearer_stats_get_total_tx_bytes: + * @self: a #MMBearerStats. + * + * Gets the total number of bytes transmitted without error during all the + * connections of this bearer. + * + * Returns: a #guint64. + * + * Since: 1.14 + */ +guint64 +mm_bearer_stats_get_total_tx_bytes (MMBearerStats *self) +{ + g_return_val_if_fail (MM_IS_BEARER_STATS (self), 0); + + return self->priv->total_tx_bytes; +} + +/** + * mm_bearer_stats_set_total_tx_bytes: (skip) + */ +void +mm_bearer_stats_set_total_tx_bytes (MMBearerStats *self, + guint64 total_bytes) +{ + g_return_if_fail (MM_IS_BEARER_STATS (self)); + + self->priv->total_tx_bytes = total_bytes; +} + +/*****************************************************************************/ + /** * mm_bearer_stats_get_dictionary: (skip) */ @@ -242,6 +346,18 @@ mm_bearer_stats_get_dictionary (MMBearerStats *self) "{sv}", PROPERTY_FAILED_ATTEMPTS, g_variant_new_uint32 (self->priv->failed_attempts)); + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_TOTAL_DURATION, + g_variant_new_uint32 (self->priv->total_duration)); + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_TOTAL_RX_BYTES, + g_variant_new_uint64 (self->priv->total_rx_bytes)); + g_variant_builder_add (&builder, + "{sv}", + PROPERTY_TOTAL_TX_BYTES, + g_variant_new_uint64 (self->priv->total_tx_bytes)); return g_variant_builder_end (&builder); } @@ -295,7 +411,20 @@ mm_bearer_stats_new_from_dictionary (GVariant *dictionary, mm_bearer_stats_set_failed_attempts ( self, g_variant_get_uint32 (value)); + } else if (g_str_equal (key, PROPERTY_TOTAL_DURATION)) { + mm_bearer_stats_set_total_duration ( + self, + g_variant_get_uint32 (value)); + } else if (g_str_equal (key, PROPERTY_TOTAL_RX_BYTES)) { + mm_bearer_stats_set_total_rx_bytes ( + self, + g_variant_get_uint64 (value)); + } else if (g_str_equal (key, PROPERTY_TOTAL_TX_BYTES)) { + mm_bearer_stats_set_total_tx_bytes ( + self, + g_variant_get_uint64 (value)); } + g_free (key); g_variant_unref (value); } diff --git a/libmm-glib/mm-bearer-stats.h b/libmm-glib/mm-bearer-stats.h index 000bd07b..bfaba1dd 100644 --- a/libmm-glib/mm-bearer-stats.h +++ b/libmm-glib/mm-bearer-stats.h @@ -63,6 +63,9 @@ guint64 mm_bearer_stats_get_rx_bytes (MMBearerStats *self); guint64 mm_bearer_stats_get_tx_bytes (MMBearerStats *self); guint mm_bearer_stats_get_attempts (MMBearerStats *self); guint mm_bearer_stats_get_failed_attempts (MMBearerStats *self); +guint mm_bearer_stats_get_total_duration (MMBearerStats *self); +guint64 mm_bearer_stats_get_total_rx_bytes (MMBearerStats *self); +guint64 mm_bearer_stats_get_total_tx_bytes (MMBearerStats *self); /*****************************************************************************/ /* ModemManager/libmm-glib/mmcli specific methods */ @@ -80,6 +83,9 @@ void mm_bearer_stats_set_rx_bytes (MMBearerStats *self, guint64 rx_b void mm_bearer_stats_set_tx_bytes (MMBearerStats *self, guint64 tx_bytes); void mm_bearer_stats_set_attempts (MMBearerStats *self, guint attempts); void mm_bearer_stats_set_failed_attempts (MMBearerStats *self, guint failed_attempts); +void mm_bearer_stats_set_total_duration (MMBearerStats *self, guint duration); +void mm_bearer_stats_set_total_rx_bytes (MMBearerStats *self, guint64 rx_bytes); +void mm_bearer_stats_set_total_tx_bytes (MMBearerStats *self, guint64 tx_bytes); GVariant *mm_bearer_stats_get_dictionary (MMBearerStats *self); diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c index 718956fd..dd4f1ef2 100644 --- a/src/mm-base-bearer.c +++ b/src/mm-base-bearer.c @@ -262,11 +262,65 @@ bearer_reset_ongoing_interface_stats (MMBaseBearer *self) bearer_update_interface_stats (self); } +static void +bearer_set_ongoing_interface_stats (MMBaseBearer *self, + guint duration, + guint64 rx_bytes, + guint64 tx_bytes) +{ + guint n_updates = 0; + + /* Make sure we don't reset to 0 these values if we had ever set them + * before. Just ignore the update if we're reported 0 */ + + if (duration) { + gint delta_duration; + + delta_duration = duration - mm_bearer_stats_get_duration (self->priv->stats); + if (delta_duration > 0) { + mm_bearer_stats_set_duration (self->priv->stats, duration); + mm_bearer_stats_set_total_duration (self->priv->stats, + mm_bearer_stats_get_total_duration (self->priv->stats) + delta_duration); + n_updates++; + } + } + + if (rx_bytes) { + gint64 delta_rx_bytes; + + delta_rx_bytes = rx_bytes - mm_bearer_stats_get_rx_bytes (self->priv->stats); + if (delta_rx_bytes > 0) { + mm_bearer_stats_set_rx_bytes (self->priv->stats, rx_bytes); + mm_bearer_stats_set_total_rx_bytes (self->priv->stats, + mm_bearer_stats_get_total_rx_bytes (self->priv->stats) + delta_rx_bytes); + n_updates++; + } + } + + if (tx_bytes) { + gint64 delta_tx_bytes; + + delta_tx_bytes = tx_bytes - mm_bearer_stats_get_tx_bytes (self->priv->stats); + if (delta_tx_bytes > 0) { + mm_bearer_stats_set_tx_bytes (self->priv->stats, tx_bytes); + mm_bearer_stats_set_total_tx_bytes (self->priv->stats, + mm_bearer_stats_get_total_tx_bytes (self->priv->stats) + delta_tx_bytes); + n_updates++; + } + } + + if (n_updates) + bearer_update_interface_stats (self); +} + static void bearer_stats_stop (MMBaseBearer *self) { if (self->priv->duration_timer) { - mm_bearer_stats_set_duration (self->priv->stats, (guint64) g_timer_elapsed (self->priv->duration_timer, NULL)); + bearer_set_ongoing_interface_stats (self, + (guint64) g_timer_elapsed (self->priv->duration_timer, NULL), + 0, + 0); g_timer_destroy (self->priv->duration_timer); self->priv->duration_timer = NULL; } @@ -303,10 +357,10 @@ reload_stats_ready (MMBaseBearer *self, } /* We only update stats if they were retrieved properly */ - mm_bearer_stats_set_duration (self->priv->stats, (guint32) g_timer_elapsed (self->priv->duration_timer, NULL)); - mm_bearer_stats_set_tx_bytes (self->priv->stats, tx_bytes); - mm_bearer_stats_set_rx_bytes (self->priv->stats, rx_bytes); - bearer_update_interface_stats (self); + bearer_set_ongoing_interface_stats (self, + (guint32) g_timer_elapsed (self->priv->duration_timer, NULL), + rx_bytes, + tx_bytes); } static gboolean @@ -328,10 +382,10 @@ stats_update_cb (MMBaseBearer *self) } /* Otherwise, just update duration and we're done */ - mm_bearer_stats_set_duration (self->priv->stats, (guint32) g_timer_elapsed (self->priv->duration_timer, NULL)); - mm_bearer_stats_set_tx_bytes (self->priv->stats, 0); - mm_bearer_stats_set_rx_bytes (self->priv->stats, 0); - bearer_update_interface_stats (self); + bearer_set_ongoing_interface_stats (self, + (guint32) g_timer_elapsed (self->priv->duration_timer, NULL), + 0, + 0); return G_SOURCE_CONTINUE; } From eebd7582bbd7a47d32838e5031a1315f15317f59 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 06:57:13 +0100 Subject: [PATCH 183/675] base-bearer: don't run disconnection path multiple times --- src/mm-base-bearer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c index dd4f1ef2..be702132 100644 --- a/src/mm-base-bearer.c +++ b/src/mm-base-bearer.c @@ -428,6 +428,10 @@ bearer_update_status (MMBaseBearer *self, /* NOTE: we do allow status 'CONNECTED' here; it may happen if we go into * DISCONNECTING and we cannot disconnect */ + /* Do nothing if the status is the same */ + if (self->priv->status == status) + return; + /* Update the property value */ self->priv->status = status; g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STATUS]); From 073043ca6bf8644881d768041d6b7779ebfbd88d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 06:57:42 +0100 Subject: [PATCH 184/675] base-bearer: log stats on disconnection --- src/mm-base-bearer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c index be702132..e01c082b 100644 --- a/src/mm-base-bearer.c +++ b/src/mm-base-bearer.c @@ -439,6 +439,8 @@ bearer_update_status (MMBaseBearer *self, /* Ensure that we don't expose any connection related data in the * interface when going into disconnected state. */ if (self->priv->status == MM_BEARER_STATUS_DISCONNECTED) { + g_autoptr(GString) report = NULL; + bearer_reset_interface_status (self); /* Cleanup flag to ignore disconnection reports */ self->priv->ignore_disconnection_reports = FALSE; @@ -446,6 +448,19 @@ bearer_update_status (MMBaseBearer *self, bearer_stats_stop (self); /* Stop connection monitoring */ connection_monitor_stop (self); + + /* Build and log report */ + report = g_string_new (NULL); + g_string_append_printf (report, + "connection #%u finished: duration %us", + mm_bearer_stats_get_attempts (self->priv->stats), + mm_bearer_stats_get_duration (self->priv->stats)); + if (!self->priv->reload_stats_unsupported) + g_string_append_printf (report, + ", tx: %" G_GUINT64_FORMAT " bytes, rx :%" G_GUINT64_FORMAT " bytes", + mm_bearer_stats_get_tx_bytes (self->priv->stats), + mm_bearer_stats_get_rx_bytes (self->priv->stats)); + mm_obj_info (self, "%s", report->str); } } From 330e0b33a40754d2a952df0c25bc2315ad3f9a8b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 28 Mar 2020 07:16:17 +0100 Subject: [PATCH 185/675] base-bearer: log connection attempt failure reason We were logging it as debug, increase logging level to warning to make sure it's always logged. --- src/mm-base-bearer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c index e01c082b..163f0bd7 100644 --- a/src/mm-base-bearer.c +++ b/src/mm-base-bearer.c @@ -800,7 +800,9 @@ connect_ready (MMBaseBearer *self, /* NOTE: connect() implementations *MUST* handle cancellations themselves */ result = MM_BASE_BEARER_GET_CLASS (self)->connect_finish (self, res, &error); if (!result) { - mm_obj_dbg (self, "couldn't connect: %s", error->message); + mm_obj_warn (self, "connection attempt #%u failed: %s", + mm_bearer_stats_get_attempts (self->priv->stats), + error->message); /* Update failed attempts */ mm_bearer_stats_set_failed_attempts (self->priv->stats, From d93526a11481847a7e318c9d4ca0e5c83748a119 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 12 Apr 2020 17:15:58 +0200 Subject: [PATCH 186/675] api,location: improve Location property docs Clearly specify that GetLocation() is another way to retrieve the location information instead of the Location property. --- ...org.freedesktop.ModemManager1.Modem.Location.xml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.Location.xml b/introspection/org.freedesktop.ModemManager1.Modem.Location.xml index d785a24c..4201615c 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.Location.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.Location.xml @@ -168,9 +168,16 @@ gathering is enabled. If the modem supports multiple location types it may return more than one here. - Note that if the device was told not to emit updated location - information when location information gathering was initially enabled, - this property may not return any location information for security reasons. + For security reasons, the location information updates via this + property are disabled by default. Users can use this property to monitor + location updates only if the location signals are enabled with + Setup(), + but considering that enabling the location signals would allow all users + to receive property updates as well, not just the process that enabled them. + For a finer grained access control, the user can use the + GetLocation() + method instead, which may require the client to authenticate itself on every + call. This dictionary is composed of a MMModemLocationSource From ef5611424448854d45f3ed3055bd46db93ed473e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 12 Apr 2020 17:38:43 +0200 Subject: [PATCH 187/675] api,location: improve Setup() method docs Explicitly state that the signals_location argument affects the behavior of the Location property. --- ...eedesktop.ModemManager1.Modem.Location.xml | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.Location.xml b/introspection/org.freedesktop.ModemManager1.Modem.Location.xml index 4201615c..8344648a 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.Location.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.Location.xml @@ -33,18 +33,26 @@ @signal_location: Flag to control whether the device emits signals with the new location information. This argument is ignored when disabling location information gathering. Configure the location sources to use when gathering location - information. Also enable or disable location information gathering. + information. Adding new location sources may require to enable them + in the device (e.g. the GNSS engine will need to be started explicitly + if a GPS source is requested by the user). In the same way, removing + location sources may require to disable them in the device (e.g. when + no GPS sources are requested by the user, the GNSS engine will need + to be stopped explicitly). + This method may require the client to authenticate itself. - When signals are emitted, any client application (including malicious - ones!) can listen for location updates unless D-Bus permissions restrict - these signals from certain users. If further security is desired, the + When location signaling is enabled by the user, any client application (including + malicious ones!) would be able to use the #org.freedesktop.ModemManager1.Modem.Location:Location + property to receive location updates. If further security is desired, the @signal_location argument can be set to %FALSE to disable location updates via D-Bus signals and require applications to call - authenticated APIs (like - GetLocation() - ) to get - location information. + authenticated APIs (like GetLocation()) + to get the location information. + + By default location signaling is disabled, and therefore the + #org.freedesktop.ModemManager1.Modem.Location:Location property will not + be usable until explicitly enabled by the user. The optional MM_MODEM_LOCATION_SOURCE_AGPS_MSA From b95bcfe6e37662e9947ded7b1c73ae9b6ada0631 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 12 Apr 2020 17:49:36 +0200 Subject: [PATCH 188/675] api,location: improve InjectAssistanceData() method docs Explain when this method should be used instead of A-GPS. --- ...rg.freedesktop.ModemManager1.Modem.Location.xml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.Location.xml b/introspection/org.freedesktop.ModemManager1.Modem.Location.xml index 8344648a..e0ac537d 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.Location.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.Location.xml @@ -104,13 +104,19 @@ InjectAssistanceData: @data: assistance data to be injected to the GNSS module. - Inject assistance data to the GNSS module. - The data files should be downloaded using external means from the URLs specified in - the AssistanceDataServers property. + Inject assistance data to the GNSS module, which will allow it to have a more + accurate positioning information. - The user does not need to specify the assistance data type being given. + The data files should be downloaded using external means from the URLs specified in + the AssistanceDataServers property. The + user does not need to specify the assistance data type being given. There is no maximum @data size limit specified, default DBus system bus limits apply. + + This method may be used when the device does not have a mobile network connection by + itself, and therefore it cannot use any A-GPS server to improve the accuracy of the + position. In this case, the user can instead download the assistance data files using + a WiFi or LAN network, and inject them to the GNSS engine manually. --> From 1802bd07ac82faab9f0b196a92a69784f386daa1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 16 Apr 2020 15:52:50 +0200 Subject: [PATCH 189/675] man,mmcli: remove non-existent --list-bearers option Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/203 --- docs/man/mmcli.1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/man/mmcli.1 b/docs/man/mmcli.1 index 4a087925..3730a883 100644 --- a/docs/man/mmcli.1 +++ b/docs/man/mmcli.1 @@ -229,9 +229,6 @@ Send an AT \fBCOMMAND\fR to the given modem. For example, \fBCOMMAND\fR could be 'AT+GMM' to probe for phone model information. This operation is only available when ModemManager is run in debug mode. .TP -.B \-\-list\-bearers -List packet data bearers that are available for the given modem. -.TP .B \-\-create\-bearer=['KEY1=VALUE1,KEY2=VALUE2,...'] Create a new packet data bearer for a given modem. The \fBKEY\fRs and some \fBVALUE\fRs are listed below: From d98597e4302983f2b12f2f70759015044c12ecf6 Mon Sep 17 00:00:00 2001 From: Teijo Kinnunen Date: Thu, 16 Apr 2020 13:16:28 +0300 Subject: [PATCH 190/675] quectel: Check SIM swap after "+QUSIM: 1" URC Quectel emits "+QUSIM: 1" after eUICC reinitialization. Detect it and perform SIM swap check if one is encountered. The motivation here is that M2M eUICC profile switch causes eUICC reset and this is one way to detect and handle profile switches properly on Quectel modems. The existing SIM hot swap mechanism is used as it appears to be suitable for handling profile switches as well as physical swapping of SIM cards. --- .../quectel/mm-broadband-modem-qmi-quectel.c | 9 ++ plugins/quectel/mm-broadband-modem-quectel.c | 9 ++ plugins/quectel/mm-shared-quectel.c | 89 +++++++++++++++++++ plugins/quectel/mm-shared-quectel.h | 6 ++ 4 files changed, 113 insertions(+) diff --git a/plugins/quectel/mm-broadband-modem-qmi-quectel.c b/plugins/quectel/mm-broadband-modem-qmi-quectel.c index 14adf984..96eda0e5 100644 --- a/plugins/quectel/mm-broadband-modem-qmi-quectel.c +++ b/plugins/quectel/mm-broadband-modem-qmi-quectel.c @@ -19,10 +19,12 @@ #include "mm-shared-quectel.h" #include "mm-iface-modem-firmware.h" +static void iface_modem_init (MMIfaceModem *iface); static void shared_quectel_init (MMSharedQuectel *iface); static void iface_modem_firmware_init (MMIfaceModemFirmware *iface); G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQmiQuectel, mm_broadband_modem_qmi_quectel, MM_TYPE_BROADBAND_MODEM_QMI, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init) G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init)) @@ -49,6 +51,13 @@ mm_broadband_modem_qmi_quectel_init (MMBroadbandModemQmiQuectel *self) { } +static void +iface_modem_init (MMIfaceModem *iface) +{ + iface->setup_sim_hot_swap = mm_shared_quectel_setup_sim_hot_swap; + iface->setup_sim_hot_swap_finish = mm_shared_quectel_setup_sim_hot_swap_finish; +} + static void iface_modem_firmware_init (MMIfaceModemFirmware *iface) { diff --git a/plugins/quectel/mm-broadband-modem-quectel.c b/plugins/quectel/mm-broadband-modem-quectel.c index 6a43a87d..6dfa5bb7 100644 --- a/plugins/quectel/mm-broadband-modem-quectel.c +++ b/plugins/quectel/mm-broadband-modem-quectel.c @@ -19,10 +19,12 @@ #include "mm-shared-quectel.h" #include "mm-iface-modem-firmware.h" +static void iface_modem_init (MMIfaceModem *iface); static void shared_quectel_init (MMSharedQuectel *iface); static void iface_modem_firmware_init (MMIfaceModemFirmware *iface); G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQuectel, mm_broadband_modem_quectel, MM_TYPE_BROADBAND_MODEM, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init) G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init)) @@ -56,6 +58,13 @@ mm_broadband_modem_quectel_init (MMBroadbandModemQuectel *self) { } +static void +iface_modem_init (MMIfaceModem *iface) +{ + iface->setup_sim_hot_swap = mm_shared_quectel_setup_sim_hot_swap; + iface->setup_sim_hot_swap_finish = mm_shared_quectel_setup_sim_hot_swap_finish; +} + static void shared_quectel_init (MMSharedQuectel *iface) { diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index f451026b..76107e79 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -21,6 +21,7 @@ #define _LIBMM_INSIDE_MM #include +#include "mm-log-object.h" #include "mm-iface-modem-firmware.h" #include "mm-base-modem.h" #include "mm-base-modem-at.h" @@ -71,6 +72,94 @@ mm_shared_quectel_firmware_load_update_settings (MMIfaceModemFirmware *self, task); } +/*****************************************************************************/ +/* "+QUSIM: 1" URC is emitted by Quectel modems after the USIM has been + * (re)initialized. We register a handler for this URC and perform a check + * for SIM swap when it is encountered. The motivation for this is to detect + * M2M eUICC profile switches. According to SGP.02 chapter 3.2.1, the eUICC + * shall trigger a REFRESH operation with eUICC reset when a new profile is + * enabled. The +QUSIM URC appears after the eUICC has restarted and can act + * as a trigger for profile switch check. This should basically be handled + * the same as a physical SIM swap, so the existing SIM hot swap mechanism + * is used. + */ + +static void +quectel_qusim_check_for_sim_swap_ready (MMIfaceModem *self, + GAsyncResult *res) +{ + GError *error = NULL; + + if (!MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish (self, res, &error)) { + mm_obj_warn (self, "couldn't check SIM swap: %s", error->message); + g_error_free (error); + } else + mm_obj_dbg (self, "check SIM swap completed"); +} + +static void +quectel_qusim_unsolicited_handler (MMPortSerialAt *port, + GMatchInfo *match_info, + MMIfaceModem* self) +{ + if (MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap && + MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish) { + mm_obj_dbg (self, "checking SIM swap"); + MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap ( + self, + (GAsyncReadyCallback)quectel_qusim_check_for_sim_swap_ready, + NULL); + } +} + +gboolean +mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +void +mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + MMPortSerialAt *port_primary; + MMPortSerialAt *port_secondary; + GTask *task; + GRegex *pattern; + + task = g_task_new (self, NULL, callback, user_data); + + port_primary = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + port_secondary = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); + + pattern = g_regex_new ("\\+QUSIM:\\s*1\\r\\n", G_REGEX_RAW, 0, NULL); + g_assert (pattern); + + if (port_primary) + mm_port_serial_at_add_unsolicited_msg_handler ( + port_primary, + pattern, + (MMPortSerialAtUnsolicitedMsgFn)quectel_qusim_unsolicited_handler, + self, + NULL); + + if (port_secondary) + mm_port_serial_at_add_unsolicited_msg_handler ( + port_secondary, + pattern, + (MMPortSerialAtUnsolicitedMsgFn)quectel_qusim_unsolicited_handler, + self, + NULL); + + g_regex_unref (pattern); + mm_obj_dbg (self, "+QUSIM detection set up"); + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + /*****************************************************************************/ static void diff --git a/plugins/quectel/mm-shared-quectel.h b/plugins/quectel/mm-shared-quectel.h index 4ebcfd61..22ee8bee 100644 --- a/plugins/quectel/mm-shared-quectel.h +++ b/plugins/quectel/mm-shared-quectel.h @@ -45,5 +45,11 @@ void mm_shared_quectel_firmware_load_update_settings MMFirmwareUpdateSettings *mm_shared_quectel_firmware_load_update_settings_finish (MMIfaceModemFirmware *self, GAsyncResult *res, GError **error); +void mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error); #endif /* MM_SHARED_QUECTEL_H */ From ae90ed66a2ee94eed28da19e914feb75f03fd504 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 20 Apr 2020 11:25:59 +0200 Subject: [PATCH 191/675] broadband-modem-qmi: 3GPP USSD support Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/26 --- configure.ac | 2 +- src/mm-broadband-modem-qmi.c | 517 ++++++++++++++++++++++++++++++++++- 2 files changed, 515 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 9f21f98f..e9883ad4 100644 --- a/configure.ac +++ b/configure.ac @@ -391,7 +391,7 @@ dnl----------------------------------------------------------------------------- dnl QMI support (enabled by default) dnl -LIBQMI_VERSION=1.25.4 +LIBQMI_VERSION=1.25.5 AC_ARG_WITH(qmi, AS_HELP_STRING([--without-qmi], [Build without QMI support]), [], [with_qmi=yes]) AM_CONDITIONAL(WITH_QMI, test "x$with_qmi" = "xyes") diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index cf7ebf55..f7734c9a 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -126,6 +126,12 @@ struct _MMBroadbandModemQmiPrivate { gboolean oma_unsolicited_events_setup; guint oma_event_report_indication_id; + /* 3GPP USSD helpers */ + guint ussd_indication_id; + gboolean ussd_unsolicited_events_enabled; + gboolean ussd_unsolicited_events_setup; + GTask *pending_ussd_action; + /* Firmware helpers */ gboolean firmware_list_preloaded; GList *firmware_list; @@ -7128,6 +7134,499 @@ oma_enable_unsolicited_events (MMIfaceModemOma *self, user_data); } +/*****************************************************************************/ +/* Check support (3GPP USSD interface) */ + +static gboolean +modem_3gpp_ussd_check_support_finish (MMIfaceModem3gppUssd *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +modem_3gpp_ussd_check_support (MMIfaceModem3gppUssd *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + + task = g_task_new (self, NULL, callback, user_data); + + /* If we have support for the Voice client, USSD is supported */ + if (!mm_shared_qmi_peek_client (MM_SHARED_QMI (self), + QMI_SERVICE_VOICE, + MM_PORT_QMI_FLAG_DEFAULT, + NULL)) { + mm_obj_dbg (self, "USSD capabilities not supported"); + g_task_return_boolean (task, FALSE); + } else { + mm_obj_dbg (self, "USSD capabilities supported"); + g_task_return_boolean (task, TRUE); + } + + g_object_unref (task); +} + +/*****************************************************************************/ +/* USSD indications */ + +static void +process_ussd_message (MMBroadbandModemQmi *self, + QmiVoiceUserAction user_action, + gchar *utf8_take, + GError *error_take) +{ + MMModem3gppUssdSessionState ussd_state = MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE; + g_autoptr(GTask) task = NULL; + g_autofree gchar *utf8 = utf8_take; + g_autoptr(GError) error = error_take; + + task = g_steal_pointer (&self->priv->pending_ussd_action); + + if (error) { + g_assert (!utf8); + if (task) + g_task_return_error (task, g_steal_pointer (&error)); + else + mm_obj_dbg (self, "USSD operation failed: %s", error->message); + return; + } + + switch (user_action) { + case QMI_VOICE_USER_ACTION_NOT_REQUIRED: + /* no response, or a response to user's request? */ + if (!utf8 || task) + break; + /* Network-initiated USSD-Notify */ + mm_iface_modem_3gpp_ussd_update_network_notification (MM_IFACE_MODEM_3GPP_USSD (self), utf8); + g_clear_pointer (&utf8, g_free); + break; + case QMI_VOICE_USER_ACTION_REQUIRED: + /* further action required */ + ussd_state = MM_MODEM_3GPP_USSD_SESSION_STATE_USER_RESPONSE; + /* no response, or a response to user's request? */ + if (!utf8 || task) + break; + /* Network-initiated USSD-Request */ + mm_iface_modem_3gpp_ussd_update_network_request (MM_IFACE_MODEM_3GPP_USSD (self), utf8); + g_clear_pointer (&utf8, g_free); + break; + case QMI_VOICE_USER_ACTION_UNKNOWN: + default: + /* Not an indication */ + break; + } + + mm_iface_modem_3gpp_ussd_update_state (MM_IFACE_MODEM_3GPP_USSD (self), ussd_state); + + if (!task) { + if (utf8) + mm_obj_dbg (self, "ignoring unprocessed USSD message: %s", utf8); + return; + } + + /* Complete the pending action, if any */ + if (utf8) + g_task_return_pointer (task, g_steal_pointer (&utf8), g_free); + else + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "USSD action response not processed correctly"); +} + +static void +ussd_indication_cb (QmiClientVoice *client, + QmiIndicationVoiceUssdOutput *output, + MMBroadbandModemQmi *self) +{ + QmiVoiceUserAction user_action = QMI_VOICE_USER_ACTION_UNKNOWN; + GArray *uss_data_utf16 = NULL; + gchar *utf8 = NULL; + GError *error = NULL; + + qmi_indication_voice_ussd_output_get_user_action (output, &user_action, NULL); + if (qmi_indication_voice_ussd_output_get_uss_data_utf16 (output, &uss_data_utf16, NULL) && uss_data_utf16) + /* always prefer the data field in UTF-16 */ + utf8 = g_convert ((const gchar *) uss_data_utf16->data, (2 * uss_data_utf16->len), "UTF8", "UTF16LE", NULL, NULL, &error); + + process_ussd_message (self, user_action, utf8, error); +} + +/*****************************************************************************/ +/* Setup/cleanup unsolicited events */ + +static gboolean +common_3gpp_ussd_setup_cleanup_unsolicited_events_finish (MMIfaceModem3gppUssd *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +common_3gpp_ussd_setup_cleanup_unsolicited_events (MMBroadbandModemQmi *self, + gboolean setup, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + QmiClient *client = NULL; + + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_VOICE, &client, + callback, user_data)) + return; + + task = g_task_new (self, NULL, callback, user_data); + + if (setup == self->priv->ussd_unsolicited_events_setup) { + mm_obj_dbg (self, "USSD unsolicited events already %s; skipping", + setup ? "setup" : "cleanup"); + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + self->priv->ussd_unsolicited_events_setup = setup; + + if (setup) { + g_assert (self->priv->ussd_indication_id == 0); + self->priv->ussd_indication_id = + g_signal_connect (client, + "ussd", + G_CALLBACK (ussd_indication_cb), + self); + } else { + g_assert (self->priv->ussd_indication_id != 0); + g_signal_handler_disconnect (client, self->priv->ussd_indication_id); + self->priv->ussd_indication_id = 0; + } + + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +modem_3gpp_ussd_setup_unsolicited_events (MMIfaceModem3gppUssd *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + common_3gpp_ussd_setup_cleanup_unsolicited_events (MM_BROADBAND_MODEM_QMI (self), TRUE, callback, user_data); +} + +static void +modem_3gpp_ussd_cleanup_unsolicited_events (MMIfaceModem3gppUssd *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + common_3gpp_ussd_setup_cleanup_unsolicited_events (MM_BROADBAND_MODEM_QMI (self), FALSE, callback, user_data); +} + +/*****************************************************************************/ +/* Enable/disable unsolicited events */ + +static gboolean +common_3gpp_ussd_enable_disable_unsolicited_events_finish (MMIfaceModem3gppUssd *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +voice_indication_register_ready (QmiClientVoice *client, + GAsyncResult *res, + GTask *task) +{ + g_autoptr(QmiMessageVoiceIndicationRegisterOutput) output = NULL; + GError *error = NULL; + + output = qmi_client_voice_indication_register_finish (client, res, &error); + if (!output) { + g_prefix_error (&error, "QMI operation failed: "); + g_task_return_error (task, error); + } else if (!qmi_message_voice_indication_register_output_get_result (output, &error)) { + g_prefix_error (&error, "Couldn't register voice USSD indications: "); + g_task_return_error (task, error); + } else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +common_3gpp_ussd_enable_disable_unsolicited_events (MMBroadbandModemQmi *self, + gboolean enable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_autoptr(QmiMessageVoiceIndicationRegisterInput) input = NULL; + GTask *task; + QmiClient *client; + + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_VOICE, &client, + callback, user_data)) + return; + + task = g_task_new (self, NULL, callback, user_data); + + if (enable == self->priv->ussd_unsolicited_events_enabled) { + mm_obj_dbg (self, "USSD unsolicited events already %s; skipping", + enable ? "enabled" : "disabled"); + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + self->priv->ussd_unsolicited_events_enabled = enable; + + input = qmi_message_voice_indication_register_input_new (); + qmi_message_voice_indication_register_input_set_ussd_notification_events (input, enable, NULL); + qmi_client_voice_indication_register (QMI_CLIENT_VOICE (client), + input, + 10, + NULL, + (GAsyncReadyCallback) voice_indication_register_ready, + task); +} + +static void +modem_3gpp_ussd_enable_unsolicited_events (MMIfaceModem3gppUssd *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + common_3gpp_ussd_enable_disable_unsolicited_events (MM_BROADBAND_MODEM_QMI (self), TRUE, callback, user_data); +} + +static void +modem_3gpp_ussd_disable_unsolicited_events (MMIfaceModem3gppUssd *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + common_3gpp_ussd_enable_disable_unsolicited_events (MM_BROADBAND_MODEM_QMI (self), FALSE, callback, user_data); +} + +/*****************************************************************************/ +/* Send command (3GPP/USSD interface) */ + +static GArray * +ussd_encode (const gchar *command, + QmiVoiceUssDataCodingScheme *scheme, + GError **error) +{ + gsize command_len; + g_autoptr(GByteArray) barray = NULL; + g_autoptr(GError) inner_error = NULL; + + command_len = strlen (command); + + if (g_str_is_ascii (command)) { + *scheme = QMI_VOICE_USS_DATA_CODING_SCHEME_ASCII; + return g_array_append_vals (g_array_sized_new (FALSE, FALSE, 1, command_len), command, command_len); + } + + barray = g_byte_array_sized_new (strlen (command) * 2); + if (!mm_modem_charset_byte_array_append (barray, command, FALSE, MM_MODEM_CHARSET_UCS2, &inner_error)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "Failed to encode USSD command in UCS2 charset: %s", inner_error->message); + return NULL; + } + + *scheme = QMI_VOICE_USS_DATA_CODING_SCHEME_UCS2; + return g_array_append_vals (g_array_sized_new (FALSE, FALSE, 1, barray->len), barray->data, barray->len); +} + +static gchar * +modem_3gpp_ussd_send_finish (MMIfaceModem3gppUssd *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_pointer (G_TASK (res), error); +} + +static void +voice_answer_ussd_ready (QmiClientVoice *client, + GAsyncResult *res, + MMBroadbandModemQmi *self) +{ + g_autoptr(QmiMessageVoiceAnswerUssdOutput) output = NULL; + GError *error = NULL; + + output = qmi_client_voice_answer_ussd_finish (client, res, &error); + if (!output) + g_prefix_error (&error, "QMI operation failed: "); + else if (!qmi_message_voice_answer_ussd_output_get_result (output, &error)) + g_prefix_error (&error, "Couldn't answer USSD operation: "); + + process_ussd_message (self, QMI_VOICE_USER_ACTION_UNKNOWN, error ? NULL : g_strdup (""), error); + + /* balance out the full reference we received */ + g_object_unref (self); +} + +static void +voice_originate_ussd_ready (QmiClientVoice *client, + GAsyncResult *res, + MMBroadbandModemQmi *self) +{ + g_autoptr(QmiMessageVoiceOriginateUssdOutput) output = NULL; + GError *error = NULL; + GArray *uss_data_utf16 = NULL; + gchar *utf8 = NULL; + + output = qmi_client_voice_originate_ussd_finish (client, res, &error); + if (!output) + g_prefix_error (&error, "QMI operation failed: "); + else if (!qmi_message_voice_originate_ussd_output_get_result (output, &error)) + g_prefix_error (&error, "Couldn't originate USSD operation: "); + else if (qmi_message_voice_originate_ussd_output_get_uss_data_utf16 (output, &uss_data_utf16, NULL) && uss_data_utf16) + /* always prefer the data field in UTF-16 */ + utf8 = g_convert ((const gchar *) uss_data_utf16->data, (2 * uss_data_utf16->len), "UTF8", "UTF16LE", NULL, NULL, &error); + + process_ussd_message (self, QMI_VOICE_USER_ACTION_UNKNOWN, utf8, error); + + /* balance out the full reference we received */ + g_object_unref (self); +} + +static void +modem_3gpp_ussd_send (MMIfaceModem3gppUssd *_self, + const gchar *command, + GAsyncReadyCallback callback, + gpointer user_data) +{ + MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); + GTask *task; + QmiClient *client; + QmiVoiceUssDataCodingScheme scheme; + g_autoptr(GArray) encoded = NULL; + GError *error = NULL; + MMModem3gppUssdSessionState state; + + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_VOICE, &client, + callback, user_data)) + return; + + task = g_task_new (self, NULL, callback, user_data); + + /* Fail if there is an ongoing operation already */ + if (self->priv->pending_ussd_action) { + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_IN_PROGRESS, + "there is already an ongoing USSD operation"); + g_object_unref (task); + return; + } + + encoded = ussd_encode (command, &scheme, &error); + if (!encoded) { + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + state = mm_iface_modem_3gpp_ussd_get_state (MM_IFACE_MODEM_3GPP_USSD (self)); + + /* Cache the action, as it may be completed via URCs */ + self->priv->pending_ussd_action = task; + mm_iface_modem_3gpp_ussd_update_state (_self, MM_MODEM_3GPP_USSD_SESSION_STATE_ACTIVE); + + switch (state) { + case MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE: { + g_autoptr(QmiMessageVoiceOriginateUssdInput) input = NULL; + + input = qmi_message_voice_originate_ussd_input_new (); + qmi_message_voice_originate_ussd_input_set_uss_data (input, scheme, encoded, NULL); + qmi_client_voice_originate_ussd (QMI_CLIENT_VOICE (client), input, 100, NULL, + (GAsyncReadyCallback) voice_originate_ussd_ready, + g_object_ref (self)); /* full reference! */ + return; + } + case MM_MODEM_3GPP_USSD_SESSION_STATE_USER_RESPONSE: { + g_autoptr(QmiMessageVoiceAnswerUssdInput) input = NULL; + + input = qmi_message_voice_answer_ussd_input_new (); + qmi_message_voice_answer_ussd_input_set_uss_data (input, scheme, encoded, NULL); + qmi_client_voice_answer_ussd (QMI_CLIENT_VOICE (client), input, 100, NULL, + (GAsyncReadyCallback) voice_answer_ussd_ready, + g_object_ref (self)); /* full reference! */ + return; + } + case MM_MODEM_3GPP_USSD_SESSION_STATE_UNKNOWN: + case MM_MODEM_3GPP_USSD_SESSION_STATE_ACTIVE: + default: + g_assert_not_reached (); + return; + } +} + +/*****************************************************************************/ +/* Cancel USSD (3GPP/USSD interface) */ + +static gboolean +modem_3gpp_ussd_cancel_finish (MMIfaceModem3gppUssd *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +voice_cancel_ussd_ready (QmiClientVoice *client, + GAsyncResult *res, + GTask *task) +{ + g_autoptr(QmiMessageVoiceCancelUssdOutput) output = NULL; + MMBroadbandModemQmi *self; + GTask *pending_task; + GError *error = NULL; + + self = g_task_get_source_object (task); + + output = qmi_client_voice_cancel_ussd_finish (client, res, &error); + if (!output) + g_prefix_error (&error, "QMI operation failed: "); + else if (!qmi_message_voice_cancel_ussd_output_get_result (output, &error)) + g_prefix_error (&error, "Couldn't cancel USSD operation: "); + + /* Complete the pending action, regardless of the operation result */ + pending_task = g_steal_pointer (&self->priv->pending_ussd_action); + if (pending_task) { + g_task_return_new_error (pending_task, MM_CORE_ERROR, MM_CORE_ERROR_ABORTED, + "USSD session was cancelled"); + g_object_unref (pending_task); + } + + mm_iface_modem_3gpp_ussd_update_state (MM_IFACE_MODEM_3GPP_USSD (self), + MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE); + + if (error) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +modem_3gpp_ussd_cancel (MMIfaceModem3gppUssd *_self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); + GTask *task; + QmiClient *client; + + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_VOICE, &client, + callback, user_data)) + return; + + task = g_task_new (self, NULL, callback, user_data); + + qmi_client_voice_cancel_ussd (QMI_CLIENT_VOICE (client), NULL, 100, NULL, + (GAsyncReadyCallback) voice_cancel_ussd_ready, + task); +} + /*****************************************************************************/ /* Check firmware support (Firmware interface) */ @@ -8611,6 +9110,7 @@ static const QmiService qmi_services[] = { QMI_SERVICE_UIM, QMI_SERVICE_LOC, QMI_SERVICE_PDC, + QMI_SERVICE_VOICE, }; typedef struct { @@ -9056,9 +9556,20 @@ iface_modem_3gpp_init (MMIfaceModem3gpp *iface) static void iface_modem_3gpp_ussd_init (MMIfaceModem3gppUssd *iface) { - /* Assume we don't have USSD support */ - iface->check_support = NULL; - iface->check_support_finish = NULL; + iface->check_support = modem_3gpp_ussd_check_support; + iface->check_support_finish = modem_3gpp_ussd_check_support_finish; + iface->setup_unsolicited_events = modem_3gpp_ussd_setup_unsolicited_events; + iface->setup_unsolicited_events_finish = common_3gpp_ussd_setup_cleanup_unsolicited_events_finish; + iface->cleanup_unsolicited_events = modem_3gpp_ussd_cleanup_unsolicited_events; + iface->cleanup_unsolicited_events_finish = common_3gpp_ussd_setup_cleanup_unsolicited_events_finish; + iface->enable_unsolicited_events = modem_3gpp_ussd_enable_unsolicited_events; + iface->enable_unsolicited_events_finish = common_3gpp_ussd_enable_disable_unsolicited_events_finish; + iface->disable_unsolicited_events = modem_3gpp_ussd_disable_unsolicited_events; + iface->disable_unsolicited_events_finish = common_3gpp_ussd_enable_disable_unsolicited_events_finish; + iface->send = modem_3gpp_ussd_send; + iface->send_finish = modem_3gpp_ussd_send_finish; + iface->cancel = modem_3gpp_ussd_cancel; + iface->cancel_finish = modem_3gpp_ussd_cancel_finish; } static void From 6086c6877c6bca341f6a3b2b07798e8353575d11 Mon Sep 17 00:00:00 2001 From: Maxim Anisimov Date: Wed, 22 Apr 2020 15:33:40 +0200 Subject: [PATCH 192/675] broadband-modem-qmi: fix unicode names in USSD iconv() operations So that the limited iconv() in OpenWRT supports the conversion properly. --- src/mm-broadband-modem-qmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index f7734c9a..98584956 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -7248,7 +7248,7 @@ ussd_indication_cb (QmiClientVoice *client, qmi_indication_voice_ussd_output_get_user_action (output, &user_action, NULL); if (qmi_indication_voice_ussd_output_get_uss_data_utf16 (output, &uss_data_utf16, NULL) && uss_data_utf16) /* always prefer the data field in UTF-16 */ - utf8 = g_convert ((const gchar *) uss_data_utf16->data, (2 * uss_data_utf16->len), "UTF8", "UTF16LE", NULL, NULL, &error); + utf8 = g_convert ((const gchar *) uss_data_utf16->data, (2 * uss_data_utf16->len), "UTF-8", "UTF16-LE", NULL, NULL, &error); process_ussd_message (self, user_action, utf8, error); } @@ -7480,7 +7480,7 @@ voice_originate_ussd_ready (QmiClientVoice *client, g_prefix_error (&error, "Couldn't originate USSD operation: "); else if (qmi_message_voice_originate_ussd_output_get_uss_data_utf16 (output, &uss_data_utf16, NULL) && uss_data_utf16) /* always prefer the data field in UTF-16 */ - utf8 = g_convert ((const gchar *) uss_data_utf16->data, (2 * uss_data_utf16->len), "UTF8", "UTF16LE", NULL, NULL, &error); + utf8 = g_convert ((const gchar *) uss_data_utf16->data, (2 * uss_data_utf16->len), "UTF-8", "UTF-16LE", NULL, NULL, &error); process_ussd_message (self, QMI_VOICE_USER_ACTION_UNKNOWN, utf8, error); From d3c5771b1ff8d7acf1c26fccc275f81f59868635 Mon Sep 17 00:00:00 2001 From: Maxim Anisimov Date: Wed, 22 Apr 2020 15:39:36 +0200 Subject: [PATCH 193/675] broadband-modem-qmi: USSD data in UTF-16 not always given E.g. in the Quectel EP06-E only the ASCII/UCS-2 data TLV is given. --- src/mm-broadband-modem-qmi.c | 113 ++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 40 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 98584956..a550072b 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -7169,6 +7169,62 @@ modem_3gpp_ussd_check_support (MMIfaceModem3gppUssd *self, g_object_unref (task); } +/*****************************************************************************/ +/* USSD encode/decode helpers */ + +static GArray * +ussd_encode (const gchar *command, + QmiVoiceUssDataCodingScheme *scheme, + GError **error) +{ + gsize command_len; + g_autoptr(GByteArray) barray = NULL; + g_autoptr(GError) inner_error = NULL; + + command_len = strlen (command); + + if (g_str_is_ascii (command)) { + *scheme = QMI_VOICE_USS_DATA_CODING_SCHEME_ASCII; + return g_array_append_vals (g_array_sized_new (FALSE, FALSE, 1, command_len), command, command_len); + } + + barray = g_byte_array_sized_new (strlen (command) * 2); + if (!mm_modem_charset_byte_array_append (barray, command, FALSE, MM_MODEM_CHARSET_UCS2, &inner_error)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "Failed to encode USSD command in UCS2 charset: %s", inner_error->message); + return NULL; + } + + *scheme = QMI_VOICE_USS_DATA_CODING_SCHEME_UCS2; + return g_array_append_vals (g_array_sized_new (FALSE, FALSE, 1, barray->len), barray->data, barray->len); +} + +static gchar * +ussd_decode (QmiVoiceUssDataCodingScheme scheme, + GArray *data, + GError **error) +{ + gchar *decoded = NULL; + + if (scheme == QMI_VOICE_USS_DATA_CODING_SCHEME_ASCII) { + decoded = g_strndup ((const gchar *) data->data, data->len); + if (!decoded) + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "Error decoding USSD command in 0x%04x scheme (ASCII charset)", + scheme); + } else if (scheme == QMI_VOICE_USS_DATA_CODING_SCHEME_UCS2) { + decoded = mm_modem_charset_byte_array_to_utf8 ((GByteArray *) data, MM_MODEM_CHARSET_UCS2); + if (!decoded) + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "Error decoding USSD command in 0x%04x scheme (UCS2 charset)", + scheme); + } else + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "Failed to decode USSD command in unsupported 0x%04x scheme", scheme); + + return decoded; +} + /*****************************************************************************/ /* USSD indications */ @@ -7240,15 +7296,17 @@ ussd_indication_cb (QmiClientVoice *client, QmiIndicationVoiceUssdOutput *output, MMBroadbandModemQmi *self) { - QmiVoiceUserAction user_action = QMI_VOICE_USER_ACTION_UNKNOWN; - GArray *uss_data_utf16 = NULL; - gchar *utf8 = NULL; - GError *error = NULL; + QmiVoiceUserAction user_action = QMI_VOICE_USER_ACTION_UNKNOWN; + QmiVoiceUssDataCodingScheme scheme; + GArray *uss_data = NULL; + gchar *utf8 = NULL; + GError *error = NULL; qmi_indication_voice_ussd_output_get_user_action (output, &user_action, NULL); - if (qmi_indication_voice_ussd_output_get_uss_data_utf16 (output, &uss_data_utf16, NULL) && uss_data_utf16) - /* always prefer the data field in UTF-16 */ - utf8 = g_convert ((const gchar *) uss_data_utf16->data, (2 * uss_data_utf16->len), "UTF-8", "UTF16-LE", NULL, NULL, &error); + if (qmi_indication_voice_ussd_output_get_uss_data_utf16 (output, &uss_data, NULL) && uss_data) + utf8 = g_convert ((const gchar *) uss_data->data, (2 * uss_data->len), "UTF-8", "UTF16-LE", NULL, NULL, &error); + else if (qmi_indication_voice_ussd_output_get_uss_data (output, &scheme, &uss_data, NULL) && uss_data) + utf8 = ussd_decode(scheme, uss_data, &error); process_ussd_message (self, user_action, utf8, error); } @@ -7408,33 +7466,6 @@ modem_3gpp_ussd_disable_unsolicited_events (MMIfaceModem3gppUssd *self, /*****************************************************************************/ /* Send command (3GPP/USSD interface) */ -static GArray * -ussd_encode (const gchar *command, - QmiVoiceUssDataCodingScheme *scheme, - GError **error) -{ - gsize command_len; - g_autoptr(GByteArray) barray = NULL; - g_autoptr(GError) inner_error = NULL; - - command_len = strlen (command); - - if (g_str_is_ascii (command)) { - *scheme = QMI_VOICE_USS_DATA_CODING_SCHEME_ASCII; - return g_array_append_vals (g_array_sized_new (FALSE, FALSE, 1, command_len), command, command_len); - } - - barray = g_byte_array_sized_new (strlen (command) * 2); - if (!mm_modem_charset_byte_array_append (barray, command, FALSE, MM_MODEM_CHARSET_UCS2, &inner_error)) { - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, - "Failed to encode USSD command in UCS2 charset: %s", inner_error->message); - return NULL; - } - - *scheme = QMI_VOICE_USS_DATA_CODING_SCHEME_UCS2; - return g_array_append_vals (g_array_sized_new (FALSE, FALSE, 1, barray->len), barray->data, barray->len); -} - static gchar * modem_3gpp_ussd_send_finish (MMIfaceModem3gppUssd *self, GAsyncResult *res, @@ -7469,18 +7500,20 @@ voice_originate_ussd_ready (QmiClientVoice *client, MMBroadbandModemQmi *self) { g_autoptr(QmiMessageVoiceOriginateUssdOutput) output = NULL; - GError *error = NULL; - GArray *uss_data_utf16 = NULL; - gchar *utf8 = NULL; + QmiVoiceUssDataCodingScheme scheme; + GError *error = NULL; + GArray *uss_data = NULL; + gchar *utf8 = NULL; output = qmi_client_voice_originate_ussd_finish (client, res, &error); if (!output) g_prefix_error (&error, "QMI operation failed: "); else if (!qmi_message_voice_originate_ussd_output_get_result (output, &error)) g_prefix_error (&error, "Couldn't originate USSD operation: "); - else if (qmi_message_voice_originate_ussd_output_get_uss_data_utf16 (output, &uss_data_utf16, NULL) && uss_data_utf16) - /* always prefer the data field in UTF-16 */ - utf8 = g_convert ((const gchar *) uss_data_utf16->data, (2 * uss_data_utf16->len), "UTF-8", "UTF-16LE", NULL, NULL, &error); + else if (qmi_message_voice_originate_ussd_output_get_uss_data_utf16 (output, &uss_data, NULL) && uss_data) + utf8 = g_convert ((const gchar *) uss_data->data, (2 * uss_data->len), "UTF-8", "UTF-16LE", NULL, NULL, &error); + else if (qmi_message_voice_originate_ussd_output_get_uss_data (output, &scheme, &uss_data, NULL) && uss_data) + utf8 = ussd_decode (scheme, uss_data, &error); process_ussd_message (self, QMI_VOICE_USER_ACTION_UNKNOWN, utf8, error); From 18a7d9da7a810dcfe22f810e318f1c6fe34c6e03 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 22 Apr 2020 15:49:05 +0200 Subject: [PATCH 194/675] broadband-modem-qmi: GByteArray can be casted to GArray in USSD encoding Reported by: Maxim Anisimov --- src/mm-broadband-modem-qmi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index a550072b..648bf1a5 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -7184,11 +7184,14 @@ ussd_encode (const gchar *command, command_len = strlen (command); if (g_str_is_ascii (command)) { + barray = g_byte_array_sized_new (command_len); + g_byte_array_append (barray, (const guint8 *)command, command_len); + *scheme = QMI_VOICE_USS_DATA_CODING_SCHEME_ASCII; - return g_array_append_vals (g_array_sized_new (FALSE, FALSE, 1, command_len), command, command_len); + return (GArray *) g_steal_pointer (&barray); } - barray = g_byte_array_sized_new (strlen (command) * 2); + barray = g_byte_array_sized_new (command_len * 2); if (!mm_modem_charset_byte_array_append (barray, command, FALSE, MM_MODEM_CHARSET_UCS2, &inner_error)) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Failed to encode USSD command in UCS2 charset: %s", inner_error->message); @@ -7196,7 +7199,7 @@ ussd_encode (const gchar *command, } *scheme = QMI_VOICE_USS_DATA_CODING_SCHEME_UCS2; - return g_array_append_vals (g_array_sized_new (FALSE, FALSE, 1, barray->len), barray->data, barray->len); + return (GArray *) g_steal_pointer (&barray); } static gchar * From 479d8e723c9965ee064a7a57d39d29f6c098da0f Mon Sep 17 00:00:00 2001 From: Murithi Borona Date: Mon, 27 Apr 2020 15:43:54 +0300 Subject: [PATCH 195/675] huawei: updated HCSQ regex to match unquoted response --- plugins/huawei/mm-modem-helpers-huawei.c | 2 +- plugins/huawei/tests/test-modem-helpers-huawei.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c index c582dfbb..a1422be6 100644 --- a/plugins/huawei/mm-modem-helpers-huawei.c +++ b/plugins/huawei/mm-modem-helpers-huawei.c @@ -1353,7 +1353,7 @@ mm_huawei_parse_hcsq_response (const gchar *response, gboolean ret = FALSE; char *s; - r = g_regex_new ("\\^HCSQ:\\s*\"([a-zA-Z]*)\",(\\d+),?(\\d+)?,?(\\d+)?,?(\\d+)?,?(\\d+)?$", 0, 0, NULL); + r = g_regex_new ("\\^HCSQ:\\s*\"?([a-zA-Z]*)\"?,(\\d+),?(\\d+)?,?(\\d+)?,?(\\d+)?,?(\\d+)?$", 0, 0, NULL); g_assert (r != NULL); if (!g_regex_match_full (r, response, -1, 0, 0, &match_info, &match_error)) { diff --git a/plugins/huawei/tests/test-modem-helpers-huawei.c b/plugins/huawei/tests/test-modem-helpers-huawei.c index 1aa50c9e..45d48b03 100644 --- a/plugins/huawei/tests/test-modem-helpers-huawei.c +++ b/plugins/huawei/tests/test-modem-helpers-huawei.c @@ -1202,11 +1202,13 @@ typedef struct { } HcsqTest; static const HcsqTest hcsq_tests[] = { - { "^HCSQ:\"LTE\",30,19,66,0\r\n", TRUE, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 30, 19, 66, 0, 0 }, - { "^HCSQ: \"WCDMA\",30,30,58\r\n", TRUE, MM_MODEM_ACCESS_TECHNOLOGY_UMTS, 30, 30, 58, 0, 0 }, - { "^HCSQ: \"GSM\",36,255\r\n", TRUE, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 36, 255, 0, 0, 0 }, - { "^HCSQ: \"NOSERVICE\"\r\n", FALSE, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, 0, 0, 0, 0 }, - { NULL, FALSE, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, 0, 0, 0, 0 } + { "^HCSQ:\"LTE\",30,19,66,0\r\n", TRUE, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 30, 19, 66, 0, 0 }, + { "^HCSQ: \"WCDMA\",30,30,58\r\n", TRUE, MM_MODEM_ACCESS_TECHNOLOGY_UMTS, 30, 30, 58, 0, 0 }, + { "^HCSQ: \"GSM\",36,255\r\n", TRUE, MM_MODEM_ACCESS_TECHNOLOGY_GSM, 36, 255, 0, 0, 0 }, + { "^HCSQ: LTE,33,40,135,11\r\n", TRUE, MM_MODEM_ACCESS_TECHNOLOGY_LTE, 33, 40, 135, 11, 0 }, + { "^HCSQ: \"NOSERVICE\"\r\n", FALSE, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, 0, 0, 0, 0 }, + { "^HCSQ: NOSERVICE\r\n", FALSE, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, 0, 0, 0, 0 }, + { NULL, FALSE, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN, 0, 0, 0, 0, 0 } }; static void From dfc2c51b9cc7d9c780763d42c91bf696c2b8880a Mon Sep 17 00:00:00 2001 From: Eric Caruso Date: Fri, 1 May 2020 14:12:43 -0700 Subject: [PATCH 196/675] introspection: use correct node name for ModemManager1 object In the D-Bus specification it is stated that the root node of an introspection file should have an absolute path[1]. This path should not be the root path in D-Bus as putting objects there is considered incorrect, and also because the MM1 object does not actually sit at the root path (instead, it uses MM_DBUS_PATH, which is /org/freedesktop/ModemManager1). Fix this in the introspection file. [1] https://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format --- introspection/org.freedesktop.ModemManager1.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/introspection/org.freedesktop.ModemManager1.xml b/introspection/org.freedesktop.ModemManager1.xml index 85b62134..e9ec032d 100644 --- a/introspection/org.freedesktop.ModemManager1.xml +++ b/introspection/org.freedesktop.ModemManager1.xml @@ -9,7 +9,7 @@ Copyright (C) 2011-2013 Lanedo GmbH --> - + GPS chips blacklisted !!!!! foxconn -> 0x0489 -> None in blacklist/greylist broadmobi -> 0x2020 -> None in blacklist/greylist fibocom -> 0x2cb7 -> None in blacklist/greylist tplink -> 0x2357 -> None in blacklist/greylist zte -> 0x19d2 -> None in blacklist/greylist The rules used to blacklist the u-blox GPS chips have already been moved to the u-blox plugin itself, and now they use the broader ID_MM_DEVICE_IGNORE tag that applies in all filter modes. --- NEWS | 4 ++++ src/mm-filter.c | 37 +++++++++++++++++++++++++++++++++++++ src/mm-filter.h | 2 ++ src/mm-plugin-manager.c | 18 +++++++++++++++++- src/mm-plugin.c | 6 ++++++ src/mm-plugin.h | 1 + 6 files changed, 67 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 8545a277..b3ea5f1b 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,10 @@ The most important features and changes in this release are the following: port probing mechanism uses its own heuristics to guess whether a given TTY is owned by a modem or not. + * Added a new implicit whitelist rules applicable in 'STRICT' filter mode, so + that all devices with a USB vid matching one of the vids allowed by the + different installed plugins are implicitly allowed. + * Updated daemon logging so that we always prefix the messages with a string identifying which modem the log refers to, making it easy to grep logs for one specific device if the system has more than one. diff --git a/src/mm-filter.c b/src/mm-filter.c index cfa620b4..18ea08f6 100644 --- a/src/mm-filter.c +++ b/src/mm-filter.c @@ -39,6 +39,7 @@ enum { struct _MMFilterPrivate { MMFilterRule enabled_rules; GList *plugin_whitelist_tags; + GArray *plugin_whitelist_vendor_ids; GArray *plugin_whitelist_product_ids; }; @@ -54,6 +55,27 @@ mm_filter_register_plugin_whitelist_tag (MMFilter *self, } } +void +mm_filter_register_plugin_whitelist_vendor_id (MMFilter *self, + guint16 vid) +{ + guint i; + + if (!self->priv->plugin_whitelist_vendor_ids) + self->priv->plugin_whitelist_vendor_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint16), 64); + + for (i = 0; i < self->priv->plugin_whitelist_vendor_ids->len; i++) { + guint16 item; + + item = g_array_index (self->priv->plugin_whitelist_vendor_ids, guint16, i); + if (item == vid) + return; + } + + g_array_append_val (self->priv->plugin_whitelist_vendor_ids, vid); + mm_obj_dbg (self, "registered plugin whitelist vendor id: %04x", vid); +} + void mm_filter_register_plugin_whitelist_product_id (MMFilter *self, guint16 vid, @@ -140,6 +162,20 @@ mm_filter_port (MMFilter *self, } } } + + if (vid && self->priv->plugin_whitelist_vendor_ids) { + guint i; + + for (i = 0; i < self->priv->plugin_whitelist_vendor_ids->len; i++) { + guint16 item; + + item = g_array_index (self->priv->plugin_whitelist_vendor_ids, guint16, i); + if (item == vid) { + mm_obj_dbg (self, "(%s/%s) port allowed: device is whitelisted by plugin (vid)", subsystem, name); + return TRUE; + } + } + } } /* If this is a virtual device, don't allow it */ @@ -483,6 +519,7 @@ finalize (GObject *object) { MMFilter *self = MM_FILTER (object); + g_clear_pointer (&self->priv->plugin_whitelist_vendor_ids, g_array_unref); g_clear_pointer (&self->priv->plugin_whitelist_product_ids, g_array_unref); g_list_free_full (self->priv->plugin_whitelist_tags, g_free); diff --git a/src/mm-filter.h b/src/mm-filter.h index b567edb1..c3579979 100644 --- a/src/mm-filter.h +++ b/src/mm-filter.h @@ -145,6 +145,8 @@ gboolean mm_filter_device_and_port (MMFilter *self, void mm_filter_register_plugin_whitelist_tag (MMFilter *self, const gchar *tag); +void mm_filter_register_plugin_whitelist_vendor_id (MMFilter *self, + guint16 vid); void mm_filter_register_plugin_whitelist_product_id (MMFilter *self, guint16 vid, guint16 pid); diff --git a/src/mm-plugin-manager.c b/src/mm-plugin-manager.c index 9ee4edae..e76c9a82 100644 --- a/src/mm-plugin-manager.c +++ b/src/mm-plugin-manager.c @@ -1616,6 +1616,21 @@ register_plugin_whitelist_tags (MMPluginManager *self, mm_filter_register_plugin_whitelist_tag (self->priv->filter, tags[i]); } +static void +register_plugin_whitelist_vendor_ids (MMPluginManager *self, + MMPlugin *plugin) +{ + const guint16 *vendor_ids; + guint i; + + if (!mm_filter_check_rule_enabled (self->priv->filter, MM_FILTER_RULE_PLUGIN_WHITELIST)) + return; + + vendor_ids = mm_plugin_get_allowed_vendor_ids (plugin); + for (i = 0; vendor_ids && vendor_ids[i]; i++) + mm_filter_register_plugin_whitelist_vendor_id (self->priv->filter, vendor_ids[i]); +} + static void register_plugin_whitelist_product_ids (MMPluginManager *self, MMPlugin *plugin) @@ -1812,7 +1827,8 @@ load_plugins (MMPluginManager *self, self->priv->plugins = g_list_append (self->priv->plugins, plugin); /* Register plugin whitelist rules in filter, if any */ - register_plugin_whitelist_tags (self, plugin); + register_plugin_whitelist_tags (self, plugin); + register_plugin_whitelist_vendor_ids (self, plugin); register_plugin_whitelist_product_ids (self, plugin); } diff --git a/src/mm-plugin.c b/src/mm-plugin.c index 4f3ec18d..adfe4bf2 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -152,6 +152,12 @@ mm_plugin_get_allowed_udev_tags (MMPlugin *self) return (const gchar **) self->priv->udev_tags; } +const guint16 * +mm_plugin_get_allowed_vendor_ids (MMPlugin *self) +{ + return self->priv->vendor_ids; +} + const mm_uint16_pair * mm_plugin_get_allowed_product_ids (MMPlugin *self) { diff --git a/src/mm-plugin.h b/src/mm-plugin.h index fe0469c1..f5863522 100644 --- a/src/mm-plugin.h +++ b/src/mm-plugin.h @@ -126,6 +126,7 @@ GType mm_plugin_get_type (void); const gchar *mm_plugin_get_name (MMPlugin *self); const gchar **mm_plugin_get_allowed_udev_tags (MMPlugin *self); +const guint16 *mm_plugin_get_allowed_vendor_ids (MMPlugin *self); const mm_uint16_pair *mm_plugin_get_allowed_product_ids (MMPlugin *self); gboolean mm_plugin_is_generic (MMPlugin *self); From cd501c4d2657e8273d928748056050fc5b696f7c Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 4 Jun 2020 11:38:48 +0200 Subject: [PATCH 261/675] NEWS: add details about the plugin configure options --- NEWS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NEWS b/NEWS index b3ea5f1b..1267bb10 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,14 @@ The following notes are directed to package maintainers: errors), --enable-compile-warnings=no (to disable all the extra warnings enabled by default) or --disable-Werror (to unconditionally make all compiler warnings non-fatal). + ** Users can now preselect which plugins to build and install during + configure, with the --enable-plugin-[PLUGIN-NAME] options. The user can + also build and install all except for some, just by using the + --enable-all-plugins option followed by --disable-plugin-[PLUGIN-NAME]. + By default all plugins are enabled, so all of them built and installed. + This new set of options are useful for users building custom systems + where they already know what kind of devices they're going to have, it + isn't recommended for standard distributions. The only updates in the public API are the following: From cbcc14110521fdb360a3028b1b15d59ffc74257e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 4 Jun 2020 09:48:10 +0200 Subject: [PATCH 262/675] build: bump version to 1.13.900 (1.14-rc1) --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 8555bccc..37c4d8d1 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ dnl m4_define([mm_major_version], [1]) m4_define([mm_minor_version], [13]) -m4_define([mm_micro_version], [0]) +m4_define([mm_micro_version], [900]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From 1e0b38d98aff792481f4635c524bbf669b0be5ad Mon Sep 17 00:00:00 2001 From: Maxim Anisimov Date: Fri, 5 Jun 2020 08:43:05 +0300 Subject: [PATCH 263/675] sms-part-3gpp: fix unicode names in sms decode iconv() operations So that the limited iconv() in OpenWRT supports the conversion properly. Signed-off-by: Maxim Anisimov --- src/mm-sms-part-3gpp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index 183d2868..c4f6154f 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -271,10 +271,10 @@ sms_decode_text (const guint8 *text, * in UCS-2BE. */ mm_obj_dbg (log_object, "converting SMS part text from UTF-16BE to UTF-8..."); - utf8 = g_convert ((const gchar *) text, len, "UTF8", "UTF16BE", NULL, NULL, NULL); + utf8 = g_convert ((const gchar *) text, len, "UTF-8", "UTF-16BE", NULL, NULL, NULL); if (!utf8) { - mm_obj_dbg (log_object, "converting SMS part text from UCS-2BE to UTF8..."); - utf8 = g_convert ((const gchar *) text, len, "UTF8", "UCS-2BE", NULL, NULL, NULL); + mm_obj_dbg (log_object, "converting SMS part text from UCS-2BE to UTF-8..."); + utf8 = g_convert ((const gchar *) text, len, "UTF-8", "UCS-2BE", NULL, NULL, NULL); } if (!utf8) { mm_obj_warn (log_object, "couldn't convert SMS part contents from UTF-16BE/UCS-2BE to UTF-8: not decoding any text"); From 62c6f941a2ea44b0f67fbb849c92335d78137b96 Mon Sep 17 00:00:00 2001 From: Maxim Anisimov Date: Fri, 5 Jun 2020 09:29:23 +0300 Subject: [PATCH 264/675] cli: make control chars in strings are escaped correctly for json output We need to change json output escaping according to this https://bugzilla.gnome.org/show_bug.cgi?id=730425 Signed-off-by: Maxim Anisimov --- cli/mmcli-output.c | 47 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c index 6799ab6d..1265856d 100644 --- a/cli/mmcli-output.c +++ b/cli/mmcli-output.c @@ -1087,6 +1087,49 @@ dump_output_list_keyvalue (MmcF field) /******************************************************************************/ /* JSON-friendly output */ +static gchar * +json_strescape (const gchar *str) +{ + const gchar *p; + const gchar *end; + GString *output; + gsize len; + + len = strlen (str); + end = str + len; + output = g_string_sized_new (len); + + for (p = str; p < end; p++) { + if (*p == '\\' || *p == '"') { + g_string_append_c (output, '\\'); + g_string_append_c (output, *p); + } else if ((*p > 0 && *p < 0x1f) || *p == 0x7f) { + switch (*p) { + case '\b': + g_string_append (output, "\\b"); + break; + case '\f': + g_string_append (output, "\\f"); + break; + case '\n': + g_string_append (output, "\\n"); + break; + case '\r': + g_string_append (output, "\\r"); + break; + case '\t': + g_string_append (output, "\\t"); + break; + default: + g_string_append_printf (output, "\\u00%02x", (guint)*p); + break; + } + } else + g_string_append_c (output, *p); + } + return g_string_free (output, FALSE); +} + static gint list_sort_by_keys (const OutputItem *item_a, const OutputItem *item_b) @@ -1146,7 +1189,7 @@ dump_output_json (void) gchar *escaped = NULL; if (single->value) - escaped = g_strescape (single->value, "\v"); + escaped = json_strescape (single->value); g_print ("\"%s\":\"%s\"", current_path[cur_dlen], escaped ? escaped : "--"); g_free (escaped); @@ -1160,7 +1203,7 @@ dump_output_json (void) for (i = 0; i < n; i++) { gchar *escaped; - escaped = g_strescape (multiple->values[i], "\v"); + escaped = json_strescape (multiple->values[i]); g_print("\"%s\"", escaped); if (i < n - 1) g_print(","); From 3af93cbe18709864a10c3efd752e7db44f41c18f Mon Sep 17 00:00:00 2001 From: Maxim Anisimov Date: Fri, 5 Jun 2020 08:57:48 +0300 Subject: [PATCH 265/675] broadband-modem-qmi: switch USSD state to idle when ussd session is terminated by network The cellular operator can break the interactive USSD session. In this case, it is necessary to process this situation otherwise --3gpp-ussd-initiate or --3gpp-ussd-respond will give an error. Signed-off-by: Maxim Anisimov --- src/mm-broadband-modem-qmi.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index ea52ea00..2926d2fb 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -128,6 +128,7 @@ struct _MMBroadbandModemQmiPrivate { /* 3GPP USSD helpers */ guint ussd_indication_id; + guint ussd_release_indication_id; gboolean ussd_unsolicited_events_enabled; gboolean ussd_unsolicited_events_setup; GTask *pending_ussd_action; @@ -7314,6 +7315,30 @@ ussd_indication_cb (QmiClientVoice *client, process_ussd_message (self, user_action, utf8, error); } +static void +ussd_release_indication_cb (QmiClientVoice *client, + MMBroadbandModemQmi *self) +{ + GTask *pending_task; + GError *error; + + mm_iface_modem_3gpp_ussd_update_state (MM_IFACE_MODEM_3GPP_USSD (self), + MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE); + + error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_ABORTED, "USSD terminated by network"); + + pending_task = g_steal_pointer (&self->priv->pending_ussd_action); + if (pending_task) { + g_task_return_error (pending_task, error); + g_object_unref (pending_task); + return; + } + + /* If no pending task, just report the error */ + mm_obj_dbg (self, "USSD release indication: %s", error->message); + g_error_free (error); +} + /*****************************************************************************/ /* Setup/cleanup unsolicited events */ @@ -7357,10 +7382,19 @@ common_3gpp_ussd_setup_cleanup_unsolicited_events (MMBroadbandModemQmi *self, "ussd", G_CALLBACK (ussd_indication_cb), self); + g_assert (self->priv->ussd_release_indication_id == 0); + self->priv->ussd_release_indication_id = + g_signal_connect (client, + "release-ussd", + G_CALLBACK (ussd_release_indication_cb), + self); } else { g_assert (self->priv->ussd_indication_id != 0); g_signal_handler_disconnect (client, self->priv->ussd_indication_id); self->priv->ussd_indication_id = 0; + g_assert (self->priv->ussd_release_indication_id != 0); + g_signal_handler_disconnect (client, self->priv->ussd_release_indication_id); + self->priv->ussd_release_indication_id = 0; } g_task_return_boolean (task, TRUE); From 8340237f9da911ca6ecc58fd6c453e9ea32616d4 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 12 Jun 2020 09:17:40 +0200 Subject: [PATCH 266/675] broadband-modem-qmi: avoid using stale EPS registration state When the device goes from LTE to UMTS, we must make sure we also always update the EPS registration state as unknown, or the built consolidated state will be wrong. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/225 --- src/mm-broadband-modem-qmi.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 2926d2fb..e6a05b2c 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -2766,11 +2766,18 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, g_free (new_operator_id); } - /* Report new registration states */ + /* Report new registration states. The QMI serving system API reports "CS" + * and "PS" registration states, and if the device is in LTE, we'll take the "PS" + * one as "EPS". But, if the device is not in LTE, we should also set the "EPS" + * state as unknown, so that the "PS" one takes precedence when building + * the consolidated registration state (otherwise we may be using some old cached + * "EPS" state wrongly). */ mm_iface_modem_3gpp_update_cs_registration_state (MM_IFACE_MODEM_3GPP (self), mm_cs_registration_state); mm_iface_modem_3gpp_update_ps_registration_state (MM_IFACE_MODEM_3GPP (self), mm_ps_registration_state); - if (mm_access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_LTE) - mm_iface_modem_3gpp_update_eps_registration_state (MM_IFACE_MODEM_3GPP (self), mm_ps_registration_state); + if (mm_iface_modem_is_3gpp_lte (MM_IFACE_MODEM (self))) + mm_iface_modem_3gpp_update_eps_registration_state (MM_IFACE_MODEM_3GPP (self), + (mm_access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_LTE) ? + mm_ps_registration_state : MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN); /* Get 3GPP location LAC/TAC and CI */ lac = 0; From 569990f38cc241b0309ec7d8c92a7b2de3e89005 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 12 Jun 2020 09:25:09 +0200 Subject: [PATCH 267/675] broadband-modem-qmi: also build 5GS reg state from Serving System --- src/mm-broadband-modem-qmi.c | 6 ++++++ src/mm-iface-modem.c | 6 ++++++ src/mm-iface-modem.h | 1 + 3 files changed, 13 insertions(+) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index e6a05b2c..357a3fae 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -2778,6 +2778,12 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, mm_iface_modem_3gpp_update_eps_registration_state (MM_IFACE_MODEM_3GPP (self), (mm_access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_LTE) ? mm_ps_registration_state : MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN); + /* Same thing for "5GS" state */ + if (mm_iface_modem_is_3gpp_5gnr (MM_IFACE_MODEM (self))) + mm_iface_modem_3gpp_update_5gs_registration_state (MM_IFACE_MODEM_3GPP (self), + (mm_access_technologies & MM_MODEM_ACCESS_TECHNOLOGY_5GNR) ? + mm_ps_registration_state : MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN); + /* Get 3GPP location LAC/TAC and CI */ lac = 0; diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 84104d46..48105afe 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -5573,6 +5573,12 @@ mm_iface_modem_is_3gpp_lte (MMIfaceModem *self) return (mm_iface_modem_get_current_capabilities (self) & MM_MODEM_CAPABILITY_LTE); } +gboolean +mm_iface_modem_is_3gpp_5gnr (MMIfaceModem *self) +{ + return (mm_iface_modem_get_current_capabilities (self) & MM_MODEM_CAPABILITY_5GNR); +} + gboolean mm_iface_modem_is_cdma (MMIfaceModem *self) { diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index 541d6f6b..2df3b59c 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -391,6 +391,7 @@ MMModemCapability mm_iface_modem_get_current_capabilities (MMIfaceModem *self); gboolean mm_iface_modem_is_3gpp (MMIfaceModem *self); gboolean mm_iface_modem_is_3gpp_only (MMIfaceModem *self); gboolean mm_iface_modem_is_3gpp_lte (MMIfaceModem *self); +gboolean mm_iface_modem_is_3gpp_5gnr (MMIfaceModem *self); gboolean mm_iface_modem_is_cdma (MMIfaceModem *self); gboolean mm_iface_modem_is_cdma_only (MMIfaceModem *self); From cb8d810583690ea2c011e66d36c1eeb346f83690 Mon Sep 17 00:00:00 2001 From: Brendan Peter Date: Mon, 15 Jun 2020 15:48:01 -0700 Subject: [PATCH 268/675] quectel: add port type hints for EG95 --- plugins/quectel/77-mm-quectel-port-types.rules | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/quectel/77-mm-quectel-port-types.rules b/plugins/quectel/77-mm-quectel-port-types.rules index 71138580..caa7b10e 100644 --- a/plugins/quectel/77-mm-quectel-port-types.rules +++ b/plugins/quectel/77-mm-quectel-port-types.rules @@ -27,6 +27,16 @@ ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0191", ENV{.MM_USBIFNUM}=="01", ENV{ ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0191", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0191", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +# Quectel EG95 +# ttyUSB0 (if #0): QCDM/DIAG port +# ttyUSB1 (if #1): GPS data port +# ttyUSB2 (if #2): AT primary port +# ttyUSB3 (if #3): AT secondary port +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0195", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_QCDM}="1" +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0195", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_PORT_TYPE_GPS}="1" +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0195", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0195", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" + # Quectel BG96 # ttyUSB0 (if #0): QCDM/DIAG port # ttyUSB1 (if #1): GPS data port From 12ea728112f562a572a5c0ecc7bba47bb529d41c Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 16 Jun 2020 09:41:14 +0200 Subject: [PATCH 269/675] AUTHORS: update with latest commit stats --- AUTHORS | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index 06aeb98d..a7b93cd3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,13 +17,16 @@ Other contributors: Riccardo Vangelisti Alexander Sack Guido Günther + Eric Caruso Eric Shienbrood Elly Jones - Eric Caruso + Bob Ham + Giacinto Cifelli David McCullough Prathmesh Prabhu Thieu Le Thomas Tuttle + Maxim Anisimov Bjørn Mork Marius B. Kotsbak Michael Biebl @@ -33,7 +36,6 @@ Other contributors: Christian Persch Sven Schwermer Thomas Sailer - Bob Ham Colin Walters Franko Fang Jakub Sitnicki @@ -49,6 +51,7 @@ Other contributors: Martyn Russell Thomas Haller Tomas Jura + Amol Lad Colin Helliwell Graham Inggs Javier Viguera @@ -56,15 +59,17 @@ Other contributors: Maksim Salau Martin Pitt Matthew Stanger - Maxim Anisimov + Milo Casagrande Nick Stevens Norbert Frese Piotr Drąg Thomas Bechtold Yegor Yefremov + Yuri Chornoivan Adrian Bunk Alexander Couzens Amit Mendapara + Andika Triwidada Andrew Bird Anton Blanchard Arnd Hannemann @@ -72,6 +77,7 @@ Other contributors: Arun Raghavan Baruch Siach Beniamino Galvani + Brendan Peter Brian Norris Brian, Sam Bryan Duff @@ -80,6 +86,7 @@ Other contributors: David Castellanos David Herrmann David Härdeman + David Khouya Dmitry Ivanyushin Enrico Mioso Eugene Crosser @@ -99,6 +106,7 @@ Other contributors: Krzysztof Kotlenga Lech Perczak LiuQiFeng + Louis-Alexis Eyraud Luis A. Lozano M. I. Spozta Marc Murphy @@ -107,18 +115,20 @@ Other contributors: Mark-Jablonsky Michael Farrell Michał Sroczyński - Milo Casagrande Mohammed Sadiq Moo + Murithi Borona Nathan J. Williams Noel J. Bergman Oskar Enoksson Piotr Figiel Quentin.Li + Rafael Fontenelle Roshan Pius Sam Spilsbury Sławomir Bocheński Tabor Kelly + Teijo Kinnunen Thomas Grenman Thomas Voß Ting-Yuan Huang @@ -131,10 +141,13 @@ Other contributors: Ville Skyttä Vincent Untz Vitaly Gimly - Yuri Chornoivan Amol Lad + emintufan kuonirat + mozzwald + mstanger poma scootergrisen wi24rd yparitcher + Артемий Судаков From 9d31cbaa2dc2efb77d174134156b612072d6bf0b Mon Sep 17 00:00:00 2001 From: Eric Caruso Date: Wed, 17 Jun 2020 16:19:07 -0700 Subject: [PATCH 270/675] mm-kernel-device: give cmp a total order This allows MMKernelDevice::cmp to compare two kernel devices with different object types, which means that subclasses can continue to only handle comparisons with their own type. The order may not be stable across builds. --- src/kerneldevice/mm-kernel-device.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kerneldevice/mm-kernel-device.c b/src/kerneldevice/mm-kernel-device.c index abe0ddd0..fa865394 100644 --- a/src/kerneldevice/mm-kernel-device.c +++ b/src/kerneldevice/mm-kernel-device.c @@ -203,6 +203,9 @@ mm_kernel_device_cmp (MMKernelDevice *a, g_return_val_if_fail (MM_IS_KERNEL_DEVICE (a), FALSE); g_return_val_if_fail (MM_IS_KERNEL_DEVICE (b), FALSE); + if (G_OBJECT_TYPE (a) != G_OBJECT_TYPE (b)) + return G_OBJECT_TYPE (a) < G_OBJECT_TYPE (b); + return (MM_KERNEL_DEVICE_GET_CLASS (a)->cmp ? MM_KERNEL_DEVICE_GET_CLASS (a)->cmp (a, b) : FALSE); From 54de41928b73b2c7fdfe5b4c791625f6973510f0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 18 Jun 2020 10:58:14 +0200 Subject: [PATCH 271/675] build: require libmbim 1.24.0 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 37c4d8d1..2ae4cb69 100644 --- a/configure.ac +++ b/configure.ac @@ -370,7 +370,7 @@ dnl----------------------------------------------------------------------------- dnl MBIM support (enabled by default) dnl -LIBMBIM_VERSION=1.23.900 +LIBMBIM_VERSION=1.24.0 AC_ARG_WITH(mbim, AS_HELP_STRING([--without-mbim], [Build without MBIM support]), [], [with_mbim=yes]) AM_CONDITIONAL(WITH_MBIM, test "x$with_mbim" = "xyes") From c2ee73173e77b57108e52a09bfecadef19ae13a8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 17 Jun 2020 14:26:58 +0200 Subject: [PATCH 272/675] cinterion: allow MBIM-powered devices Like the mPLS62-w when setup to be controlled in MBIM mode instead of plain AT commands. --- plugins/cinterion/mm-plugin-cinterion.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/cinterion/mm-plugin-cinterion.c b/plugins/cinterion/mm-plugin-cinterion.c index 5fdd48b5..f2eb5d73 100644 --- a/plugins/cinterion/mm-plugin-cinterion.c +++ b/plugins/cinterion/mm-plugin-cinterion.c @@ -35,6 +35,10 @@ #include "mm-broadband-modem-qmi-cinterion.h" #endif +#if defined WITH_MBIM +#include "mm-broadband-modem-mbim.h" +#endif + G_DEFINE_TYPE (MMPluginCinterion, mm_plugin_cinterion, MM_TYPE_PLUGIN) MM_PLUGIN_DEFINE_MAJOR_VERSION @@ -124,6 +128,17 @@ create_modem (MMPlugin *self, } #endif +#if defined WITH_MBIM + if (mm_port_probe_list_has_mbim_port (probes)) { + mm_obj_dbg (self, "MBIM-powered Cinterion modem found..."); + return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); + } +#endif + return MM_BASE_MODEM (mm_broadband_modem_cinterion_new (uid, drivers, mm_plugin_get_name (self), @@ -182,6 +197,7 @@ mm_plugin_create (void) MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, MM_PLUGIN_ALLOWED_QMI, TRUE, + MM_PLUGIN_ALLOWED_MBIM, TRUE, MM_PLUGIN_CUSTOM_INIT, &custom_init, NULL)); } From ecf54efc671b8c05e6354470e6ed8f496985d3a9 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 17 Jun 2020 14:53:45 +0200 Subject: [PATCH 273/675] cinterion: added port type hints for the mPLS62-w in MBIM mode T: Bus=01 Lev=02 Prnt=04 Port=01 Cnt=01 Dev#= 40 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=1e2d ProdID=005d Rev=17.30 S: Manufacturer=Cinterion Wireless Modules S: Product=PLSx C: #Ifs=12 Cfg#= 1 Atr=e0 MxPwr=100mA I: If#=0x0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=01 Driver=cdc_acm I: If#=0x1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm I: If#=0xa Alt= 1 #EPs= 1 Cls=02(commc) Sub=0e Prot=00 Driver=cdc_mbim I: If#=0xb Alt= 2 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim I: If#=0x2 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=00 Driver=cdc_acm I: If#=0x3 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm I: If#=0x4 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=00 Driver=cdc_acm I: If#=0x5 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm I: If#=0x6 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=00 Driver=cdc_acm I: If#=0x7 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm I: If#=0x8 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=00 Driver=cdc_acm I: If#=0x9 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm --- plugins/cinterion/77-mm-cinterion-port-types.rules | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/cinterion/77-mm-cinterion-port-types.rules b/plugins/cinterion/77-mm-cinterion-port-types.rules index 4883f764..f5ceee3a 100644 --- a/plugins/cinterion/77-mm-cinterion-port-types.rules +++ b/plugins/cinterion/77-mm-cinterion-port-types.rules @@ -32,4 +32,16 @@ ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="04", ENV{ ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1" +# PLS62 family mbim enumeration +# ttyACM0 (if #0): AT port +# ttyACM1 (if #2): AT port +# ttyACM2 (if #4): AT port +# ttyACM3 (if #6): unknown +# ttyACM4 (if #8): unknown +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1" + LABEL="mm_cinterion_port_types_end" From 57422ec0bb6403bd17efab174f1d9b67079a5b1e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 19 Jun 2020 14:27:27 +0200 Subject: [PATCH 274/675] NEWS: add info about MBIM-powered Cinterion devices --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 1267bb10..a57854ba 100644 --- a/NEWS +++ b/NEWS @@ -126,6 +126,7 @@ The most important features and changes in this release are the following: ** cinterion: skip sim ready check for modules that don't support it. ** cinterion: implemented radio/band handling for LTE modems. ** cinterion: added Signal interface support bsaed on AT^SMONI. + ** cinterion: added support for MBIM based devices like the PLS62-W. ** quectel: updated to detect SIM hot swap via +QUSIM URCs. ** fibocom: added support for QMI based devices like the FM150. ** ublox: ignore error when disconnecting last LTE bearer. From 5cbeeb1b99939f9bc6faea1c29e99bc1f274d077 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 20 Jun 2020 12:05:18 +0200 Subject: [PATCH 275/675] build: require libqmi 1.26.0 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 2ae4cb69..37789f7d 100644 --- a/configure.ac +++ b/configure.ac @@ -394,7 +394,7 @@ dnl----------------------------------------------------------------------------- dnl QMI support (enabled by default) dnl -LIBQMI_VERSION=1.25.900 +LIBQMI_VERSION=1.26.0 AC_ARG_WITH(qmi, AS_HELP_STRING([--without-qmi], [Build without QMI support]), [], [with_qmi=yes]) AM_CONDITIONAL(WITH_QMI, test "x$with_qmi" = "xyes") From fbf38753441ee6eb9635a0f7b24e7a1b3ac818c3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 22 Jun 2020 09:30:09 +0200 Subject: [PATCH 276/675] blacklist: add chinese clone of Arduino nano Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/228 --- src/77-mm-usb-device-blacklist.rules | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/77-mm-usb-device-blacklist.rules b/src/77-mm-usb-device-blacklist.rules index 4674816f..6ad4f87c 100644 --- a/src/77-mm-usb-device-blacklist.rules +++ b/src/77-mm-usb-device-blacklist.rules @@ -81,6 +81,9 @@ ATTRS{idVendor}=="2a03", ENV{ID_MM_TTY_BLACKLIST}="1" ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="9207", ENV{ID_MM_TTY_BLACKLIST}="1" ATTRS{idVendor}=="1b4f", ATTRS{idProduct}=="9208", ENV{ID_MM_TTY_BLACKLIST}="1" +# Chinese clone of Arduino nano with a LGT8F328P MCU +ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="b534", ENV{ID_MM_TTY_BLACKLIST}="1" + # Adafruit Flora ATTRS{idVendor}=="239a", ATTRS{idProduct}=="0004", ENV{ID_MM_TTY_BLACKLIST}="1" ATTRS{idVendor}=="239a", ATTRS{idProduct}=="8004", ENV{ID_MM_TTY_BLACKLIST}="1" From 71d65bbe7e98248c21c4c35f4ec4210264ba745a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 22 Jun 2020 14:10:28 +0200 Subject: [PATCH 277/675] u-blox: always ignore M8 and M9 GPS modules --- plugins/ublox/77-mm-ublox-port-types.rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/ublox/77-mm-ublox-port-types.rules b/plugins/ublox/77-mm-ublox-port-types.rules index c07de334..c2a1ac99 100644 --- a/plugins/ublox/77-mm-ublox-port-types.rules +++ b/plugins/ublox/77-mm-ublox-port-types.rules @@ -11,6 +11,8 @@ SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInte ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a5", ENV{ID_MM_DEVICE_IGNORE}="1" ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a6", ENV{ID_MM_DEVICE_IGNORE}="1" ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a7", ENV{ID_MM_DEVICE_IGNORE}="1" +ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a8", ENV{ID_MM_DEVICE_IGNORE}="1" +ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a9", ENV{ID_MM_DEVICE_IGNORE}="1" # Toby-L4 port types # ttyACM0 (if #2): secondary (ignore) From 5f20662aeb9b0f79865a9a9df151349a29b4a2bd Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 23 Jun 2020 14:06:03 +0200 Subject: [PATCH 278/675] release: bump version to 1.14.0 --- configure.ac | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 37789f7d..0d5033e5 100644 --- a/configure.ac +++ b/configure.ac @@ -5,8 +5,8 @@ dnl Package and library versioning support dnl m4_define([mm_major_version], [1]) -m4_define([mm_minor_version], [13]) -m4_define([mm_micro_version], [900]) +m4_define([mm_minor_version], [14]) +m4_define([mm_micro_version], [0]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) @@ -18,9 +18,9 @@ dnl If the interface has grown (that is, the new library is compatible dnl with old code), increment a. dnl If the interface has changed in an incompatible way (that is, dnl functions have changed or been removed), then zero a. -m4_define([mm_glib_lt_current], [5]) +m4_define([mm_glib_lt_current], [6]) m4_define([mm_glib_lt_revision], [0]) -m4_define([mm_glib_lt_age], [5]) +m4_define([mm_glib_lt_age], [6]) dnl----------------------------------------------------------------------------- dnl autoconf, automake, libtool initialization From 62956b5c7a1bcfa143e6f5915562c55c4923eec4 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 23 Jun 2020 14:22:39 +0200 Subject: [PATCH 279/675] build: post-release version bump to 1.15.0 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 0d5033e5..3495cee5 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ dnl Package and library versioning support dnl m4_define([mm_major_version], [1]) -m4_define([mm_minor_version], [14]) +m4_define([mm_minor_version], [15]) m4_define([mm_micro_version], [0]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From c6d213d6523a70aa8504bda4dbd1796a0b1cd4c7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 11 Jun 2020 14:41:44 +0200 Subject: [PATCH 280/675] broadband-modem-qmi,bearer-qmi: avoid depending on the client version The QMI client version is an information provided by the QMI protocol only when QMUX or MBIM backends are used, it won't be available when e.g. QRTR is used. The logic in ModemManager should not rely on this information. --- src/mm-bearer-qmi.c | 39 +-- src/mm-broadband-modem-qmi.c | 542 ++++++++++++++--------------------- 2 files changed, 230 insertions(+), 351 deletions(-) diff --git a/src/mm-bearer-qmi.c b/src/mm-bearer-qmi.c index 7a6c2941..1afb6c25 100644 --- a/src/mm-bearer-qmi.c +++ b/src/mm-bearer-qmi.c @@ -1372,8 +1372,7 @@ connect_context_step (GTask *task) case CONNECT_STEP_IP_FAMILY_IPV4: /* If client is new enough, select IP family */ - if (!ctx->no_ip_family_preference && - qmi_client_check_version (QMI_CLIENT (ctx->client_ipv4), 1, 9)) { + if (!ctx->no_ip_family_preference) { QmiMessageWdsSetIpFamilyInput *input; mm_obj_dbg (self, "setting default IP family to: IPv4"); @@ -1467,31 +1466,23 @@ connect_context_step (GTask *task) ctx->step++; } /* fall through */ - case CONNECT_STEP_IP_FAMILY_IPV6: + case CONNECT_STEP_IP_FAMILY_IPV6: { + QmiMessageWdsSetIpFamilyInput *input; g_assert (ctx->no_ip_family_preference == FALSE); - /* If client is new enough, select IP family */ - if (qmi_client_check_version (QMI_CLIENT (ctx->client_ipv6), 1, 9)) { - QmiMessageWdsSetIpFamilyInput *input; - - mm_obj_dbg (self, "setting default IP family to: IPv6"); - input = qmi_message_wds_set_ip_family_input_new (); - qmi_message_wds_set_ip_family_input_set_preference (input, QMI_WDS_IP_FAMILY_IPV6, NULL); - qmi_client_wds_set_ip_family (ctx->client_ipv6, - input, - 10, - g_task_get_cancellable (task), - (GAsyncReadyCallback)set_ip_family_ready, - task); - qmi_message_wds_set_ip_family_input_unref (input); - return; - } - - ctx->default_ip_family_set = FALSE; - - ctx->step++; - /* fall through */ + mm_obj_dbg (self, "setting default IP family to: IPv6"); + input = qmi_message_wds_set_ip_family_input_new (); + qmi_message_wds_set_ip_family_input_set_preference (input, QMI_WDS_IP_FAMILY_IPV6, NULL); + qmi_client_wds_set_ip_family (ctx->client_ipv6, + input, + 10, + g_task_get_cancellable (task), + (GAsyncReadyCallback)set_ip_family_ready, + task); + qmi_message_wds_set_ip_family_input_unref (input); + return; + } case CONNECT_STEP_ENABLE_INDICATIONS_IPV6: common_setup_cleanup_packet_service_status_unsolicited_events (ctx->self, diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 357a3fae..6125cd4f 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -1715,24 +1715,20 @@ load_signal_quality (MMIfaceModem *self, mm_obj_dbg (self, "loading signal quality..."); #if defined WITH_NEWEST_QMI_COMMANDS - /* Signal info introduced in NAS 1.8 */ - if (qmi_client_check_version (client, 1, 8)) { - qmi_client_nas_get_signal_info (QMI_CLIENT_NAS (client), - NULL, - 10, - NULL, - (GAsyncReadyCallback)get_signal_info_ready, - task); - return; - } -#endif /* WITH_NEWEST_QMI_COMMANDS */ - + qmi_client_nas_get_signal_info (QMI_CLIENT_NAS (client), + NULL, + 10, + NULL, + (GAsyncReadyCallback)get_signal_info_ready, + task); +#else qmi_client_nas_get_signal_strength (QMI_CLIENT_NAS (client), NULL, 10, NULL, (GAsyncReadyCallback)get_signal_strength_ready, task); +#endif /* WITH_NEWEST_QMI_COMMANDS */ } /*****************************************************************************/ @@ -3373,24 +3369,20 @@ modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, task = g_task_new (self, NULL, callback, user_data); #if defined WITH_NEWEST_QMI_COMMANDS - /* System Info was added in NAS 1.8 */ - if (qmi_client_check_version (client, 1, 8)) { - qmi_client_nas_get_system_info (QMI_CLIENT_NAS (client), - NULL, - 10, - NULL, - (GAsyncReadyCallback)get_system_info_ready, - task); - return; - } -#endif /* WITH_NEWEST_QMI_COMMANDS */ - + qmi_client_nas_get_system_info (QMI_CLIENT_NAS (client), + NULL, + 10, + NULL, + (GAsyncReadyCallback)get_system_info_ready, + task); +#else qmi_client_nas_get_serving_system (QMI_CLIENT_NAS (client), NULL, 10, NULL, (GAsyncReadyCallback)get_serving_system_3gpp_ready, task); +#endif /* WITH_NEWEST_QMI_COMMANDS */ } /*****************************************************************************/ @@ -3429,9 +3421,9 @@ unsolicited_registration_events_task_new (MMBroadbandModemQmi *self, } static gboolean -modem_3gpp_enable_disable_unsolicited_registration_events_finish (MMIfaceModem3gpp *self, - GAsyncResult *res, - GError **error) +modem_3gpp_enable_disable_unsolicited_registration_events_finish (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } @@ -3439,28 +3431,28 @@ modem_3gpp_enable_disable_unsolicited_registration_events_finish (MMIfaceModem3g static void ri_serving_system_or_system_info_ready (QmiClientNas *client, GAsyncResult *res, - GTask *task) + GTask *task) { - MMBroadbandModemQmi *self; - UnsolicitedRegistrationEventsContext *ctx; - QmiMessageNasRegisterIndicationsOutput *output = NULL; - GError *error = NULL; + MMBroadbandModemQmi *self; + UnsolicitedRegistrationEventsContext *ctx; + g_autoptr(QmiMessageNasRegisterIndicationsOutput) output = NULL; + g_autoptr(GError) error = NULL; self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); + ctx = g_task_get_task_data (task); output = qmi_client_nas_register_indications_finish (client, res, &error); - if (!output) { - mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); - g_error_free (error); - } else if (!qmi_message_nas_register_indications_output_get_result (output, &error)) { + if (!output || !qmi_message_nas_register_indications_output_get_result (output, &error)) { mm_obj_dbg (self, "couldn't register indications: '%s'", error->message); - g_error_free (error); + if (ctx->enable) { +#if defined WITH_NEWEST_QMI_COMMANDS + mm_obj_dbg (self, "assuming system info indications are always enabled"); +#else + mm_obj_dbg (self, "assuming serving system indications are always enabled"); +#endif + } } - if (output) - qmi_message_nas_register_indications_output_unref (output); - /* Just ignore errors for now */ self->priv->unsolicited_registration_events_enabled = ctx->enable; g_task_return_boolean (task, TRUE); @@ -3470,8 +3462,8 @@ ri_serving_system_or_system_info_ready (QmiClientNas *client, static void common_enable_disable_unsolicited_registration_events_serving_system (GTask *task) { - UnsolicitedRegistrationEventsContext *ctx; - QmiMessageNasRegisterIndicationsInput *input; + UnsolicitedRegistrationEventsContext *ctx; + g_autoptr(QmiMessageNasRegisterIndicationsInput) input = NULL; ctx = g_task_get_task_data (task); input = qmi_message_nas_register_indications_input_new (); @@ -3483,15 +3475,14 @@ common_enable_disable_unsolicited_registration_events_serving_system (GTask *tas NULL, (GAsyncReadyCallback)ri_serving_system_or_system_info_ready, task); - qmi_message_nas_register_indications_input_unref (input); } #if defined WITH_NEWEST_QMI_COMMANDS static void common_enable_disable_unsolicited_registration_events_system_info (GTask *task) { - UnsolicitedRegistrationEventsContext *ctx; - QmiMessageNasRegisterIndicationsInput *input; + UnsolicitedRegistrationEventsContext *ctx; + g_autoptr(QmiMessageNasRegisterIndicationsInput) input = NULL; ctx = g_task_get_task_data (task); input = qmi_message_nas_register_indications_input_new (); @@ -3503,20 +3494,18 @@ common_enable_disable_unsolicited_registration_events_system_info (GTask *task) NULL, (GAsyncReadyCallback)ri_serving_system_or_system_info_ready, task); - qmi_message_nas_register_indications_input_unref (input); } #endif /* WITH_NEWEST_QMI_COMMANDS */ static void -modem_3gpp_disable_unsolicited_registration_events (MMIfaceModem3gpp *_self, - gboolean cs_supported, - gboolean ps_supported, - gboolean eps_supported, - GAsyncReadyCallback callback, - gpointer user_data) +modem_3gpp_disable_unsolicited_registration_events (MMIfaceModem3gpp *self, + gboolean cs_supported, + gboolean ps_supported, + gboolean eps_supported, + GAsyncReadyCallback callback, + gpointer user_data) { - MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); - GTask *task; + GTask *task; QmiClient *client = NULL; if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), @@ -3524,46 +3513,28 @@ modem_3gpp_disable_unsolicited_registration_events (MMIfaceModem3gpp *_self, callback, user_data)) return; - task = unsolicited_registration_events_task_new (self, + task = unsolicited_registration_events_task_new (MM_BROADBAND_MODEM_QMI (self), client, FALSE, callback, user_data); #if defined WITH_NEWEST_QMI_COMMANDS - /* System Info was added in NAS 1.8 */ - if (qmi_client_check_version (client, 1, 8)) { - common_enable_disable_unsolicited_registration_events_system_info (task); - return; - } + common_enable_disable_unsolicited_registration_events_system_info (task); +#else + common_enable_disable_unsolicited_registration_events_serving_system (task); #endif /* WITH_NEWEST_QMI_COMMANDS */ - - /* Ability to explicitly enable/disable serving system indications was - * added in NAS 1.2 */ - if (qmi_client_check_version (client, 1, 2)) { - common_enable_disable_unsolicited_registration_events_serving_system (task); - return; - } - - /* Devices with NAS < 1.2 will just always issue serving system indications */ - self->priv->unsolicited_registration_events_enabled = FALSE; - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Device doesn't allow disabling registration events"); - g_object_unref (task); } static void -modem_3gpp_enable_unsolicited_registration_events (MMIfaceModem3gpp *_self, - gboolean cs_supported, - gboolean ps_supported, - gboolean eps_supported, - GAsyncReadyCallback callback, - gpointer user_data) +modem_3gpp_enable_unsolicited_registration_events (MMIfaceModem3gpp *self, + gboolean cs_supported, + gboolean ps_supported, + gboolean eps_supported, + GAsyncReadyCallback callback, + gpointer user_data) { - MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); - GTask *task; + GTask *task; QmiClient *client = NULL; if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), @@ -3571,24 +3542,17 @@ modem_3gpp_enable_unsolicited_registration_events (MMIfaceModem3gpp *_self, callback, user_data)) return; - task = unsolicited_registration_events_task_new (self, + task = unsolicited_registration_events_task_new (MM_BROADBAND_MODEM_QMI (self), client, TRUE, callback, user_data); - /* Ability to explicitly enable/disable serving system indications was - * added in NAS 1.2 */ - if (qmi_client_check_version (client, 1, 2)) { - common_enable_disable_unsolicited_registration_events_serving_system (task); - return; - } - - /* Devices with NAS < 1.2 will just always issue serving system indications */ - mm_obj_dbg (self, "assuming serving system indications are always enabled"); - self->priv->unsolicited_registration_events_enabled = TRUE; - g_task_return_boolean (task, TRUE); - g_object_unref (task); +#if defined WITH_NEWEST_QMI_COMMANDS + common_enable_disable_unsolicited_registration_events_system_info (task); +#else + common_enable_disable_unsolicited_registration_events_serving_system (task); +#endif /* WITH_NEWEST_QMI_COMMANDS */ } /*****************************************************************************/ @@ -4594,38 +4558,34 @@ common_setup_cleanup_unsolicited_registration_events (MMBroadbandModemQmi *self, self->priv->unsolicited_registration_events_setup = enable; #if defined WITH_NEWEST_QMI_COMMANDS - /* Signal info introduced in NAS 1.8 */ - if (qmi_client_check_version (client, 1, 8)) { - /* Connect/Disconnect "System Info" indications */ - if (enable) { - g_assert (self->priv->system_info_indication_id == 0); - self->priv->system_info_indication_id = - g_signal_connect (client, - "system-info", - G_CALLBACK (system_info_indication_cb), - self); - } else { - g_assert (self->priv->system_info_indication_id != 0); - g_signal_handler_disconnect (client, self->priv->system_info_indication_id); - self->priv->system_info_indication_id = 0; - } - } else -#endif /* WITH_NEWEST_QMI_COMMANDS */ - { - /* Connect/Disconnect "Serving System" indications */ - if (enable) { - g_assert (self->priv->serving_system_indication_id == 0); - self->priv->serving_system_indication_id = - g_signal_connect (client, - "serving-system", - G_CALLBACK (serving_system_indication_cb), - self); - } else { - g_assert (self->priv->serving_system_indication_id != 0); - g_signal_handler_disconnect (client, self->priv->serving_system_indication_id); - self->priv->serving_system_indication_id = 0; - } + /* Connect/Disconnect "System Info" indications */ + if (enable) { + g_assert (self->priv->system_info_indication_id == 0); + self->priv->system_info_indication_id = + g_signal_connect (client, + "system-info", + G_CALLBACK (system_info_indication_cb), + self); + } else { + g_assert (self->priv->system_info_indication_id != 0); + g_signal_handler_disconnect (client, self->priv->system_info_indication_id); + self->priv->system_info_indication_id = 0; } +#else + /* Connect/Disconnect "Serving System" indications */ + if (enable) { + g_assert (self->priv->serving_system_indication_id == 0); + self->priv->serving_system_indication_id = + g_signal_connect (client, + "serving-system", + G_CALLBACK (serving_system_indication_cb), + self); + } else { + g_assert (self->priv->serving_system_indication_id != 0); + g_signal_handler_disconnect (client, self->priv->serving_system_indication_id); + self->priv->serving_system_indication_id = 0; + } +#endif /* WITH_NEWEST_QMI_COMMANDS */ g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -4727,19 +4687,11 @@ modem_cdma_load_esn (MMIfaceModemCdma *_self, } /*****************************************************************************/ -/* Enabling/disabling unsolicited events (3GPP and CDMA interface) - * - * If NAS >= 1.8: - * - Config Signal Info (only when enabling) - * - Register Indications with Signal Info - * - * If NAS < 1.8: - * - Set Event Report with Signal Strength - */ +/* Enabling/disabling unsolicited events (3GPP and CDMA interface) */ typedef struct { QmiClientNas *client; - gboolean enable; + gboolean enable; } EnableUnsolicitedEventsContext; static void @@ -4750,9 +4702,9 @@ enable_unsolicited_events_context_free (EnableUnsolicitedEventsContext *ctx) } static gboolean -common_enable_disable_unsolicited_events_finish (MMBroadbandModemQmi *self, - GAsyncResult *res, - GError **error) +common_enable_disable_unsolicited_events_finish (MMBroadbandModemQmi *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } @@ -4760,27 +4712,19 @@ common_enable_disable_unsolicited_events_finish (MMBroadbandModemQmi *self, static void ser_signal_strength_ready (QmiClientNas *client, GAsyncResult *res, - GTask *task) + GTask *task) { - MMBroadbandModemQmi *self; - EnableUnsolicitedEventsContext *ctx; - QmiMessageNasSetEventReportOutput *output = NULL; - GError *error = NULL; + MMBroadbandModemQmi *self; + EnableUnsolicitedEventsContext *ctx; + g_autoptr(QmiMessageNasSetEventReportOutput) output = NULL; + g_autoptr(GError) error = NULL; self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); + ctx = g_task_get_task_data (task); output = qmi_client_nas_set_event_report_finish (client, res, &error); - if (!output) { - mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); - g_error_free (error); - } else if (!qmi_message_nas_set_event_report_output_get_result (output, &error)) { + if (!output || !qmi_message_nas_set_event_report_output_get_result (output, &error)) mm_obj_dbg (self, "couldn't set event report: '%s'", error->message); - g_error_free (error); - } - - if (output) - qmi_message_nas_set_event_report_output_unref (output); /* Just ignore errors for now */ self->priv->unsolicited_events_enabled = ctx->enable; @@ -4791,30 +4735,28 @@ ser_signal_strength_ready (QmiClientNas *client, static void common_enable_disable_unsolicited_events_signal_strength (GTask *task) { - EnableUnsolicitedEventsContext *ctx; - - /* The device doesn't really like to have many threshold values, so don't - * grow this array without checking first */ - static const gint8 thresholds_data[] = { -80, -40, 0, 40, 80 }; - QmiMessageNasSetEventReportInput *input; - GArray *thresholds; + EnableUnsolicitedEventsContext *ctx; + g_autoptr(QmiMessageNasSetEventReportInput) input = NULL; + g_autoptr(GArray) thresholds = NULL; ctx = g_task_get_task_data (task); - input = qmi_message_nas_set_event_report_input_new (); - - /* Prepare thresholds, separated 20 each */ - thresholds = g_array_sized_new (FALSE, FALSE, sizeof (gint8), G_N_ELEMENTS (thresholds_data)); /* Only set thresholds during enable */ - if (ctx->enable) + if (ctx->enable) { + /* The device doesn't really like to have many threshold values, so don't + * grow this array without checking first */ + static const gint8 thresholds_data[] = { -80, -40, 0, 40, 80 }; + + thresholds = g_array_sized_new (FALSE, FALSE, sizeof (gint8), G_N_ELEMENTS (thresholds_data)); g_array_append_vals (thresholds, thresholds_data, G_N_ELEMENTS (thresholds_data)); + } + input = qmi_message_nas_set_event_report_input_new (); qmi_message_nas_set_event_report_input_set_signal_strength_indicator ( input, ctx->enable, thresholds, NULL); - g_array_unref (thresholds); qmi_client_nas_set_event_report ( ctx->client, input, @@ -4822,7 +4764,6 @@ common_enable_disable_unsolicited_events_signal_strength (GTask *task) NULL, (GAsyncReadyCallback)ser_signal_strength_ready, task); - qmi_message_nas_set_event_report_input_unref (input); } #if defined WITH_NEWEST_QMI_COMMANDS @@ -4830,27 +4771,19 @@ common_enable_disable_unsolicited_events_signal_strength (GTask *task) static void ri_signal_info_ready (QmiClientNas *client, GAsyncResult *res, - GTask *task) + GTask *task) { - MMBroadbandModemQmi *self; - EnableUnsolicitedEventsContext *ctx; - QmiMessageNasRegisterIndicationsOutput *output = NULL; - GError *error = NULL; + MMBroadbandModemQmi *self; + EnableUnsolicitedEventsContext *ctx; + g_autoptr(QmiMessageNasRegisterIndicationsOutput) output = NULL; + g_autoptr(GError) error = NULL; self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); + ctx = g_task_get_task_data (task); output = qmi_client_nas_register_indications_finish (client, res, &error); - if (!output) { - mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); - g_error_free (error); - } else if (!qmi_message_nas_register_indications_output_get_result (output, &error)) { + if (!output || !qmi_message_nas_register_indications_output_get_result (output, &error)) mm_obj_dbg (self, "couldn't register indications: '%s'", error->message); - g_error_free (error); - } - - if (output) - qmi_message_nas_register_indications_output_unref (output); /* Just ignore errors for now */ self->priv->unsolicited_events_enabled = ctx->enable; @@ -4861,8 +4794,8 @@ ri_signal_info_ready (QmiClientNas *client, static void common_enable_disable_unsolicited_events_signal_info (GTask *task) { - EnableUnsolicitedEventsContext *ctx; - QmiMessageNasRegisterIndicationsInput *input; + EnableUnsolicitedEventsContext *ctx; + g_autoptr(QmiMessageNasRegisterIndicationsInput) input = NULL; ctx = g_task_get_task_data (task); input = qmi_message_nas_register_indications_input_new (); @@ -4874,28 +4807,19 @@ common_enable_disable_unsolicited_events_signal_info (GTask *task) NULL, (GAsyncReadyCallback)ri_signal_info_ready, task); - qmi_message_nas_register_indications_input_unref (input); } static void config_signal_info_ready (QmiClientNas *client, GAsyncResult *res, - GTask *task) + GTask *task) { - QmiMessageNasConfigSignalInfoOutput *output = NULL; - GError *error = NULL; + g_autoptr(QmiMessageNasConfigSignalInfoOutput) output = NULL; + g_autoptr(GError) error = NULL; output = qmi_client_nas_config_signal_info_finish (client, res, &error); - if (!output) { - mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); - g_error_free (error); - } else if (!qmi_message_nas_config_signal_info_output_get_result (output, &error)) { + if (!output || !qmi_message_nas_config_signal_info_output_get_result (output, &error)) mm_obj_dbg (self, "couldn't config signal info: '%s'", error->message); - g_error_free (error); - } - - if (output) - qmi_message_nas_config_signal_info_output_unref (output); /* Keep on */ common_enable_disable_unsolicited_events_signal_info (task); @@ -4904,12 +4828,8 @@ config_signal_info_ready (QmiClientNas *client, static void common_enable_disable_unsolicited_events_signal_info_config (GTask *task) { - EnableUnsolicitedEventsContext *ctx; - /* RSSI values go between -105 and -60 for 3GPP technologies, - * and from -105 to -90 in 3GPP2 technologies (approx). */ - static const gint8 thresholds_data[] = { -100, -97, -95, -92, -90, -85, -80, -75, -70, -65 }; - QmiMessageNasConfigSignalInfoInput *input; - GArray *thresholds; + EnableUnsolicitedEventsContext *ctx; + g_autoptr(QmiMessageNasConfigSignalInfoInput) input = NULL; ctx = g_task_get_task_data (task); @@ -4922,14 +4842,20 @@ common_enable_disable_unsolicited_events_signal_info_config (GTask *task) input = qmi_message_nas_config_signal_info_input_new (); /* Prepare thresholds, separated 20 each */ - thresholds = g_array_sized_new (FALSE, FALSE, sizeof (gint8), G_N_ELEMENTS (thresholds_data)); - g_array_append_vals (thresholds, thresholds_data, G_N_ELEMENTS (thresholds_data)); + { + /* RSSI values go between -105 and -60 for 3GPP technologies, + * and from -105 to -90 in 3GPP2 technologies (approx). */ + static const gint8 thresholds_data[] = { -100, -97, -95, -92, -90, -85, -80, -75, -70, -65 }; + g_autoptr(GArray) thresholds = NULL; + + thresholds = g_array_sized_new (FALSE, FALSE, sizeof (gint8), G_N_ELEMENTS (thresholds_data)); + g_array_append_vals (thresholds, thresholds_data, G_N_ELEMENTS (thresholds_data)); + qmi_message_nas_config_signal_info_input_set_rssi_threshold ( + input, + thresholds, + NULL); + } - qmi_message_nas_config_signal_info_input_set_rssi_threshold ( - input, - thresholds, - NULL); - g_array_unref (thresholds); qmi_client_nas_config_signal_info ( ctx->client, input, @@ -4937,20 +4863,19 @@ common_enable_disable_unsolicited_events_signal_info_config (GTask *task) NULL, (GAsyncReadyCallback)config_signal_info_ready, task); - qmi_message_nas_config_signal_info_input_unref (input); } #endif /* WITH_NEWEST_QMI_COMMANDS */ static void common_enable_disable_unsolicited_events (MMBroadbandModemQmi *self, - gboolean enable, - GAsyncReadyCallback callback, - gpointer user_data) + gboolean enable, + GAsyncReadyCallback callback, + gpointer user_data) { EnableUnsolicitedEventsContext *ctx; - GTask *task; - QmiClient *client = NULL; + GTask *task; + QmiClient *client = NULL; if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), QMI_SERVICE_NAS, &client, @@ -4973,14 +4898,10 @@ common_enable_disable_unsolicited_events (MMBroadbandModemQmi *self, g_task_set_task_data (task, ctx, (GDestroyNotify)enable_unsolicited_events_context_free); #if defined WITH_NEWEST_QMI_COMMANDS - /* Signal info introduced in NAS 1.8 */ - if (qmi_client_check_version (client, 1, 8)) { - common_enable_disable_unsolicited_events_signal_info_config (task); - return; - } -#endif /* WITH_NEWEST_QMI_COMMANDS */ - + common_enable_disable_unsolicited_events_signal_info_config (task); +#else common_enable_disable_unsolicited_events_signal_strength (task); +#endif /* WITH_NEWEST_QMI_COMMANDS */ } /*****************************************************************************/ @@ -5177,21 +5098,17 @@ common_setup_cleanup_unsolicited_events (MMBroadbandModemQmi *self, } #if defined WITH_NEWEST_QMI_COMMANDS - /* Connect/Disconnect "Signal Info" indications. - * Signal info introduced in NAS 1.8 */ - if (qmi_client_check_version (client, 1, 8)) { - if (enable) { - g_assert (self->priv->signal_info_indication_id == 0); - self->priv->signal_info_indication_id = - g_signal_connect (client, - "signal-info", - G_CALLBACK (signal_info_indication_cb), - self); - } else { - g_assert (self->priv->signal_info_indication_id != 0); - g_signal_handler_disconnect (client, self->priv->signal_info_indication_id); - self->priv->signal_info_indication_id = 0; - } + if (enable) { + g_assert (self->priv->signal_info_indication_id == 0); + self->priv->signal_info_indication_id = + g_signal_connect (client, + "signal-info", + G_CALLBACK (signal_info_indication_cb), + self); + } else { + g_assert (self->priv->signal_info_indication_id != 0); + g_signal_handler_disconnect (client, self->priv->signal_info_indication_id); + self->priv->signal_info_indication_id = 0; } #endif /* WITH_NEWEST_QMI_COMMANDS */ @@ -8549,32 +8466,25 @@ typedef struct { } SignalLoadValuesResult; typedef struct { - QmiClientNas *client; - SignalLoadValuesStep step; + QmiClientNas *client; + SignalLoadValuesStep step; SignalLoadValuesResult *values_result; } SignalLoadValuesContext; static void signal_load_values_result_free (SignalLoadValuesResult *result) { - if (result->cdma) - g_object_unref (result->cdma); - if (result->evdo) - g_object_unref (result->evdo); - if (result->gsm) - g_object_unref (result->gsm); - if (result->umts) - g_object_unref (result->umts); - if (result->lte) - g_object_unref (result->lte); + g_clear_object (&result->cdma); + g_clear_object (&result->evdo); + g_clear_object (&result->gsm); + g_clear_object (&result->lte); g_slice_free (SignalLoadValuesResult, result); } static void signal_load_values_context_free (SignalLoadValuesContext *ctx) { - if (ctx->values_result) - signal_load_values_result_free (ctx->values_result); + g_clear_pointer (&ctx->values_result, (GDestroyNotify)signal_load_values_result_free); g_slice_free (SignalLoadValuesContext, ctx); } @@ -8599,14 +8509,14 @@ get_db_from_sinr_level (MMBroadbandModemQmi *self, } static gboolean -signal_load_values_finish (MMIfaceModemSignal *self, - GAsyncResult *res, - MMSignal **cdma, - MMSignal **evdo, - MMSignal **gsm, - MMSignal **umts, - MMSignal **lte, - GError **error) +signal_load_values_finish (MMIfaceModemSignal *self, + GAsyncResult *res, + MMSignal **cdma, + MMSignal **evdo, + MMSignal **gsm, + MMSignal **umts, + MMSignal **lte, + GError **error) { SignalLoadValuesResult *values_result; @@ -8628,28 +8538,26 @@ static void signal_load_values_context_step (GTask *task); static void signal_load_values_get_signal_strength_ready (QmiClientNas *client, GAsyncResult *res, - GTask *task) -{ - MMBroadbandModemQmi *self; - SignalLoadValuesContext *ctx; - QmiMessageNasGetSignalStrengthOutput *output; - GArray *array; - gint32 aux_int32; - gint16 aux_int16; - gint8 aux_int8; - QmiNasRadioInterface radio_interface; - QmiNasEvdoSinrLevel sinr; + GTask *task) +{ + MMBroadbandModemQmi *self; + SignalLoadValuesContext *ctx; + GArray *array; + gint32 aux_int32; + gint16 aux_int16; + gint8 aux_int8; + QmiNasRadioInterface radio_interface; + QmiNasEvdoSinrLevel sinr; + g_autoptr(QmiMessageNasGetSignalStrengthOutput) output = NULL; self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); + ctx = g_task_get_task_data (task); output = qmi_client_nas_get_signal_strength_finish (client, res, NULL); if (!output || !qmi_message_nas_get_signal_strength_output_get_result (output, NULL)) { /* No hard errors, go on to next step */ ctx->step++; signal_load_values_context_step (task); - if (output) - qmi_message_nas_get_signal_strength_output_unref (output); return; } @@ -8775,8 +8683,6 @@ signal_load_values_get_signal_strength_ready (QmiClientNas *client, mm_signal_set_sinr (ctx->values_result->evdo, get_db_from_sinr_level (self, sinr)); } - qmi_message_nas_get_signal_strength_output_unref (output); - /* Go on */ ctx->step++; signal_load_values_context_step (task); @@ -8785,29 +8691,27 @@ signal_load_values_get_signal_strength_ready (QmiClientNas *client, static void signal_load_values_get_signal_info_ready (QmiClientNas *client, GAsyncResult *res, - GTask *task) + GTask *task) { - MMBroadbandModemQmi *self; - SignalLoadValuesContext *ctx; - QmiMessageNasGetSignalInfoOutput *output; - gint8 rssi; - gint16 ecio; - QmiNasEvdoSinrLevel sinr_level; - gint32 io; - gint8 rsrq; - gint16 rsrp; - gint16 snr; + MMBroadbandModemQmi *self; + SignalLoadValuesContext *ctx; + gint8 rssi; + gint16 ecio; + QmiNasEvdoSinrLevel sinr_level; + gint32 io; + gint8 rsrq; + gint16 rsrp; + gint16 snr; + g_autoptr(QmiMessageNasGetSignalInfoOutput) output = NULL; self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); + ctx = g_task_get_task_data (task); output = qmi_client_nas_get_signal_info_finish (client, res, NULL); if (!output || !qmi_message_nas_get_signal_info_output_get_result (output, NULL)) { /* No hard errors, go on to next step */ ctx->step++; signal_load_values_context_step (task); - if (output) - qmi_message_nas_get_signal_info_output_unref (output); return; } @@ -8870,8 +8774,6 @@ signal_load_values_get_signal_info_ready (QmiClientNas *client, mm_signal_set_snr (ctx->values_result->lte, (0.1) * ((gdouble)snr)); } - qmi_message_nas_get_signal_info_output_unref (output); - /* Keep on */ ctx->step++; signal_load_values_context_step (task); @@ -8898,22 +8800,18 @@ signal_load_values_context_step (GTask *task) /* Fall through */ case SIGNAL_LOAD_VALUES_STEP_SIGNAL_INFO: - if (qmi_client_check_version (QMI_CLIENT (ctx->client), 1, 8)) { - qmi_client_nas_get_signal_info (ctx->client, - NULL, - 5, - NULL, - (GAsyncReadyCallback)signal_load_values_get_signal_info_ready, - task); - return; - } - ctx->step++; - /* Fall through */ + qmi_client_nas_get_signal_info (ctx->client, + NULL, + 5, + NULL, + (GAsyncReadyCallback)signal_load_values_get_signal_info_ready, + task); + return; case SIGNAL_LOAD_VALUES_STEP_SIGNAL_STRENGTH: /* If already loaded with signal info, don't try signal strength */ if (!VALUES_RESULT_LOADED (ctx)) { - QmiMessageNasGetSignalStrengthInput *input; + g_autoptr(QmiMessageNasGetSignalStrengthInput) input = NULL; input = qmi_message_nas_get_signal_strength_input_new (); qmi_message_nas_get_signal_strength_input_set_request_mask ( @@ -8932,7 +8830,6 @@ signal_load_values_context_step (GTask *task) NULL, (GAsyncReadyCallback)signal_load_values_get_signal_strength_ready, task); - qmi_message_nas_get_signal_strength_input_unref (input); return; } ctx->step++; @@ -8940,22 +8837,15 @@ signal_load_values_context_step (GTask *task) case SIGNAL_LOAD_VALUES_STEP_SIGNAL_LAST: /* If any result is set, succeed */ - if (VALUES_RESULT_LOADED (ctx)) { - SignalLoadValuesResult *values_result; - - /* Steal results from context in order to return them */ - values_result = ctx->values_result; - ctx->values_result = NULL; - + if (VALUES_RESULT_LOADED (ctx)) g_task_return_pointer (task, - values_result, + g_steal_pointer (&ctx->values_result), (GDestroyNotify)signal_load_values_result_free); - } else { + else g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "No way to load extended signal information"); - } g_object_unref (task); return; @@ -8969,14 +8859,14 @@ signal_load_values_context_step (GTask *task) } static void -signal_load_values (MMIfaceModemSignal *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +signal_load_values (MMIfaceModemSignal *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { SignalLoadValuesContext *ctx; - GTask *task; - QmiClient *client = NULL; + GTask *task; + QmiClient *client = NULL; mm_obj_dbg (self, "loading extended signal information..."); @@ -8990,9 +8880,7 @@ signal_load_values (MMIfaceModemSignal *self, ctx->step = SIGNAL_LOAD_VALUES_STEP_SIGNAL_FIRST; task = g_task_new (self, cancellable, callback, user_data); - g_task_set_task_data (task, - ctx, - (GDestroyNotify)signal_load_values_context_free); + g_task_set_task_data (task, ctx, (GDestroyNotify)signal_load_values_context_free); signal_load_values_context_step (task); } From 408e9f327e09cda73ab87c92aab34176186d2c3d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 24 Jun 2020 09:31:30 +0200 Subject: [PATCH 281/675] broadband-modem-qmi: fix assertion when disabling unsolicited events Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/230 --- src/mm-broadband-modem-qmi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 6125cd4f..e3a616ae 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -4739,17 +4739,17 @@ common_enable_disable_unsolicited_events_signal_strength (GTask *task) g_autoptr(QmiMessageNasSetEventReportInput) input = NULL; g_autoptr(GArray) thresholds = NULL; - ctx = g_task_get_task_data (task); + /* The device doesn't really like to have many threshold values, so don't + * grow this array without checking first */ + static const gint8 thresholds_data[] = { -80, -40, 0, 40, 80 }; - /* Only set thresholds during enable */ - if (ctx->enable) { - /* The device doesn't really like to have many threshold values, so don't - * grow this array without checking first */ - static const gint8 thresholds_data[] = { -80, -40, 0, 40, 80 }; + ctx = g_task_get_task_data (task); - thresholds = g_array_sized_new (FALSE, FALSE, sizeof (gint8), G_N_ELEMENTS (thresholds_data)); + /* Only set thresholds during enable, but always create the array anyway, + * as the TLV setter expects it */ + thresholds = g_array_sized_new (FALSE, FALSE, sizeof (gint8), G_N_ELEMENTS (thresholds_data)); + if (ctx->enable) g_array_append_vals (thresholds, thresholds_data, G_N_ELEMENTS (thresholds_data)); - } input = qmi_message_nas_set_event_report_input_new (); qmi_message_nas_set_event_report_input_set_signal_strength_indicator ( From 7e3863897e73227a7de54db967fd95b40a8833d1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 7 Jun 2020 15:16:49 +0200 Subject: [PATCH 282/675] broadband-modem: run implicit disabling if enabling fails The disabling sequence is updated so that the steps to disable the interfaces never fail. This is done so that the modem is not left in an "inconsistent" enabled state, if e.g. the modem is enabled and one of the disabling steps for the interfaces ends up failing. In this case, it is preferred to say that the modem is disabled, than having it wrongly enabled. The enabling sequence is updated so that if any of the steps to enable the interfaces fail, we end up running an implicit disabling operation to disable all the interfaces. This is to attempt to cleanup whatever we had enabled during the enabling operation, including e.g. the open ports context. --- src/mm-broadband-modem.c | 270 +++++++++++++++++++++++++-------------- 1 file changed, 175 insertions(+), 95 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index a56ae354..2e651190 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -10421,9 +10421,13 @@ schedule_initial_registration_checks (MMBroadbandModem *self) /*****************************************************************************/ typedef enum { + /* When user requests a disable operation, the process starts here */ DISABLING_STEP_FIRST, DISABLING_STEP_WAIT_FOR_FINAL_STATE, DISABLING_STEP_DISCONNECT_BEARERS, + /* When the disabling is launched due to a failed enable, the process + * starts here */ + DISABLING_STEP_FIRST_AFTER_ENABLE_FAILED, DISABLING_STEP_IFACE_SIMPLE, DISABLING_STEP_IFACE_FIRMWARE, DISABLING_STEP_IFACE_VOICE, @@ -10441,9 +10445,10 @@ typedef enum { typedef struct { MMBroadbandModem *self; - DisablingStep step; - MMModemState previous_state; - gboolean disabled; + gboolean state_updates; + DisablingStep step; + MMModemState previous_state; + gboolean disabled; } DisablingContext; static void disabling_step (GTask *task); @@ -10459,15 +10464,18 @@ disabling_context_free (DisablingContext *ctx) g_error_free (error); } - if (ctx->disabled) - mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), - MM_MODEM_STATE_DISABLED, - MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED); - else if (ctx->previous_state != MM_MODEM_STATE_DISABLED) { - /* Fallback to previous state */ - mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), - ctx->previous_state, - MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); + /* Only perform state updates if we're asked to do so */ + if (ctx->state_updates) { + if (ctx->disabled) + mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), + MM_MODEM_STATE_DISABLED, + MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED); + else if (ctx->previous_state != MM_MODEM_STATE_DISABLED) { + /* Fallback to previous state */ + mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), + ctx->previous_state, + MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); + } } g_object_unref (ctx->self); @@ -10475,42 +10483,34 @@ disabling_context_free (DisablingContext *ctx) } static gboolean -disable_finish (MMBaseModem *self, - GAsyncResult *res, - GError **error) +common_disable_finish (MMBroadbandModem *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } #undef INTERFACE_DISABLE_READY_FN -#define INTERFACE_DISABLE_READY_FN(NAME,TYPE,FATAL_ERRORS) \ - static void \ - NAME##_disable_ready (MMBroadbandModem *self, \ - GAsyncResult *result, \ - GTask *task) \ - { \ - DisablingContext *ctx; \ - GError *error = NULL; \ - \ - if (!mm_##NAME##_disable_finish (TYPE (self), \ - result, \ - &error)) { \ - if (FATAL_ERRORS) { \ - g_task_return_error (task, error); \ - g_object_unref (task); \ - return; \ - } \ - \ - mm_obj_dbg (self, "couldn't disable interface: %s", \ - error->message); \ - g_error_free (error); \ - return; \ - } \ - \ - /* Go on to next step */ \ - ctx = g_task_get_task_data (task); \ - ctx->step++; \ - disabling_step (task); \ +#define INTERFACE_DISABLE_READY_FN(NAME,TYPE,WARN_ERRORS) \ + static void \ + NAME##_disable_ready (MMBroadbandModem *self, \ + GAsyncResult *result, \ + GTask *task) \ + { \ + DisablingContext *ctx; \ + g_autoptr(GError) error = NULL; \ + \ + if (!mm_##NAME##_disable_finish (TYPE (self), result, &error)) { \ + if (WARN_ERRORS) \ + mm_obj_warn (self, "couldn't disable interface: %s", error->message); \ + else \ + mm_obj_dbg (self, "couldn't disable interface: %s", error->message); \ + } \ + \ + /* Go on to next step */ \ + ctx = g_task_get_task_data (task); \ + ctx->step++; \ + disabling_step (task); \ } INTERFACE_DISABLE_READY_FN (iface_modem, MM_IFACE_MODEM, TRUE) @@ -10588,6 +10588,7 @@ disabling_wait_for_final_state_ready (MMIfaceModem *self, /* We're in a final state now, go on */ + g_assert (ctx->state_updates); mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), MM_MODEM_STATE_DISABLING, MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED); @@ -10601,11 +10602,6 @@ disabling_step (GTask *task) { DisablingContext *ctx; - /* Don't run new steps if we're cancelled */ - if (g_task_return_error_if_cancelled (task)) { - g_object_unref (task); - return; - } ctx = g_task_get_task_data (task); switch (ctx->step) { @@ -10614,6 +10610,11 @@ disabling_step (GTask *task) /* fall through */ case DISABLING_STEP_WAIT_FOR_FINAL_STATE: + /* cancellability allowed at this point */ + if (g_task_return_error_if_cancelled (task)) { + g_object_unref (task); + return; + } mm_iface_modem_wait_for_final_state (MM_IFACE_MODEM (ctx->self), MM_MODEM_STATE_UNKNOWN, /* just any */ (GAsyncReadyCallback)disabling_wait_for_final_state_ready, @@ -10621,6 +10622,11 @@ disabling_step (GTask *task) return; case DISABLING_STEP_DISCONNECT_BEARERS: + /* cancellability allowed at this point */ + if (g_task_return_error_if_cancelled (task)) { + g_object_unref (task); + return; + } if (ctx->self->priv->modem_bearer_list) { mm_bearer_list_disconnect_all_bearers ( ctx->self->priv->modem_bearer_list, @@ -10631,6 +10637,14 @@ disabling_step (GTask *task) ctx->step++; /* fall through */ + case DISABLING_STEP_FIRST_AFTER_ENABLE_FAILED: + /* From this point onwards, the disabling sequence will NEVER fail, all + * errors will be treated as non-fatal, including a possible task + * cancellation. */ + g_task_set_check_cancellable (task, FALSE); + ctx->step++; + /* fall through */ + case DISABLING_STEP_IFACE_SIMPLE: ctx->step++; /* fall through */ @@ -10642,7 +10656,6 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_VOICE: if (ctx->self->priv->modem_voice_dbus_skeleton) { mm_obj_dbg (ctx->self, "modem has voice capabilities, disabling the Voice interface..."); - /* Disabling the Modem Voice interface */ mm_iface_modem_voice_disable (MM_IFACE_MODEM_VOICE (ctx->self), (GAsyncReadyCallback)iface_modem_voice_disable_ready, task); @@ -10654,7 +10667,6 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_SIGNAL: if (ctx->self->priv->modem_signal_dbus_skeleton) { mm_obj_dbg (ctx->self, "modem has extended signal reporting capabilities, disabling the Signal interface..."); - /* Disabling the Modem Signal interface */ mm_iface_modem_signal_disable (MM_IFACE_MODEM_SIGNAL (ctx->self), (GAsyncReadyCallback)iface_modem_signal_disable_ready, task); @@ -10666,7 +10678,6 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_OMA: if (ctx->self->priv->modem_oma_dbus_skeleton) { mm_obj_dbg (ctx->self, "modem has OMA capabilities, disabling the OMA interface..."); - /* Disabling the Modem Oma interface */ mm_iface_modem_oma_disable (MM_IFACE_MODEM_OMA (ctx->self), (GAsyncReadyCallback)iface_modem_oma_disable_ready, task); @@ -10678,7 +10689,6 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_TIME: if (ctx->self->priv->modem_time_dbus_skeleton) { mm_obj_dbg (ctx->self, "modem has time capabilities, disabling the Time interface..."); - /* Disabling the Modem Time interface */ mm_iface_modem_time_disable (MM_IFACE_MODEM_TIME (ctx->self), (GAsyncReadyCallback)iface_modem_time_disable_ready, task); @@ -10690,7 +10700,6 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_MESSAGING: if (ctx->self->priv->modem_messaging_dbus_skeleton) { mm_obj_dbg (ctx->self, "modem has messaging capabilities, disabling the Messaging interface..."); - /* Disabling the Modem Messaging interface */ mm_iface_modem_messaging_disable (MM_IFACE_MODEM_MESSAGING (ctx->self), (GAsyncReadyCallback)iface_modem_messaging_disable_ready, task); @@ -10702,7 +10711,6 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_LOCATION: if (ctx->self->priv->modem_location_dbus_skeleton) { mm_obj_dbg (ctx->self, "modem has location capabilities, disabling the Location interface..."); - /* Disabling the Modem Location interface */ mm_iface_modem_location_disable (MM_IFACE_MODEM_LOCATION (ctx->self), (GAsyncReadyCallback)iface_modem_location_disable_ready, task); @@ -10714,7 +10722,6 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_CDMA: if (ctx->self->priv->modem_cdma_dbus_skeleton) { mm_obj_dbg (ctx->self, "modem has CDMA capabilities, disabling the Modem CDMA interface..."); - /* Disabling the Modem CDMA interface */ mm_iface_modem_cdma_disable (MM_IFACE_MODEM_CDMA (ctx->self), (GAsyncReadyCallback)iface_modem_cdma_disable_ready, task); @@ -10726,7 +10733,6 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_3GPP_USSD: if (ctx->self->priv->modem_3gpp_ussd_dbus_skeleton) { mm_obj_dbg (ctx->self, "modem has 3GPP/USSD capabilities, disabling the Modem 3GPP/USSD interface..."); - /* Disabling the Modem 3GPP USSD interface */ mm_iface_modem_3gpp_ussd_disable (MM_IFACE_MODEM_3GPP_USSD (ctx->self), (GAsyncReadyCallback)iface_modem_3gpp_ussd_disable_ready, task); @@ -10738,7 +10744,6 @@ disabling_step (GTask *task) case DISABLING_STEP_IFACE_3GPP: if (ctx->self->priv->modem_3gpp_dbus_skeleton) { mm_obj_dbg (ctx->self, "modem has 3GPP capabilities, disabling the Modem 3GPP interface..."); - /* Disabling the Modem 3GPP interface */ mm_iface_modem_3gpp_disable (MM_IFACE_MODEM_3GPP (ctx->self), (GAsyncReadyCallback)iface_modem_3gpp_disable_ready, task); @@ -10751,7 +10756,7 @@ disabling_step (GTask *task) /* This skeleton may be NULL when mm_base_modem_disable() gets called at * the same time as modem object disposal. */ if (ctx->self->priv->modem_dbus_skeleton) { - /* Disabling the Modem interface */ + mm_obj_dbg (ctx->self, "disabling the Modem interface..."); mm_iface_modem_disable (MM_IFACE_MODEM (ctx->self), (GAsyncReadyCallback)iface_modem_disable_ready, task); @@ -10761,8 +10766,8 @@ disabling_step (GTask *task) /* fall through */ case DISABLING_STEP_LAST: - ctx->disabled = TRUE; /* All disabled without errors! */ + ctx->disabled = TRUE; g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -10775,17 +10780,20 @@ disabling_step (GTask *task) } static void -disable (MMBaseModem *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +common_disable (MMBroadbandModem *self, + gboolean state_updates, + DisablingStep first_step, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { DisablingContext *ctx; - GTask *task; + GTask *task; ctx = g_new0 (DisablingContext, 1); ctx->self = g_object_ref (self); - ctx->step = DISABLING_STEP_FIRST; + ctx->state_updates = state_updates; + ctx->step = first_step; task = g_task_new (self, cancellable, callback, user_data); g_task_set_task_data (task, ctx, (GDestroyNotify)disabling_context_free); @@ -10793,6 +10801,55 @@ disable (MMBaseModem *self, disabling_step (task); } +/* Implicit disabling after failed enable */ + +static gboolean +enable_failed_finish (MMBroadbandModem *self, + GAsyncResult *res, + GError **error) +{ + /* The implicit disabling should never ever fail */ + g_assert (common_disable_finish (self, res, NULL)); + return TRUE; +} + +static void +enable_failed (MMBroadbandModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + common_disable (self, + FALSE, /* don't perform state updates */ + DISABLING_STEP_FIRST_AFTER_ENABLE_FAILED, + NULL, /* no cancellable */ + callback, + user_data); +} + +/* User-requested disable operation */ + +static gboolean +disable_finish (MMBaseModem *self, + GAsyncResult *res, + GError **error) +{ + return common_disable_finish (MM_BROADBAND_MODEM (self), res, error); +} + +static void +disable (MMBaseModem *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + common_disable (MM_BROADBAND_MODEM (self), + TRUE, /* perform state updates */ + DISABLING_STEP_FIRST_AFTER_ENABLE_FAILED, + cancellable, + callback, + user_data); +} + /*****************************************************************************/ typedef enum { @@ -10816,9 +10873,10 @@ typedef enum { typedef struct { MMBroadbandModem *self; - EnablingStep step; - MMModemState previous_state; - gboolean enabled; + EnablingStep step; + MMModemState previous_state; + gboolean enabled; + GError *saved_error; } EnablingContext; static void enabling_step (GTask *task); @@ -10826,6 +10884,8 @@ static void enabling_step (GTask *task); static void enabling_context_free (EnablingContext *ctx) { + g_assert (!ctx->saved_error); + if (ctx->enabled) mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), MM_MODEM_STATE_ENABLED, @@ -10849,34 +10909,51 @@ enable_finish (MMBaseModem *self, return g_task_propagate_boolean (G_TASK (res), error); } +static void +enable_failed_ready (MMBroadbandModem *self, + GAsyncResult *res, + GTask *task) +{ + EnablingContext *ctx; + + ctx = g_task_get_task_data (task); + + /* The disabling run after a failed enable will never fail */ + g_assert (enable_failed_finish (self, res, NULL)); + + g_assert (ctx->saved_error); + g_task_return_error (task, g_steal_pointer (&ctx->saved_error)); + g_object_unref (task); +} + #undef INTERFACE_ENABLE_READY_FN -#define INTERFACE_ENABLE_READY_FN(NAME,TYPE,FATAL_ERRORS) \ - static void \ - NAME##_enable_ready (MMBroadbandModem *self, \ - GAsyncResult *result, \ - GTask *task) \ - { \ - EnablingContext *ctx; \ - GError *error = NULL; \ - \ - if (!mm_##NAME##_enable_finish (TYPE (self), \ - result, \ - &error)) { \ - if (FATAL_ERRORS) { \ - g_task_return_error (task, error); \ - g_object_unref (task); \ - return; \ - } \ - \ - mm_obj_dbg (self, "couldn't enable interface: '%s'", \ - error->message); \ - g_error_free (error); \ - } \ - \ - /* Go on to next step */ \ - ctx = g_task_get_task_data (task); \ - ctx->step++; \ - enabling_step (task); \ +#define INTERFACE_ENABLE_READY_FN(NAME,TYPE,FATAL_ERRORS) \ + static void \ + NAME##_enable_ready (MMBroadbandModem *self, \ + GAsyncResult *result, \ + GTask *task) \ + { \ + EnablingContext *ctx; \ + g_autoptr(GError) error = NULL; \ + \ + ctx = g_task_get_task_data (task); \ + \ + if (!mm_##NAME##_enable_finish (TYPE (self), result, &error)) { \ + if (FATAL_ERRORS) { \ + mm_obj_warn (self, "couldn't enable interface: '%s'", error->message); \ + g_assert (!ctx->saved_error); \ + ctx->saved_error = g_steal_pointer (&error); \ + mm_obj_dbg (self, "running implicit disable after failed enable..."); \ + enable_failed (self, (GAsyncReadyCallback) enable_failed_ready, task); \ + return; \ + } \ + \ + mm_obj_dbg (self, "couldn't enable interface: '%s'", error->message); \ + } \ + \ + /* Go on to next step */ \ + ctx->step++; \ + enabling_step (task); \ } INTERFACE_ENABLE_READY_FN (iface_modem, MM_IFACE_MODEM, TRUE) @@ -10981,6 +11058,9 @@ enabling_step (GTask *task) /* fall through */ case ENABLING_STEP_IFACE_MODEM: + /* From now on, the failure to enable one of the mandatory interfaces + * will trigger the implicit disabling process */ + g_assert (ctx->self->priv->modem_dbus_skeleton != NULL); /* Enabling the Modem interface */ mm_iface_modem_enable (MM_IFACE_MODEM (ctx->self), From c4d82aaf1e7cf10475204102533ac7784f83f0d3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 12:06:51 +0200 Subject: [PATCH 283/675] base-modem,at: improve documentation on response processor methods --- src/mm-base-modem-at.c | 68 +++++++++++++++-------------- src/mm-base-modem-at.h | 98 ++++++++++++++++++++++++++---------------- 2 files changed, 98 insertions(+), 68 deletions(-) diff --git a/src/mm-base-modem-at.c b/src/mm-base-modem-at.c index 101c9549..94bd3956 100644 --- a/src/mm-base-modem-at.c +++ b/src/mm-base-modem-at.c @@ -355,16 +355,17 @@ mm_base_modem_at_sequence (MMBaseModem *self, /* Response processor helpers */ gboolean -mm_base_modem_response_processor_string (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +mm_base_modem_response_processor_string (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { if (error) { + /* Abort sequence on command error */ *result_error = g_error_copy (error); return FALSE; } @@ -374,16 +375,17 @@ mm_base_modem_response_processor_string (MMBaseModem *self, } gboolean -mm_base_modem_response_processor_no_result (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +mm_base_modem_response_processor_no_result (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { if (error) { + /* Abort sequence on command error */ *result_error = g_error_copy (error); return FALSE; } @@ -393,16 +395,17 @@ mm_base_modem_response_processor_no_result (MMBaseModem *self, } gboolean -mm_base_modem_response_processor_no_result_continue (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +mm_base_modem_response_processor_no_result_continue (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { if (error) + /* Abort sequence on command error */ *result_error = g_error_copy (error); /* Return FALSE so that we keep on with the next steps in the sequence */ @@ -410,16 +413,17 @@ mm_base_modem_response_processor_no_result_continue (MMBaseModem *self, } gboolean -mm_base_modem_response_processor_continue_on_error (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +mm_base_modem_response_processor_continue_on_error (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { if (error) + /* Ignore errors, continue to next command */ return FALSE; *result = NULL; diff --git a/src/mm-base-modem-at.h b/src/mm-base-modem-at.h index d92a0610..f5f0601e 100644 --- a/src/mm-base-modem-at.h +++ b/src/mm-base-modem-at.h @@ -93,42 +93,68 @@ GVariant *mm_base_modem_at_sequence_full_finish (MMBaseModem *self, /* Common helper response processors */ -/* Every string received as response, will be set as result */ -gboolean mm_base_modem_response_processor_string (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error); -/* Just abort if error without result set, otherwise finish sequence */ -gboolean mm_base_modem_response_processor_no_result (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error); -/* Just abort if error without result set, otherwise continue sequence */ -gboolean mm_base_modem_response_processor_no_result_continue (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error); -/* If error, continue sequence, otherwise finish it */ -gboolean mm_base_modem_response_processor_continue_on_error (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error); +/* + * Response processor for commands that are treated as MANDATORY, where a + * failure in the command triggers a failure in the sequence. If successful, + * provides the output result as a STRING. + */ +gboolean mm_base_modem_response_processor_string (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error); + +/* + * Response processor for commands that are treated as MANDATORY, where a + * failure in the command triggers a failure in the sequence. If successful, + * provides the output result as a BOOLEAN. + */ +gboolean mm_base_modem_response_processor_no_result (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error); + +/* + * Response processor for commands that are treated as MANDATORY, where a + * failure in the command triggers a failure in the sequence. If successful, + * it will run the next command in the sequence. + * + * E.g. used when we provide a list of commands and we want to run all of + * them successfully, and fail the sequence if one of them fails. + */ +gboolean mm_base_modem_response_processor_no_result_continue (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error); + +/* + * Response processor for commands that are treated as OPTIONAL, where a + * failure in the command doesn't trigger a failure in the sequence. If + * successful, it finishes the sequence. + * + * E.g. used when we provide a list of commands and we want to stop + * as soon as one of them doesn't fail. + */ +gboolean mm_base_modem_response_processor_continue_on_error (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error); + /* Generic AT command handling, using the best AT port available and without * explicit cancellations. */ From 4b37b7d3cfd8c8e98af25eed334b1880b6b6c597 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 14:05:58 +0200 Subject: [PATCH 284/675] base-modem,at: response processors return a more specific enum Instead of using the FALSE return of the method to indicate either a fatal error (if result_error was set) or the continuation request (if result_error wasn't set), provide a enum that has explicit states for all three possible values (failure, success or continue). --- .../altair/mm-broadband-modem-altair-lte.c | 27 +-- plugins/huawei/mm-broadband-modem-huawei.c | 22 +- plugins/icera/mm-broadband-modem-icera.c | 29 +-- .../novatel/mm-broadband-modem-novatel-lte.c | 61 +++--- plugins/sierra/mm-broadband-modem-sierra.c | 28 +-- plugins/telit/mm-broadband-modem-telit.c | 81 ++++---- src/mm-base-modem-at.c | 189 ++++++++++------- src/mm-base-modem-at.h | 112 +++++----- src/mm-broadband-modem.c | 192 +++++++++--------- 9 files changed, 402 insertions(+), 339 deletions(-) diff --git a/plugins/altair/mm-broadband-modem-altair-lte.c b/plugins/altair/mm-broadband-modem-altair-lte.c index 54702172..9e555f5b 100644 --- a/plugins/altair/mm-broadband-modem-altair-lte.c +++ b/plugins/altair/mm-broadband-modem-altair-lte.c @@ -857,30 +857,11 @@ modem_3gpp_cleanup_unsolicited_events (MMIfaceModem3gpp *self, /*****************************************************************************/ /* Enabling unsolicited events (3GPP interface) */ -static gboolean -response_processor_no_result_stop_on_error (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) -{ - if (error) { - *result_error = g_error_copy (error); - return TRUE; - } - - *result = NULL; - return FALSE; -} - static const MMBaseModemAtCommand unsolicited_events_enable_sequence[] = { - { "%STATCM=1", 10, FALSE, response_processor_no_result_stop_on_error }, - { "%NOTIFYEV=\"SIMREFRESH\",1", 10, FALSE, NULL }, - { "%PCOINFO=1", 10, FALSE, NULL }, - { NULL } + { "%STATCM=1", 10, FALSE, mm_base_modem_response_processor_no_result_continue }, + { "%NOTIFYEV=\"SIMREFRESH\",1", 10, FALSE, NULL }, + { "%PCOINFO=1", 10, FALSE, NULL }, + { NULL } }; static gboolean diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index a676b7a7..82e439e1 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -4137,15 +4137,15 @@ modem_time_check_ready (MMBaseModem *_self, g_object_unref (task); } -static gboolean -modem_check_time_reply (MMBaseModem *_self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +static MMBaseModemAtResponseProcessorResult +modem_check_time_reply (MMBaseModem *_self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); @@ -4161,7 +4161,9 @@ modem_check_time_reply (MMBaseModem *_self, self->priv->time_support = FEATURE_NOT_SUPPORTED; } - return FALSE; + *result = NULL; + *result_error = NULL; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } static const MMBaseModemAtCommand time_cmd_sequence[] = { diff --git a/plugins/icera/mm-broadband-modem-icera.c b/plugins/icera/mm-broadband-modem-icera.c index b459cb57..ebaac9ad 100644 --- a/plugins/icera/mm-broadband-modem-icera.c +++ b/plugins/icera/mm-broadband-modem-icera.c @@ -1223,18 +1223,21 @@ load_supported_bands_ready (MMBaseModem *self, g_object_unref (task); } -static gboolean -load_supported_bands_response_processor (MMBaseModem *self, - gpointer context, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) -{ - SupportedBandsContext *ctx = context; - Band *b = g_slist_nth_data (ctx->check_bands, ctx->idx++); +static MMBaseModemAtResponseProcessorResult +load_supported_bands_response_processor (MMBaseModem *self, + gpointer context, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) +{ + SupportedBandsContext *ctx; + Band *b; + + ctx = context; + b = g_slist_nth_data (ctx->check_bands, ctx->idx++); /* If there was no error setting the band, that band is supported. We * abuse the 'enabled' item to mean supported/unsupported. @@ -1242,7 +1245,7 @@ load_supported_bands_response_processor (MMBaseModem *self, b->enabled = !error; /* Continue to next band */ - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } static void diff --git a/plugins/novatel/mm-broadband-modem-novatel-lte.c b/plugins/novatel/mm-broadband-modem-novatel-lte.c index ebcbe499..df331381 100644 --- a/plugins/novatel/mm-broadband-modem-novatel-lte.c +++ b/plugins/novatel/mm-broadband-modem-novatel-lte.c @@ -184,54 +184,65 @@ load_own_numbers_finish (MMIfaceModem *self, return own_numbers; } -static gboolean -response_processor_cnum_ignore_at_errors (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +static MMBaseModemAtResponseProcessorResult +response_processor_cnum_ignore_at_errors (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { GStrv own_numbers; + *result = NULL; + *result_error = NULL; + if (error) { /* Ignore AT errors (ie, ERROR or CMx ERROR) */ - if (error->domain != MM_MOBILE_EQUIPMENT_ERROR || last_command) + if (error->domain != MM_MOBILE_EQUIPMENT_ERROR || last_command) { *result_error = g_error_copy (error); + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; + } - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } own_numbers = mm_3gpp_parse_cnum_exec_response (response); if (!own_numbers) - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; *result = g_variant_new_strv ((const gchar *const *) own_numbers, -1); g_strfreev (own_numbers); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } -static gboolean -response_processor_nwmdn_ignore_at_errors (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +static MMBaseModemAtResponseProcessorResult +response_processor_nwmdn_ignore_at_errors (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { g_auto(GStrv) own_numbers = NULL; GPtrArray *array; gchar *mdn; + *result = NULL; + *result_error = NULL; + if (error) { /* Ignore AT errors (ie, ERROR or CMx ERROR) */ - if (error->domain != MM_MOBILE_EQUIPMENT_ERROR || last_command) + if (error->domain != MM_MOBILE_EQUIPMENT_ERROR || last_command) { *result_error = g_error_copy (error); - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; + } + + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } mdn = g_strdup (mm_strip_tag (response, "$NWMDN:")); @@ -242,7 +253,7 @@ response_processor_nwmdn_ignore_at_errors (MMBaseModem *self, own_numbers = (GStrv) g_ptr_array_free (array, FALSE); *result = g_variant_new_strv ((const gchar *const *) own_numbers, -1); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } static const MMBaseModemAtCommand own_numbers_commands[] = { diff --git a/plugins/sierra/mm-broadband-modem-sierra.c b/plugins/sierra/mm-broadband-modem-sierra.c index c08aec48..7e2dba9b 100644 --- a/plugins/sierra/mm-broadband-modem-sierra.c +++ b/plugins/sierra/mm-broadband-modem-sierra.c @@ -1780,16 +1780,18 @@ modem_time_check_ready (MMBaseModem *self, g_object_unref (task); } -static gboolean -parse_time_reply (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) -{ +static MMBaseModemAtResponseProcessorResult +parse_time_reply (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) +{ + *result_error = NULL; + /* If error, try next command */ if (!error) { if (strstr (command, "!TIME")) @@ -1799,11 +1801,13 @@ parse_time_reply (MMBaseModem *self, } /* Stop sequence if we get a result, but not on errors */ - return *result ? TRUE : FALSE; + return (*result ? + MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS : + MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE); } static const MMBaseModemAtCommand time_check_sequence[] = { - { "!TIME?", 3, FALSE, parse_time_reply }, /* 3GPP */ + { "!TIME?", 3, FALSE, parse_time_reply }, /* 3GPP */ { "!SYSTIME?", 3, FALSE, parse_time_reply }, /* CDMA */ { NULL } }; diff --git a/plugins/telit/mm-broadband-modem-telit.c b/plugins/telit/mm-broadband-modem-telit.c index 48ae4de1..94a6ddcc 100644 --- a/plugins/telit/mm-broadband-modem-telit.c +++ b/plugins/telit/mm-broadband-modem-telit.c @@ -1080,23 +1080,30 @@ load_access_technologies_finish (MMIfaceModem *self, return TRUE; } -static gboolean -response_processor_psnt_ignore_at_errors (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +static MMBaseModemAtResponseProcessorResult +response_processor_psnt_ignore_at_errors (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { - const gchar *psnt, *mode; + const gchar *psnt; + const gchar *mode; + + *result = NULL; + *result_error = NULL; if (error) { /* Ignore AT errors (ie, ERROR or CMx ERROR) */ - if (error->domain != MM_MOBILE_EQUIPMENT_ERROR || last_command) + if (error->domain != MM_MOBILE_EQUIPMENT_ERROR || last_command) { *result_error = g_error_copy (error); - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; + } + + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } psnt = mm_strip_tag (response, "#PSNT:"); @@ -1105,26 +1112,26 @@ response_processor_psnt_ignore_at_errors (MMBaseModem *self, switch (atoi (++mode)) { case 0: *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_GPRS); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; case 1: *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_EDGE); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; case 2: *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_UMTS); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; case 3: *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_HSDPA); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; case 4: if (mm_iface_modem_is_3gpp_lte (MM_IFACE_MODEM (self))) *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_LTE); else *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; case 5: if (mm_iface_modem_is_3gpp_lte (MM_IFACE_MODEM (self))) { *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } /* Fall-through since #PSNT: 5 is not supported in other than lte modems */ default: @@ -1137,26 +1144,32 @@ response_processor_psnt_ignore_at_errors (MMBaseModem *self, MM_CORE_ERROR_FAILED, "Failed to parse #PSNT response: '%s'", response); - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; } -static gboolean -response_processor_service_ignore_at_errors (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +static MMBaseModemAtResponseProcessorResult +response_processor_service_ignore_at_errors (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { const gchar *service; + *result = NULL; + *result_error = NULL; + if (error) { /* Ignore AT errors (ie, ERROR or CMx ERROR) */ - if (error->domain != MM_MOBILE_EQUIPMENT_ERROR || last_command) + if (error->domain != MM_MOBILE_EQUIPMENT_ERROR || last_command) { *result_error = g_error_copy (error); - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; + } + + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } service = mm_strip_tag (response, "+SERVICE:"); @@ -1164,13 +1177,13 @@ response_processor_service_ignore_at_errors (MMBaseModem *self, switch (atoi (service)) { case 1: *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_1XRTT); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; case 2: *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_EVDO0); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; case 3: *result = g_variant_new_uint32 (MM_MODEM_ACCESS_TECHNOLOGY_EVDOA); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; default: break; } @@ -1181,7 +1194,7 @@ response_processor_service_ignore_at_errors (MMBaseModem *self, MM_CORE_ERROR_FAILED, "Failed to parse +SERVICE response: '%s'", response); - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; } static const MMBaseModemAtCommand access_tech_commands[] = { diff --git a/src/mm-base-modem-at.c b/src/mm-base-modem-at.c index 94bd3956..d1352e08 100644 --- a/src/mm-base-modem-at.c +++ b/src/mm-base-modem-at.c @@ -90,18 +90,18 @@ modem_cancellable_cancelled (GCancellable *modem_cancellable, /* AT sequence handling */ typedef struct { - MMBaseModem *self; - MMPortSerialAt *port; - GCancellable *cancellable; - gulong cancelled_id; - GCancellable *modem_cancellable; - GCancellable *user_cancellable; + MMBaseModem *self; + MMPortSerialAt *port; + GCancellable *cancellable; + gulong cancelled_id; + GCancellable *modem_cancellable; + GCancellable *user_cancellable; const MMBaseModemAtCommand *current; const MMBaseModemAtCommand *sequence; - GSimpleAsyncResult *simple; - gpointer response_processor_context; - GDestroyNotify response_processor_context_free; - GVariant *result; + GSimpleAsyncResult *simple; + gpointer response_processor_context; + GDestroyNotify response_processor_context_free; + GVariant *result; } AtSequenceContext; static void @@ -131,15 +131,14 @@ at_sequence_context_free (AtSequenceContext *ctx) } GVariant * -mm_base_modem_at_sequence_full_finish (MMBaseModem *self, - GAsyncResult *res, - gpointer *response_processor_context, - GError **error) +mm_base_modem_at_sequence_full_finish (MMBaseModem *self, + GAsyncResult *res, + gpointer *response_processor_context, + GError **error) { AtSequenceContext *ctx; - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), - error)) + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) return NULL; ctx = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)); @@ -153,63 +152,67 @@ mm_base_modem_at_sequence_full_finish (MMBaseModem *self, } static void -at_sequence_parse_response (MMPortSerialAt *port, - GAsyncResult *res, +at_sequence_parse_response (MMPortSerialAt *port, + GAsyncResult *res, AtSequenceContext *ctx) { - GVariant *result = NULL; - GError *result_error = NULL; - gboolean continue_sequence; - GSimpleAsyncResult *simple; - const gchar *response; - GError *error = NULL; + MMBaseModemAtResponseProcessorResult processor_result; + GVariant *result = NULL; + GError *result_error = NULL; + GSimpleAsyncResult *simple; + const gchar *response; + GError *error = NULL; response = mm_port_serial_at_command_finish (port, res, &error); /* Cancelled? */ if (g_cancellable_is_cancelled (ctx->cancellable)) { - g_simple_async_result_set_error (ctx->simple, G_IO_ERROR, G_IO_ERROR_CANCELLED, - "AT sequence was cancelled"); - if (error) - g_error_free (error); + g_simple_async_result_set_error (ctx->simple, G_IO_ERROR, G_IO_ERROR_CANCELLED, "AT sequence was cancelled"); + g_clear_error (&error); g_simple_async_result_complete (ctx->simple); at_sequence_context_free (ctx); return; } if (!ctx->current->response_processor) - /* No need to process response, go on to next command */ - continue_sequence = TRUE; + processor_result = MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; else { const MMBaseModemAtCommand *next = ctx->current + 1; /* Response processor will tell us if we need to keep on the sequence */ - continue_sequence = !ctx->current->response_processor ( - ctx->self, - ctx->response_processor_context, - ctx->current->command, - response, - next->command ? FALSE : TRUE, /* Last command in sequence? */ - error, - &result, - &result_error); - /* Were we told to abort the sequence? */ - if (result_error) { - g_assert (result == NULL); - g_simple_async_result_take_error (ctx->simple, result_error); - g_simple_async_result_complete (ctx->simple); - at_sequence_context_free (ctx); - if (error) - g_error_free (error); - return; + processor_result = ctx->current->response_processor (ctx->self, + ctx->response_processor_context, + ctx->current->command, + response, + next->command ? FALSE : TRUE, /* Last command in sequence? */ + error, + &result, + &result_error); + switch (processor_result) { + case MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE: + g_assert (!result && !result_error); + break; + case MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS: + g_assert (!result_error); /* result is optional */ + break; + case MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE: + /* On failure, complete with error right away */ + g_assert (!result && result_error); /* result is optional */ + g_simple_async_result_take_error (ctx->simple, result_error); + g_simple_async_result_complete (ctx->simple); + at_sequence_context_free (ctx); + if (error) + g_error_free (error); + return; + default: + g_assert_not_reached (); } } if (error) g_error_free (error); - if (continue_sequence) { - g_assert (result == NULL); + if (processor_result == MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE) { ctx->current++; if (ctx->current->command) { /* Schedule the next command in the probing group */ @@ -224,7 +227,6 @@ at_sequence_parse_response (MMPortSerialAt *port, ctx); return; } - /* On last command, end. */ } @@ -250,14 +252,14 @@ at_sequence_parse_response (MMPortSerialAt *port, } void -mm_base_modem_at_sequence_full (MMBaseModem *self, - MMPortSerialAt *port, +mm_base_modem_at_sequence_full (MMBaseModem *self, + MMPortSerialAt *port, const MMBaseModemAtCommand *sequence, - gpointer response_processor_context, - GDestroyNotify response_processor_context_free, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) + gpointer response_processor_context, + GDestroyNotify response_processor_context_free, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) { AtSequenceContext *ctx; @@ -354,7 +356,7 @@ mm_base_modem_at_sequence (MMBaseModem *self, /*****************************************************************************/ /* Response processor helpers */ -gboolean +MMBaseModemAtResponseProcessorResult mm_base_modem_response_processor_string (MMBaseModem *self, gpointer none, const gchar *command, @@ -365,16 +367,17 @@ mm_base_modem_response_processor_string (MMBaseModem *self, GError **result_error) { if (error) { - /* Abort sequence on command error */ + *result = NULL; *result_error = g_error_copy (error); - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; } *result = g_variant_new_string (response); - return TRUE; + *result_error = NULL; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } -gboolean +MMBaseModemAtResponseProcessorResult mm_base_modem_response_processor_no_result (MMBaseModem *self, gpointer none, const gchar *command, @@ -385,16 +388,17 @@ mm_base_modem_response_processor_no_result (MMBaseModem *self, GError **result_error) { if (error) { - /* Abort sequence on command error */ + *result = NULL; *result_error = g_error_copy (error); - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; } *result = NULL; - return TRUE; + *result_error = NULL; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } -gboolean +MMBaseModemAtResponseProcessorResult mm_base_modem_response_processor_no_result_continue (MMBaseModem *self, gpointer none, const gchar *command, @@ -404,15 +408,18 @@ mm_base_modem_response_processor_no_result_continue (MMBaseModem *self, GVariant **result, GError **result_error) { - if (error) - /* Abort sequence on command error */ + *result = NULL; + + if (error) { *result_error = g_error_copy (error); + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; + } - /* Return FALSE so that we keep on with the next steps in the sequence */ - return FALSE; + *result_error = NULL; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } -gboolean +MMBaseModemAtResponseProcessorResult mm_base_modem_response_processor_continue_on_error (MMBaseModem *self, gpointer none, const gchar *command, @@ -422,12 +429,40 @@ mm_base_modem_response_processor_continue_on_error (MMBaseModem *self, GVariant **result, GError **result_error) { - if (error) - /* Ignore errors, continue to next command */ - return FALSE; - *result = NULL; - return TRUE; + *result_error = NULL; + + return (error ? + MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE : + MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS); +} + +MMBaseModemAtResponseProcessorResult +mm_base_modem_response_processor_string_ignore_at_errors (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) +{ + if (error) { + *result = NULL; + + /* Ignore AT errors (ie, ERROR or CMx ERROR) */ + if (error->domain != MM_MOBILE_EQUIPMENT_ERROR || last_command) { + + *result_error = g_error_copy (error); + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; + } + + *result_error = NULL; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; + } + + *result = g_variant_new_string (response); + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } /*****************************************************************************/ diff --git a/src/mm-base-modem-at.h b/src/mm-base-modem-at.h index f5f0601e..770c0e4b 100644 --- a/src/mm-base-modem-at.h +++ b/src/mm-base-modem-at.h @@ -21,19 +21,25 @@ #include "mm-base-modem.h" #include "mm-port-serial-at.h" +typedef enum { + MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE, + MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS, + MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE, +} MMBaseModemAtResponseProcessorResult; + /* * The expected result depends on the specific operation, so the GVariant * created by the response processor needs to match the one expected in * finish(). * - * TRUE must be returned when the operation is to be considered successful, + * SUCCESS must be returned when the operation is to be considered successful, * and a result may be given. * - * FALSE must be returned when: - * - A GError is propagated into result_error, which will be treated as a - * critical error and therefore the operation will be aborted. - * - When no result_error is given, to instruct the operation to go on with - * the next scheduled command. + * FAILURE must be returned when a GError is propagated into result_error, + * which will be treated as a critical error and therefore the operation will be aborted. + * + * CONTINUE must be returned when neither result nor result_error are given and + * the operation should go on with the next scheduled command. * * This setup, therefore allows: * - Running a single command and processing its result. @@ -42,14 +48,14 @@ * - Running a set of N commands out of M (Ndomain != MM_MOBILE_EQUIPMENT_ERROR || last_command) - *result_error = g_error_copy (error); - - return FALSE; - } - - *result = g_variant_new_string (response); - return TRUE; -} - /*****************************************************************************/ /* Create Bearer (Modem interface) */ @@ -583,27 +559,30 @@ static const ModemCaps modem_caps[] = { { NULL } }; -static gboolean -parse_caps_gcap (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **variant, - GError **result_error) +static MMBaseModemAtResponseProcessorResult +parse_caps_gcap (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { const ModemCaps *cap = modem_caps; guint32 ret = 0; + *result = NULL; + *result_error = NULL; + if (!response) - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; /* Some modems (Huawei E160g) won't respond to +GCAP with no SIM, but * will respond to ATI. Ignore the error and continue. */ - if (strstr (response, "+CME ERROR:")) - return FALSE; + if (strstr (response, "+CME ERROR:") || (error && error->domain == MM_MOBILE_EQUIPMENT_ERROR)) + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; while (cap->name) { if (strstr (response, cap->name)) @@ -613,22 +592,25 @@ parse_caps_gcap (MMBaseModem *self, /* No result built? */ if (ret == 0) - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; - *variant = g_variant_new_uint32 (ret); - return TRUE; + *result = g_variant_new_uint32 (ret); + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } -static gboolean -parse_caps_cpin (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +static MMBaseModemAtResponseProcessorResult +parse_caps_cpin (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { + *result = NULL; + *result_error = NULL; + if (!response) { if (error && (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_SIM_NOT_INSERTED) || @@ -637,9 +619,9 @@ parse_caps_cpin (MMBaseModem *self, g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG))) { /* At least, it's a GSM modem */ *result = g_variant_new_uint32 (MM_MODEM_CAPABILITY_GSM_UMTS); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } if (strcasestr (response, "SIM PIN") || @@ -660,23 +642,27 @@ parse_caps_cpin (MMBaseModem *self, strcasestr (response, "READY")) { /* At least, it's a GSM modem */ *result = g_variant_new_uint32 (MM_MODEM_CAPABILITY_GSM_UMTS); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } - return FALSE; + + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } -static gboolean -parse_caps_cgmm (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +static MMBaseModemAtResponseProcessorResult +parse_caps_cgmm (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { + *result = NULL; + *result_error = NULL; + if (!response) - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; /* This check detects some really old Motorola GPRS dongles and phones */ if (strstr (response, "GSM900") || @@ -685,9 +671,10 @@ parse_caps_cgmm (MMBaseModem *self, strstr (response, "GSM850")) { /* At least, it's a GSM modem */ *result = g_variant_new_uint32 (MM_MODEM_CAPABILITY_GSM_UMTS); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } - return FALSE; + + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } static const MMBaseModemAtCommand capabilities[] = { @@ -942,8 +929,8 @@ modem_load_manufacturer_finish (MMIfaceModem *self, } static const MMBaseModemAtCommand manufacturers[] = { - { "+CGMI", 3, TRUE, response_processor_string_ignore_at_errors }, - { "+GMI", 3, TRUE, response_processor_string_ignore_at_errors }, + { "+CGMI", 3, TRUE, mm_base_modem_response_processor_string_ignore_at_errors }, + { "+GMI", 3, TRUE, mm_base_modem_response_processor_string_ignore_at_errors }, { NULL } }; @@ -982,8 +969,8 @@ modem_load_model_finish (MMIfaceModem *self, } static const MMBaseModemAtCommand models[] = { - { "+CGMM", 3, TRUE, response_processor_string_ignore_at_errors }, - { "+GMM", 3, TRUE, response_processor_string_ignore_at_errors }, + { "+CGMM", 3, TRUE, mm_base_modem_response_processor_string_ignore_at_errors }, + { "+GMM", 3, TRUE, mm_base_modem_response_processor_string_ignore_at_errors }, { NULL } }; @@ -1022,8 +1009,8 @@ modem_load_revision_finish (MMIfaceModem *self, } static const MMBaseModemAtCommand revisions[] = { - { "+CGMR", 3, TRUE, response_processor_string_ignore_at_errors }, - { "+GMR", 3, TRUE, response_processor_string_ignore_at_errors }, + { "+CGMR", 3, TRUE, mm_base_modem_response_processor_string_ignore_at_errors }, + { "+GMR", 3, TRUE, mm_base_modem_response_processor_string_ignore_at_errors }, { NULL } }; @@ -1082,8 +1069,8 @@ modem_load_equipment_identifier_finish (MMIfaceModem *self, } static const MMBaseModemAtCommand equipment_identifiers[] = { - { "+CGSN", 3, TRUE, response_processor_string_ignore_at_errors }, - { "+GSN", 3, TRUE, response_processor_string_ignore_at_errors }, + { "+CGSN", 3, TRUE, mm_base_modem_response_processor_string_ignore_at_errors }, + { "+GSN", 3, TRUE, mm_base_modem_response_processor_string_ignore_at_errors }, { NULL } }; @@ -2099,8 +2086,8 @@ signal_quality_csq_ready (MMBroadbandModem *self, * try the other command if the first one fails. */ static const MMBaseModemAtCommand signal_quality_csq_sequence[] = { - { "+CSQ", 3, FALSE, response_processor_string_ignore_at_errors }, - { "+CSQ?", 3, FALSE, response_processor_string_ignore_at_errors }, + { "+CSQ", 3, FALSE, mm_base_modem_response_processor_string_ignore_at_errors }, + { "+CSQ?", 3, FALSE, mm_base_modem_response_processor_string_ignore_at_errors }, { NULL } }; @@ -5269,23 +5256,27 @@ modem_3gpp_enable_disable_unsolicited_registration_events_finish (MMIfaceModem3g return g_task_propagate_boolean (G_TASK (res), error); } -static gboolean -parse_registration_setup_reply (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, +static MMBaseModemAtResponseProcessorResult +parse_registration_setup_reply (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, const GError *error, - GVariant **result, - GError **result_error) + GVariant **result, + GError **result_error) { + *result_error = NULL; + /* If error, try next command */ - if (error) - return FALSE; + if (error) { + *result = NULL; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; + } /* Set COMMAND as result! */ *result = g_variant_new_string (command); - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } static const MMBaseModemAtCommand cs_registration_sequence[] = { @@ -7060,28 +7051,31 @@ modem_messaging_enable_unsolicited_events_finish (MMIfaceModemMessaging *self, return g_task_propagate_boolean (G_TASK (res), error); } -static gboolean -cnmi_response_processor (MMBaseModem *self, - gpointer none, - const gchar *command, - const gchar *response, - gboolean last_command, - const GError *error, - GVariant **result, - GError **result_error) +static MMBaseModemAtResponseProcessorResult +cnmi_response_processor (MMBaseModem *self, + gpointer none, + const gchar *command, + const gchar *response, + gboolean last_command, + const GError *error, + GVariant **result, + GError **result_error) { + *result = NULL; + *result_error = NULL; + if (error) { /* If we get a not-supported error and we're not in the last command, we * won't set 'result_error', so we'll keep on the sequence */ - if (!g_error_matches (error, MM_MESSAGE_ERROR, MM_MESSAGE_ERROR_NOT_SUPPORTED) || - last_command) + if (!g_error_matches (error, MM_MESSAGE_ERROR, MM_MESSAGE_ERROR_NOT_SUPPORTED) || last_command) { *result_error = g_error_copy (error); + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_FAILURE; + } - return FALSE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE; } - *result = NULL; - return TRUE; + return MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_SUCCESS; } static const MMBaseModemAtCommand cnmi_sequence[] = { From df393df1479ab79f028b17eb3df0ea0eb96b9140 Mon Sep 17 00:00:00 2001 From: ArenM Date: Fri, 5 Jun 2020 15:25:54 -0400 Subject: [PATCH 285/675] quectel: implement GPS support with +QGPS Quectel modems allow provide location information via AT commands. Add this as a location source. --- plugins/quectel/mm-broadband-modem-quectel.c | 29 +- plugins/quectel/mm-shared-quectel.c | 504 +++++++++++++++++++ plugins/quectel/mm-shared-quectel.h | 36 ++ 3 files changed, 567 insertions(+), 2 deletions(-) diff --git a/plugins/quectel/mm-broadband-modem-quectel.c b/plugins/quectel/mm-broadband-modem-quectel.c index 6dfa5bb7..b9fdaeb3 100644 --- a/plugins/quectel/mm-broadband-modem-quectel.c +++ b/plugins/quectel/mm-broadband-modem-quectel.c @@ -18,15 +18,20 @@ #include "mm-broadband-modem-quectel.h" #include "mm-shared-quectel.h" #include "mm-iface-modem-firmware.h" +#include "mm-iface-modem-location.h" -static void iface_modem_init (MMIfaceModem *iface); +static void iface_modem_init (MMIfaceModem *iface); static void shared_quectel_init (MMSharedQuectel *iface); static void iface_modem_firmware_init (MMIfaceModemFirmware *iface); +static void iface_modem_location_init (MMIfaceModemLocation *iface); + +static MMIfaceModemLocation *iface_modem_location_parent; G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQuectel, mm_broadband_modem_quectel, MM_TYPE_BROADBAND_MODEM, 0, G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init) - G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init)) + G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, iface_modem_location_init)) /*****************************************************************************/ @@ -65,9 +70,29 @@ iface_modem_init (MMIfaceModem *iface) iface->setup_sim_hot_swap_finish = mm_shared_quectel_setup_sim_hot_swap_finish; } +static MMIfaceModemLocation * +peek_parent_location_interface (MMSharedQuectel *self) +{ + return iface_modem_location_parent; +} + static void shared_quectel_init (MMSharedQuectel *iface) { + iface->peek_parent_location_interface = peek_parent_location_interface; +} + +static void +iface_modem_location_init(MMIfaceModemLocation *iface) +{ + iface_modem_location_parent = g_type_interface_peek_parent (iface); + + iface->load_capabilities = mm_shared_quectel_location_load_capabilities; + iface->load_capabilities_finish = mm_shared_quectel_location_load_capabilities_finish; + iface->enable_location_gathering = mm_shared_quectel_enable_location_gathering; + iface->enable_location_gathering_finish = mm_shared_quectel_enable_location_gathering_finish; + iface->disable_location_gathering = mm_shared_quectel_disable_location_gathering; + iface->disable_location_gathering_finish = mm_shared_quectel_disable_location_gathering_finish; } static void diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index 76107e79..bda7db06 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -22,7 +22,9 @@ #include #include "mm-log-object.h" +#include "mm-iface-modem.h" #include "mm-iface-modem-firmware.h" +#include "mm-iface-modem-location.h" #include "mm-base-modem.h" #include "mm-base-modem-at.h" #include "mm-shared-quectel.h" @@ -161,6 +163,508 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self, } /*****************************************************************************/ +/* Location State Variables */ + +#define PRIVATE_TAG "shared-quectel-private-tag" +static GQuark private_quark; + +static const gchar *gps_startup[] = { + "+QGPSCFG=\"outport\",\"usbnmea\"", + // TODO: "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data without the nmea port + + // perhaps these should be the highest value of everything that has nmea in it? + // TODO: it may be necessary to set "+QGPSCFG=\"gpsnmeatype\", however + // the correct value will very based on the modem, it may be enough to + + // TODO: is it possible to report a gps interval, + // or even better, allow users to set one? + "+QGPS=1", +}; + +static const int qgps_nmea_port_sources = ( + MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_NMEA); + +typedef struct { + MMModemLocationSource source; + unsigned long idx; + GError *command_error; +} LocationGatheringContext; + +typedef enum { + FEATURE_SUPPORT_UNKNOWN, + FEATURE_NOT_SUPPORTED, + FEATURE_SUPPORTED, +} FeatureSupport; + +typedef struct { + MMIfaceModemLocation *iface_modem_location_parent; + MMModemLocationSource provided_sources; + MMModemLocationSource enabled_sources; + FeatureSupport qgps_supported; +} Private; + +static LocationGatheringContext * +location_gathering_context_new (MMModemLocationSource source) +{ + LocationGatheringContext *ctx = g_new (LocationGatheringContext, 1); + ctx->source = source; + ctx->idx = 0; + ctx->command_error = NULL; + + return ctx; +} + +static Private * +get_private (MMSharedQuectel *self) +{ + Private *priv; + + if (G_UNLIKELY (!private_quark)) + private_quark = g_quark_from_static_string (PRIVATE_TAG); + + priv = g_object_get_qdata (G_OBJECT (self), private_quark); + if (!priv) { + priv = g_slice_new0 (Private); + + priv->provided_sources = MM_MODEM_LOCATION_SOURCE_NONE; + priv->enabled_sources = MM_MODEM_LOCATION_SOURCE_NONE; + priv->qgps_supported = FEATURE_SUPPORT_UNKNOWN; + + g_assert (MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_location_interface); + priv->iface_modem_location_parent = MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_location_interface (self); + + g_object_set_qdata (G_OBJECT (self), private_quark, priv); + } + return priv; +} + +/*****************************************************************************/ +/* Functions used to probe & report Location Support */ + +MMModemLocationSource +mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) +{ + GError *inner_error = NULL; + gssize value; + + value = g_task_propagate_int (G_TASK (res), &inner_error); + if (inner_error) { + g_propagate_error (error, inner_error); + return MM_MODEM_LOCATION_SOURCE_NONE; + } + return (MMModemLocationSource)value; +} + +static void +build_provided_location_sources (GTask *task) +{ + MMModemLocationSource parent_sources; + MMSharedQuectel *self; + Private *priv; + + parent_sources = GPOINTER_TO_UINT (g_task_get_task_data (task)); + self = MM_SHARED_QUECTEL (g_task_get_source_object (task)); + priv = get_private (self); + + /* Only enable any location sources the modem supports gps + * Then only report supporting a location source + * if it's not already supported by the parent location source */ + if (priv->qgps_supported == FEATURE_SUPPORTED) { + if (!(parent_sources & MM_MODEM_LOCATION_SOURCE_GPS_NMEA)) + priv->provided_sources |= MM_MODEM_LOCATION_SOURCE_GPS_NMEA; + if (!(parent_sources & MM_MODEM_LOCATION_SOURCE_GPS_RAW)) + priv->provided_sources |= MM_MODEM_LOCATION_SOURCE_GPS_RAW; + if (!(parent_sources & MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) + priv->provided_sources |= MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED; + } + + /* So we're done, complete */ + g_task_return_int (task, priv->provided_sources); + g_object_unref (task); +} + +static void +probe_qgps_ready (MMBaseModem *_self, + GAsyncResult *res, + GTask *task) +{ + MMSharedQuectel *self; + Private *priv; + GError *error = NULL; + + self = MM_SHARED_QUECTEL (g_task_get_source_object (task)); + priv = get_private (self); + + priv->qgps_supported = (!!mm_base_modem_at_command_full_finish (_self, res, &error) ? + FEATURE_SUPPORTED : FEATURE_NOT_SUPPORTED); + + build_provided_location_sources (task); +} + +static void +probe_qgps (GTask *task) +{ + MMSharedQuectel *self; + + self = MM_SHARED_QUECTEL (g_task_get_source_object (task)); + + mm_base_modem_at_command (MM_BASE_MODEM (self), + "+QGPS?", + 3, + FALSE, /* not cached */ + (GAsyncReadyCallback)probe_qgps_ready, + task); +} + +static void +parent_load_capabilities_ready (MMIfaceModemLocation *self, + GAsyncResult *res, + GTask *task) +{ + Private *priv; + MMModemLocationSource sources; + GError *error = NULL; + + priv = get_private (MM_SHARED_QUECTEL (self)); + sources = priv->iface_modem_location_parent->load_capabilities_finish (self, res, &error); + if (error) { + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + g_task_set_task_data (task, GUINT_TO_POINTER (sources), NULL); + + if (priv->qgps_supported == FEATURE_SUPPORT_UNKNOWN) + probe_qgps (task); + else + build_provided_location_sources (task); +} + +void +mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *_self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + Private *priv; + + task = g_task_new (_self, NULL, callback, user_data); + priv = get_private (MM_SHARED_QUECTEL (_self)); + + /* Chain up parent's setup */ + priv->iface_modem_location_parent->load_capabilities (_self, + (GAsyncReadyCallback)parent_load_capabilities_ready, + task); +} + +/*****************************************************************************/ +/* Functions used to Enable Location */ + +static void qgps_enable_loop (MMBaseModem *self, GTask *task); + +gboolean +mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +qgps_check_enabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) +{ + const gchar *response; + GError *error = NULL; + LocationGatheringContext *ctx = g_task_get_task_data (task); + + response = mm_base_modem_at_command_finish (self, res, &error); + + if (!response) + g_task_return_error (task, error); + else if (!g_str_equal (mm_strip_tag (response, "+QGPS:"), "1")) + g_task_return_error (task, ctx->command_error); + else { + // TODO: Do I need to free ctx->command_error? + ctx->command_error = NULL; + qgps_enable_loop (self, task); + return; + } + g_object_unref (task); +} + +static void +qgps_enable_command_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) +{ + LocationGatheringContext *ctx = g_task_get_task_data (task); + GError *error = NULL; + + if (!mm_base_modem_at_command_full_finish (self, res, &error)) { + ctx->command_error = error; + } + + qgps_enable_loop (self, task); +} + +static void +qgps_enable_loop (MMBaseModem *self, GTask *task) +{ + MMPortSerialGps *gps_port; + LocationGatheringContext *ctx = g_task_get_task_data (task); + GError *error = NULL; + + /* If there are more commands run them, then return */ + if (ctx->idx < G_N_ELEMENTS (gps_startup)) { + mm_base_modem_at_command_full (MM_BASE_MODEM (self), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), + gps_startup[ctx->idx], + 3, + FALSE, + FALSE, /* raw */ + NULL, /* cancellable */ + (GAsyncReadyCallback)qgps_enable_command_ready, + task); + ctx->idx++; + return; + } + + if (ctx->command_error != NULL) { + mm_base_modem_at_command (self, + "+QGPS?", + 3, // timeout + FALSE, // not cached + (GAsyncReadyCallback)qgps_check_enabled_ready, + task); + return; + } + + // TODO: The NMEA port isn't necessary to get NMEA data, use +QGPSNMEA to retrive data + /* Last run Only: Check if the nmea/raw gps port + * exists and is available Otherwise throw an error */ + if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { + gps_port = mm_base_modem_peek_port_gps (self); + if (!gps_port || + !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) { + if (error) + g_task_return_error (task, error); + else + g_task_return_new_error (task, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't open raw GPS serial port"); + } else + g_task_return_boolean (task, TRUE); + } else + g_task_return_boolean (task, TRUE); + + g_object_unref (task); +} + +static void +parent_enable_location_gathering_ready (MMIfaceModemLocation *self, + GAsyncResult *res, + GTask *task) +{ + GError *error; + Private *priv; + + priv = get_private (MM_SHARED_QUECTEL (self)); + + g_assert (priv->iface_modem_location_parent); + if (!priv->iface_modem_location_parent-> + enable_location_gathering_finish (self, res, &error)) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +void +mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data) +{ + LocationGatheringContext *ctx; + GTask *task; + Private *priv; + gboolean start_gps = FALSE; + + priv = get_private (MM_SHARED_QUECTEL (self)); + task = g_task_new (self, NULL, callback, user_data); + + /* If the parent can enable the modem let it */ + if (!(priv->provided_sources& source)) { + if (priv->iface_modem_location_parent->enable_location_gathering && + priv->iface_modem_location_parent->enable_location_gathering_finish) { + g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL); + priv->iface_modem_location_parent->enable_location_gathering ( + self, + source, + (GAsyncReadyCallback)parent_enable_location_gathering_ready, + task); + return; + } + + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + + ctx = location_gathering_context_new (source); + g_task_set_task_data (task, ctx, g_free); + + // NMEA and UNMANAGED are both enabled in the same way + if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { + if (priv->enabled_sources == MM_MODEM_LOCATION_SOURCE_NONE) + start_gps = TRUE; + + priv->enabled_sources |= ctx->source; + } + + if (start_gps) { + qgps_enable_loop (MM_BASE_MODEM (self), task); + return; + } + + /* For any other location (e.g. 3GPP), or if the GPS is already running just return */ + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +/*****************************************************************************/ +/* Functions used to Disable Location */ + +gboolean +mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +qgps_check_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) +{ + const gchar *response; + GError *error = NULL; + + /* Something is very wrong if we can't query the + * state of gps while we're disabling the gps */ + // TODO: could it make sense to report success? + // if the modem won't tell us what the state of the gps is, + // and modem manager should prbably treat it as disabled right? + response = mm_base_modem_at_command_finish (self, res, &error); + if (!response) { + g_assert_not_reached (); + g_task_return_error (task, error); + } else if (!g_str_equal (mm_strip_tag (response, "+QGPS:"), "0")) + g_task_return_new_error (task, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Modem did not turn off"); + else + g_task_return_boolean (task, TRUE); + + g_object_unref (task); +} + +static void +qgps_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) +{ + GError *error = NULL; + + if (!mm_base_modem_at_command_full_finish (self, res, &error)) { + mm_base_modem_at_command (self, + "+QGPS?", + 3, // timeout + FALSE, // not cached + (GAsyncReadyCallback)qgps_check_disabled_ready, + task); + return; + } + + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +disable_location_gathering_parent_ready (MMIfaceModemLocation *self, + GAsyncResult *res, + GTask *task) +{ + GError *error; + Private *priv = get_private (MM_SHARED_QUECTEL (self)); + + g_assert (priv->iface_modem_location_parent); + if (!priv->iface_modem_location_parent-> + disable_location_gathering_finish (self, res, &error)) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +void +mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + MMPortSerialGps *gps_port; + Private *priv = get_private (MM_SHARED_QUECTEL (self)); + + task = g_task_new (self, NULL, callback, user_data); + priv->enabled_sources &= ~source; + + /* Pass handling to parent if we don't handle it */ + if (!(source & priv->provided_sources) && + priv->iface_modem_location_parent->disable_location_gathering && + priv->iface_modem_location_parent->disable_location_gathering_finish) { + // TODO: Is there anything I can do about this long line? + priv->iface_modem_location_parent-> + disable_location_gathering (self, + source, + (GAsyncReadyCallback)disable_location_gathering_parent_ready, + user_data); + return; + } + + /* Close the nmea port if we don't need it anymore */ + if (source & qgps_nmea_port_sources && + !(priv->enabled_sources & qgps_nmea_port_sources)) { + gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self)); + if (gps_port) + mm_port_serial_close (MM_PORT_SERIAL (gps_port)); + } + + /* Turn off gps on the modem if the source uses gps, + * and there are no other gps sources enabled */ + if ((source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) && + priv->enabled_sources == MM_MODEM_LOCATION_SOURCE_NONE) { + mm_base_modem_at_command_full (MM_BASE_MODEM (self), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), + "+QGPSEND", + 3, + FALSE, + FALSE, /* raw */ + NULL, /* cancellable */ + (GAsyncReadyCallback)qgps_disabled_ready, + task); + return; + } + + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} static void shared_quectel_init (gpointer g_iface) diff --git a/plugins/quectel/mm-shared-quectel.h b/plugins/quectel/mm-shared-quectel.h index 22ee8bee..a019bdf7 100644 --- a/plugins/quectel/mm-shared-quectel.h +++ b/plugins/quectel/mm-shared-quectel.h @@ -25,6 +25,7 @@ #include "mm-broadband-modem.h" #include "mm-iface-modem.h" #include "mm-iface-modem-firmware.h" +#include "mm-iface-modem-location.h" #define MM_TYPE_SHARED_QUECTEL (mm_shared_quectel_get_type ()) #define MM_SHARED_QUECTEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_SHARED_QUECTEL, MMSharedQuectel)) @@ -35,6 +36,7 @@ typedef struct _MMSharedQuectel MMSharedQuectel; struct _MMSharedQuectel { GTypeInterface g_iface; + MMIfaceModemLocation * (* peek_parent_location_interface) (MMSharedQuectel *self); }; GType mm_shared_quectel_get_type (void); @@ -42,14 +44,48 @@ GType mm_shared_quectel_get_type (void); void mm_shared_quectel_firmware_load_update_settings (MMIfaceModemFirmware *self, GAsyncReadyCallback callback, gpointer user_data); + MMFirmwareUpdateSettings *mm_shared_quectel_firmware_load_update_settings_finish (MMIfaceModemFirmware *self, GAsyncResult *res, GError **error); + void mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data); + gboolean mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self, GAsyncResult *res, GError **error); +void +mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *self, + GAsyncReadyCallback callback, + gpointer user_data); + +MMModemLocationSource +mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error); + +void +mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean +mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error); + +void +mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *_self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean +mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error); #endif /* MM_SHARED_QUECTEL_H */ From 5a9d321346df5e964780def158072df794c604dd Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 10:35:57 +0200 Subject: [PATCH 286/675] quectel,shared: fix parent location disabling The GTask must be passed as user_data. --- plugins/quectel/mm-shared-quectel.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index bda7db06..c53b4660 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -627,12 +627,10 @@ mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self, if (!(source & priv->provided_sources) && priv->iface_modem_location_parent->disable_location_gathering && priv->iface_modem_location_parent->disable_location_gathering_finish) { - // TODO: Is there anything I can do about this long line? - priv->iface_modem_location_parent-> - disable_location_gathering (self, - source, - (GAsyncReadyCallback)disable_location_gathering_parent_ready, - user_data); + priv->iface_modem_location_parent->disable_location_gathering (self, + source, + (GAsyncReadyCallback)disable_location_gathering_parent_ready, + task); return; } From 234ba4544b324765a3ba9f7d468715378c585106 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 10:53:33 +0200 Subject: [PATCH 287/675] quectel: coding style fixes in the QGPS logic --- plugins/quectel/mm-broadband-modem-quectel.c | 38 ++-- plugins/quectel/mm-shared-quectel.c | 203 ++++++++++--------- plugins/quectel/mm-shared-quectel.h | 50 ++--- 3 files changed, 149 insertions(+), 142 deletions(-) diff --git a/plugins/quectel/mm-broadband-modem-quectel.c b/plugins/quectel/mm-broadband-modem-quectel.c index b9fdaeb3..4fdfdfcf 100644 --- a/plugins/quectel/mm-broadband-modem-quectel.c +++ b/plugins/quectel/mm-broadband-modem-quectel.c @@ -21,17 +21,17 @@ #include "mm-iface-modem-location.h" static void iface_modem_init (MMIfaceModem *iface); -static void shared_quectel_init (MMSharedQuectel *iface); static void iface_modem_firmware_init (MMIfaceModemFirmware *iface); static void iface_modem_location_init (MMIfaceModemLocation *iface); +static void shared_quectel_init (MMSharedQuectel *iface); static MMIfaceModemLocation *iface_modem_location_parent; G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQuectel, mm_broadband_modem_quectel, MM_TYPE_BROADBAND_MODEM, 0, G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init) - G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init) - G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, iface_modem_location_init)) + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, iface_modem_location_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init)) /*****************************************************************************/ @@ -51,13 +51,6 @@ mm_broadband_modem_quectel_new (const gchar *device, NULL); } -static void -iface_modem_firmware_init (MMIfaceModemFirmware *iface) -{ - iface->load_update_settings = mm_shared_quectel_firmware_load_update_settings; - iface->load_update_settings_finish = mm_shared_quectel_firmware_load_update_settings_finish; -} - static void mm_broadband_modem_quectel_init (MMBroadbandModemQuectel *self) { @@ -70,20 +63,15 @@ iface_modem_init (MMIfaceModem *iface) iface->setup_sim_hot_swap_finish = mm_shared_quectel_setup_sim_hot_swap_finish; } -static MMIfaceModemLocation * -peek_parent_location_interface (MMSharedQuectel *self) -{ - return iface_modem_location_parent; -} - static void -shared_quectel_init (MMSharedQuectel *iface) +iface_modem_firmware_init (MMIfaceModemFirmware *iface) { - iface->peek_parent_location_interface = peek_parent_location_interface; + iface->load_update_settings = mm_shared_quectel_firmware_load_update_settings; + iface->load_update_settings_finish = mm_shared_quectel_firmware_load_update_settings_finish; } static void -iface_modem_location_init(MMIfaceModemLocation *iface) +iface_modem_location_init (MMIfaceModemLocation *iface) { iface_modem_location_parent = g_type_interface_peek_parent (iface); @@ -95,6 +83,18 @@ iface_modem_location_init(MMIfaceModemLocation *iface) iface->disable_location_gathering_finish = mm_shared_quectel_disable_location_gathering_finish; } +static MMIfaceModemLocation * +peek_parent_location_interface (MMSharedQuectel *self) +{ + return iface_modem_location_parent; +} + +static void +shared_quectel_init (MMSharedQuectel *iface) +{ + iface->peek_parent_location_interface = peek_parent_location_interface; +} + static void mm_broadband_modem_quectel_class_init (MMBroadbandModemQuectelClass *klass) { diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index c53b4660..fae9805e 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -169,15 +169,12 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self, static GQuark private_quark; static const gchar *gps_startup[] = { + /* NOTES: + * 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data + * without the nmea port. + * 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\". + */ "+QGPSCFG=\"outport\",\"usbnmea\"", - // TODO: "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data without the nmea port - - // perhaps these should be the highest value of everything that has nmea in it? - // TODO: it may be necessary to set "+QGPSCFG=\"gpsnmeatype\", however - // the correct value will very based on the modem, it may be enough to - - // TODO: is it possible to report a gps interval, - // or even better, allow users to set one? "+QGPS=1", }; @@ -203,14 +200,20 @@ typedef struct { FeatureSupport qgps_supported; } Private; +static void +location_gathering_context_free (LocationGatheringContext *ctx) +{ + g_clear_error (&ctx->command_error); + g_slice_free (LocationGatheringContext, ctx); +} + static LocationGatheringContext * location_gathering_context_new (MMModemLocationSource source) { - LocationGatheringContext *ctx = g_new (LocationGatheringContext, 1); - ctx->source = source; - ctx->idx = 0; - ctx->command_error = NULL; + LocationGatheringContext *ctx; + ctx = g_slice_new0 (LocationGatheringContext); + ctx->source = source; return ctx; } @@ -239,15 +242,15 @@ get_private (MMSharedQuectel *self) } /*****************************************************************************/ -/* Functions used to probe & report Location Support */ +/* Location capabilities loading (Location interface) */ MMModemLocationSource -mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self, - GAsyncResult *res, - GError **error) +mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) { GError *inner_error = NULL; - gssize value; + gssize value; value = g_task_propagate_int (G_TASK (res), &inner_error); if (inner_error) { @@ -260,9 +263,9 @@ mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self, static void build_provided_location_sources (GTask *task) { - MMModemLocationSource parent_sources; - MMSharedQuectel *self; - Private *priv; + MMModemLocationSource parent_sources; + MMSharedQuectel *self; + Private *priv; parent_sources = GPOINTER_TO_UINT (g_task_get_task_data (task)); self = MM_SHARED_QUECTEL (g_task_get_source_object (task)); @@ -286,13 +289,13 @@ build_provided_location_sources (GTask *task) } static void -probe_qgps_ready (MMBaseModem *_self, +probe_qgps_ready (MMBaseModem *_self, GAsyncResult *res, - GTask *task) + GTask *task) { MMSharedQuectel *self; - Private *priv; - GError *error = NULL; + Private *priv; + GError *error = NULL; self = MM_SHARED_QUECTEL (g_task_get_source_object (task)); priv = get_private (self); @@ -320,12 +323,12 @@ probe_qgps (GTask *task) static void parent_load_capabilities_ready (MMIfaceModemLocation *self, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { - Private *priv; - MMModemLocationSource sources; - GError *error = NULL; + Private *priv; + MMModemLocationSource sources; + GError *error = NULL; priv = get_private (MM_SHARED_QUECTEL (self)); sources = priv->iface_modem_location_parent->load_capabilities_finish (self, res, &error); @@ -337,18 +340,20 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self, g_task_set_task_data (task, GUINT_TO_POINTER (sources), NULL); - if (priv->qgps_supported == FEATURE_SUPPORT_UNKNOWN) + if (priv->qgps_supported == FEATURE_SUPPORT_UNKNOWN) { probe_qgps (task); - else - build_provided_location_sources (task); + return; + } + + build_provided_location_sources (task); } void mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *_self, - GAsyncReadyCallback callback, - gpointer user_data) + GAsyncReadyCallback callback, + gpointer user_data) { - GTask *task; + GTask *task; Private *priv; task = g_task_new (_self, NULL, callback, user_data); @@ -356,29 +361,34 @@ mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *_self, /* Chain up parent's setup */ priv->iface_modem_location_parent->load_capabilities (_self, - (GAsyncReadyCallback)parent_load_capabilities_ready, - task); + (GAsyncReadyCallback)parent_load_capabilities_ready, + task); } /*****************************************************************************/ /* Functions used to Enable Location */ -static void qgps_enable_loop (MMBaseModem *self, GTask *task); +static void qgps_enable_loop (MMBaseModem *self, + GTask *task); gboolean -mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, - GAsyncResult *res, - GError **error) +mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } static void -qgps_check_enabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) +qgps_check_enabled_ready (MMBaseModem *self, + GAsyncResult *res, + GTask *task) { - const gchar *response; - GError *error = NULL; - LocationGatheringContext *ctx = g_task_get_task_data (task); + const gchar *response; + GError *error = NULL; + LocationGatheringContext *ctx; + + ctx = g_task_get_task_data (task); response = mm_base_modem_at_command_finish (self, res, &error); @@ -387,8 +397,6 @@ qgps_check_enabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) else if (!g_str_equal (mm_strip_tag (response, "+QGPS:"), "1")) g_task_return_error (task, ctx->command_error); else { - // TODO: Do I need to free ctx->command_error? - ctx->command_error = NULL; qgps_enable_loop (self, task); return; } @@ -396,25 +404,31 @@ qgps_check_enabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) } static void -qgps_enable_command_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) +qgps_enable_command_ready (MMBaseModem *self, + GAsyncResult *res, + GTask *task) { - LocationGatheringContext *ctx = g_task_get_task_data (task); - GError *error = NULL; + LocationGatheringContext *ctx; + GError *error = NULL; - if (!mm_base_modem_at_command_full_finish (self, res, &error)) { + ctx = g_task_get_task_data (task); + + if (!mm_base_modem_at_command_full_finish (self, res, &error)) ctx->command_error = error; - } qgps_enable_loop (self, task); } static void -qgps_enable_loop (MMBaseModem *self, GTask *task) +qgps_enable_loop (MMBaseModem *self, + GTask *task) { - MMPortSerialGps *gps_port; - LocationGatheringContext *ctx = g_task_get_task_data (task); - GError *error = NULL; - + MMPortSerialGps *gps_port; + LocationGatheringContext *ctx; + GError *error = NULL; + + ctx = g_task_get_task_data (task); + /* If there are more commands run them, then return */ if (ctx->idx < G_N_ELEMENTS (gps_startup)) { mm_base_modem_at_command_full (MM_BASE_MODEM (self), @@ -433,21 +447,19 @@ qgps_enable_loop (MMBaseModem *self, GTask *task) if (ctx->command_error != NULL) { mm_base_modem_at_command (self, "+QGPS?", - 3, // timeout - FALSE, // not cached + 3, + FALSE, (GAsyncReadyCallback)qgps_check_enabled_ready, task); return; } - // TODO: The NMEA port isn't necessary to get NMEA data, use +QGPSNMEA to retrive data /* Last run Only: Check if the nmea/raw gps port * exists and is available Otherwise throw an error */ if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { gps_port = mm_base_modem_peek_port_gps (self); - if (!gps_port || - !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) { + if (!gps_port || !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) { if (error) g_task_return_error (task, error); else @@ -465,8 +477,8 @@ qgps_enable_loop (MMBaseModem *self, GTask *task) static void parent_enable_location_gathering_ready (MMIfaceModemLocation *self, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { GError *error; Private *priv; @@ -474,8 +486,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self, priv = get_private (MM_SHARED_QUECTEL (self)); g_assert (priv->iface_modem_location_parent); - if (!priv->iface_modem_location_parent-> - enable_location_gathering_finish (self, res, &error)) + if (!priv->iface_modem_location_parent->enable_location_gathering_finish (self, res, &error)) g_task_return_error (task, error); else g_task_return_boolean (task, TRUE); @@ -483,15 +494,15 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self, } void -mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, - MMModemLocationSource source, - GAsyncReadyCallback callback, - gpointer user_data) +mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data) { LocationGatheringContext *ctx; - GTask *task; - Private *priv; - gboolean start_gps = FALSE; + GTask *task; + Private *priv; + gboolean start_gps = FALSE; priv = get_private (MM_SHARED_QUECTEL (self)); task = g_task_new (self, NULL, callback, user_data); @@ -515,9 +526,9 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, } ctx = location_gathering_context_new (source); - g_task_set_task_data (task, ctx, g_free); + g_task_set_task_data (task, ctx, (GDestroyNotify) location_gathering_context_free); - // NMEA and UNMANAGED are both enabled in the same way + /* NMEA and UNMANAGED are both enabled in the same way */ if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { @@ -541,15 +552,17 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, /* Functions used to Disable Location */ gboolean -mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self, - GAsyncResult *res, - GError **error) +mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } static void -qgps_check_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) +qgps_check_disabled_ready (MMBaseModem *self, + GAsyncResult *res, + GTask *task) { const gchar *response; GError *error = NULL; @@ -575,15 +588,17 @@ qgps_check_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) } static void -qgps_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) +qgps_end_ready (MMBaseModem *self, + GAsyncResult *res, + GTask *task) { GError *error = NULL; if (!mm_base_modem_at_command_full_finish (self, res, &error)) { mm_base_modem_at_command (self, "+QGPS?", - 3, // timeout - FALSE, // not cached + 3, + FALSE, (GAsyncReadyCallback)qgps_check_disabled_ready, task); return; @@ -595,15 +610,16 @@ qgps_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) static void disable_location_gathering_parent_ready (MMIfaceModemLocation *self, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { GError *error; - Private *priv = get_private (MM_SHARED_QUECTEL (self)); + Private *priv; + + priv = get_private (MM_SHARED_QUECTEL (self)); g_assert (priv->iface_modem_location_parent); - if (!priv->iface_modem_location_parent-> - disable_location_gathering_finish (self, res, &error)) + if (!priv->iface_modem_location_parent->disable_location_gathering_finish (self, res, &error)) g_task_return_error (task, error); else g_task_return_boolean (task, TRUE); @@ -611,15 +627,16 @@ disable_location_gathering_parent_ready (MMIfaceModemLocation *self, } void -mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self, - MMModemLocationSource source, - GAsyncReadyCallback callback, - gpointer user_data) +mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data) { GTask *task; MMPortSerialGps *gps_port; - Private *priv = get_private (MM_SHARED_QUECTEL (self)); + Private *priv; + priv = get_private (MM_SHARED_QUECTEL (self)); task = g_task_new (self, NULL, callback, user_data); priv->enabled_sources &= ~source; @@ -655,7 +672,7 @@ mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self, FALSE, FALSE, /* raw */ NULL, /* cancellable */ - (GAsyncReadyCallback)qgps_disabled_ready, + (GAsyncReadyCallback)qgps_end_ready, task); return; } diff --git a/plugins/quectel/mm-shared-quectel.h b/plugins/quectel/mm-shared-quectel.h index a019bdf7..e628b22c 100644 --- a/plugins/quectel/mm-shared-quectel.h +++ b/plugins/quectel/mm-shared-quectel.h @@ -57,35 +57,25 @@ gboolean mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceMo GAsyncResult *res, GError **error); -void -mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *self, - GAsyncReadyCallback callback, - gpointer user_data); +void mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *self, + GAsyncReadyCallback callback, + gpointer user_data); +MMModemLocationSource mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error); +void mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error); +void mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error); -MMModemLocationSource -mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self, - GAsyncResult *res, - GError **error); - -void -mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, - MMModemLocationSource source, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean -mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, - GAsyncResult *res, - GError **error); - -void -mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *_self, - MMModemLocationSource source, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean -mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self, - GAsyncResult *res, - GError **error); #endif /* MM_SHARED_QUECTEL_H */ From 0f9d69fd355a05b51b8367fa75dbd49440a9bd7e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 10:55:15 +0200 Subject: [PATCH 288/675] quectel,shared: private context at beginning of source file --- plugins/quectel/mm-shared-quectel.c | 83 +++++++++++++++-------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index fae9805e..c6b3c1d2 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -29,6 +29,49 @@ #include "mm-base-modem-at.h" #include "mm-shared-quectel.h" +/*****************************************************************************/ +/* Private context */ + +#define PRIVATE_TAG "shared-quectel-private-tag" +static GQuark private_quark; + +typedef enum { + FEATURE_SUPPORT_UNKNOWN, + FEATURE_NOT_SUPPORTED, + FEATURE_SUPPORTED, +} FeatureSupport; + +typedef struct { + MMIfaceModemLocation *iface_modem_location_parent; + MMModemLocationSource provided_sources; + MMModemLocationSource enabled_sources; + FeatureSupport qgps_supported; +} Private; + +static Private * +get_private (MMSharedQuectel *self) +{ + Private *priv; + + if (G_UNLIKELY (!private_quark)) + private_quark = g_quark_from_static_string (PRIVATE_TAG); + + priv = g_object_get_qdata (G_OBJECT (self), private_quark); + if (!priv) { + priv = g_slice_new0 (Private); + + priv->provided_sources = MM_MODEM_LOCATION_SOURCE_NONE; + priv->enabled_sources = MM_MODEM_LOCATION_SOURCE_NONE; + priv->qgps_supported = FEATURE_SUPPORT_UNKNOWN; + + g_assert (MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_location_interface); + priv->iface_modem_location_parent = MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_location_interface (self); + + g_object_set_qdata (G_OBJECT (self), private_quark, priv); + } + return priv; +} + /*****************************************************************************/ /* Firmware update settings loading (Firmware interface) */ @@ -165,9 +208,6 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self, /*****************************************************************************/ /* Location State Variables */ -#define PRIVATE_TAG "shared-quectel-private-tag" -static GQuark private_quark; - static const gchar *gps_startup[] = { /* NOTES: * 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data @@ -187,19 +227,6 @@ typedef struct { GError *command_error; } LocationGatheringContext; -typedef enum { - FEATURE_SUPPORT_UNKNOWN, - FEATURE_NOT_SUPPORTED, - FEATURE_SUPPORTED, -} FeatureSupport; - -typedef struct { - MMIfaceModemLocation *iface_modem_location_parent; - MMModemLocationSource provided_sources; - MMModemLocationSource enabled_sources; - FeatureSupport qgps_supported; -} Private; - static void location_gathering_context_free (LocationGatheringContext *ctx) { @@ -217,30 +244,6 @@ location_gathering_context_new (MMModemLocationSource source) return ctx; } -static Private * -get_private (MMSharedQuectel *self) -{ - Private *priv; - - if (G_UNLIKELY (!private_quark)) - private_quark = g_quark_from_static_string (PRIVATE_TAG); - - priv = g_object_get_qdata (G_OBJECT (self), private_quark); - if (!priv) { - priv = g_slice_new0 (Private); - - priv->provided_sources = MM_MODEM_LOCATION_SOURCE_NONE; - priv->enabled_sources = MM_MODEM_LOCATION_SOURCE_NONE; - priv->qgps_supported = FEATURE_SUPPORT_UNKNOWN; - - g_assert (MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_location_interface); - priv->iface_modem_location_parent = MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_location_interface (self); - - g_object_set_qdata (G_OBJECT (self), private_quark, priv); - } - return priv; -} - /*****************************************************************************/ /* Location capabilities loading (Location interface) */ From 77f6637750362a8c319e2debc6f781ceb217675a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 11:04:20 +0200 Subject: [PATCH 289/675] quectel,shared: fix reporting supported location capabilities The method that reports what location capabilities are supported must report the capabilities provided by the parent interface plus the additional capabilities supported by the shared implementation. Also, simplify the logic a bit reducing the amount of implemented methods. --- plugins/quectel/mm-shared-quectel.c | 78 +++++++++++------------------ 1 file changed, 29 insertions(+), 49 deletions(-) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index c6b3c1d2..2d3a0d72 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -264,66 +264,43 @@ mm_shared_quectel_location_load_capabilities_finish (MMIfaceModemLocation *self } static void -build_provided_location_sources (GTask *task) +probe_qgps_ready (MMBaseModem *_self, + GAsyncResult *res, + GTask *task) { - MMModemLocationSource parent_sources; MMSharedQuectel *self; Private *priv; + MMModemLocationSource sources; - parent_sources = GPOINTER_TO_UINT (g_task_get_task_data (task)); self = MM_SHARED_QUECTEL (g_task_get_source_object (task)); priv = get_private (self); - /* Only enable any location sources the modem supports gps - * Then only report supporting a location source - * if it's not already supported by the parent location source */ + priv->qgps_supported = (!!mm_base_modem_at_command_finish (_self, res, NULL) ? + FEATURE_SUPPORTED : FEATURE_NOT_SUPPORTED); + + mm_obj_dbg (self, "GPS management with +QGPS is %ssupported", + priv->qgps_supported ? "" : "not "); + + /* Recover parent sources */ + sources = GPOINTER_TO_UINT (g_task_get_task_data (task)); + + /* Only flag as provided those sources not already provided by the parent */ if (priv->qgps_supported == FEATURE_SUPPORTED) { - if (!(parent_sources & MM_MODEM_LOCATION_SOURCE_GPS_NMEA)) + if (!(sources & MM_MODEM_LOCATION_SOURCE_GPS_NMEA)) priv->provided_sources |= MM_MODEM_LOCATION_SOURCE_GPS_NMEA; - if (!(parent_sources & MM_MODEM_LOCATION_SOURCE_GPS_RAW)) + if (!(sources & MM_MODEM_LOCATION_SOURCE_GPS_RAW)) priv->provided_sources |= MM_MODEM_LOCATION_SOURCE_GPS_RAW; - if (!(parent_sources & MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) + if (!(sources & MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) priv->provided_sources |= MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED; + + sources |= priv->provided_sources; } /* So we're done, complete */ - g_task_return_int (task, priv->provided_sources); + g_task_return_int (task, sources); g_object_unref (task); } -static void -probe_qgps_ready (MMBaseModem *_self, - GAsyncResult *res, - GTask *task) -{ - MMSharedQuectel *self; - Private *priv; - GError *error = NULL; - - self = MM_SHARED_QUECTEL (g_task_get_source_object (task)); - priv = get_private (self); - - priv->qgps_supported = (!!mm_base_modem_at_command_full_finish (_self, res, &error) ? - FEATURE_SUPPORTED : FEATURE_NOT_SUPPORTED); - - build_provided_location_sources (task); -} - -static void -probe_qgps (GTask *task) -{ - MMSharedQuectel *self; - - self = MM_SHARED_QUECTEL (g_task_get_source_object (task)); - - mm_base_modem_at_command (MM_BASE_MODEM (self), - "+QGPS?", - 3, - FALSE, /* not cached */ - (GAsyncReadyCallback)probe_qgps_ready, - task); -} - static void parent_load_capabilities_ready (MMIfaceModemLocation *self, GAsyncResult *res, @@ -341,14 +318,17 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self, return; } + /* Store parent supported sources in task data */ g_task_set_task_data (task, GUINT_TO_POINTER (sources), NULL); - if (priv->qgps_supported == FEATURE_SUPPORT_UNKNOWN) { - probe_qgps (task); - return; - } - - build_provided_location_sources (task); + /* Probe QGPS support */ + g_assert (priv->qgps_supported == FEATURE_SUPPORT_UNKNOWN); + mm_base_modem_at_command (MM_BASE_MODEM (self), + "+QGPS?", + 3, + FALSE, /* not cached */ + (GAsyncReadyCallback)probe_qgps_ready, + task); } void From 538ed3f24e9ec5d64abc1543476e5ee34b504455 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 11:06:06 +0200 Subject: [PATCH 290/675] quectel,shared: don't report GPS capabilities if no GPS port found The QGPS based implementation needs the existence of a port flagged as GPS data; if there is no such port, we cannot provide GPS support. --- plugins/quectel/mm-shared-quectel.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index 2d3a0d72..2bdc7d78 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -318,6 +318,14 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self, return; } + /* Now our own check. If we don't have any GPS port, we're done */ + if (!mm_base_modem_peek_port_gps (MM_BASE_MODEM (self))) { + mm_obj_dbg (self, "no GPS data port found: no GPS capabilities"); + g_task_return_int (task, sources); + g_object_unref (task); + return; + } + /* Store parent supported sources in task data */ g_task_set_task_data (task, GUINT_TO_POINTER (sources), NULL); From bbfc10d7c5246b120e71143f59e1ea66e052a018 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 11:38:48 +0200 Subject: [PATCH 291/675] huawei: minor refactor in GPS enabling/disabling logic --- plugins/huawei/mm-broadband-modem-huawei.c | 131 ++++++++++----------- 1 file changed, 65 insertions(+), 66 deletions(-) diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index 82e439e1..998f6e06 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -3875,36 +3875,35 @@ location_load_capabilities (MMIfaceModemLocation *self, typedef struct { MMModemLocationSource source; - int idx; + guint idx; } LocationGatheringContext; /******************************/ /* Disable location gathering */ static gboolean -disable_location_gathering_finish (MMIfaceModemLocation *self, - GAsyncResult *res, - GError **error) +disable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } static void -gps_disabled_ready (MMBaseModem *self, +gps_disabled_ready (MMBaseModem *self, GAsyncResult *res, - GTask *task) + GTask *task) { LocationGatheringContext *ctx; - MMPortSerialGps *gps_port; - GError *error = NULL; + MMPortSerialGps *gps_port; + GError *error = NULL; ctx = g_task_get_task_data (task); mm_base_modem_at_command_full_finish (self, res, &error); /* Only use the GPS port in NMEA/RAW setups */ - if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { + if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { /* Even if we get an error here, we try to close the GPS port */ gps_port = mm_base_modem_peek_port_gps (self); if (gps_port) @@ -3919,15 +3918,15 @@ gps_disabled_ready (MMBaseModem *self, } static void -disable_location_gathering (MMIfaceModemLocation *_self, - MMModemLocationSource source, - GAsyncReadyCallback callback, - gpointer user_data) +disable_location_gathering (MMIfaceModemLocation *_self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data) { - MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); - gboolean stop_gps = FALSE; + MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); + gboolean stop_gps = FALSE; LocationGatheringContext *ctx; - GTask *task; + GTask *task; ctx = g_new (LocationGatheringContext, 1); ctx->source = source; @@ -3968,58 +3967,66 @@ disable_location_gathering (MMIfaceModemLocation *_self, /*****************************************************************************/ /* Enable location gathering (Location interface) */ -static gboolean -enable_location_gathering_finish (MMIfaceModemLocation *self, - GAsyncResult *res, - GError **error) -{ - return g_task_propagate_boolean (G_TASK (res), error); -} - static const gchar *gps_startup[] = { "^WPDOM=0", "^WPDST=1", "^WPDFR=65535,30", "^WPDGP", - NULL }; +static gboolean +enable_location_gathering_finish (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void run_gps_startup (GTask *task); + static void -gps_enabled_ready (MMBaseModem *self, - GAsyncResult *res, - GTask *task) +gps_startup_command_ready (MMBaseModem *self, + GAsyncResult *res, + GTask *task) { - LocationGatheringContext *ctx; GError *error = NULL; - MMPortSerialGps *gps_port; - ctx = g_task_get_task_data (task); - - if (!mm_base_modem_at_command_full_finish (self, res, &error)) { - ctx->idx = 0; + if (!mm_base_modem_at_command_finish (self, res, &error)) { g_task_return_error (task, error); g_object_unref (task); return; } - /* ctx->idx++; make sure ctx->idx is a valid command */ - if (gps_startup[ctx->idx++] && gps_startup[ctx->idx]) { - mm_base_modem_at_command_full (MM_BASE_MODEM (self), - mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), - gps_startup[ctx->idx], - 3, - FALSE, - FALSE, /* raw */ - NULL, /* cancellable */ - (GAsyncReadyCallback)gps_enabled_ready, - task); + /* continue with next command */ + run_gps_startup (task); +} + +static void +run_gps_startup (GTask *task) +{ + MMBroadbandModemHuawei *self; + LocationGatheringContext *ctx; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + + if (ctx->idx < G_N_ELEMENTS (gps_startup)) { + mm_base_modem_at_command (MM_BASE_MODEM (self), + gps_startup[ctx->idx++], + 3, + FALSE, + (GAsyncReadyCallback)gps_startup_command_ready, + task); return; } /* Only use the GPS port in NMEA/RAW setups */ if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { - gps_port = mm_base_modem_peek_port_gps (self); + GError *error = NULL; + MMPortSerialGps *gps_port; + + gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self)); if (!gps_port || !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) { if (error) @@ -4039,13 +4046,13 @@ gps_enabled_ready (MMBaseModem *self, static void parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, - GAsyncResult *res, - GTask *task) + GAsyncResult *res, + GTask *task) { - MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); + MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); LocationGatheringContext *ctx; - gboolean start_gps = FALSE; - GError *error = NULL; + gboolean start_gps = FALSE; + GError *error = NULL; if (!iface_modem_location_parent->enable_location_gathering_finish (_self, res, &error)) { g_task_return_error (task, error); @@ -4070,15 +4077,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, } if (start_gps) { - mm_base_modem_at_command_full (MM_BASE_MODEM (self), - mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), - gps_startup[ctx->idx], - 3, - FALSE, - FALSE, /* raw */ - NULL, /* cancellable */ - (GAsyncReadyCallback)gps_enabled_ready, - task); + run_gps_startup (task); return; } @@ -4088,13 +4087,13 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, } static void -enable_location_gathering (MMIfaceModemLocation *self, - MMModemLocationSource source, - GAsyncReadyCallback callback, - gpointer user_data) +enable_location_gathering (MMIfaceModemLocation *self, + MMModemLocationSource source, + GAsyncReadyCallback callback, + gpointer user_data) { LocationGatheringContext *ctx; - GTask *task; + GTask *task; ctx = g_new (LocationGatheringContext, 1); ctx->source = source; From bbca65d682d6de03ba199a5a0a5c388e90e2764c Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 11:43:51 +0200 Subject: [PATCH 292/675] quectel,shared: skip QGPS? check after enabling/disabling failures If any enabling/disabling command fails, we consider the operation failed, regardless of the QGPS status. This is because e.g. enabling involves more operations than just QGPS=1, and so we should treat a failure in the command sequence as a failure in the whole operation. --- plugins/quectel/mm-shared-quectel.c | 290 +++++++++------------------- 1 file changed, 96 insertions(+), 194 deletions(-) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index 2bdc7d78..00384787 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -205,45 +205,6 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self, g_object_unref (task); } -/*****************************************************************************/ -/* Location State Variables */ - -static const gchar *gps_startup[] = { - /* NOTES: - * 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data - * without the nmea port. - * 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\". - */ - "+QGPSCFG=\"outport\",\"usbnmea\"", - "+QGPS=1", -}; - -static const int qgps_nmea_port_sources = ( - MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_NMEA); - -typedef struct { - MMModemLocationSource source; - unsigned long idx; - GError *command_error; -} LocationGatheringContext; - -static void -location_gathering_context_free (LocationGatheringContext *ctx) -{ - g_clear_error (&ctx->command_error); - g_slice_free (LocationGatheringContext, ctx); -} - -static LocationGatheringContext * -location_gathering_context_new (MMModemLocationSource source) -{ - LocationGatheringContext *ctx; - - ctx = g_slice_new0 (LocationGatheringContext); - ctx->source = source; - return ctx; -} - /*****************************************************************************/ /* Location capabilities loading (Location interface) */ @@ -357,10 +318,22 @@ mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *_self, } /*****************************************************************************/ -/* Functions used to Enable Location */ +/* Enable location gathering (Location interface) */ + +static const gchar *gps_startup[] = { + /* NOTES: + * 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data + * without the nmea port. + * 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\". + */ + "+QGPSCFG=\"outport\",\"usbnmea\"", + "+QGPS=1", +}; -static void qgps_enable_loop (MMBaseModem *self, - GTask *task); +typedef struct { + MMModemLocationSource source; + guint idx; +} LocationGatheringContext; gboolean mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, @@ -370,86 +343,51 @@ mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, return g_task_propagate_boolean (G_TASK (res), error); } -static void -qgps_check_enabled_ready (MMBaseModem *self, - GAsyncResult *res, - GTask *task) -{ - const gchar *response; - GError *error = NULL; - LocationGatheringContext *ctx; - - ctx = g_task_get_task_data (task); - - response = mm_base_modem_at_command_finish (self, res, &error); - - if (!response) - g_task_return_error (task, error); - else if (!g_str_equal (mm_strip_tag (response, "+QGPS:"), "1")) - g_task_return_error (task, ctx->command_error); - else { - qgps_enable_loop (self, task); - return; - } - g_object_unref (task); -} +static void run_gps_startup (GTask *task); static void -qgps_enable_command_ready (MMBaseModem *self, +gps_startup_command_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) { - LocationGatheringContext *ctx; - GError *error = NULL; - - ctx = g_task_get_task_data (task); + GError *error = NULL; - if (!mm_base_modem_at_command_full_finish (self, res, &error)) - ctx->command_error = error; + if (!mm_base_modem_at_command_full_finish (self, res, &error)) { + g_task_return_error (task, error); + g_object_unref (task); + return; + } - qgps_enable_loop (self, task); + /* continue with next command */ + run_gps_startup (task); } static void -qgps_enable_loop (MMBaseModem *self, - GTask *task) +run_gps_startup (GTask *task) { - MMPortSerialGps *gps_port; + MMSharedQuectel *self; LocationGatheringContext *ctx; - GError *error = NULL; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); - /* If there are more commands run them, then return */ + /* If there are more commands run them */ if (ctx->idx < G_N_ELEMENTS (gps_startup)) { - mm_base_modem_at_command_full (MM_BASE_MODEM (self), - mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), - gps_startup[ctx->idx], - 3, - FALSE, - FALSE, /* raw */ - NULL, /* cancellable */ - (GAsyncReadyCallback)qgps_enable_command_ready, - task); - ctx->idx++; - return; - } - - if (ctx->command_error != NULL) { - mm_base_modem_at_command (self, - "+QGPS?", + mm_base_modem_at_command (MM_BASE_MODEM (self), + gps_startup[ctx->idx++], 3, FALSE, - (GAsyncReadyCallback)qgps_check_enabled_ready, + (GAsyncReadyCallback)gps_startup_command_ready, task); return; } - /* Last run Only: Check if the nmea/raw gps port - * exists and is available Otherwise throw an error */ - if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { - gps_port = mm_base_modem_peek_port_gps (self); + /* Check if the nmea/raw gps port exists and is available */ + if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { + GError *error = NULL; + MMPortSerialGps *gps_port; + + gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self)); if (!gps_port || !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) { if (error) g_task_return_error (task, error); @@ -462,7 +400,6 @@ qgps_enable_loop (MMBaseModem *self, g_task_return_boolean (task, TRUE); } else g_task_return_boolean (task, TRUE); - g_object_unref (task); } @@ -471,12 +408,10 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self, GAsyncResult *res, GTask *task) { - GError *error; + GError *error = NULL; Private *priv; priv = get_private (MM_SHARED_QUECTEL (self)); - - g_assert (priv->iface_modem_location_parent); if (!priv->iface_modem_location_parent->enable_location_gathering_finish (self, res, &error)) g_task_return_error (task, error); else @@ -496,30 +431,27 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, gboolean start_gps = FALSE; priv = get_private (MM_SHARED_QUECTEL (self)); - task = g_task_new (self, NULL, callback, user_data); + g_assert (priv->iface_modem_location_parent); + g_assert (priv->iface_modem_location_parent->enable_location_gathering); + g_assert (priv->iface_modem_location_parent->enable_location_gathering_finish); - /* If the parent can enable the modem let it */ - if (!(priv->provided_sources& source)) { - if (priv->iface_modem_location_parent->enable_location_gathering && - priv->iface_modem_location_parent->enable_location_gathering_finish) { - g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL); - priv->iface_modem_location_parent->enable_location_gathering ( - self, - source, - (GAsyncReadyCallback)parent_enable_location_gathering_ready, - task); - return; - } + task = g_task_new (self, NULL, callback, user_data); - g_task_return_boolean (task, TRUE); - g_object_unref (task); + /* Check if the source is provided by the parent */ + if (!(priv->provided_sources & source)) { + priv->iface_modem_location_parent->enable_location_gathering ( + self, + source, + (GAsyncReadyCallback)parent_enable_location_gathering_ready, + task); return; } - ctx = location_gathering_context_new (source); - g_task_set_task_data (task, ctx, (GDestroyNotify) location_gathering_context_free); + ctx = g_new0 (LocationGatheringContext, 1); + ctx->source = source; + g_task_set_task_data (task, ctx, g_free); - /* NMEA and UNMANAGED are both enabled in the same way */ + /* RAW, NMEA and UNMANAGED are all enabled in the same way */ if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { @@ -530,7 +462,7 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, } if (start_gps) { - qgps_enable_loop (MM_BASE_MODEM (self), task); + run_gps_startup (task); return; } @@ -540,7 +472,7 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, } /*****************************************************************************/ -/* Functions used to Disable Location */ +/* Disable location gathering (Location interface) */ gboolean mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self, @@ -550,34 +482,6 @@ mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self return g_task_propagate_boolean (G_TASK (res), error); } -static void -qgps_check_disabled_ready (MMBaseModem *self, - GAsyncResult *res, - GTask *task) -{ - const gchar *response; - GError *error = NULL; - - /* Something is very wrong if we can't query the - * state of gps while we're disabling the gps */ - // TODO: could it make sense to report success? - // if the modem won't tell us what the state of the gps is, - // and modem manager should prbably treat it as disabled right? - response = mm_base_modem_at_command_finish (self, res, &error); - if (!response) { - g_assert_not_reached (); - g_task_return_error (task, error); - } else if (!g_str_equal (mm_strip_tag (response, "+QGPS:"), "0")) - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Modem did not turn off"); - else - g_task_return_boolean (task, TRUE); - - g_object_unref (task); -} - static void qgps_end_ready (MMBaseModem *self, GAsyncResult *res, @@ -585,17 +489,10 @@ qgps_end_ready (MMBaseModem *self, { GError *error = NULL; - if (!mm_base_modem_at_command_full_finish (self, res, &error)) { - mm_base_modem_at_command (self, - "+QGPS?", - 3, - FALSE, - (GAsyncReadyCallback)qgps_check_disabled_ready, - task); - return; - } - - g_task_return_boolean (task, TRUE); + if (!mm_base_modem_at_command_finish (self, res, &error)) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); g_object_unref (task); } @@ -608,8 +505,6 @@ disable_location_gathering_parent_ready (MMIfaceModemLocation *self, Private *priv; priv = get_private (MM_SHARED_QUECTEL (self)); - - g_assert (priv->iface_modem_location_parent); if (!priv->iface_modem_location_parent->disable_location_gathering_finish (self, res, &error)) g_task_return_error (task, error); else @@ -623,31 +518,30 @@ mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self, GAsyncReadyCallback callback, gpointer user_data) { - GTask *task; - MMPortSerialGps *gps_port; - Private *priv; + GTask *task; + Private *priv; priv = get_private (MM_SHARED_QUECTEL (self)); + g_assert (priv->iface_modem_location_parent); + task = g_task_new (self, NULL, callback, user_data); priv->enabled_sources &= ~source; /* Pass handling to parent if we don't handle it */ - if (!(source & priv->provided_sources) && - priv->iface_modem_location_parent->disable_location_gathering && - priv->iface_modem_location_parent->disable_location_gathering_finish) { - priv->iface_modem_location_parent->disable_location_gathering (self, - source, - (GAsyncReadyCallback)disable_location_gathering_parent_ready, - task); - return; - } + if (!(source & priv->provided_sources)) { + /* The step to disable location gathering may not exist */ + if (priv->iface_modem_location_parent->disable_location_gathering && + priv->iface_modem_location_parent->disable_location_gathering_finish) { + priv->iface_modem_location_parent->disable_location_gathering (self, + source, + (GAsyncReadyCallback)disable_location_gathering_parent_ready, + task); + return; + } - /* Close the nmea port if we don't need it anymore */ - if (source & qgps_nmea_port_sources && - !(priv->enabled_sources & qgps_nmea_port_sources)) { - gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self)); - if (gps_port) - mm_port_serial_close (MM_PORT_SERIAL (gps_port)); + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; } /* Turn off gps on the modem if the source uses gps, @@ -655,16 +549,24 @@ mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self, if ((source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) && - priv->enabled_sources == MM_MODEM_LOCATION_SOURCE_NONE) { - mm_base_modem_at_command_full (MM_BASE_MODEM (self), - mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), - "+QGPSEND", - 3, - FALSE, - FALSE, /* raw */ - NULL, /* cancellable */ - (GAsyncReadyCallback)qgps_end_ready, - task); + !(priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))) { + /* Close the data port if we don't need it anymore */ + if (source & (MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_NMEA)) { + MMPortSerialGps *gps_port; + + gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self)); + if (gps_port) + mm_port_serial_close (MM_PORT_SERIAL (gps_port)); + } + + mm_base_modem_at_command (MM_BASE_MODEM (self), + "+QGPSEND", + 3, + FALSE, + (GAsyncReadyCallback)qgps_end_ready, + task); return; } From aa4851ed03932fed5e4401e6d3e8c4fa0a20f589 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 14:22:24 +0200 Subject: [PATCH 293/675] huawei: port GPS enabling to use AT sequence --- plugins/huawei/mm-broadband-modem-huawei.c | 143 ++++++++------------- 1 file changed, 53 insertions(+), 90 deletions(-) diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index 998f6e06..ae0a28eb 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -3871,15 +3871,7 @@ location_load_capabilities (MMIfaceModemLocation *self, } /*****************************************************************************/ -/* Enable/Disable location gathering (Location interface) */ - -typedef struct { - MMModemLocationSource source; - guint idx; -} LocationGatheringContext; - -/******************************/ -/* Disable location gathering */ +/* Disable location gathering (Location interface) */ static gboolean disable_location_gathering_finish (MMIfaceModemLocation *self, @@ -3894,16 +3886,16 @@ gps_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) { - LocationGatheringContext *ctx; - MMPortSerialGps *gps_port; - GError *error = NULL; + MMModemLocationSource source; + GError *error = NULL; - ctx = g_task_get_task_data (task); - - mm_base_modem_at_command_full_finish (self, res, &error); + mm_base_modem_at_command_finish (self, res, &error); /* Only use the GPS port in NMEA/RAW setups */ - if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { + source = GPOINTER_TO_UINT (g_task_get_task_data (task)); + if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { + MMPortSerialGps *gps_port; + /* Even if we get an error here, we try to close the GPS port */ gps_port = mm_base_modem_peek_port_gps (self); if (gps_port) @@ -3923,16 +3915,12 @@ disable_location_gathering (MMIfaceModemLocation *_self, GAsyncReadyCallback callback, gpointer user_data) { - MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); - gboolean stop_gps = FALSE; - LocationGatheringContext *ctx; - GTask *task; - - ctx = g_new (LocationGatheringContext, 1); - ctx->source = source; + MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); + gboolean stop_gps = FALSE; + GTask *task; task = g_task_new (self, NULL, callback, user_data); - g_task_set_task_data (task, ctx, g_free); + g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL); /* Only stop GPS engine if no GPS-related sources enabled */ if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | @@ -3947,15 +3935,12 @@ disable_location_gathering (MMIfaceModemLocation *_self, } if (stop_gps) { - mm_base_modem_at_command_full (MM_BASE_MODEM (_self), - mm_base_modem_peek_port_primary (MM_BASE_MODEM (_self)), - "^WPEND", - 3, - FALSE, - FALSE, /* raw */ - NULL, /* cancellable */ - (GAsyncReadyCallback)gps_disabled_ready, - task); + mm_base_modem_at_command (MM_BASE_MODEM (_self), + "^WPEND", + 3, + FALSE, + (GAsyncReadyCallback)gps_disabled_ready, + task); return; } @@ -3967,11 +3952,12 @@ disable_location_gathering (MMIfaceModemLocation *_self, /*****************************************************************************/ /* Enable location gathering (Location interface) */ -static const gchar *gps_startup[] = { - "^WPDOM=0", - "^WPDST=1", - "^WPDFR=65535,30", - "^WPDGP", +static const MMBaseModemAtCommand gps_startup[] = { + { "^WPDOM=0", 3, FALSE, mm_base_modem_response_processor_no_result_continue }, + { "^WPDST=1", 3, FALSE, mm_base_modem_response_processor_no_result_continue }, + { "^WPDFR=65535,30", 3, FALSE, mm_base_modem_response_processor_no_result_continue }, + { "^WPDGP", 3, FALSE, mm_base_modem_response_processor_no_result_continue }, + { NULL } }; static gboolean @@ -3982,53 +3968,29 @@ enable_location_gathering_finish (MMIfaceModemLocation *self, return g_task_propagate_boolean (G_TASK (res), error); } -static void run_gps_startup (GTask *task); - static void -gps_startup_command_ready (MMBaseModem *self, - GAsyncResult *res, - GTask *task) +gps_startup_ready (MMBaseModem *self, + GAsyncResult *res, + GTask *task) { - GError *error = NULL; + MMModemLocationSource source; + GError *error = NULL; - if (!mm_base_modem_at_command_finish (self, res, &error)) { + mm_base_modem_at_sequence_finish (self, res, NULL, &error); + if (error) { g_task_return_error (task, error); g_object_unref (task); return; } - /* continue with next command */ - run_gps_startup (task); -} - -static void -run_gps_startup (GTask *task) -{ - MMBroadbandModemHuawei *self; - LocationGatheringContext *ctx; + source = GPOINTER_TO_UINT (g_task_get_task_data (task)); - self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); - - if (ctx->idx < G_N_ELEMENTS (gps_startup)) { - mm_base_modem_at_command (MM_BASE_MODEM (self), - gps_startup[ctx->idx++], - 3, - FALSE, - (GAsyncReadyCallback)gps_startup_command_ready, - task); - return; - } - - /* Only use the GPS port in NMEA/RAW setups */ - if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { - GError *error = NULL; + /* Only open the GPS port in NMEA/RAW setups */ + if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { MMPortSerialGps *gps_port; gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self)); - if (!gps_port || - !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) { + if (!gps_port || !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) { if (error) g_task_return_error (task, error); else @@ -4049,10 +4011,10 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, GAsyncResult *res, GTask *task) { - MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); - LocationGatheringContext *ctx; - gboolean start_gps = FALSE; - GError *error = NULL; + MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); + GError *error = NULL; + MMModemLocationSource source; + gboolean start_gps = FALSE; if (!iface_modem_location_parent->enable_location_gathering_finish (_self, res, &error)) { g_task_return_error (task, error); @@ -4062,22 +4024,28 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, /* Now our own enabling */ - ctx = g_task_get_task_data (task); + source = GPOINTER_TO_UINT (g_task_get_task_data (task)); /* NMEA and RAW are both enabled in the same way */ - if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW | - MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { + if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { /* Only start GPS engine if not done already */ if (!(self->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))) start_gps = TRUE; - self->priv->enabled_sources |= ctx->source; + self->priv->enabled_sources |= source; } if (start_gps) { - run_gps_startup (task); + mm_base_modem_at_sequence ( + MM_BASE_MODEM (self), + gps_startup, + NULL, /* response_processor_context */ + NULL, /* response_processor_context_free */ + (GAsyncReadyCallback)gps_startup_ready, + task); return; } @@ -4092,15 +4060,10 @@ enable_location_gathering (MMIfaceModemLocation *self, GAsyncReadyCallback callback, gpointer user_data) { - LocationGatheringContext *ctx; - GTask *task; - - ctx = g_new (LocationGatheringContext, 1); - ctx->source = source; - ctx->idx = 0; + GTask *task; task = g_task_new (self, NULL, callback, user_data); - g_task_set_task_data (task, ctx, g_free); + g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL); /* Chain up parent's gathering enable */ iface_modem_location_parent->enable_location_gathering (self, From 41ba7d667ab7b6e7161a96b559823c832a3b8ba5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 14:41:47 +0200 Subject: [PATCH 294/675] huawei: simplify GPS stop logic The NMEA data port is closed right before stopping the engine. --- plugins/huawei/mm-broadband-modem-huawei.c | 69 +++++++++------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index ae0a28eb..cecfa6d4 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -3886,23 +3886,9 @@ gps_disabled_ready (MMBaseModem *self, GAsyncResult *res, GTask *task) { - MMModemLocationSource source; - GError *error = NULL; - - mm_base_modem_at_command_finish (self, res, &error); - - /* Only use the GPS port in NMEA/RAW setups */ - source = GPOINTER_TO_UINT (g_task_get_task_data (task)); - if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { - MMPortSerialGps *gps_port; - - /* Even if we get an error here, we try to close the GPS port */ - gps_port = mm_base_modem_peek_port_gps (self); - if (gps_port) - mm_port_serial_close (MM_PORT_SERIAL (gps_port)); - } + GError *error = NULL; - if (error) + if (!mm_base_modem_at_command_finish (self, res, &error)) g_task_return_error (task, error); else g_task_return_boolean (task, TRUE); @@ -3916,25 +3902,30 @@ disable_location_gathering (MMIfaceModemLocation *_self, gpointer user_data) { MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); - gboolean stop_gps = FALSE; GTask *task; + /* NOTE: no parent disable_location_gathering() implementation */ + task = g_task_new (self, NULL, callback, user_data); - g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL); + + self->priv->enabled_sources &= ~source; /* Only stop GPS engine if no GPS-related sources enabled */ - if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW | - MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { - self->priv->enabled_sources &= ~source; - - if (!(self->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW | - MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))) - stop_gps = TRUE; - } + if ((source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) && + !(self->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))) { + MMPortSerialGps *gps_port; + + /* Close the data port if we don't need it anymore */ + if (source & (MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_NMEA)) { + gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self)); + if (gps_port) + mm_port_serial_close (MM_PORT_SERIAL (gps_port)); + } - if (stop_gps) { mm_base_modem_at_command (MM_BASE_MODEM (_self), "^WPEND", 3, @@ -4026,17 +4017,15 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, source = GPOINTER_TO_UINT (g_task_get_task_data (task)); - /* NMEA and RAW are both enabled in the same way */ - if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW | - MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { - /* Only start GPS engine if not done already */ - if (!(self->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW | - MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))) - start_gps = TRUE; - self->priv->enabled_sources |= source; - } + /* Only start GPS engine if not done already */ + start_gps = ((source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) && + !(self->priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))); + + self->priv->enabled_sources |= source; if (start_gps) { mm_base_modem_at_sequence ( From 78d19c10ba50bbe6525e7f58d28e96e3e4614d86 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 14:57:49 +0200 Subject: [PATCH 295/675] quectel,shared: port GPS enabling to use AT sequence --- plugins/quectel/mm-shared-quectel.c | 101 +++++++++++----------------- 1 file changed, 38 insertions(+), 63 deletions(-) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index 00384787..1b8fe6f5 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -320,21 +320,17 @@ mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *_self, /*****************************************************************************/ /* Enable location gathering (Location interface) */ -static const gchar *gps_startup[] = { - /* NOTES: - * 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data - * without the nmea port. - * 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\". - */ - "+QGPSCFG=\"outport\",\"usbnmea\"", - "+QGPS=1", +/* NOTES: + * 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data + * without the nmea port. + * 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\". + */ +static const MMBaseModemAtCommand gps_startup[] = { + { "+QGPSCFG=\"outport\",\"usbnmea\"", 3, FALSE, mm_base_modem_response_processor_no_result_continue }, + { "+QGPS=1", 3, FALSE, mm_base_modem_response_processor_no_result_continue }, + { NULL } }; -typedef struct { - MMModemLocationSource source; - guint idx; -} LocationGatheringContext; - gboolean mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, GAsyncResult *res, @@ -343,48 +339,25 @@ mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self, return g_task_propagate_boolean (G_TASK (res), error); } -static void run_gps_startup (GTask *task); - static void -gps_startup_command_ready (MMBaseModem *self, - GAsyncResult *res, - GTask *task) +gps_startup_ready (MMBaseModem *self, + GAsyncResult *res, + GTask *task) { - GError *error = NULL; + MMModemLocationSource source; + GError *error = NULL; - if (!mm_base_modem_at_command_full_finish (self, res, &error)) { + mm_base_modem_at_sequence_finish (self, res, NULL, &error); + if (error) { g_task_return_error (task, error); g_object_unref (task); return; } - /* continue with next command */ - run_gps_startup (task); -} - -static void -run_gps_startup (GTask *task) -{ - MMSharedQuectel *self; - LocationGatheringContext *ctx; - - self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); - - /* If there are more commands run them */ - if (ctx->idx < G_N_ELEMENTS (gps_startup)) { - mm_base_modem_at_command (MM_BASE_MODEM (self), - gps_startup[ctx->idx++], - 3, - FALSE, - (GAsyncReadyCallback)gps_startup_command_ready, - task); - return; - } + source = GPOINTER_TO_UINT (g_task_get_task_data (task)); /* Check if the nmea/raw gps port exists and is available */ - if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { - GError *error = NULL; + if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { MMPortSerialGps *gps_port; gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self)); @@ -425,10 +398,9 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, GAsyncReadyCallback callback, gpointer user_data) { - LocationGatheringContext *ctx; - GTask *task; - Private *priv; - gboolean start_gps = FALSE; + GTask *task; + Private *priv; + gboolean start_gps = FALSE; priv = get_private (MM_SHARED_QUECTEL (self)); g_assert (priv->iface_modem_location_parent); @@ -436,6 +408,7 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, g_assert (priv->iface_modem_location_parent->enable_location_gathering_finish); task = g_task_new (self, NULL, callback, user_data); + g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL); /* Check if the source is provided by the parent */ if (!(priv->provided_sources & source)) { @@ -447,26 +420,28 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, return; } - ctx = g_new0 (LocationGatheringContext, 1); - ctx->source = source; - g_task_set_task_data (task, ctx, g_free); + /* Only start GPS engine if not done already */ + start_gps = ((source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) && + !(priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | + MM_MODEM_LOCATION_SOURCE_GPS_RAW | + MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))); - /* RAW, NMEA and UNMANAGED are all enabled in the same way */ - if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | - MM_MODEM_LOCATION_SOURCE_GPS_RAW | - MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { - if (priv->enabled_sources == MM_MODEM_LOCATION_SOURCE_NONE) - start_gps = TRUE; - - priv->enabled_sources |= ctx->source; - } + priv->enabled_sources |= source; if (start_gps) { - run_gps_startup (task); + mm_base_modem_at_sequence ( + MM_BASE_MODEM (self), + gps_startup, + NULL, /* response_processor_context */ + NULL, /* response_processor_context_free */ + (GAsyncReadyCallback)gps_startup_ready, + task); return; } - /* For any other location (e.g. 3GPP), or if the GPS is already running just return */ + /* If the GPS is already running just return */ g_task_return_boolean (task, TRUE); g_object_unref (task); } From 58dbb68fa0c0a30d33d93969016f39880b142920 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 28 Jun 2020 15:05:14 +0200 Subject: [PATCH 296/675] quectel,qmi: add QGPS based fallback support --- .../quectel/mm-broadband-modem-qmi-quectel.c | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/quectel/mm-broadband-modem-qmi-quectel.c b/plugins/quectel/mm-broadband-modem-qmi-quectel.c index 96eda0e5..800c2341 100644 --- a/plugins/quectel/mm-broadband-modem-qmi-quectel.c +++ b/plugins/quectel/mm-broadband-modem-qmi-quectel.c @@ -19,13 +19,17 @@ #include "mm-shared-quectel.h" #include "mm-iface-modem-firmware.h" -static void iface_modem_init (MMIfaceModem *iface); -static void shared_quectel_init (MMSharedQuectel *iface); +static void iface_modem_init (MMIfaceModem *iface); static void iface_modem_firmware_init (MMIfaceModemFirmware *iface); +static void iface_modem_location_init (MMIfaceModemLocation *iface); +static void shared_quectel_init (MMSharedQuectel *iface); + +static MMIfaceModemLocation *iface_modem_location_parent; G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQmiQuectel, mm_broadband_modem_qmi_quectel, MM_TYPE_BROADBAND_MODEM_QMI, 0, G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, iface_modem_location_init) G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init)) /*****************************************************************************/ @@ -65,9 +69,29 @@ iface_modem_firmware_init (MMIfaceModemFirmware *iface) iface->load_update_settings_finish = mm_shared_quectel_firmware_load_update_settings_finish; } +static void +iface_modem_location_init (MMIfaceModemLocation *iface) +{ + iface_modem_location_parent = g_type_interface_peek_parent (iface); + + iface->load_capabilities = mm_shared_quectel_location_load_capabilities; + iface->load_capabilities_finish = mm_shared_quectel_location_load_capabilities_finish; + iface->enable_location_gathering = mm_shared_quectel_enable_location_gathering; + iface->enable_location_gathering_finish = mm_shared_quectel_enable_location_gathering_finish; + iface->disable_location_gathering = mm_shared_quectel_disable_location_gathering; + iface->disable_location_gathering_finish = mm_shared_quectel_disable_location_gathering_finish; +} + +static MMIfaceModemLocation * +peek_parent_location_interface (MMSharedQuectel *self) +{ + return iface_modem_location_parent; +} + static void shared_quectel_init (MMSharedQuectel *iface) { + iface->peek_parent_location_interface = peek_parent_location_interface; } static void From 60211b51b112db23c07dfd62dd6336a964a287e0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 29 Jun 2020 09:57:28 +0200 Subject: [PATCH 297/675] =?UTF-8?q?quectel,shared:=20use=20QGPS=3D=3F=20te?= =?UTF-8?q?st=20to=20check=20capabilities?= --- plugins/quectel/mm-shared-quectel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index 1b8fe6f5..c485f6f5 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -293,9 +293,9 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self, /* Probe QGPS support */ g_assert (priv->qgps_supported == FEATURE_SUPPORT_UNKNOWN); mm_base_modem_at_command (MM_BASE_MODEM (self), - "+QGPS?", + "+QGPS=?", 3, - FALSE, /* not cached */ + TRUE, /* cached */ (GAsyncReadyCallback)probe_qgps_ready, task); } From 619b054e5c874844a73594a724b4e5ce5ec18b6d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 29 Jun 2020 10:06:18 +0200 Subject: [PATCH 298/675] libmm-glib,location: avoid warnings when no traces available ModemManager[201411]: [1593417744.011884] [modem0/ttyUSB1/gps] <-- '$GPVTG,,T,,M,,N,,K,N*2C$GPGSA,A,1,,,,,,,,,,,,,,,*1E$GPGGA,,,,,,0,,,,,,,,*66$GPRMC,,V,,,,,,,,,,N*53' (ModemManager:201411): GLib-CRITICAL **: 10:02:24.054: g_strjoinv: assertion 'str_array != NULL' failed Thread 1 "ModemManager" received signal SIGTRAP, Trace/breakpoint trap. 0x00007ffff7832473 in g_logv () from /usr/lib/libglib-2.0.so.0 (gdb) bt #0 0x00007ffff7832473 in g_logv () at /usr/lib/libglib-2.0.so.0 #1 0x00007ffff78326f0 in g_log () at /usr/lib/libglib-2.0.so.0 #2 0x00007ffff7846b5e in g_strjoinv () at /usr/lib/libglib-2.0.so.0 #3 0x00007ffff7ee9663 in mm_location_gps_nmea_get_string_variant (self=0x5555557dde50) at mm-location-gps-nmea.c:246 #4 0x00005555555e7c47 in build_location_dictionary (previous=0x0, location_3gpp=0x55555573e660, location_gps_nmea=0x5555557dde50, location_gps_raw=0x0, location_cdma_bs=0x0) at mm-iface-modem-location.c:183 ... (gdb) fr 3 #3 0x00007ffff7ee9663 in mm_location_gps_nmea_get_string_variant (self=0x5555557dde50) at mm-location-gps-nmea.c:246 246 built = g_strjoinv ("\r\n", traces); (gdb) p traces $1 = (GStrv) 0x0 --- libmm-glib/mm-location-gps-nmea.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libmm-glib/mm-location-gps-nmea.c b/libmm-glib/mm-location-gps-nmea.c index fde811fe..22e7ab46 100644 --- a/libmm-glib/mm-location-gps-nmea.c +++ b/libmm-glib/mm-location-gps-nmea.c @@ -243,8 +243,9 @@ mm_location_gps_nmea_get_string_variant (MMLocationGpsNmea *self) g_return_val_if_fail (MM_IS_LOCATION_GPS_NMEA (self), NULL); traces = mm_location_gps_nmea_get_traces (self); - built = g_strjoinv ("\r\n", traces); - return g_variant_ref_sink (g_variant_new_string (built)); + if (traces) + built = g_strjoinv ("\r\n", traces); + return g_variant_ref_sink (g_variant_new_string (built ? built : "")); } /*****************************************************************************/ From af8afcc6c9fd6eb6b88d43c88dee013d4a02c0cf Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 29 Jun 2020 10:13:44 +0200 Subject: [PATCH 299/675] quectel,shared: only flag GPS source as enabled if it was successful --- plugins/quectel/mm-shared-quectel.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index c485f6f5..aaeca95f 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -346,6 +346,9 @@ gps_startup_ready (MMBaseModem *self, { MMModemLocationSource source; GError *error = NULL; + Private *priv; + + priv = get_private (MM_SHARED_QUECTEL (self)); mm_base_modem_at_sequence_finish (self, res, NULL, &error); if (error) { @@ -369,10 +372,16 @@ gps_startup_ready (MMBaseModem *self, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't open raw GPS serial port"); - } else + } else { + /* GPS port was successfully opened */ + priv->enabled_sources |= source; g_task_return_boolean (task, TRUE); - } else + } + } else { + /* No need to open GPS port */ + priv->enabled_sources |= source; g_task_return_boolean (task, TRUE); + } g_object_unref (task); } @@ -428,8 +437,6 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))); - priv->enabled_sources |= source; - if (start_gps) { mm_base_modem_at_sequence ( MM_BASE_MODEM (self), @@ -442,6 +449,7 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self, } /* If the GPS is already running just return */ + priv->enabled_sources |= source; g_task_return_boolean (task, TRUE); g_object_unref (task); } From 70b7218b7b303ba01f0be20ee14f1e4186884f79 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 29 Jun 2020 10:23:37 +0200 Subject: [PATCH 300/675] huawei: only flag GPS source as enabled if it was successful --- plugins/huawei/mm-broadband-modem-huawei.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index cecfa6d4..023b58fa 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -3960,14 +3960,15 @@ enable_location_gathering_finish (MMIfaceModemLocation *self, } static void -gps_startup_ready (MMBaseModem *self, +gps_startup_ready (MMBaseModem *_self, GAsyncResult *res, GTask *task) { - MMModemLocationSource source; - GError *error = NULL; + MMBroadbandModemHuawei *self = MM_BROADBAND_MODEM_HUAWEI (_self); + MMModemLocationSource source; + GError *error = NULL; - mm_base_modem_at_sequence_finish (self, res, NULL, &error); + mm_base_modem_at_sequence_finish (_self, res, NULL, &error); if (error) { g_task_return_error (task, error); g_object_unref (task); @@ -3989,10 +3990,16 @@ gps_startup_ready (MMBaseModem *self, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't open raw GPS serial port"); - } else + } else { + /* GPS port was successfully opened */ + self->priv->enabled_sources |= source; g_task_return_boolean (task, TRUE); - } else + } + } else { + /* No need to open GPS port */ + self->priv->enabled_sources |= source; g_task_return_boolean (task, TRUE); + } g_object_unref (task); } @@ -4025,8 +4032,6 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))); - self->priv->enabled_sources |= source; - if (start_gps) { mm_base_modem_at_sequence ( MM_BASE_MODEM (self), @@ -4039,6 +4044,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, } /* For any other location (e.g. 3GPP), or if GPS already running just return */ + self->priv->enabled_sources |= source; g_task_return_boolean (task, TRUE); g_object_unref (task); } From ffca45d9cc416879881b75fb93880aee8c7563d2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 29 Jun 2020 10:46:47 +0200 Subject: [PATCH 301/675] quectel,shared: add GPS trace handler --- plugins/quectel/mm-shared-quectel.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index aaeca95f..e10d581d 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -205,6 +205,17 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self, g_object_unref (task); } +/*****************************************************************************/ +/* GPS trace received */ + +static void +trace_received (MMPortSerialGps *port, + const gchar *trace, + MMIfaceModemLocation *self) +{ + mm_iface_modem_location_gps_update (self, trace); +} + /*****************************************************************************/ /* Location capabilities loading (Location interface) */ @@ -255,6 +266,12 @@ probe_qgps_ready (MMBaseModem *_self, priv->provided_sources |= MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED; sources |= priv->provided_sources; + + /* Add handler for the NMEA traces in the GPS data port */ + mm_port_serial_gps_add_trace_handler (mm_base_modem_peek_port_gps (MM_BASE_MODEM (self)), + (MMPortSerialGpsTraceFn)trace_received, + self, + NULL); } /* So we're done, complete */ From 23f8b580c3f394c10404ea346202cbe8997026db Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 30 Jun 2020 13:11:17 +0200 Subject: [PATCH 302/675] quectel,shared: implement custom time support check We require CTZU=3 during the time support check, instead of CTZU=1, so that the Quectel modem reports localtime instead of UTC time in +CCLK. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/233 --- .../quectel/mm-broadband-modem-qmi-quectel.c | 15 ++++++-- plugins/quectel/mm-broadband-modem-quectel.c | 14 ++++++-- plugins/quectel/mm-shared-quectel.c | 35 ++++++++++++++++++- plugins/quectel/mm-shared-quectel.h | 10 +++++- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/plugins/quectel/mm-broadband-modem-qmi-quectel.c b/plugins/quectel/mm-broadband-modem-qmi-quectel.c index 800c2341..067b4601 100644 --- a/plugins/quectel/mm-broadband-modem-qmi-quectel.c +++ b/plugins/quectel/mm-broadband-modem-qmi-quectel.c @@ -10,18 +10,21 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2018 Aleksander Morgado + * Copyright (C) 2018-2020 Aleksander Morgado */ #include #include "mm-broadband-modem-qmi-quectel.h" -#include "mm-shared-quectel.h" #include "mm-iface-modem-firmware.h" +#include "mm-iface-modem-location.h" +#include "mm-iface-modem-time.h" +#include "mm-shared-quectel.h" static void iface_modem_init (MMIfaceModem *iface); static void iface_modem_firmware_init (MMIfaceModemFirmware *iface); static void iface_modem_location_init (MMIfaceModemLocation *iface); +static void iface_modem_time_init (MMIfaceModemTime *iface); static void shared_quectel_init (MMSharedQuectel *iface); static MMIfaceModemLocation *iface_modem_location_parent; @@ -30,6 +33,7 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQmiQuectel, mm_broadband_modem_qmi_quect G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, iface_modem_location_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_TIME, iface_modem_time_init) G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init)) /*****************************************************************************/ @@ -88,6 +92,13 @@ peek_parent_location_interface (MMSharedQuectel *self) return iface_modem_location_parent; } +static void +iface_modem_time_init (MMIfaceModemTime *iface) +{ + iface->check_support = mm_shared_quectel_time_check_support; + iface->check_support_finish = mm_shared_quectel_time_check_support_finish; +} + static void shared_quectel_init (MMSharedQuectel *iface) { diff --git a/plugins/quectel/mm-broadband-modem-quectel.c b/plugins/quectel/mm-broadband-modem-quectel.c index 4fdfdfcf..f6b6e176 100644 --- a/plugins/quectel/mm-broadband-modem-quectel.c +++ b/plugins/quectel/mm-broadband-modem-quectel.c @@ -10,19 +10,21 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2018 Aleksander Morgado + * Copyright (C) 2018-2020 Aleksander Morgado */ #include #include "mm-broadband-modem-quectel.h" -#include "mm-shared-quectel.h" #include "mm-iface-modem-firmware.h" #include "mm-iface-modem-location.h" +#include "mm-iface-modem-time.h" +#include "mm-shared-quectel.h" static void iface_modem_init (MMIfaceModem *iface); static void iface_modem_firmware_init (MMIfaceModemFirmware *iface); static void iface_modem_location_init (MMIfaceModemLocation *iface); +static void iface_modem_time_init (MMIfaceModemTime *iface); static void shared_quectel_init (MMSharedQuectel *iface); static MMIfaceModemLocation *iface_modem_location_parent; @@ -31,6 +33,7 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQuectel, mm_broadband_modem_quectel, MM_ G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, iface_modem_location_init) + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_TIME, iface_modem_time_init) G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_QUECTEL, shared_quectel_init)) /*****************************************************************************/ @@ -89,6 +92,13 @@ peek_parent_location_interface (MMSharedQuectel *self) return iface_modem_location_parent; } +static void +iface_modem_time_init (MMIfaceModemTime *iface) +{ + iface->check_support = mm_shared_quectel_time_check_support; + iface->check_support_finish = mm_shared_quectel_time_check_support_finish; +} + static void shared_quectel_init (MMSharedQuectel *iface) { diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index e10d581d..cdb7dab3 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -10,7 +10,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2018 Aleksander Morgado + * Copyright (C) 2018-2020 Aleksander Morgado */ #include @@ -574,6 +574,39 @@ mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self, g_object_unref (task); } +/*****************************************************************************/ + +/* Custom time support check because Quectel modems require +CTZU=3 in order to + * have the CCLK? time reported in localtime, instead of UTC time. */ +static const MMBaseModemAtCommand time_check_sequence[] = { + { "+CTZU=3", 3, TRUE, mm_base_modem_response_processor_no_result_continue }, + { "+CCLK?", 3, TRUE, mm_base_modem_response_processor_string }, + { NULL } +}; + +gboolean +mm_shared_quectel_time_check_support_finish (MMIfaceModemTime *self, + GAsyncResult *res, + GError **error) +{ + return !!mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, error); +} + +void +mm_shared_quectel_time_check_support (MMIfaceModemTime *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + mm_base_modem_at_sequence (MM_BASE_MODEM (self), + time_check_sequence, + NULL, /* response_processor_context */ + NULL, /* response_processor_context_free */ + callback, + user_data); +} + +/*****************************************************************************/ + static void shared_quectel_init (gpointer g_iface) { diff --git a/plugins/quectel/mm-shared-quectel.h b/plugins/quectel/mm-shared-quectel.h index e628b22c..88023b3b 100644 --- a/plugins/quectel/mm-shared-quectel.h +++ b/plugins/quectel/mm-shared-quectel.h @@ -10,7 +10,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2018 Aleksander Morgado + * Copyright (C) 2018-2020 Aleksander Morgado */ #ifndef MM_SHARED_QUECTEL_H @@ -26,6 +26,7 @@ #include "mm-iface-modem.h" #include "mm-iface-modem-firmware.h" #include "mm-iface-modem-location.h" +#include "mm-iface-modem-time.h" #define MM_TYPE_SHARED_QUECTEL (mm_shared_quectel_get_type ()) #define MM_SHARED_QUECTEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_SHARED_QUECTEL, MMSharedQuectel)) @@ -78,4 +79,11 @@ gboolean mm_shared_quectel_disable_location_gathering_finish (MMIfa GAsyncResult *res, GError **error); +void mm_shared_quectel_time_check_support (MMIfaceModemTime *self, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_shared_quectel_time_check_support_finish (MMIfaceModemTime *self, + GAsyncResult *res, + GError **error); + #endif /* MM_SHARED_QUECTEL_H */ From fff47478cc5887176830a5debe2c4204434c222f Mon Sep 17 00:00:00 2001 From: Daniele Palmas Date: Thu, 2 Jul 2020 13:09:19 +0200 Subject: [PATCH 303/675] telit: added port type hints for default MEx10G1 composition While at this change also the previous generic reference to ME910 in order to differentiate between ME910C1 (based on MDM9206) and MEx10G1 (based on MDM9205). --- plugins/telit/77-mm-telit-port-types.rules | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/telit/77-mm-telit-port-types.rules b/plugins/telit/77-mm-telit-port-types.rules index edacd9e3..bb7c8bd5 100644 --- a/plugins/telit/77-mm-telit-port-types.rules +++ b/plugins/telit/77-mm-telit-port-types.rules @@ -47,11 +47,16 @@ ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="1201", ENV{.MM_USBIFNUM}=="04", ENV{ ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="1201", ENV{.MM_USBIFNUM}=="05", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="1201", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1" -# ME910 +# ME910C1 ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="1101", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_IGNORE}="1" ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="1101", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="1101", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +# MEx10G1 +ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="110a", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_IGNORE}="1" +ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="110a", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="110a", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" + # LM940/960 use alternate settings for 3G band management ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="0x1040", ENV{ID_MM_TELIT_BND_ALTERNATE}="1" ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="0x1041", ENV{ID_MM_TELIT_BND_ALTERNATE}="1" From 6df9cc084489a3aa8ab06b1e87f597b96dc79ffa Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 3 Jul 2020 08:26:57 +0200 Subject: [PATCH 304/675] plugin: define an autofree value to NULL This satisfies -Werror=maybe-uninitialized. --- src/mm-plugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-plugin.c b/src/mm-plugin.c index adfe4bf2..77bd6528 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -1089,7 +1089,7 @@ static gchar * log_object_build_id (MMLogObject *_self) { MMPlugin *self; - g_autofree gchar *plugin_name_lowercase; + g_autofree gchar *plugin_name_lowercase = NULL; self = MM_PLUGIN (_self); plugin_name_lowercase = g_ascii_strdown (self->priv->name, -1); From 711b17278edecbc474418ecf95e7582f515711cb Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 05:29:36 +0200 Subject: [PATCH 305/675] build: require 5G signal info support from libqmi 1.27.1 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3495cee5..e03edcb0 100644 --- a/configure.ac +++ b/configure.ac @@ -394,7 +394,7 @@ dnl----------------------------------------------------------------------------- dnl QMI support (enabled by default) dnl -LIBQMI_VERSION=1.26.0 +LIBQMI_VERSION=1.27.1 AC_ARG_WITH(qmi, AS_HELP_STRING([--without-qmi], [Build without QMI support]), [], [with_qmi=yes]) AM_CONDITIONAL(WITH_QMI, test "x$with_qmi" = "xyes") From 88923ffe3996fdef83dc13a7a4762855af77706d Mon Sep 17 00:00:00 2001 From: Walter Hagstrom Date: Tue, 23 Jun 2020 11:14:43 -0400 Subject: [PATCH 306/675] iface-modem-signal: added 5G signal information Extended the ModemManager Signal interface to include 5G signal information for RSRP, RSRQ and SINR via libqmi. Also extended mmci to print 5G signal info. --- cli/mmcli-modem-signal.c | 16 +++++ cli/mmcli-output.c | 4 ++ cli/mmcli-output.h | 4 ++ .../libmm-glib/libmm-glib-sections.txt | 2 + ...freedesktop.ModemManager1.Modem.Signal.xml | 38 ++++++++++++ libmm-glib/mm-modem-signal.c | 62 ++++++++++++++++++- libmm-glib/mm-modem-signal.h | 3 + .../cinterion/mm-broadband-modem-cinterion.c | 5 +- plugins/huawei/mm-broadband-modem-huawei.c | 3 + plugins/xmm/mm-shared-xmm.c | 3 + plugins/xmm/mm-shared-xmm.h | 1 + src/mm-broadband-modem-mbim.c | 6 +- src/mm-broadband-modem-qmi.c | 54 +++++++++++----- src/mm-broadband-modem.c | 4 ++ src/mm-iface-modem-signal.c | 12 ++++ src/mm-iface-modem-signal.h | 1 + 16 files changed, 198 insertions(+), 20 deletions(-) diff --git a/cli/mmcli-modem-signal.c b/cli/mmcli-modem-signal.c index 506d7370..7fa476c1 100644 --- a/cli/mmcli-modem-signal.c +++ b/cli/mmcli-modem-signal.c @@ -153,6 +153,9 @@ print_signal_info (void) gchar *lte_rsrp = NULL; gchar *lte_rsrq = NULL; gchar *lte_snr = NULL; + gchar *nr5g_rsrp = NULL; + gchar *nr5g_rsrq = NULL; + gchar *nr5g_snr = NULL; refresh_rate = g_strdup_printf ("%u", mm_modem_signal_get_rate (ctx->modem_signal)); @@ -204,6 +207,16 @@ print_signal_info (void) lte_snr = g_strdup_printf ("%.2lf", value); } + signal = mm_modem_signal_peek_nr5g (ctx->modem_signal); + if (signal) { + if ((value = mm_signal_get_rsrq (signal)) != MM_SIGNAL_UNKNOWN) + nr5g_rsrq = g_strdup_printf ("%.2lf", value); + if ((value = mm_signal_get_rsrp (signal)) != MM_SIGNAL_UNKNOWN) + nr5g_rsrp = g_strdup_printf ("%.2lf", value); + if ((value = mm_signal_get_snr (signal)) != MM_SIGNAL_UNKNOWN) + nr5g_snr = g_strdup_printf ("%.2lf", value); + } + mmcli_output_string_take_typed (MMC_F_SIGNAL_REFRESH_RATE, refresh_rate, "seconds"); mmcli_output_string_take_typed (MMC_F_SIGNAL_CDMA1X_RSSI, cdma1x_rssi, "dBm"); mmcli_output_string_take_typed (MMC_F_SIGNAL_CDMA1X_ECIO, cdma1x_ecio, "dBm"); @@ -219,6 +232,9 @@ print_signal_info (void) mmcli_output_string_take_typed (MMC_F_SIGNAL_LTE_RSRQ, lte_rsrq, "dB"); mmcli_output_string_take_typed (MMC_F_SIGNAL_LTE_RSRP, lte_rsrp, "dBm"); mmcli_output_string_take_typed (MMC_F_SIGNAL_LTE_SNR, lte_snr, "dB"); + mmcli_output_string_take_typed (MMC_F_SIGNAL_5G_RSRQ, nr5g_rsrq, "dB"); + mmcli_output_string_take_typed (MMC_F_SIGNAL_5G_RSRP, nr5g_rsrp, "dBm"); + mmcli_output_string_take_typed (MMC_F_SIGNAL_5G_SNR, nr5g_snr, "dB"); mmcli_output_dump (); } diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c index 1265856d..2242de8f 100644 --- a/cli/mmcli-output.c +++ b/cli/mmcli-output.c @@ -57,6 +57,7 @@ static SectionInfo section_infos[] = { [MMC_S_MODEM_SIGNAL_GSM] = { "GSM" }, [MMC_S_MODEM_SIGNAL_UMTS] = { "UMTS" }, [MMC_S_MODEM_SIGNAL_LTE] = { "LTE" }, + [MMC_S_MODEM_SIGNAL_5G] = { "5G" }, [MMC_S_MODEM_OMA] = { "OMA" }, [MMC_S_MODEM_OMA_CURRENT] = { "Current session" }, [MMC_S_MODEM_OMA_PENDING] = { "Pending sessions" }, @@ -169,6 +170,9 @@ static FieldInfo field_infos[] = { [MMC_F_SIGNAL_LTE_RSRQ] = { "modem.signal.lte.rsrq", "rsrq", MMC_S_MODEM_SIGNAL_LTE, }, [MMC_F_SIGNAL_LTE_RSRP] = { "modem.signal.lte.rsrp", "rsrp", MMC_S_MODEM_SIGNAL_LTE, }, [MMC_F_SIGNAL_LTE_SNR] = { "modem.signal.lte.snr", "s/n", MMC_S_MODEM_SIGNAL_LTE, }, + [MMC_F_SIGNAL_5G_RSRQ] = { "modem.signal.5g.rsrq", "rsrq", MMC_S_MODEM_SIGNAL_5G, }, + [MMC_F_SIGNAL_5G_RSRP] = { "modem.signal.5g.rsrp", "rsrp", MMC_S_MODEM_SIGNAL_5G, }, + [MMC_F_SIGNAL_5G_SNR] = { "modem.signal.5g.snr", "s/n", MMC_S_MODEM_SIGNAL_5G, }, [MMC_F_OMA_FEATURES] = { "modem.oma.features", "features", MMC_S_MODEM_OMA, }, [MMC_F_OMA_CURRENT_TYPE] = { "modem.oma.current.type", "type", MMC_S_MODEM_OMA_CURRENT, }, [MMC_F_OMA_CURRENT_STATE] = { "modem.oma.current.state", "state", MMC_S_MODEM_OMA_CURRENT, }, diff --git a/cli/mmcli-output.h b/cli/mmcli-output.h index 2cd02b4b..e350b340 100644 --- a/cli/mmcli-output.h +++ b/cli/mmcli-output.h @@ -54,6 +54,7 @@ typedef enum { MMC_S_MODEM_SIGNAL_GSM, MMC_S_MODEM_SIGNAL_UMTS, MMC_S_MODEM_SIGNAL_LTE, + MMC_S_MODEM_SIGNAL_5G, MMC_S_MODEM_OMA, MMC_S_MODEM_OMA_CURRENT, MMC_S_MODEM_OMA_PENDING, @@ -179,6 +180,9 @@ typedef enum { MMC_F_SIGNAL_LTE_RSRQ, MMC_F_SIGNAL_LTE_RSRP, MMC_F_SIGNAL_LTE_SNR, + MMC_F_SIGNAL_5G_RSRQ, + MMC_F_SIGNAL_5G_RSRP, + MMC_F_SIGNAL_5G_SNR, /* OMA section */ MMC_F_OMA_FEATURES, MMC_F_OMA_CURRENT_TYPE, diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 00c3adfb..9bdbb21c 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -2793,11 +2793,13 @@ mm_gdbus_modem_signal_get_evdo mm_gdbus_modem_signal_get_gsm mm_gdbus_modem_signal_get_umts mm_gdbus_modem_signal_get_lte +mm_gdbus_modem_signal_get_nr5g mm_gdbus_modem_signal_dup_cdma mm_gdbus_modem_signal_dup_evdo mm_gdbus_modem_signal_dup_gsm mm_gdbus_modem_signal_dup_umts mm_gdbus_modem_signal_dup_lte +mm_gdbus_modem_signal_dup_nr5g mm_gdbus_modem_signal_call_setup mm_gdbus_modem_signal_call_setup_finish diff --git a/introspection/org.freedesktop.ModemManager1.Modem.Signal.xml b/introspection/org.freedesktop.ModemManager1.Modem.Signal.xml index 38c79578..610c6db9 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.Signal.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.Signal.xml @@ -221,5 +221,43 @@ --> + + + diff --git a/libmm-glib/mm-modem-signal.c b/libmm-glib/mm-modem-signal.c index 7727be6a..0b740c72 100644 --- a/libmm-glib/mm-modem-signal.c +++ b/libmm-glib/mm-modem-signal.c @@ -53,6 +53,7 @@ typedef enum { UPDATED_PROPERTY_TYPE_GSM = 2, UPDATED_PROPERTY_TYPE_UMTS = 3, UPDATED_PROPERTY_TYPE_LTE = 4, + UPDATED_PROPERTY_TYPE_NR5G = 5, UPDATED_PROPERTY_TYPE_LAST } UpdatedPropertyType; @@ -250,6 +251,13 @@ lte_updated (MMModemSignal *self, values_updated (self, pspec, UPDATED_PROPERTY_TYPE_LTE); } +static void +nr5g_updated (MMModemSignal *self, + GParamSpec *pspec) +{ + values_updated (self, pspec, UPDATED_PROPERTY_TYPE_NR5G); +} + typedef GVariant * (* Getter) (MmGdbusModemSignal *self); typedef GVariant * (* Dupper) (MmGdbusModemSignal *self); typedef void (* UpdatedCallback) (MMModemSignal *self, GParamSpec *pspec); @@ -265,7 +273,8 @@ static const SignalData signal_data [UPDATED_PROPERTY_TYPE_LAST] = { { "notify::evdo", mm_gdbus_modem_signal_get_evdo, mm_gdbus_modem_signal_dup_evdo, evdo_updated }, { "notify::gsm", mm_gdbus_modem_signal_get_gsm, mm_gdbus_modem_signal_dup_gsm, gsm_updated }, { "notify::umts", mm_gdbus_modem_signal_get_umts, mm_gdbus_modem_signal_dup_umts, umts_updated }, - { "notify::lte", mm_gdbus_modem_signal_get_lte, mm_gdbus_modem_signal_dup_lte, lte_updated } + { "notify::lte", mm_gdbus_modem_signal_get_lte, mm_gdbus_modem_signal_dup_lte, lte_updated }, + { "notify::nr5g", mm_gdbus_modem_signal_get_nr5g, mm_gdbus_modem_signal_dup_nr5g, nr5g_updated } }; static void @@ -571,6 +580,33 @@ mm_modem_signal_get_lte (MMModemSignal *self) return info; } +/** + * mm_modem_signal_get_nr5g: + * @self: A #MMModem. + * + * Gets a #MMSignal object specifying the 5G signal information. + * + * The values reported by @self are not updated when the values in the + * interface change. Instead, the client is expected to call + * mm_modem_signal_get_nr5g() again to get a new #MMSignal with the new values. + * + * + * Returns: (transfer full): A #MMSignal that must be freed with + * g_object_unref() or %NULL if unknown. + * + * Since: 1.16 + */ +MMSignal * +mm_modem_signal_get_nr5g (MMModemSignal *self) +{ + MMSignal *info = NULL; + + g_return_val_if_fail (MM_IS_MODEM_SIGNAL (self), NULL); + + ensure_internal (self, &info, UPDATED_PROPERTY_TYPE_NR5G); + return info; +} + /** * mm_modem_signal_peek_lte: * @self: A #MMModem. @@ -595,6 +631,30 @@ mm_modem_signal_peek_lte (MMModemSignal *self) return self->priv->values[UPDATED_PROPERTY_TYPE_LTE].info; } +/** + * mm_modem_signal_peek_nr5g: + * @self: A #MMModem. + * + * Gets a #MMSignal object specifying the 5G signal information. + * + * The returned value is only valid until the property changes so it is + * only safe to use this function on the thread where @self was constructed. Use + * mm_modem_signal_get_nr5g() if on another thread. + * + * Returns: (transfer none): A #MMSignal. Do not free the returned value, it + * belongs to @self. + * + * Since: 1.16 + */ +MMSignal * +mm_modem_signal_peek_nr5g (MMModemSignal *self) +{ + g_return_val_if_fail (MM_IS_MODEM_SIGNAL (self), NULL); + + ensure_internal (self, NULL, UPDATED_PROPERTY_TYPE_NR5G); + return self->priv->values[UPDATED_PROPERTY_TYPE_NR5G].info; +} + /*****************************************************************************/ static void diff --git a/libmm-glib/mm-modem-signal.h b/libmm-glib/mm-modem-signal.h index 63b82ab9..5c0cb6aa 100644 --- a/libmm-glib/mm-modem-signal.h +++ b/libmm-glib/mm-modem-signal.h @@ -97,6 +97,9 @@ MMSignal *mm_modem_signal_peek_umts (MMModemSignal *self); MMSignal *mm_modem_signal_get_lte (MMModemSignal *self); MMSignal *mm_modem_signal_peek_lte (MMModemSignal *self); +MMSignal *mm_modem_signal_get_nr5g (MMModemSignal *self); +MMSignal *mm_modem_signal_peek_nr5g (MMModemSignal *self); + G_END_DECLS #endif /* _MM_MODEM_SIGNAL_H_ */ diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 99875210..e1e558c3 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -2187,13 +2187,14 @@ signal_load_values_finish (MMIfaceModemSignal *_self, MMSignal **gsm, MMSignal **umts, MMSignal **lte, + MMSignal **nr5g, GError **error) { MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self); const gchar *response; if (self->priv->smoni_support == FEATURE_NOT_SUPPORTED) - return iface_modem_signal_parent->load_values_finish (_self, res, cdma, evdo, gsm, umts, lte, error); + return iface_modem_signal_parent->load_values_finish (_self, res, cdma, evdo, gsm, umts, lte, nr5g, error); response = mm_base_modem_at_command_finish (MM_BASE_MODEM (_self), res, error); if (!response || !mm_cinterion_smoni_response_to_signal_info (response, gsm, umts, lte, error)) @@ -2203,6 +2204,8 @@ signal_load_values_finish (MMIfaceModemSignal *_self, *cdma = NULL; if (evdo) *evdo = NULL; + if (nr5g) + *nr5g = NULL; return TRUE; } diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index 023b58fa..fafd097b 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -87,6 +87,7 @@ typedef struct { MMSignal *gsm; MMSignal *umts; MMSignal *lte; + MMSignal *nr5g; } DetailedSignal; struct _MMBroadbandModemHuaweiPrivate { @@ -4209,6 +4210,7 @@ signal_load_values_finish (MMIfaceModemSignal *self, MMSignal **gsm, MMSignal **umts, MMSignal **lte, + MMSignal **nr5g, GError **error) { DetailedSignal *signals; @@ -4222,6 +4224,7 @@ signal_load_values_finish (MMIfaceModemSignal *self, *gsm = signals->gsm ? g_object_ref (signals->gsm) : NULL; *umts = signals->umts ? g_object_ref (signals->umts) : NULL; *lte = signals->lte ? g_object_ref (signals->lte) : NULL; + *nr5g = signals->nr5g ? g_object_ref (signals->nr5g) : NULL; detailed_signal_free (signals); return TRUE; diff --git a/plugins/xmm/mm-shared-xmm.c b/plugins/xmm/mm-shared-xmm.c index 746aff36..e2203942 100644 --- a/plugins/xmm/mm-shared-xmm.c +++ b/plugins/xmm/mm-shared-xmm.c @@ -761,6 +761,7 @@ mm_shared_xmm_signal_load_values_finish (MMIfaceModemSignal *self, MMSignal **gsm, MMSignal **umts, MMSignal **lte, + MMSignal **nr5g, GError **error) { const gchar *response; @@ -773,6 +774,8 @@ mm_shared_xmm_signal_load_values_finish (MMIfaceModemSignal *self, *cdma = NULL; if (evdo) *evdo = NULL; + if (nr5g) + *nr5g = NULL; return TRUE; } diff --git a/plugins/xmm/mm-shared-xmm.h b/plugins/xmm/mm-shared-xmm.h index 1a4f4744..a1f51639 100644 --- a/plugins/xmm/mm-shared-xmm.h +++ b/plugins/xmm/mm-shared-xmm.h @@ -140,6 +140,7 @@ gboolean mm_shared_xmm_signal_load_values_finish (MMIfaceModemSign MMSignal **gsm, MMSignal **umts, MMSignal **lte, + MMSignal **nr5g, GError **error); void mm_shared_xmm_signal_load_values (MMIfaceModemSignal *self, GCancellable *cancellable, diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 8954889b..4bf941d5 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4342,6 +4342,7 @@ typedef struct { MMSignal *gsm; MMSignal *umts; MMSignal *lte; + MMSignal *nr5g; } SignalLoadValuesResult; static void @@ -4361,6 +4362,7 @@ modem_signal_load_values_finish (MMIfaceModemSignal *self, MMSignal **gsm, MMSignal **umts, MMSignal **lte, + MMSignal **nr5g, GError **error) { SignalLoadValuesResult *result; @@ -4391,6 +4393,8 @@ modem_signal_load_values_finish (MMIfaceModemSignal *self, *cdma = NULL; if (evdo) *evdo = NULL; + if (nr5g) + *nr5g = NULL; return TRUE; } @@ -4489,7 +4493,7 @@ parent_signal_load_values_ready (MMIfaceModemSignal *self, result = g_slice_new0 (SignalLoadValuesResult); if (!iface_modem_signal_parent->load_values_finish (self, res, NULL, NULL, - &result->gsm, &result->umts, &result->lte, + &result->gsm, &result->umts, &result->lte, &result->nr5g, &error)) { signal_load_values_result_free (result); g_task_return_error (task, error); diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index e3a616ae..4169fa15 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -8463,6 +8463,7 @@ typedef struct { MMSignal *gsm; MMSignal *umts; MMSignal *lte; + MMSignal *nr5g; } SignalLoadValuesResult; typedef struct { @@ -8509,14 +8510,15 @@ get_db_from_sinr_level (MMBroadbandModemQmi *self, } static gboolean -signal_load_values_finish (MMIfaceModemSignal *self, - GAsyncResult *res, - MMSignal **cdma, - MMSignal **evdo, - MMSignal **gsm, - MMSignal **umts, - MMSignal **lte, - GError **error) +signal_load_values_finish (MMIfaceModemSignal *self, + GAsyncResult *res, + MMSignal **cdma, + MMSignal **evdo, + MMSignal **gsm, + MMSignal **umts, + MMSignal **lte, + MMSignal **nr5g, + GError **error) { SignalLoadValuesResult *values_result; @@ -8529,6 +8531,7 @@ signal_load_values_finish (MMIfaceModemSignal *self, *gsm = values_result->gsm ? g_object_ref (values_result->gsm) : NULL; *umts = values_result->umts ? g_object_ref (values_result->umts) : NULL; *lte = values_result->lte ? g_object_ref (values_result->lte) : NULL; + *nr5g = values_result->nr5g ? g_object_ref (values_result->nr5g) : NULL; signal_load_values_result_free (values_result); return TRUE; } @@ -8693,15 +8696,16 @@ signal_load_values_get_signal_info_ready (QmiClientNas *client, GAsyncResult *res, GTask *task) { - MMBroadbandModemQmi *self; - SignalLoadValuesContext *ctx; - gint8 rssi; - gint16 ecio; - QmiNasEvdoSinrLevel sinr_level; - gint32 io; - gint8 rsrq; - gint16 rsrp; - gint16 snr; + MMBroadbandModemQmi *self; + SignalLoadValuesContext *ctx; + gint8 rssi; + gint16 ecio; + QmiNasEvdoSinrLevel sinr_level; + gint32 io; + gint8 rsrq; + gint16 rsrp; + gint16 snr; + gint16 rsrq_5g; g_autoptr(QmiMessageNasGetSignalInfoOutput) output = NULL; self = g_task_get_source_object (task); @@ -8774,6 +8778,22 @@ signal_load_values_get_signal_info_ready (QmiClientNas *client, mm_signal_set_snr (ctx->values_result->lte, (0.1) * ((gdouble)snr)); } + /* 5G */ + if (qmi_message_nas_get_signal_info_output_get_5g_signal_strength (output, + &rsrp, + &snr, + NULL)) { + ctx->values_result->nr5g = mm_signal_new (); + mm_signal_set_rsrp (ctx->values_result->nr5g, (gdouble)rsrp); + mm_signal_set_snr (ctx->values_result->nr5g, (gdouble)snr); + } + + if (qmi_message_nas_get_signal_info_output_get_5g_signal_strength_extended (output, + &rsrq_5g, + NULL)) { + mm_signal_set_rsrq (ctx->values_result->nr5g, (gdouble)rsrq_5g); + } + /* Keep on */ ctx->step++; signal_load_values_context_step (task); diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 6977fe33..f3b19402 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -9981,6 +9981,7 @@ modem_signal_load_values_finish (MMIfaceModemSignal *self, MMSignal **gsm, MMSignal **umts, MMSignal **lte, + MMSignal **nr5g, GError **error) { const gchar *response; @@ -9994,6 +9995,9 @@ modem_signal_load_values_finish (MMIfaceModemSignal *self, *cdma = NULL; if (evdo) *evdo = NULL; + if (nr5g) + *nr5g = NULL; + return TRUE; } diff --git a/src/mm-iface-modem-signal.c b/src/mm-iface-modem-signal.c index 03e4ce1f..447b7cf2 100644 --- a/src/mm-iface-modem-signal.c +++ b/src/mm-iface-modem-signal.c @@ -68,6 +68,7 @@ clear_values (MMIfaceModemSignal *self) mm_gdbus_modem_signal_set_gsm (skeleton, NULL); mm_gdbus_modem_signal_set_umts (skeleton, NULL); mm_gdbus_modem_signal_set_lte (skeleton, NULL); + mm_gdbus_modem_signal_set_nr5g (skeleton, NULL); g_object_unref (skeleton); } @@ -82,6 +83,7 @@ load_values_ready (MMIfaceModemSignal *self, MMSignal *gsm = NULL; MMSignal *umts = NULL; MMSignal *lte = NULL; + MMSignal *nr5g = NULL; MmGdbusModemSignal *skeleton; if (!MM_IFACE_MODEM_SIGNAL_GET_INTERFACE (self)->load_values_finish ( @@ -92,6 +94,7 @@ load_values_ready (MMIfaceModemSignal *self, &gsm, &umts, <e, + &nr5g, &error)) { mm_obj_warn (self, "couldn't load extended signal information: %s", error->message); g_error_free (error); @@ -147,6 +150,15 @@ load_values_ready (MMIfaceModemSignal *self, } else mm_gdbus_modem_signal_set_lte (skeleton, NULL); + if (nr5g) { + dictionary = mm_signal_get_dictionary (nr5g); + mm_gdbus_modem_signal_set_nr5g (skeleton, dictionary); + g_variant_unref (dictionary); + g_object_unref (nr5g); + } else + mm_gdbus_modem_signal_set_nr5g (skeleton, NULL); + + /* Flush right away */ g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (skeleton)); diff --git a/src/mm-iface-modem-signal.h b/src/mm-iface-modem-signal.h index 1d49e5f3..15874b3f 100644 --- a/src/mm-iface-modem-signal.h +++ b/src/mm-iface-modem-signal.h @@ -54,6 +54,7 @@ struct _MMIfaceModemSignal { MMSignal **gsm, MMSignal **umts, MMSignal **lte, + MMSignal **nr5g, GError **error); }; From 0dd1f122221aae8d4c5b16802f5f47601ff99e10 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 05:35:00 +0200 Subject: [PATCH 307/675] mbim,signal: provide 5G signal info if loaded by parent implementation --- src/mm-broadband-modem-mbim.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 4bf941d5..b2296b2f 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4351,6 +4351,7 @@ signal_load_values_result_free (SignalLoadValuesResult *result) g_clear_object (&result->gsm); g_clear_object (&result->umts); g_clear_object (&result->lte); + g_clear_object (&result->nr5g); g_slice_free (SignalLoadValuesResult, result); } @@ -4386,6 +4387,11 @@ modem_signal_load_values_finish (MMIfaceModemSignal *self, result->lte = NULL; } + if (nr5g && result->nr5g) { + *nr5g = result->nr5g; + result->nr5g = NULL; + } + signal_load_values_result_free (result); /* No 3GPP2 support */ @@ -4393,8 +4399,6 @@ modem_signal_load_values_finish (MMIfaceModemSignal *self, *cdma = NULL; if (evdo) *evdo = NULL; - if (nr5g) - *nr5g = NULL; return TRUE; } From 10ee7f4cd9d8af46822959fc84055bac45f5c56b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 05:37:59 +0200 Subject: [PATCH 308/675] mbim,signal: make sure output pointers are always set E.g. if 'gsm' pointer is given, make sure it's always set (either to a MMSignal or to NULL). --- src/mm-broadband-modem-mbim.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index b2296b2f..73c86f49 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4372,25 +4372,14 @@ modem_signal_load_values_finish (MMIfaceModemSignal *self, if (!result) return FALSE; - if (gsm && result->gsm) { - *gsm = result->gsm; - result->gsm = NULL; - } - - if (umts && result->umts) { - *umts = result->umts; - result->umts = NULL; - } - - if (lte && result->lte) { - *lte = result->lte; - result->lte = NULL; - } - - if (nr5g && result->nr5g) { - *nr5g = result->nr5g; - result->nr5g = NULL; - } + if (gsm) + *gsm = g_steal_pointer (&result->gsm); + if (umts) + *umts = g_steal_pointer (&result->umts); + if (lte) + *lte = g_steal_pointer (&result->lte); + if (nr5g) + *nr5g = g_steal_pointer (&result->nr5g); signal_load_values_result_free (result); From 24670498bc1431388d670f07284e3a1c339b08fc Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 05:53:43 +0200 Subject: [PATCH 309/675] broadband-modem-qmi: minor alignment updates --- src/mm-broadband-modem-qmi.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 4169fa15..0137820c 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -8696,17 +8696,17 @@ signal_load_values_get_signal_info_ready (QmiClientNas *client, GAsyncResult *res, GTask *task) { - MMBroadbandModemQmi *self; + MMBroadbandModemQmi *self; SignalLoadValuesContext *ctx; - gint8 rssi; - gint16 ecio; - QmiNasEvdoSinrLevel sinr_level; - gint32 io; - gint8 rsrq; - gint16 rsrp; - gint16 snr; - gint16 rsrq_5g; - g_autoptr(QmiMessageNasGetSignalInfoOutput) output = NULL; + gint8 rssi; + gint16 ecio; + QmiNasEvdoSinrLevel sinr_level; + gint32 io; + gint8 rsrq; + gint16 rsrp; + gint16 snr; + gint16 rsrq_5g; + g_autoptr(QmiMessageNasGetSignalInfoOutput) output = NULL; self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); @@ -8793,7 +8793,7 @@ signal_load_values_get_signal_info_ready (QmiClientNas *client, NULL)) { mm_signal_set_rsrq (ctx->values_result->nr5g, (gdouble)rsrq_5g); } - + /* Keep on */ ctx->step++; signal_load_values_context_step (task); From 6f6c09007667828d70708cedc04bbb9b680504ec Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 05:55:17 +0200 Subject: [PATCH 310/675] broadband-modem: remove misleading comment 5GNR is not 3GPP2 --- src/mm-broadband-modem.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index f3b19402..613748bf 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -9990,7 +9990,6 @@ modem_signal_load_values_finish (MMIfaceModemSignal *self, if (!response || !mm_3gpp_cesq_response_to_signal_info (response, self, gsm, umts, lte, error)) return FALSE; - /* No 3GPP2 support */ if (cdma) *cdma = NULL; if (evdo) From 900f318d535f5775a544ae8b1551efb931460392 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 06:32:04 +0200 Subject: [PATCH 311/675] docs,libmm-glib: add missing nr5g methods in signal interface --- docs/reference/libmm-glib/libmm-glib-sections.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 9bdbb21c..32524e7a 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -943,6 +943,8 @@ mm_modem_signal_peek_umts mm_modem_signal_get_umts mm_modem_signal_peek_lte mm_modem_signal_get_lte +mm_modem_signal_peek_nr5g +mm_modem_signal_get_nr5g mm_modem_signal_setup mm_modem_signal_setup_finish @@ -2809,6 +2811,7 @@ mm_gdbus_modem_signal_set_cdma mm_gdbus_modem_signal_set_evdo mm_gdbus_modem_signal_set_gsm mm_gdbus_modem_signal_set_lte +mm_gdbus_modem_signal_set_nr5g mm_gdbus_modem_signal_set_rate mm_gdbus_modem_signal_set_umts mm_gdbus_modem_signal_complete_setup From 2cb8e5ef5d30330442af152fa7d65ec7cc612e89 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 05:45:28 +0200 Subject: [PATCH 312/675] cinterion,signal: minor coding style fixes --- .../cinterion/mm-broadband-modem-cinterion.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index e1e558c3..59fa779d 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -2143,7 +2143,7 @@ check_smoni_support (MMBaseModem *_self, if (mm_base_modem_at_command_finish (_self, res, NULL)) { mm_obj_dbg (self, "SMONI supported"); self->priv->smoni_support = FEATURE_SUPPORTED; - g_task_return_boolean (task, TRUE); // otherwise the whole interface is not available + g_task_return_boolean (task, TRUE); g_object_unref (task); return; } @@ -2153,21 +2153,19 @@ check_smoni_support (MMBaseModem *_self, /* Otherwise, check if the parent CESQ-based implementation works */ g_assert (iface_modem_signal_parent->check_support && iface_modem_signal_parent->check_support_finish); - iface_modem_signal_parent->check_support (g_task_get_task_data (task), - (GAsyncReadyCallback)parent_signal_check_support_ready, + iface_modem_signal_parent->check_support (MM_IFACE_MODEM_SIGNAL (self), + (GAsyncReadyCallback) parent_signal_check_support_ready, task); } static void -signal_check_support (MMIfaceModemSignal *_self, +signal_check_support (MMIfaceModemSignal *self, GAsyncReadyCallback callback, gpointer user_data) { - MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self); - - GTask *task = g_task_new (self, NULL, callback, user_data); - g_task_set_task_data (task, _self, NULL); + GTask *task; + task = g_task_new (self, NULL, callback, user_data); mm_base_modem_at_command (MM_BASE_MODEM (self), "^SMONI=?", 3, @@ -2217,8 +2215,9 @@ signal_load_values (MMIfaceModemSignal *_self, gpointer user_data) { MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self); + if (self->priv->smoni_support == FEATURE_SUPPORTED) { - mm_base_modem_at_command (MM_BASE_MODEM (_self), + mm_base_modem_at_command (MM_BASE_MODEM (self), "^SMONI", 3, FALSE, From ee262a473dcfd5702f66c532d42285c2763bad11 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 05:46:56 +0200 Subject: [PATCH 313/675] cinterion,signal: report error from parent signal support check --- plugins/cinterion/mm-broadband-modem-cinterion.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 59fa779d..852cf055 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -2125,10 +2125,12 @@ parent_signal_check_support_ready (MMIfaceModemSignal *self, GAsyncResult *res, GTask *task) { - gboolean parent_supported; + GError *error = NULL; - parent_supported = iface_modem_signal_parent->check_support_finish (self, res, NULL); - g_task_return_boolean (task, parent_supported); + if (!iface_modem_signal_parent->check_support_finish (self, res, &error)) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); g_object_unref (task); } From c79dcf794041724b5504a9576b07c1e53ca0affb Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 05:47:25 +0200 Subject: [PATCH 314/675] =?UTF-8?q?cinterion,signal:=20^SMONI=3D=3F=20supp?= =?UTF-8?q?ort=20check=20may=20be=20cached?= --- plugins/cinterion/mm-broadband-modem-cinterion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 852cf055..de36fcbc 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -2171,7 +2171,7 @@ signal_check_support (MMIfaceModemSignal *self, mm_base_modem_at_command (MM_BASE_MODEM (self), "^SMONI=?", 3, - FALSE, + TRUE, (GAsyncReadyCallback) check_smoni_support, task); } From 3d138f9f80823d2caafbc5117329b43472fe7d45 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 06:02:37 +0200 Subject: [PATCH 315/675] iface-modem-signal: remove unneeded skeleton clear attempt It won't do anything because clear_values() tries to get the skeleton from the modem object, and the skeleton hasn't been set at that point. --- src/mm-iface-modem-signal.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mm-iface-modem-signal.c b/src/mm-iface-modem-signal.c index 447b7cf2..b7e9b7fc 100644 --- a/src/mm-iface-modem-signal.c +++ b/src/mm-iface-modem-signal.c @@ -536,7 +536,6 @@ mm_iface_modem_signal_initialize (MMIfaceModemSignal *self, NULL); if (!skeleton) { skeleton = mm_gdbus_modem_signal_skeleton_new (); - clear_values (self); g_object_set (self, MM_IFACE_MODEM_SIGNAL_DBUS_SKELETON, skeleton, NULL); From bdbd0fc049f7e818b8ac29285bcbf187d9a0b8ed Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 4 Jul 2020 06:08:40 +0200 Subject: [PATCH 316/675] iface-modem-signal: port skeleton update logic to use g_autoptr --- src/mm-iface-modem-signal.c | 112 ++++++++++++++---------------------- 1 file changed, 44 insertions(+), 68 deletions(-) diff --git a/src/mm-iface-modem-signal.c b/src/mm-iface-modem-signal.c index b7e9b7fc..25d0840c 100644 --- a/src/mm-iface-modem-signal.c +++ b/src/mm-iface-modem-signal.c @@ -55,7 +55,7 @@ refresh_context_free (RefreshContext *ctx) static void clear_values (MMIfaceModemSignal *self) { - MmGdbusModemSignal *skeleton; + g_autoptr(MmGdbusModemSignalSkeleton) skeleton = NULL; g_object_get (self, MM_IFACE_MODEM_SIGNAL_DBUS_SKELETON, &skeleton, @@ -63,28 +63,32 @@ clear_values (MMIfaceModemSignal *self) if (!skeleton) return; - mm_gdbus_modem_signal_set_cdma (skeleton, NULL); - mm_gdbus_modem_signal_set_evdo (skeleton, NULL); - mm_gdbus_modem_signal_set_gsm (skeleton, NULL); - mm_gdbus_modem_signal_set_umts (skeleton, NULL); - mm_gdbus_modem_signal_set_lte (skeleton, NULL); - mm_gdbus_modem_signal_set_nr5g (skeleton, NULL); - g_object_unref (skeleton); + mm_gdbus_modem_signal_set_cdma (MM_GDBUS_MODEM_SIGNAL (skeleton), NULL); + mm_gdbus_modem_signal_set_evdo (MM_GDBUS_MODEM_SIGNAL (skeleton), NULL); + mm_gdbus_modem_signal_set_gsm (MM_GDBUS_MODEM_SIGNAL (skeleton), NULL); + mm_gdbus_modem_signal_set_umts (MM_GDBUS_MODEM_SIGNAL (skeleton), NULL); + mm_gdbus_modem_signal_set_lte (MM_GDBUS_MODEM_SIGNAL (skeleton), NULL); + mm_gdbus_modem_signal_set_nr5g (MM_GDBUS_MODEM_SIGNAL (skeleton), NULL); } static void load_values_ready (MMIfaceModemSignal *self, - GAsyncResult *res) + GAsyncResult *res) { - GVariant *dictionary; - GError *error = NULL; - MMSignal *cdma = NULL; - MMSignal *evdo = NULL; - MMSignal *gsm = NULL; - MMSignal *umts = NULL; - MMSignal *lte = NULL; - MMSignal *nr5g = NULL; - MmGdbusModemSignal *skeleton; + g_autoptr(GError) error = NULL; + g_autoptr(MMSignal) cdma = NULL; + g_autoptr(GVariant) dict_cdma = NULL; + g_autoptr(MMSignal) evdo = NULL; + g_autoptr(GVariant) dict_evdo = NULL; + g_autoptr(MMSignal) gsm = NULL; + g_autoptr(GVariant) dict_gsm = NULL; + g_autoptr(MMSignal) umts = NULL; + g_autoptr(GVariant) dict_umts = NULL; + g_autoptr(MMSignal) lte = NULL; + g_autoptr(GVariant) dict_lte = NULL; + g_autoptr(MMSignal) nr5g = NULL; + g_autoptr(GVariant) dict_nr5g = NULL; + g_autoptr(MmGdbusModemSignalSkeleton) skeleton = NULL; if (!MM_IFACE_MODEM_SIGNAL_GET_INTERFACE (self)->load_values_finish ( self, @@ -97,7 +101,6 @@ load_values_ready (MMIfaceModemSignal *self, &nr5g, &error)) { mm_obj_warn (self, "couldn't load extended signal information: %s", error->message); - g_error_free (error); clear_values (self); return; } @@ -110,59 +113,32 @@ load_values_ready (MMIfaceModemSignal *self, return; } - if (cdma) { - dictionary = mm_signal_get_dictionary (cdma); - mm_gdbus_modem_signal_set_cdma (skeleton, dictionary); - g_variant_unref (dictionary); - g_object_unref (cdma); - } else - mm_gdbus_modem_signal_set_cdma (skeleton, NULL); - - if (evdo) { - dictionary = mm_signal_get_dictionary (evdo); - mm_gdbus_modem_signal_set_evdo (skeleton, dictionary); - g_variant_unref (dictionary); - g_object_unref (evdo); - } else - mm_gdbus_modem_signal_set_evdo (skeleton, NULL); - - if (gsm) { - dictionary = mm_signal_get_dictionary (gsm); - mm_gdbus_modem_signal_set_gsm (skeleton, dictionary); - g_variant_unref (dictionary); - g_object_unref (gsm); - } else - mm_gdbus_modem_signal_set_gsm (skeleton, NULL); - - if (umts) { - dictionary = mm_signal_get_dictionary (umts); - mm_gdbus_modem_signal_set_umts (skeleton, dictionary); - g_variant_unref (dictionary); - g_object_unref (umts); - } else - mm_gdbus_modem_signal_set_umts (skeleton, NULL); - - if (lte) { - dictionary = mm_signal_get_dictionary (lte); - mm_gdbus_modem_signal_set_lte (skeleton, dictionary); - g_variant_unref (dictionary); - g_object_unref (lte); - } else - mm_gdbus_modem_signal_set_lte (skeleton, NULL); - - if (nr5g) { - dictionary = mm_signal_get_dictionary (nr5g); - mm_gdbus_modem_signal_set_nr5g (skeleton, dictionary); - g_variant_unref (dictionary); - g_object_unref (nr5g); - } else - mm_gdbus_modem_signal_set_nr5g (skeleton, NULL); + if (cdma) + dict_cdma = mm_signal_get_dictionary (cdma); + mm_gdbus_modem_signal_set_cdma (MM_GDBUS_MODEM_SIGNAL (skeleton), dict_cdma); + + if (evdo) + dict_evdo = mm_signal_get_dictionary (evdo); + mm_gdbus_modem_signal_set_evdo (MM_GDBUS_MODEM_SIGNAL (skeleton), dict_evdo); + if (gsm) + dict_gsm = mm_signal_get_dictionary (gsm); + mm_gdbus_modem_signal_set_gsm (MM_GDBUS_MODEM_SIGNAL (skeleton), dict_gsm); + + if (umts) + dict_umts = mm_signal_get_dictionary (umts); + mm_gdbus_modem_signal_set_umts (MM_GDBUS_MODEM_SIGNAL (skeleton), dict_umts); + + if (lte) + dict_lte = mm_signal_get_dictionary (lte); + mm_gdbus_modem_signal_set_lte (MM_GDBUS_MODEM_SIGNAL (skeleton), dict_lte); + + if (nr5g) + dict_nr5g = mm_signal_get_dictionary (nr5g); + mm_gdbus_modem_signal_set_nr5g (MM_GDBUS_MODEM_SIGNAL (skeleton), dict_nr5g); /* Flush right away */ g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (skeleton)); - - g_object_unref (skeleton); } static gboolean From e933fe14130b20785b6ddd2993a8fc982976c7af Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 25 Jun 2020 18:43:57 +0200 Subject: [PATCH 317/675] cinterion: increase SWWAN connection attempt timeout It's critical not to timeout early on devices with AT ports, or we may end up flagging the modem as invalid. ModemManager[26829]: [1593097973.552712] [modem1/ttyACM0/at] --> 'AT^SWWAN=1,2,1' .... ModemManager[26829]: [1593098064.195217] [modem1] couldn't connect bearer: Serial command timed out .... ModemManager[26829]: [1593098091.167987] [modem1] port ttyACM0 timed out 10 consecutive times, marking modem as invalid --- plugins/cinterion/mm-broadband-bearer-cinterion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index e1a06135..ff9d008c 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -433,7 +433,7 @@ dial_3gpp_context_step (GTask *task) mm_base_modem_at_command_full (ctx->modem, ctx->primary, command, - 90, + 180, FALSE, FALSE, NULL, From 0a89a9ae4ee62ba36b616fc444a866d61c203696 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 6 Jul 2020 16:23:57 +0200 Subject: [PATCH 318/675] cinterion: if user OR password given, don't set the other as (null) [modem2/ttyACM1/at] --> 'AT^SGAUTH=8,1,t-d1,(null)' [modem2/ttyACM1/at] <-- '+CME ERROR: 4' We should use an empty string instead. --- plugins/cinterion/mm-broadband-bearer-cinterion.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index ff9d008c..a4ee87d2 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -236,7 +236,11 @@ build_auth_string (MMBroadbandBearerCinterion *self, encoded_auth = BEARER_CINTERION_AUTH_PAP; } - return g_strdup_printf ("^SGAUTH=%u,%d,%s,%s", cid, encoded_auth, passwd, user); + return g_strdup_printf ("^SGAUTH=%u,%d,%s,%s", + cid, + encoded_auth, + passwd ? passwd : "", + user ? user : ""); } /******************************************************************************/ From a131c6953a0a24a6ed8c365cb5e398fa5e52afcf Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 6 Jul 2020 16:53:08 +0200 Subject: [PATCH 319/675] cinterion: quote user/password strings in AT^SGAUTH calls The ELS61 doesn't like authentication given without quotes: [modem3/ttyACM1/at] --> 'AT^SGAUTH=8,1,tm,t-mobile' [modem3/ttyACM1/at] <-- '+CME ERROR: 4' Only when user/pass strings are quoted it works: [modem6/ttyACM1/at] --> 'AT^SGAUTH=8,1,"t-mobile","tm"' [modem6/ttyACM1/at] <-- 'OK' --- .../cinterion/mm-broadband-bearer-cinterion.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index a4ee87d2..b3b1d240 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -203,12 +203,14 @@ build_auth_string (MMBroadbandBearerCinterion *self, MMBearerProperties *config, guint cid) { - const gchar *user; - const gchar *passwd; - gboolean has_user; - gboolean has_passwd; MMBearerAllowedAuth auth; BearerCinterionAuthType encoded_auth = BEARER_CINTERION_AUTH_UNKNOWN; + gboolean has_user; + gboolean has_passwd; + const gchar *user; + const gchar *passwd; + g_autofree gchar *quoted_user = NULL; + g_autofree gchar *quoted_passwd = NULL; user = mm_bearer_properties_get_user (config); passwd = mm_bearer_properties_get_password (config); @@ -236,11 +238,14 @@ build_auth_string (MMBroadbandBearerCinterion *self, encoded_auth = BEARER_CINTERION_AUTH_PAP; } + quoted_user = mm_port_serial_at_quote_string (user ? user : ""); + quoted_passwd = mm_port_serial_at_quote_string (passwd ? passwd : ""); + return g_strdup_printf ("^SGAUTH=%u,%d,%s,%s", cid, encoded_auth, - passwd ? passwd : "", - user ? user : ""); + quoted_passwd, + quoted_user); } /******************************************************************************/ From e98bc7cc0803595db8eb498817fb0d5f99d25813 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 8 Jul 2020 11:40:41 +0200 Subject: [PATCH 320/675] broadband-modem-qmi: fix parsing of USSD indications with UTF-16 data Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/240 --- src/mm-broadband-modem-qmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 0137820c..1febe628 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -7238,7 +7238,7 @@ ussd_indication_cb (QmiClientVoice *client, qmi_indication_voice_ussd_output_get_user_action (output, &user_action, NULL); if (qmi_indication_voice_ussd_output_get_uss_data_utf16 (output, &uss_data, NULL) && uss_data) - utf8 = g_convert ((const gchar *) uss_data->data, (2 * uss_data->len), "UTF-8", "UTF16-LE", NULL, NULL, &error); + utf8 = g_convert ((const gchar *) uss_data->data, (2 * uss_data->len), "UTF-8", "UTF-16LE", NULL, NULL, &error); else if (qmi_indication_voice_ussd_output_get_uss_data (output, &scheme, &uss_data, NULL) && uss_data) utf8 = ussd_decode(scheme, uss_data, &error); From 6ec12add1ba6625a8470ae3cf7b30cefcf28d503 Mon Sep 17 00:00:00 2001 From: Justin Standring Date: Thu, 16 Jul 2020 12:55:31 +1200 Subject: [PATCH 321/675] broadband-modem-qmi: fix object logging with WITH_NEWEST_QMI_COMMANDS mm-broadband-modem-qmi.c: In function 'common_signal_info_get_quality': mm-broadband-modem-qmi.c:1469:21: error: 'self' undeclared (first use in this function) mm_obj_dbg (self, "RSSI (CDMA): %d dBm", cdma1x_rssi); ^~~~ mm-broadband-modem-qmi.c:1469:21: note: each undeclared identifier is reported only once for each function it appears in mm_obj_dbg (self, "RSSI (CDMA): %d dBm", cdma1x_rssi); ^~~~ mm-broadband-modem-qmi.c: In function 'process_gsm_info': mm-broadband-modem-qmi.c:2992:25: error: 'self' undeclared (first use in this function) mm_obj_dbg (self, "no GSM service reported"); ^~~~ mm-broadband-modem-qmi.c: In function 'process_wcdma_info': mm-broadband-modem-qmi.c:3100:25: error: 'self' undeclared (first use in this function) mm_obj_dbg (self, "no WCDMA service reported"); ^~~~ mm-broadband-modem-qmi.c: In function 'process_lte_info': mm-broadband-modem-qmi.c:3209:25: error: 'self' undeclared (first use in this function) mm_obj_dbg (self, "no LTE service reported"); ^~~~ mm-broadband-modem-qmi.c: In function 'config_signal_info_ready': mm-broadband-modem-qmi.c:4890:21: error: 'self' undeclared (first use in this function) mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); ^~~~ Signed-off-by: Justin Standring --- src/mm-broadband-modem-qmi.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 1febe628..0711a467 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -1445,7 +1445,8 @@ load_signal_quality_finish (MMIfaceModem *self, #if defined WITH_NEWEST_QMI_COMMANDS static gboolean -common_signal_info_get_quality (gint8 cdma1x_rssi, +common_signal_info_get_quality (MMBroadbandModemQmi *self, + gint8 cdma1x_rssi, gint8 evdo_rssi, gint8 gsm_rssi, gint8 wcdma_rssi, @@ -1535,7 +1536,7 @@ signal_info_get_quality (MMBroadbandModemQmi *self, qmi_message_nas_get_signal_info_output_get_wcdma_signal_strength (output, &wcdma_rssi, NULL, NULL); qmi_message_nas_get_signal_info_output_get_lte_signal_strength (output, <e_rssi, NULL, NULL, NULL, NULL); - return common_signal_info_get_quality (cdma1x_rssi, evdo_rssi, gsm_rssi, wcdma_rssi, lte_rssi, out_quality, out_act); + return common_signal_info_get_quality (self, cdma1x_rssi, evdo_rssi, gsm_rssi, wcdma_rssi, lte_rssi, out_quality, out_act); } static void @@ -2932,7 +2933,8 @@ process_common_info (QmiNasServiceStatus service_status, } static gboolean -process_gsm_info (QmiMessageNasGetSystemInfoOutput *response_output, +process_gsm_info (MMBroadbandModemQmi *self, + QmiMessageNasGetSystemInfoOutput *response_output, QmiIndicationNasSystemInfoOutput *indication_output, MMModem3gppRegistrationState *mm_cs_registration_state, MMModem3gppRegistrationState *mm_ps_registration_state, @@ -3037,7 +3039,8 @@ process_gsm_info (QmiMessageNasGetSystemInfoOutput *response_output, } static gboolean -process_wcdma_info (QmiMessageNasGetSystemInfoOutput *response_output, +process_wcdma_info (MMBroadbandModemQmi *self, + QmiMessageNasGetSystemInfoOutput *response_output, QmiIndicationNasSystemInfoOutput *indication_output, MMModem3gppRegistrationState *mm_cs_registration_state, MMModem3gppRegistrationState *mm_ps_registration_state, @@ -3146,7 +3149,8 @@ process_wcdma_info (QmiMessageNasGetSystemInfoOutput *response_output, } static gboolean -process_lte_info (QmiMessageNasGetSystemInfoOutput *response_output, +process_lte_info (MMBroadbandModemQmi *self, + QmiMessageNasGetSystemInfoOutput *response_output, QmiIndicationNasSystemInfoOutput *indication_output, MMModem3gppRegistrationState *mm_cs_registration_state, MMModem3gppRegistrationState *mm_ps_registration_state, @@ -3276,7 +3280,7 @@ common_process_system_info_3gpp (MMBroadbandModemQmi *self, * LTE > WCDMA > GSM * The first one giving results will be the one reported. */ - has_lte_info = process_lte_info (response_output, indication_output, + has_lte_info = process_lte_info (self, response_output, indication_output, &cs_registration_state, &ps_registration_state, &lac, @@ -3284,13 +3288,13 @@ common_process_system_info_3gpp (MMBroadbandModemQmi *self, &cid, &operator_id); if (!has_lte_info && - !process_wcdma_info (response_output, indication_output, + !process_wcdma_info (self, response_output, indication_output, &cs_registration_state, &ps_registration_state, &lac, &cid, &operator_id) && - !process_gsm_info (response_output, indication_output, + !process_gsm_info (self, response_output, indication_output, &cs_registration_state, &ps_registration_state, &lac, @@ -4814,8 +4818,11 @@ config_signal_info_ready (QmiClientNas *client, GAsyncResult *res, GTask *task) { - g_autoptr(QmiMessageNasConfigSignalInfoOutput) output = NULL; - g_autoptr(GError) error = NULL; + MMBroadbandModemQmi *self; + g_autoptr(QmiMessageNasConfigSignalInfoOutput) output = NULL; + g_autoptr(GError) error = NULL; + + self = g_task_get_source_object (task); output = qmi_client_nas_config_signal_info_finish (client, res, &error); if (!output || !qmi_message_nas_config_signal_info_output_get_result (output, &error)) @@ -5039,7 +5046,8 @@ signal_info_indication_cb (QmiClientNas *client, qmi_indication_nas_signal_info_output_get_wcdma_signal_strength (output, &wcdma_rssi, NULL, NULL); qmi_indication_nas_signal_info_output_get_lte_signal_strength (output, <e_rssi, NULL, NULL, NULL, NULL); - if (common_signal_info_get_quality (cdma1x_rssi, + if (common_signal_info_get_quality (self, + cdma1x_rssi, evdo_rssi, gsm_rssi, wcdma_rssi, From 47a28114baa2504c16bf2bca2325cefe426aea95 Mon Sep 17 00:00:00 2001 From: Justin Standring Date: Thu, 16 Jul 2020 13:21:23 +1200 Subject: [PATCH 322/675] broadband-modem-qmi: fix -Wempty-body warning mm-broadband-modem-qmi.c: In function 'process_common_info': mm-broadband-modem-qmi.c:2897:30: warning: suggest braces around empty body in an 'if' statement [-Wempty-body] /* both apply */ ; ^ Signed-off-by: Justin Standring --- src/mm-broadband-modem-qmi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 0711a467..d57bab94 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -2890,8 +2890,9 @@ process_common_info (QmiNasServiceStatus service_status, apply_ps = FALSE; else if (domain == QMI_NAS_NETWORK_SERVICE_DOMAIN_PS) apply_cs = FALSE; - else if (domain == QMI_NAS_NETWORK_SERVICE_DOMAIN_CS_PS) + else if (domain == QMI_NAS_NETWORK_SERVICE_DOMAIN_CS_PS) { /* both apply */ ; + } /* Check if we really are roaming or forbidden */ if (forbidden_valid && forbidden) From c70b3557184fdf1472ff0cb36e9fd937cc7f9024 Mon Sep 17 00:00:00 2001 From: Sven Schwermer Date: Fri, 3 Jul 2020 15:16:26 +0200 Subject: [PATCH 323/675] qmi: Network registration via SSSP if possible Doing the network registration via Set System Selection Preference is preferable because it doesn't override the currently set allowed mode, i.e. access technology. https://lists.freedesktop.org/archives/modemmanager-devel/2020-July/007972.html Signed-off-by: Sven Schwermer --- src/mm-shared-qmi.c | 138 +++++++++++++++++++++++++++++++++----------- 1 file changed, 105 insertions(+), 33 deletions(-) diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index bbcc169b..fb4943f7 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -326,41 +326,14 @@ initiate_network_register_ready (QmiClientNas *client, qmi_message_nas_initiate_network_register_output_unref (output); } -void -mm_shared_qmi_3gpp_register_in_network (MMIfaceModem3gpp *self, - const gchar *operator_id, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +static void +register_in_network_inr (GTask *task, + QmiClient *client, + GCancellable *cancellable, + guint16 mcc, + guint16 mnc) { - GTask *task; - RegisterInNetworkContext *ctx; QmiMessageNasInitiateNetworkRegisterInput *input; - guint16 mcc = 0; - guint16 mnc; - QmiClient *client = NULL; - GError *error = NULL; - - /* Get NAS client */ - if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), - QMI_SERVICE_NAS, &client, - callback, user_data)) - return; - - task = g_task_new (self, cancellable, callback, user_data); - - ctx = g_slice_new0 (RegisterInNetworkContext); - ctx->client = g_object_ref (client); - ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - g_task_set_task_data (task, ctx, (GDestroyNotify)register_in_network_context_free); - - /* Parse input MCC/MNC */ - if (operator_id && !mm_3gpp_parse_operator_id (operator_id, &mcc, &mnc, &error)) { - g_assert (error != NULL); - g_task_return_error (task, error); - g_object_unref (task); - return; - } input = qmi_message_nas_initiate_network_register_input_new (); @@ -395,6 +368,105 @@ mm_shared_qmi_3gpp_register_in_network (MMIfaceModem3gpp *self, qmi_message_nas_initiate_network_register_input_unref (input); } +static void +set_system_selection_preference_ready (QmiClientNas *client, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + QmiMessageNasSetSystemSelectionPreferenceOutput *output; + + output = qmi_client_nas_set_system_selection_preference_finish (client, res, &error); + if (!output || !qmi_message_nas_set_system_selection_preference_output_get_result (output, &error)) { + if (!g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_NO_EFFECT)) { + g_prefix_error (&error, "Couldn't set network selection preference: "); + g_task_return_error (task, error); + goto out; + } + g_error_free (error); + } + + g_task_return_boolean (task, TRUE); + +out: + g_object_unref (task); + + if (output) + qmi_message_nas_set_system_selection_preference_output_unref (output); +} + +static void +register_in_network_sssp (GTask *task, + QmiClient *client, + GCancellable *cancellable, + guint16 mcc, + guint16 mnc) +{ + QmiMessageNasSetSystemSelectionPreferenceInput *input; + + input = qmi_message_nas_set_system_selection_preference_input_new (); + + qmi_message_nas_set_system_selection_preference_input_set_network_selection_preference ( + input, + mcc ? QMI_NAS_NETWORK_SELECTION_PREFERENCE_MANUAL : QMI_NAS_NETWORK_SELECTION_PREFERENCE_AUTOMATIC, + mcc, + mnc, + NULL); + + qmi_client_nas_set_system_selection_preference ( + QMI_CLIENT_NAS (client), + input, + 120, + cancellable, + (GAsyncReadyCallback)set_system_selection_preference_ready, + task); + + qmi_message_nas_set_system_selection_preference_input_unref (input); +} + +void +mm_shared_qmi_3gpp_register_in_network (MMIfaceModem3gpp *self, + const gchar *operator_id, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + RegisterInNetworkContext *ctx; + guint16 mcc = 0; + guint16 mnc; + QmiClient *client = NULL; + GError *error = NULL; + Private *priv = NULL; + + /* Get NAS client */ + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_NAS, &client, + callback, user_data)) + return; + + task = g_task_new (self, cancellable, callback, user_data); + + ctx = g_slice_new0 (RegisterInNetworkContext); + ctx->client = g_object_ref (client); + ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; + g_task_set_task_data (task, ctx, (GDestroyNotify)register_in_network_context_free); + + /* Parse input MCC/MNC */ + if (operator_id && !mm_3gpp_parse_operator_id (operator_id, &mcc, &mnc, &error)) { + g_assert (error != NULL); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + priv = get_private (MM_SHARED_QMI (self)); + if (priv->feature_nas_system_selection_preference == FEATURE_SUPPORTED) + register_in_network_sssp (task, client, cancellable, mcc, mnc); + else + register_in_network_inr (task, client, cancellable, mcc, mnc); +} + /*****************************************************************************/ /* Current capabilities setting (Modem interface) */ From 4d58278d7ffd65375e93b0da85ca88c08cba96c2 Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Wed, 22 Jul 2020 06:58:22 +0200 Subject: [PATCH 324/675] changed default authentication algorithm to CHAP CHAP is almost universal nowadays, and so it is a better default than PAP Not changed for uBlox, that prefers an error if not specified, and for Huawei, which uses NONE with user/pwd and has 2 CHAP choices --- plugins/cinterion/mm-broadband-bearer-cinterion.c | 6 +++--- plugins/huawei/mm-broadband-bearer-huawei.c | 12 ++++++------ plugins/icera/mm-broadband-bearer-icera.c | 10 +++++----- plugins/option/mm-broadband-bearer-hso.c | 10 +++++----- plugins/sierra/mm-broadband-bearer-sierra.c | 10 +++++----- plugins/ublox/mm-broadband-bearer-ublox.c | 4 ++-- src/mm-bearer-qmi.c | 6 +++--- src/mm-modem-helpers-mbim.c | 8 ++++---- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index b3b1d240..676bbbd9 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -233,9 +233,9 @@ build_auth_string (MMBroadbandBearerCinterion *self, if (!has_user && !has_passwd) return NULL; - /* If user/passwd given, default to PAP */ - mm_obj_dbg (self, "APN user/password given but no authentication type explicitly requested: defaulting to 'PAP'"); - encoded_auth = BEARER_CINTERION_AUTH_PAP; + /* If user/passwd given, default to CHAP (more common than PAP) */ + mm_obj_dbg (self, "APN user/password given but no authentication type explicitly requested: defaulting to 'CHAP'"); + encoded_auth = BEARER_CINTERION_AUTH_CHAP; } quoted_user = mm_port_serial_at_quote_string (user ? user : ""); diff --git a/plugins/huawei/mm-broadband-bearer-huawei.c b/plugins/huawei/mm-broadband-bearer-huawei.c index ca20c655..6548ae7f 100644 --- a/plugins/huawei/mm-broadband-bearer-huawei.c +++ b/plugins/huawei/mm-broadband-bearer-huawei.c @@ -391,17 +391,17 @@ connect_3gpp_context_step (GTask *task) if (!user && !passwd) command = g_strdup_printf ("AT^NDISDUP=1,1,\"%s\"", apn == NULL ? "" : apn); - else if (encoded_auth == MM_BEARER_HUAWEI_AUTH_NONE) - command = g_strdup_printf ("AT^NDISDUP=1,1,\"%s\",\"%s\",\"%s\"", - apn == NULL ? "" : apn, - user == NULL ? "" : user, - passwd == NULL ? "" : passwd); - else + else { + if (encoded_auth == MM_BEARER_HUAWEI_AUTH_NONE) { + encoded_auth = MM_BEARER_HUAWEI_AUTH_CHAP; + mm_obj_dbg (self, "using default (CHAP) authentication method"); + } command = g_strdup_printf ("AT^NDISDUP=1,1,\"%s\",\"%s\",\"%s\",%d", apn == NULL ? "" : apn, user == NULL ? "" : user, passwd == NULL ? "" : passwd, encoded_auth); + } mm_base_modem_at_command_full (ctx->modem, ctx->primary, diff --git a/plugins/icera/mm-broadband-bearer-icera.c b/plugins/icera/mm-broadband-bearer-icera.c index 48bcf49a..caa8567f 100644 --- a/plugins/icera/mm-broadband-bearer-icera.c +++ b/plugins/icera/mm-broadband-bearer-icera.c @@ -734,14 +734,14 @@ authenticate (GTask *task) guint icera_auth; if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { - mm_obj_dbg (self, "using default (PAP) authentication method"); - icera_auth = 1; - } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { - mm_obj_dbg (self, "using PAP authentication method"); - icera_auth = 1; + mm_obj_dbg (self, "using default (CHAP) authentication method"); + icera_auth = 2; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_CHAP) { mm_obj_dbg (self, "using CHAP authentication method"); icera_auth = 2; + } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { + mm_obj_dbg (self, "using PAP authentication method"); + icera_auth = 1; } else { gchar *str; diff --git a/plugins/option/mm-broadband-bearer-hso.c b/plugins/option/mm-broadband-bearer-hso.c index 3ca5cd77..a5702c01 100644 --- a/plugins/option/mm-broadband-bearer-hso.c +++ b/plugins/option/mm-broadband-bearer-hso.c @@ -526,14 +526,14 @@ authenticate (GTask *task) guint hso_auth; if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { - mm_obj_dbg (self, "using default (PAP) authentication method"); - hso_auth = 1; - } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { - mm_obj_dbg (self, "using PAP authentication method"); - hso_auth = 1; + mm_obj_dbg (self, "using default (CHAP) authentication method"); + hso_auth = 2; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_CHAP) { mm_obj_dbg (self, "using CHAP authentication method"); hso_auth = 2; + } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { + mm_obj_dbg (self, "using PAP authentication method"); + hso_auth = 1; } else { gchar *str; diff --git a/plugins/sierra/mm-broadband-bearer-sierra.c b/plugins/sierra/mm-broadband-bearer-sierra.c index 24bde739..db9fdead 100644 --- a/plugins/sierra/mm-broadband-bearer-sierra.c +++ b/plugins/sierra/mm-broadband-bearer-sierra.c @@ -338,14 +338,14 @@ dial_3gpp_context_step (GTask *task) guint sierra_auth; if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { - mm_obj_dbg (self, "using default (PAP) authentication method"); - sierra_auth = 1; - } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { - mm_obj_dbg (self, "using PAP authentication method"); - sierra_auth = 1; + mm_obj_dbg (self, "using default (CHAP) authentication method"); + sierra_auth = 2; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_CHAP) { mm_obj_dbg (self, "using CHAP authentication method"); sierra_auth = 2; + } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { + mm_obj_dbg (self, "using PAP authentication method"); + sierra_auth = 1; } else { gchar *str; diff --git a/plugins/ublox/mm-broadband-bearer-ublox.c b/plugins/ublox/mm-broadband-bearer-ublox.c index 1e2ea4d5..1b209841 100644 --- a/plugins/ublox/mm-broadband-bearer-ublox.c +++ b/plugins/ublox/mm-broadband-bearer-ublox.c @@ -498,10 +498,10 @@ authenticate_3gpp (GTask *task) mm_obj_dbg (self, "using automatic authentication method"); if (self->priv->allowed_auths & MM_UBLOX_BEARER_ALLOWED_AUTH_AUTO) ublox_auth = 3; - else if (self->priv->allowed_auths & MM_UBLOX_BEARER_ALLOWED_AUTH_PAP) - ublox_auth = 1; else if (self->priv->allowed_auths & MM_UBLOX_BEARER_ALLOWED_AUTH_CHAP) ublox_auth = 2; + else if (self->priv->allowed_auths & MM_UBLOX_BEARER_ALLOWED_AUTH_PAP) + ublox_auth = 1; else if (self->priv->allowed_auths & MM_UBLOX_BEARER_ALLOWED_AUTH_NONE) ublox_auth = 0; } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { diff --git a/src/mm-bearer-qmi.c b/src/mm-bearer-qmi.c index 1afb6c25..91cb71d9 100644 --- a/src/mm-bearer-qmi.c +++ b/src/mm-bearer-qmi.c @@ -636,10 +636,10 @@ build_start_network_input (ConnectContext *ctx) /* Need to add auth info? */ if (has_user || has_password || ctx->auth != QMI_WDS_AUTHENTICATION_NONE) { /* We define a valid auth preference if we have either user or password, or an explicit - * request for one to be set. If no explicit one was given, default to PAP. */ + * request for one to be set. If no explicit one was given, default to CHAP. */ qmi_message_wds_start_network_input_set_authentication_preference ( input, - (ctx->auth != QMI_WDS_AUTHENTICATION_NONE) ? ctx->auth : QMI_WDS_AUTHENTICATION_PAP, + (ctx->auth != QMI_WDS_AUTHENTICATION_NONE) ? ctx->auth : QMI_WDS_AUTHENTICATION_CHAP, NULL); if (has_user) @@ -1740,7 +1740,7 @@ _connect (MMBaseBearer *_self, g_object_unref (properties); if (auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { - /* We'll default to PAP later if needed */ + /* We'll default to CHAP later if needed */ ctx->auth = QMI_WDS_AUTHENTICATION_NONE; } else if (auth & (MM_BEARER_ALLOWED_AUTH_PAP | MM_BEARER_ALLOWED_AUTH_CHAP | diff --git a/src/mm-modem-helpers-mbim.c b/src/mm-modem-helpers-mbim.c index 8d8697b9..0d5ff5f9 100644 --- a/src/mm-modem-helpers-mbim.c +++ b/src/mm-modem-helpers-mbim.c @@ -375,13 +375,13 @@ mm_bearer_allowed_auth_to_mbim_auth_protocol (MMBearerAllowedAuth bearer_auth, /* NOTE: the input is a BITMASK, so we try to find a "best match" */ if (bearer_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { - mm_obj_dbg (log_object, "using default (PAP) authentication method"); - return MBIM_AUTH_PROTOCOL_PAP; + mm_obj_dbg (log_object, "using default (CHAP) authentication method"); + return MBIM_AUTH_PROTOCOL_CHAP; } - if (bearer_auth & MM_BEARER_ALLOWED_AUTH_PAP) - return MBIM_AUTH_PROTOCOL_PAP; if (bearer_auth & MM_BEARER_ALLOWED_AUTH_CHAP) return MBIM_AUTH_PROTOCOL_CHAP; + if (bearer_auth & MM_BEARER_ALLOWED_AUTH_PAP) + return MBIM_AUTH_PROTOCOL_PAP; if (bearer_auth & MM_BEARER_ALLOWED_AUTH_MSCHAPV2) return MBIM_AUTH_PROTOCOL_MSCHAPV2; if (bearer_auth & MM_BEARER_ALLOWED_AUTH_NONE) From cec6fe9cce4f7f49f941262d48d081e30f8ea444 Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Fri, 24 Jul 2020 16:25:03 +0200 Subject: [PATCH 325/675] cinterion: radio/band single scfg line: no variance the AT^SCFG="Radio/Band" command does not return a different answer for different charsets. This code was working previously because the charset was left to default (GSM) at the time of this operation, and therefore the string was unchanged anyway. --- plugins/cinterion/mm-modem-helpers-cinterion.c | 13 ++----------- .../tests/test-modem-helpers-cinterion.c | 18 ------------------ 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index 9041960f..095e396c 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -270,13 +270,8 @@ mm_cinterion_parse_scfg_test (const gchar *response, *format = MM_CINTERION_RADIO_BAND_FORMAT_SINGLE; maxbandstr = mm_get_string_unquoted_from_match_info (match_info1, 2); - if (maxbandstr) { - /* Handle charset conversion if the number is given in UCS2 */ - if (charset != MM_MODEM_CHARSET_UNKNOWN) - maxbandstr = mm_charset_take_and_convert_to_utf8 (maxbandstr, charset); - + if (maxbandstr) mm_get_uint_from_str (maxbandstr, &maxband); - } if (maxband == 0) { inner_error = g_error_new (MM_CORE_ERROR, @@ -419,12 +414,8 @@ mm_cinterion_parse_scfg_response (const gchar *response, guint current = 0; currentstr = mm_get_string_unquoted_from_match_info (match_info, 1); - if (currentstr) { - /* Handle charset conversion if the number is given in UCS2 */ - if (charset != MM_MODEM_CHARSET_UNKNOWN) - currentstr = mm_charset_take_and_convert_to_utf8 (currentstr, charset); + if (currentstr) mm_get_uint_from_str (currentstr, ¤t); - } if (current == 0) { inner_error = g_error_new (MM_CORE_ERROR, diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c index b23a356e..35123283 100644 --- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c +++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c @@ -509,23 +509,6 @@ test_scfg_response_2g (void) g_array_unref (expected_bands); } -static void -test_scfg_response_2g_ucs2 (void) -{ - GArray *expected_bands; - MMModemBand single; - const gchar *response = - "^SCFG: \"Radio/Band\",\"0031\",\"0031\"\r\n" - "\r\n"; - - expected_bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 9); - single = MM_MODEM_BAND_EGSM, g_array_append_val (expected_bands, single); - - common_test_scfg_response (response, MM_MODEM_CHARSET_UCS2, expected_bands, MM_CINTERION_MODEM_FAMILY_DEFAULT, MM_CINTERION_RADIO_BAND_FORMAT_SINGLE); - - g_array_unref (expected_bands); -} - static void test_scfg_response_3g (void) { @@ -1629,7 +1612,6 @@ int main (int argc, char **argv) g_test_add_func ("/MM/cinterion/scfg/alas5", test_scfg_alas5); g_test_add_func ("/MM/cinterion/scfg/response/3g", test_scfg_response_3g); g_test_add_func ("/MM/cinterion/scfg/response/2g", test_scfg_response_2g); - g_test_add_func ("/MM/cinterion/scfg/response/2g/ucs2", test_scfg_response_2g_ucs2); g_test_add_func ("/MM/cinterion/scfg/response/pls62/gsm", test_scfg_response_pls62_gsm); g_test_add_func ("/MM/cinterion/scfg/response/pls62/ucs2",test_scfg_response_pls62_ucs2); g_test_add_func ("/MM/cinterion/scfg/response/alas5", test_scfg_response_alas5); From 408ec530e0442137194cf048de72183011fdc40b Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Mon, 27 Jul 2020 06:23:52 +0200 Subject: [PATCH 326/675] cinterion: extend SGAUTH syntax AT^SGAUTH syntax depends on the modem family: AT^SGAUTH=cid,type,user,pwd for the IMT family AT^SGAUTH=cid,type,pwd,user for the rest --- .../cinterion/mm-broadband-bearer-cinterion.c | 19 +++++++++++++++++-- .../cinterion/mm-broadband-modem-cinterion.c | 8 ++++++++ .../cinterion/mm-broadband-modem-cinterion.h | 3 +++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index 676bbbd9..fa4c3ef6 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -197,9 +197,13 @@ parse_auth_type (MMBearerAllowedAuth mm_auth) } } -/* AT^SGAUTH=[, [, , ]] */ +/* Cinterion authentication is done with the command AT^SGAUTH, + whose syntax depends on the modem family, as follow: + - AT^SGAUTH=[, [, , ]] for the IMT family + - AT^SGAUTH=[, [, , ]] for the rest */ static gchar * build_auth_string (MMBroadbandBearerCinterion *self, + MMCinterionModemFamily modem_family, MMBearerProperties *config, guint cid) { @@ -241,6 +245,13 @@ build_auth_string (MMBroadbandBearerCinterion *self, quoted_user = mm_port_serial_at_quote_string (user ? user : ""); quoted_passwd = mm_port_serial_at_quote_string (passwd ? passwd : ""); + if (modem_family == MM_CINTERION_MODEM_FAMILY_IMT) + return g_strdup_printf ("^SGAUTH=%u,%d,%s,%s", + cid, + encoded_auth, + quoted_user, + quoted_passwd); + return g_strdup_printf ("^SGAUTH=%u,%d,%s,%s", cid, encoded_auth, @@ -409,7 +420,11 @@ dial_3gpp_context_step (GTask *task) case DIAL_3GPP_CONTEXT_STEP_AUTH: { gchar *command; - command = build_auth_string (self, mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)), ctx->cid); + command = build_auth_string (self, + mm_broadband_modem_cinterion_get_family (MM_BROADBAND_MODEM_CINTERION (self)), + mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)), + ctx->cid); + if (command) { mm_obj_dbg (self, "dial step %u/%u: authenticating...", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); /* Send SGAUTH write, if User & Pass are provided. diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index de36fcbc..0e42083f 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -105,6 +105,14 @@ struct _MMBroadbandModemCinterionPrivate { MMBaseModemAtCommandAlloc *cmds; }; +MMCinterionModemFamily +mm_broadband_modem_cinterion_get_family (MMBroadbandModemCinterion * modem) +{ + g_assert_nonnull (modem); + return modem->priv->modem_family; +} + + /*****************************************************************************/ /* Enable unsolicited events (SMS indications) (Messaging interface) */ diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.h b/plugins/cinterion/mm-broadband-modem-cinterion.h index 47f0dcb4..555ee084 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.h +++ b/plugins/cinterion/mm-broadband-modem-cinterion.h @@ -19,6 +19,7 @@ #define MM_BROADBAND_MODEM_CINTERION_H #include "mm-broadband-modem.h" +#include "mm-modem-helpers-cinterion.h" #define MM_TYPE_BROADBAND_MODEM_CINTERION (mm_broadband_modem_cinterion_get_type ()) #define MM_BROADBAND_MODEM_CINTERION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_CINTERION, MMBroadbandModemCinterion)) @@ -48,4 +49,6 @@ MMBroadbandModemCinterion *mm_broadband_modem_cinterion_new (const gchar *device guint16 vendor_id, guint16 product_id); +MMCinterionModemFamily mm_broadband_modem_cinterion_get_family (MMBroadbandModemCinterion * modem); + #endif /* MM_BROADBAND_MODEM_CINTERION_H */ From 07ac85e2f70706e377c2019b07ce29958c70668c Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Mon, 27 Jul 2020 12:24:17 +0200 Subject: [PATCH 327/675] cinterion: ignore ^SYSSTART urc --- .../cinterion/mm-broadband-modem-cinterion.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 0e42083f..412339ab 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -88,6 +88,8 @@ struct _MMBroadbandModemCinterionPrivate { GArray *cnmi_supported_ds; GArray *cnmi_supported_bfr; + /* ignore regex */ + GRegex *sysstart_regex; /* +CIEV indications as configured via AT^SIND */ GRegex *ciev_regex; @@ -1954,6 +1956,8 @@ mm_broadband_modem_cinterion_init (MMBroadbandModemCinterion *self) self->priv->ciev_regex = g_regex_new ("\\r\\n\\+CIEV:\\s*([a-z]+),(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + self->priv->sysstart_regex = g_regex_new ("\\r\\n\\^SYSSTART.*\\r\\n", + G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); } static void @@ -1975,6 +1979,7 @@ finalize (GObject *object) g_array_unref (self->priv->cnmi_supported_bfr); g_regex_unref (self->priv->ciev_regex); + g_regex_unref (self->priv->sysstart_regex); G_OBJECT_CLASS (mm_broadband_modem_cinterion_parent_class)->finalize (object); } @@ -2106,15 +2111,45 @@ shared_cinterion_init (MMSharedCinterion *iface) iface->peek_parent_time_interface = peek_parent_time_interface; } +static void +setup_ports (MMBroadbandModem *_self) +{ + MMBroadbandModemCinterion *self = (MM_BROADBAND_MODEM_CINTERION (_self)); + MMPortSerialAt *port; + + /* Call parent's setup ports first always */ + MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_cinterion_parent_class)->setup_ports (_self); + + /* Primary */ + port = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); + if (port) { + mm_port_serial_at_add_unsolicited_msg_handler ( + port, + self->priv->sysstart_regex, + NULL, NULL, NULL); + } + + /* Secondary */ + port = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); + if (port) { + mm_port_serial_at_add_unsolicited_msg_handler ( + port, + self->priv->sysstart_regex, + NULL, NULL, NULL); + } +} + static void mm_broadband_modem_cinterion_class_init (MMBroadbandModemCinterionClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + MMBroadbandModemClass *broadband_modem_class = MM_BROADBAND_MODEM_CLASS (klass); g_type_class_add_private (object_class, sizeof (MMBroadbandModemCinterionPrivate)); /* Virtual methods */ object_class->finalize = finalize; + broadband_modem_class->setup_ports = setup_ports; } /*****************************************************************************/ From 4f1da8797213fb79856a5e8e1c6e6dca7236c2e0 Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Mon, 27 Jul 2020 12:27:26 +0200 Subject: [PATCH 328/675] cinterion: IMT family SGAUTH some ITM family modems require full parameters: AT^SGAUTH=cid,type,user,pwd even when type is AUTH_NONE. Fortunately, all modules of the IMT family tolerate this syntax, so it can be adopted for the entire family. --- plugins/cinterion/mm-broadband-bearer-cinterion.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index fa4c3ef6..bc9cf224 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -228,6 +228,8 @@ build_auth_string (MMBroadbandBearerCinterion *self, if (encoded_auth == BEARER_CINTERION_AUTH_NONE) { if (has_user || has_passwd) mm_obj_warn (self, "APN user/password given but 'none' authentication requested"); + if (modem_family == MM_CINTERION_MODEM_FAMILY_IMT) + return g_strdup_printf ("^SGAUTH=%u,%d,\"\",\"\"", cid, encoded_auth); return g_strdup_printf ("^SGAUTH=%u,%d", cid, encoded_auth); } From 130ea74cc953e9029a9a1662a788048ac765a0b3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 1 Aug 2020 09:59:01 +0200 Subject: [PATCH 329/675] iface-modem: move sim hot swap ready to correct place in sequence --- src/mm-iface-modem.c | 53 +++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 48105afe..9b3f2223 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -4374,6 +4374,31 @@ load_supported_ip_families_ready (MMIfaceModem *self, UINT_REPLY_READY_FN (power_state, "power state") +static void +setup_sim_hot_swap_ready (MMIfaceModem *self, + GAsyncResult *res, + GTask *task) +{ + InitializationContext *ctx; + g_autoptr(GError) error = NULL; + + ctx = g_task_get_task_data (task); + + MM_IFACE_MODEM_GET_INTERFACE (self)->setup_sim_hot_swap_finish (self, res, &error); + if (error) + mm_obj_warn (self, "SIM hot swap setup failed: %s", error->message); + else { + mm_obj_dbg (self, "SIM hot swap setup succeeded"); + g_object_set (self, + MM_IFACE_MODEM_SIM_HOT_SWAP_CONFIGURED, TRUE, + NULL); + } + + /* Go on to next step */ + ctx->step++; + interface_initialization_step (task); +} + static void modem_update_lock_info_ready (MMIfaceModem *self, GAsyncResult *res, @@ -4617,34 +4642,6 @@ load_current_bands_ready (MMIfaceModem *self, interface_initialization_step (task); } -/*****************************************************************************/ -/* Setup SIM hot swap (Modem interface) */ -static void -setup_sim_hot_swap_ready (MMIfaceModem *self, - GAsyncResult *res, - GTask *task) -{ - InitializationContext *ctx; - GError *error = NULL; - - ctx = g_task_get_task_data (task); - - MM_IFACE_MODEM_GET_INTERFACE (self)->setup_sim_hot_swap_finish (self, res, &error); - if (error) { - mm_obj_warn (self, "SIM hot swap setup failed: %s", error->message); - g_error_free (error); - } else { - mm_obj_dbg (self, "SIM hot swap setup succeeded"); - g_object_set (self, - MM_IFACE_MODEM_SIM_HOT_SWAP_CONFIGURED, TRUE, - NULL); - } - - /* Go on to next step */ - ctx->step++; - interface_initialization_step (task); -} - static void interface_initialization_step (GTask *task) { From 74dd28c4e31cca38d0b4c7ed034af4226566b404 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 1 Aug 2020 09:59:05 +0200 Subject: [PATCH 330/675] broadband-modem: minor method rename --- plugins/telit/mm-broadband-modem-telit.c | 2 +- src/mm-broadband-modem-mbim.c | 2 +- src/mm-broadband-modem.c | 4 ++-- src/mm-broadband-modem.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/telit/mm-broadband-modem-telit.c b/plugins/telit/mm-broadband-modem-telit.c index 94a6ddcc..11a86b12 100644 --- a/plugins/telit/mm-broadband-modem-telit.c +++ b/plugins/telit/mm-broadband-modem-telit.c @@ -507,7 +507,7 @@ telit_qss_unsolicited_handler (MMPortSerialAt *port, if ((prev_qss_status == QSS_STATUS_SIM_REMOVED && cur_qss_status != QSS_STATUS_SIM_REMOVED) || (prev_qss_status > QSS_STATUS_SIM_REMOVED && cur_qss_status == QSS_STATUS_SIM_REMOVED)) { mm_obj_info (self, "QSS handler: SIM swap detected"); - mm_broadband_modem_update_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); + mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); } } diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 73c86f49..d3800666 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -3123,7 +3123,7 @@ basic_connect_notification_subscriber_ready_status (MMBroadbandModemMbim *self, ready_state != MBIM_SUBSCRIBER_READY_STATE_SIM_NOT_INSERTED)) { /* SIM has been removed or reinserted, re-probe to ensure correct interfaces are exposed */ mm_obj_dbg (self, "SIM hot swap detected"); - mm_broadband_modem_update_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); + mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); } self->priv->last_ready_state = ready_state; diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 613748bf..aeb660c6 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -4119,7 +4119,7 @@ load_sim_identifier_ready (MMBaseSim *sim, if (g_strcmp0 (current_simid, cached_simid) != 0) { mm_obj_info (self, "sim identifier has changed: possible SIM swap during power down/low"); - mm_broadband_modem_update_sim_hot_swap_detected (self); + mm_broadband_modem_sim_hot_swap_detected (self); } g_task_return_boolean (task, TRUE); @@ -11914,7 +11914,7 @@ after_hotswap_event_disable_ready (MMBaseModem *self, } void -mm_broadband_modem_update_sim_hot_swap_detected (MMBroadbandModem *self) +mm_broadband_modem_sim_hot_swap_detected (MMBroadbandModem *self) { if (self->priv->sim_hot_swap_ports_ctx) { mm_obj_dbg (self, "releasing SIM hot swap ports context"); diff --git a/src/mm-broadband-modem.h b/src/mm-broadband-modem.h index 8042f509..5891f564 100644 --- a/src/mm-broadband-modem.h +++ b/src/mm-broadband-modem.h @@ -132,6 +132,6 @@ void mm_broadband_modem_unlock_sms_storages (MMBroadbandModem *self, gboolean mem1, gboolean mem2); /* Helper to update SIM hot swap */ -void mm_broadband_modem_update_sim_hot_swap_detected (MMBroadbandModem *self); +void mm_broadband_modem_sim_hot_swap_detected (MMBroadbandModem *self); #endif /* MM_BROADBAND_MODEM_H */ From 1620f04b9b1b3166c37ca7e9170322df1e185258 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 1 Aug 2020 09:59:10 +0200 Subject: [PATCH 331/675] mmcli,output: use 'path' instead of 'dbus path' in field descriptions --- cli/mmcli-output.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c index 2242de8f..81a402ac 100644 --- a/cli/mmcli-output.c +++ b/cli/mmcli-output.c @@ -94,7 +94,7 @@ typedef struct { } FieldInfo; static FieldInfo field_infos[] = { - [MMC_F_GENERAL_DBUS_PATH] = { "modem.dbus-path", "dbus path", MMC_S_MODEM_GENERAL, }, + [MMC_F_GENERAL_DBUS_PATH] = { "modem.dbus-path", "path", MMC_S_MODEM_GENERAL, }, [MMC_F_GENERAL_DEVICE_ID] = { "modem.generic.device-identifier", "device id", MMC_S_MODEM_GENERAL, }, [MMC_F_HARDWARE_MANUFACTURER] = { "modem.generic.manufacturer", "manufacturer", MMC_S_MODEM_HARDWARE, }, [MMC_F_HARDWARE_MODEL] = { "modem.generic.model", "model", MMC_S_MODEM_HARDWARE, }, @@ -131,7 +131,7 @@ static FieldInfo field_infos[] = { [MMC_F_3GPP_REGISTRATION] = { "modem.3gpp.registration-state", "registration", MMC_S_MODEM_3GPP, }, [MMC_F_3GPP_PCO] = { "modem.3gpp.pco", "pco", MMC_S_MODEM_3GPP, }, [MMC_F_3GPP_EPS_UE_MODE] = { "modem.3gpp.eps.ue-mode-operation", "ue mode of operation", MMC_S_MODEM_3GPP_EPS, }, - [MMC_F_3GPP_EPS_INITIAL_BEARER_PATH] = { "modem.3gpp.eps.initial-bearer.dbus-path", "initial bearer dbus path", MMC_S_MODEM_3GPP_EPS, }, + [MMC_F_3GPP_EPS_INITIAL_BEARER_PATH] = { "modem.3gpp.eps.initial-bearer.dbus-path", "initial bearer path", MMC_S_MODEM_3GPP_EPS, }, [MMC_F_3GPP_EPS_BEARER_SETTINGS_APN] = { "modem.3gpp.eps.initial-bearer.settings.apn", "initial bearer apn", MMC_S_MODEM_3GPP_EPS, }, [MMC_F_3GPP_EPS_BEARER_SETTINGS_IP_TYPE] = { "modem.3gpp.eps.initial-bearer.settings.ip-type", "initial bearer ip type", MMC_S_MODEM_3GPP_EPS, }, [MMC_F_3GPP_EPS_BEARER_SETTINGS_USER] = { "modem.3gpp.eps.initial-bearer.settings.user", "initial bearer user", MMC_S_MODEM_3GPP_EPS, }, @@ -147,8 +147,8 @@ static FieldInfo field_infos[] = { [MMC_F_CDMA_REGISTRATION_CDMA1X] = { "modem.cdma.cdma1x-registration-state", "registration cdma1x", MMC_S_MODEM_CDMA, }, [MMC_F_CDMA_REGISTRATION_EVDO] = { "modem.cdma.evdo-registration-state", "registration evdo", MMC_S_MODEM_CDMA, }, [MMC_F_CDMA_ACTIVATION] = { "modem.cdma.activation-state", "activation", MMC_S_MODEM_CDMA, }, - [MMC_F_SIM_PATH] = { "modem.generic.sim", "dbus path", MMC_S_MODEM_SIM, }, - [MMC_F_BEARER_PATHS] = { "modem.generic.bearers", "dbus path", MMC_S_MODEM_BEARER, }, + [MMC_F_SIM_PATH] = { "modem.generic.sim", "path", MMC_S_MODEM_SIM, }, + [MMC_F_BEARER_PATHS] = { "modem.generic.bearers", "paths", MMC_S_MODEM_BEARER, }, [MMC_F_TIME_CURRENT] = { "modem.time.current", "current", MMC_S_MODEM_TIME, }, [MMC_F_TIMEZONE_CURRENT] = { "modem.timezone.current", "current", MMC_S_MODEM_TIMEZONE, }, [MMC_F_TIMEZONE_DST_OFFSET] = { "modem.time.dst-offset", "dst offset", MMC_S_MODEM_TIMEZONE, }, @@ -202,7 +202,7 @@ static FieldInfo field_infos[] = { [MMC_F_FIRMWARE_VERSION] = { "modem.firmware.version", "version", MMC_S_MODEM_FIRMWARE, }, [MMC_F_FIRMWARE_FASTBOOT_AT] = { "modem.firmware.fastboot.at", "at command", MMC_S_MODEM_FIRMWARE_FASTBOOT, }, [MMC_F_VOICE_EMERGENCY_ONLY] = { "modem.voice.emergency-only", "emergency only", MMC_S_MODEM_VOICE, }, - [MMC_F_BEARER_GENERAL_DBUS_PATH] = { "bearer.dbus-path", "dbus path", MMC_S_BEARER_GENERAL, }, + [MMC_F_BEARER_GENERAL_DBUS_PATH] = { "bearer.dbus-path", "path", MMC_S_BEARER_GENERAL, }, [MMC_F_BEARER_GENERAL_TYPE] = { "bearer.type", "type", MMC_S_BEARER_GENERAL, }, [MMC_F_BEARER_STATUS_CONNECTED] = { "bearer.status.connected", "connected", MMC_S_BEARER_STATUS, }, [MMC_F_BEARER_STATUS_SUSPENDED] = { "bearer.status.suspended", "suspended", MMC_S_BEARER_STATUS, }, @@ -236,7 +236,7 @@ static FieldInfo field_infos[] = { [MMC_F_BEARER_STATS_TOTAL_DURATION] = { "bearer.stats.total-duration", "total-duration", MMC_S_BEARER_STATS, }, [MMC_F_BEARER_STATS_TOTAL_BYTES_RX] = { "bearer.stats.total-bytes-rx", "total-bytes rx", MMC_S_BEARER_STATS, }, [MMC_F_BEARER_STATS_TOTAL_BYTES_TX] = { "bearer.stats.total-bytes-tx", "total-bytes tx", MMC_S_BEARER_STATS, }, - [MMC_F_CALL_GENERAL_DBUS_PATH] = { "call.dbus-path", "dbus path", MMC_S_CALL_GENERAL, }, + [MMC_F_CALL_GENERAL_DBUS_PATH] = { "call.dbus-path", "path", MMC_S_CALL_GENERAL, }, [MMC_F_CALL_PROPERTIES_NUMBER] = { "call.properties.number", "number", MMC_S_CALL_PROPERTIES, }, [MMC_F_CALL_PROPERTIES_DIRECTION] = { "call.properties.direction", "direction", MMC_S_CALL_PROPERTIES, }, [MMC_F_CALL_PROPERTIES_MULTIPARTY] = { "call.properties.multiparty", "multiparty", MMC_S_CALL_PROPERTIES, }, @@ -246,7 +246,7 @@ static FieldInfo field_infos[] = { [MMC_F_CALL_AUDIO_FORMAT_ENCODING] = { "call.audio-format.encoding", "encoding", MMC_S_CALL_AUDIO_FORMAT, }, [MMC_F_CALL_AUDIO_FORMAT_RESOLUTION] = { "call.audio-format.resolution", "resolution", MMC_S_CALL_AUDIO_FORMAT, }, [MMC_F_CALL_AUDIO_FORMAT_RATE] = { "call.audio-format.rate", "rate", MMC_S_CALL_AUDIO_FORMAT, }, - [MMC_F_SMS_GENERAL_DBUS_PATH] = { "sms.dbus-path", "dbus path", MMC_S_SMS_GENERAL, }, + [MMC_F_SMS_GENERAL_DBUS_PATH] = { "sms.dbus-path", "path", MMC_S_SMS_GENERAL, }, [MMC_F_SMS_CONTENT_NUMBER] = { "sms.content.number", "number", MMC_S_SMS_CONTENT, }, [MMC_F_SMS_CONTENT_TEXT] = { "sms.content.text", "text", MMC_S_SMS_CONTENT, }, [MMC_F_SMS_CONTENT_DATA] = { "sms.content.data", "data", MMC_S_SMS_CONTENT, }, @@ -263,7 +263,7 @@ static FieldInfo field_infos[] = { [MMC_F_SMS_PROPERTIES_TIMESTAMP] = { "sms.properties.timestamp", "timestamp", MMC_S_SMS_PROPERTIES, }, [MMC_F_SMS_PROPERTIES_DELIVERY_STATE] = { "sms.properties.delivery-state", "delivery state", MMC_S_SMS_PROPERTIES, }, [MMC_F_SMS_PROPERTIES_DISCH_TIMESTAMP] = { "sms.properties.discharge-timestamp", "discharge timestamp", MMC_S_SMS_PROPERTIES, }, - [MMC_F_SIM_GENERAL_DBUS_PATH] = { "sim.dbus-path", "dbus path", MMC_S_SIM_GENERAL, }, + [MMC_F_SIM_GENERAL_DBUS_PATH] = { "sim.dbus-path", "path", MMC_S_SIM_GENERAL, }, [MMC_F_SIM_PROPERTIES_IMSI] = { "sim.properties.imsi", "imsi", MMC_S_SIM_PROPERTIES, }, [MMC_F_SIM_PROPERTIES_ICCID] = { "sim.properties.iccid", "iccid", MMC_S_SIM_PROPERTIES, }, [MMC_F_SIM_PROPERTIES_OPERATOR_ID] = { "sim.properties.operator-code", "operator id", MMC_S_SIM_PROPERTIES, }, From 422a9070c40c48847870cb2cf141fe102cd72cba Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Tue, 4 Aug 2020 11:04:17 +0200 Subject: [PATCH 332/675] cinterion: fixed cast from wrong object MM_BROADBAND_MODEM_CINTERION shall be applied to a *MMBaseModem (ctx->modem here) and not to a *MMBaseBearer (self here) --- plugins/cinterion/mm-broadband-bearer-cinterion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index bc9cf224..3ee8623d 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -423,7 +423,7 @@ dial_3gpp_context_step (GTask *task) gchar *command; command = build_auth_string (self, - mm_broadband_modem_cinterion_get_family (MM_BROADBAND_MODEM_CINTERION (self)), + mm_broadband_modem_cinterion_get_family (MM_BROADBAND_MODEM_CINTERION (ctx->modem)), mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)), ctx->cid); From 28ad994e372dc58e474567c70adbb0f58022cb22 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 10 Aug 2020 19:26:56 +0200 Subject: [PATCH 333/675] sierra: XMM-specific features in XMM based modems (e.g. EM7345) We create XMM-based modems like the EM7345 with XMM-specific features like the AT+XLCSLSR based GNSS support. E.g.: $ mmcli -m a --location-status ------------------------ Location | capabilities: 3gpp-lac-ci, gps-raw, gps-nmea, agps-msa, agps-msb | enabled: 3gpp-lac-ci | signals: no ------------------------ GPS | refresh rate: 30 seconds $ sudo mmcli -m a --location-enable-gps-nmea successfully setup location gathering $ sudo mmcli -m a --location-get -------------------------- 3GPP | operator code: 214 | operator name: 7 | location area code: 0000 | tracking area code: 6FFE | cell id: 0465CD20 -------------------------- GPS | nmea: $GPGSA,A,1,,,,,,,,,,,,,,,*1E | $GNGSA,A,1,,,,,,,,,,,,,,,,1*1D | $GNRMC,235951.000,V,,,,,,,,,,N,V*20 | $GNVTG,,T,,M,,N,,K,N*32 | $GNGGA,235951.000,,,,,0,0,,,M,,M,,*5F Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/25 --- configure.ac | 3 ++- plugins/Makefile.am | 1 + plugins/sierra/mm-plugin-sierra.c | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e03edcb0..1cda4f70 100644 --- a/configure.ac +++ b/configure.ac @@ -489,7 +489,8 @@ MM_ENABLE_PLUGIN([samsung], MM_ENABLE_PLUGIN([sierra-legacy], [with_shared_icera, with_shared_sierra]) -MM_ENABLE_PLUGIN([sierra]) +MM_ENABLE_PLUGIN([sierra], + [with_shared_xmm]) MM_ENABLE_PLUGIN([simtech]) MM_ENABLE_PLUGIN([telit], [with_shared_telit]) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 6f83ad61..f7ca2ac4 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1240,6 +1240,7 @@ libmm_plugin_sierra_la_SOURCES = \ $(NULL) libmm_plugin_sierra_la_CPPFLAGS = \ $(PLUGIN_COMMON_COMPILER_FLAGS) \ + $(XMM_COMMON_COMPILER_FLAGS) \ -DMM_MODULE_NAME=\"sierra\" \ $(NULL) libmm_plugin_sierra_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) diff --git a/plugins/sierra/mm-plugin-sierra.c b/plugins/sierra/mm-plugin-sierra.c index 6622c5e1..75fdc90d 100644 --- a/plugins/sierra/mm-plugin-sierra.c +++ b/plugins/sierra/mm-plugin-sierra.c @@ -25,6 +25,7 @@ #include "mm-log-object.h" #include "mm-plugin-sierra.h" #include "mm-broadband-modem.h" +#include "mm-broadband-modem-xmm.h" #if defined WITH_QMI #include "mm-broadband-modem-qmi.h" @@ -32,6 +33,7 @@ #if defined WITH_MBIM #include "mm-broadband-modem-mbim.h" +#include "mm-broadband-modem-mbim-xmm.h" #endif G_DEFINE_TYPE (MMPluginSierra, mm_plugin_sierra, MM_TYPE_PLUGIN) @@ -63,6 +65,14 @@ create_modem (MMPlugin *self, #if defined WITH_MBIM if (mm_port_probe_list_has_mbim_port (probes)) { + if (mm_port_probe_list_is_xmm (probes)) { + mm_obj_dbg (self, "MBIM-powered XMM-based Sierra modem found..."); + return MM_BASE_MODEM (mm_broadband_modem_mbim_xmm_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); + } mm_obj_dbg (self, "MBIM-powered Sierra modem found..."); return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, drivers, @@ -72,6 +82,15 @@ create_modem (MMPlugin *self, } #endif + if (mm_port_probe_list_is_xmm (probes)) { + mm_obj_dbg (self, "XMM-based Sierra modem found..."); + return MM_BASE_MODEM (mm_broadband_modem_xmm_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); + } + /* Fallback to default modem in the worst case */ return MM_BASE_MODEM (mm_broadband_modem_new (uid, drivers, @@ -99,6 +118,7 @@ mm_plugin_create (void) MM_PLUGIN_ALLOWED_QCDM, TRUE, MM_PLUGIN_ALLOWED_QMI, TRUE, MM_PLUGIN_ALLOWED_MBIM, TRUE, + MM_PLUGIN_XMM_PROBE, TRUE, NULL)); } From e2ab49db0f5078716156c70a23f8f5d5b6d27848 Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Mon, 27 Jul 2020 10:29:14 +0200 Subject: [PATCH 334/675] cinterion: setup initial LTE parameters --- .../cinterion/mm-broadband-bearer-cinterion.c | 37 +- .../cinterion/mm-broadband-bearer-cinterion.h | 7 + .../cinterion/mm-broadband-modem-cinterion.c | 563 +++++++++++++++++- .../cinterion/mm-modem-helpers-cinterion.c | 52 ++ .../cinterion/mm-modem-helpers-cinterion.h | 9 + .../tests/test-modem-helpers-cinterion.c | 66 ++ 6 files changed, 722 insertions(+), 12 deletions(-) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index 3ee8623d..ceeb49be 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -197,15 +197,30 @@ parse_auth_type (MMBearerAllowedAuth mm_auth) } } +MMBearerAllowedAuth +mm_auth_type_from_cinterion_auth_type (guint cinterion_auth) +{ + switch (cinterion_auth) { + case BEARER_CINTERION_AUTH_NONE: + return MM_BEARER_ALLOWED_AUTH_NONE; + case BEARER_CINTERION_AUTH_PAP: + return MM_BEARER_ALLOWED_AUTH_PAP; + case BEARER_CINTERION_AUTH_CHAP: + return MM_BEARER_ALLOWED_AUTH_CHAP; + default: + return MM_BEARER_ALLOWED_AUTH_UNKNOWN; + } +} + /* Cinterion authentication is done with the command AT^SGAUTH, whose syntax depends on the modem family, as follow: - AT^SGAUTH=[, [, , ]] for the IMT family - AT^SGAUTH=[, [, , ]] for the rest */ -static gchar * -build_auth_string (MMBroadbandBearerCinterion *self, - MMCinterionModemFamily modem_family, - MMBearerProperties *config, - guint cid) +gchar * +mm_broadband_bearer_cinterion_build_auth_string (gpointer log_object, + MMCinterionModemFamily modem_family, + MMBearerProperties *config, + guint cid) { MMBearerAllowedAuth auth; BearerCinterionAuthType encoded_auth = BEARER_CINTERION_AUTH_UNKNOWN; @@ -227,7 +242,7 @@ build_auth_string (MMBroadbandBearerCinterion *self, /* When 'none' requested, we won't require user/password */ if (encoded_auth == BEARER_CINTERION_AUTH_NONE) { if (has_user || has_passwd) - mm_obj_warn (self, "APN user/password given but 'none' authentication requested"); + mm_obj_warn (log_object, "APN user/password given but 'none' authentication requested"); if (modem_family == MM_CINTERION_MODEM_FAMILY_IMT) return g_strdup_printf ("^SGAUTH=%u,%d,\"\",\"\"", cid, encoded_auth); return g_strdup_printf ("^SGAUTH=%u,%d", cid, encoded_auth); @@ -240,7 +255,7 @@ build_auth_string (MMBroadbandBearerCinterion *self, return NULL; /* If user/passwd given, default to CHAP (more common than PAP) */ - mm_obj_dbg (self, "APN user/password given but no authentication type explicitly requested: defaulting to 'CHAP'"); + mm_obj_dbg (log_object, "APN user/password given but no authentication type explicitly requested: defaulting to 'CHAP'"); encoded_auth = BEARER_CINTERION_AUTH_CHAP; } @@ -422,10 +437,10 @@ dial_3gpp_context_step (GTask *task) case DIAL_3GPP_CONTEXT_STEP_AUTH: { gchar *command; - command = build_auth_string (self, - mm_broadband_modem_cinterion_get_family (MM_BROADBAND_MODEM_CINTERION (ctx->modem)), - mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)), - ctx->cid); + command = mm_broadband_bearer_cinterion_build_auth_string (self, + mm_broadband_modem_cinterion_get_family (MM_BROADBAND_MODEM_CINTERION (ctx->modem)), + mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)), + ctx->cid); if (command) { mm_obj_dbg (self, "dial step %u/%u: authenticating...", ctx->step, DIAL_3GPP_CONTEXT_STEP_LAST); diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.h b/plugins/cinterion/mm-broadband-bearer-cinterion.h index d514759d..d63e5b70 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.h +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.h @@ -51,4 +51,11 @@ void mm_broadband_bearer_cinterion_new (MMBroadbandModemCinterio MMBaseBearer *mm_broadband_bearer_cinterion_new_finish (GAsyncResult *res, GError **error); +gchar *mm_broadband_bearer_cinterion_build_auth_string (gpointer log_object, + MMCinterionModemFamily modem_family, + MMBearerProperties *config, + guint cid); + +MMBearerAllowedAuth mm_auth_type_from_cinterion_auth_type (guint cinterion_auth); + #endif /* MM_BROADBAND_BEARER_CINTERION_H */ diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 412339ab..95b9ed0d 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -971,6 +971,559 @@ modem_3gpp_cleanup_unsolicited_events (MMIfaceModem3gpp *self, task); } +typedef enum { + INITIAL_EPS_CONTEXT_STEP_FIRST = 0, + INITIAL_EPS_CONTEXT_STEP_CHECK_MODE, + INITIAL_EPS_CONTEXT_STEP_RF_OFF, + INITIAL_EPS_CONTEXT_STEP_PROFILE, + INITIAL_EPS_CONTEXT_STEP_APN, + INITIAL_EPS_CONTEXT_STEP_AUTH, + INITIAL_EPS_CONTEXT_STEP_RF_ON, + INITIAL_EPS_CONTEXT_STEP_LAST, +} InitialEpsStep; + +typedef struct { + MMBearerProperties *properties; + InitialEpsStep step; + guint cid; + guint initial_cfun_mode; + GError *error; + void (*step_function) (GTask *task); + gboolean get_current_status; +} InitialEpsContext; + +static void +initial_eps_context_free (InitialEpsContext *ctx) +{ + g_object_unref (ctx->properties); + g_slice_free (InitialEpsContext, ctx); +} + +/*****************************************************************************/ +/* Set initial EPS bearer settings */ + +static gboolean +modem_3gpp_set_initial_eps_bearer_settings_finish (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +initial_eps_common_cmd_check (MMBaseModem *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + InitialEpsContext *ctx; + + ctx = (InitialEpsContext *) g_task_get_task_data (task); + + mm_base_modem_at_command_finish (self, res, &error); + + if (error) { + mm_obj_warn (self, "%s", error->message); + /* do not overwrite original error */ + if (!ctx->error) + ctx->error = error; + else + g_error_free (error); + } + + /* Go to next step */ + ctx->step++; + ctx->step_function (task); +} + +static void +set_cid_from_mno_profile (MMBaseModem *self, + GAsyncResult *res, + GTask *task) +{ + const gchar *response; + InitialEpsContext *ctx; + + ctx = (InitialEpsContext *) g_task_get_task_data (task); + response = mm_base_modem_at_command_finish (self, res, NULL); + /* in case of error, it means that the MNO profiles are not supported + * and therefore that the default CID=1 is ok. */ + if (response != NULL) + mm_cinterion_provcfg_response_to_cid (response, + MM_BROADBAND_MODEM_CINTERION (self)->priv->modem_family, + mm_broadband_modem_get_current_charset (MM_BROADBAND_MODEM (self)), + self, + &ctx->cid); + + /* Go to next step */ + ctx->step++; + ctx->step_function (task); +} + +static void +check_cfun_mode (MMBaseModem *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + const gchar *response; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + InitialEpsContext *ctx; + guint mode; + + ctx = (InitialEpsContext *) g_task_get_task_data (task); + response = mm_base_modem_at_command_finish (self, res, &error); + /* in case of error, abort - something wrong with the modem */ + if (error) + goto error; + + r = g_regex_new ("\\+CFUN:\\s*(\\d+)", 0, 0, NULL); + g_assert (r != NULL); + g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, NULL); + if (!g_match_info_matches (match_info)) { + error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "unmatched CFUN response: %s", response); + goto error; + } + + if (!mm_get_uint_from_match_info (match_info, 1, &mode)) { + error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "couldn't retrieve current mode from CFUN? response: %s", response); + goto error; + } + + mm_obj_dbg (self, "current cfun mode: %u", mode); + + if (mode != 1 && mode != 4) { + error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "cannot setup the default LTE bearer at this time: the SIM must be powered"); + goto error; + } + + ctx->initial_cfun_mode = mode; + ctx->step++; + ctx->step_function (task); + return; + +error: + mm_obj_warn (self, "%s", error->message); + g_task_return_error (task, error); + g_object_unref (task); +} + +static void +modem_3gpp_set_initial_eps_bearer_settings_step (GTask *task) +{ + MMIfaceModem3gpp *self; + InitialEpsContext *ctx; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + + /* in case of error, skip all steps and restore radio if needed */ + if (ctx->error && ctx->step < INITIAL_EPS_CONTEXT_STEP_RF_ON) + ctx->step = INITIAL_EPS_CONTEXT_STEP_RF_ON; + + switch (ctx->step) { + case INITIAL_EPS_CONTEXT_STEP_FIRST: + /* set defaults */ + ctx->cid = 1; + ctx->step++; + /* fall through */ + + case INITIAL_EPS_CONTEXT_STEP_CHECK_MODE: + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "+CFUN?", + 5, + FALSE, + (GAsyncReadyCallback)check_cfun_mode, + task); + return; + + case INITIAL_EPS_CONTEXT_STEP_RF_OFF: + if (ctx->initial_cfun_mode != 4) { + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "+CFUN=4", + 5, + FALSE, + (GAsyncReadyCallback)initial_eps_common_cmd_check, + task); + return; + } + ctx->step++; + /* fall through */ + + case INITIAL_EPS_CONTEXT_STEP_PROFILE: + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "^SCFG=\"MEopMode/Prov/Cfg\"", + 20, + FALSE, + (GAsyncReadyCallback)set_cid_from_mno_profile, + task); + return; + + case INITIAL_EPS_CONTEXT_STEP_APN: { + const gchar *apn; + g_autofree gchar *quoted_apn = NULL; + g_autofree gchar *apn_cmd = NULL; + const gchar *ip_family_str; + MMBearerIpFamily ip_family; + + ip_family = mm_bearer_properties_get_ip_type (ctx->properties); + if (ip_family == MM_BEARER_IP_FAMILY_NONE || ip_family == MM_BEARER_IP_FAMILY_ANY) + ip_family = MM_BEARER_IP_FAMILY_IPV4; + + if (ip_family != MM_BEARER_IP_FAMILY_IPV4) { + /* we must have the same settings as in dial_3gpp_context_step() + * for the case when the CID is re-used for the connection PDN */ + mm_obj_dbg (self, "Only IPv4 is supported by this modem"); + ip_family = MM_BEARER_IP_FAMILY_IPV4; + } + + ip_family_str = mm_3gpp_get_pdp_type_from_ip_family (ip_family); + apn = mm_bearer_properties_get_apn (ctx->properties); + mm_obj_dbg (self, "context CID=%d with APN '%s' and PDP type '%s'", ctx->cid, apn, ip_family_str); + quoted_apn = mm_port_serial_at_quote_string (apn); + apn_cmd = g_strdup_printf ("+CGDCONT=%u,\"%s\",%s", ctx->cid, ip_family_str, quoted_apn); + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + apn_cmd, + 20, + FALSE, + (GAsyncReadyCallback)initial_eps_common_cmd_check, + task); + return; + } + + case INITIAL_EPS_CONTEXT_STEP_AUTH: { + g_autofree gchar *auth_cmd = NULL; + + auth_cmd = mm_broadband_bearer_cinterion_build_auth_string (self, + MM_BROADBAND_MODEM_CINTERION (self)->priv->modem_family, + ctx->properties, + ctx->cid); + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + auth_cmd, + 20, + FALSE, + (GAsyncReadyCallback)initial_eps_common_cmd_check, + task); + return; + } + + case INITIAL_EPS_CONTEXT_STEP_RF_ON: + if (ctx->initial_cfun_mode == 1) { + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "+CFUN=1", + 5, + FALSE, + (GAsyncReadyCallback)initial_eps_common_cmd_check, + task); + return; + } + ctx->step++; + /* fall through */ + + case INITIAL_EPS_CONTEXT_STEP_LAST: + if (ctx->error) + g_task_return_error (task, ctx->error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + + default: + g_assert_not_reached (); + } +} + +static void +modem_3gpp_set_initial_eps_bearer_settings (MMIfaceModem3gpp *self, + MMBearerProperties *properties, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + InitialEpsContext *ctx; + + task = g_task_new (self, NULL, callback, user_data); + ctx = g_slice_new0 (InitialEpsContext); + g_task_set_task_data (task, ctx, (GDestroyNotify) initial_eps_context_free); + + /* Setup context */ + ctx->properties = g_object_ref (properties); + ctx->step = INITIAL_EPS_CONTEXT_STEP_FIRST; + ctx->step_function = modem_3gpp_set_initial_eps_bearer_settings_step; + + modem_3gpp_set_initial_eps_bearer_settings_step (task); +} + +/*****************************************************************************/ +/* Initial EPS bearer info loading -> current dynamic configuration */ + +static MMBearerProperties * +modem_3gpp_load_initial_eps_bearer_finish (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error) +{ + return MM_BEARER_PROPERTIES (g_task_propagate_pointer (G_TASK (res), error)); +} + +static void +get_apn_from_cgdcont (MMBaseModem *self, + GAsyncResult *res, + GTask *task) +{ + const gchar *response; + InitialEpsContext *ctx; + GList *context_list; + GList *l; + + ctx = (InitialEpsContext *) g_task_get_task_data (task); + response = mm_base_modem_at_command_finish (self, res, NULL); + /* in case of error, skip */ + if (!response) + goto end; + + context_list = mm_3gpp_parse_cgdcont_read_response (response, NULL); + if (!context_list) + goto end; + + for (l = context_list; l; l = g_list_next (l)) { + MM3gppPdpContext *pdp = l->data; + + if (pdp->cid == ctx->cid) { + mm_bearer_properties_set_ip_type (ctx->properties, pdp->pdp_type); + mm_bearer_properties_set_apn (ctx->properties, pdp->apn ? pdp->apn : ""); + } + } + mm_3gpp_pdp_context_list_free (context_list); + +end: + /* Go to next step */ + ctx->step++; + ctx->step_function (task); +} + +static void +get_apn_from_cgcontrdp (MMBaseModem *self, + GAsyncResult *res, + GTask *task) +{ + const gchar *response; + InitialEpsContext *ctx; + gchar *apn = NULL; + + ctx = (InitialEpsContext *) g_task_get_task_data (task); + response = mm_base_modem_at_command_finish (self, res, NULL); + /* in case of error, skip */ + mm_obj_dbg (self, "response: %s", response); + if (response && mm_3gpp_parse_cgcontrdp_response (response, NULL, NULL, &apn, NULL, NULL, NULL, NULL, NULL, NULL)) { + mm_bearer_properties_set_apn (ctx->properties, apn); + g_free (apn); + } + + /* Go to next step */ + ctx->step++; + ctx->step_function (task); +} + +/* at^sgauth? + * ^SGAUTH: 1,2,"vf" + * ^SGAUTH: 3,0,"" + * ^SGAUTH: 4,0 + * + * OK + */ +static void +get_auth_params (MMBaseModem *self, + GAsyncResult *res, + GTask *task) +{ + const gchar *response; + InitialEpsContext *ctx; + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + + ctx = (InitialEpsContext *) g_task_get_task_data (task); + response = mm_base_modem_at_command_finish (self, res, NULL); + + /* in case of error, skip */ + if (response != NULL) + mm_obj_dbg (self, "response: %s", response); + + r = g_regex_new ("\\^SGAUTH:\\s*(\\d+),(\\d+),?\"?([a-zA-Z0-9_-]+)?\"?", 0, 0, NULL); + g_assert (r != NULL); + g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, NULL); + while (g_match_info_matches (match_info)) { + guint cid = 0; + guint cinterion_auth_type = 0; + g_autofree gchar *username = NULL; + + mm_get_uint_from_match_info (match_info, 1, &cid); + mm_get_uint_from_match_info (match_info, 2, &cinterion_auth_type); + username = mm_get_string_unquoted_from_match_info (match_info, 3); + if (cid == ctx->cid) { + mm_bearer_properties_set_allowed_auth (ctx->properties, mm_auth_type_from_cinterion_auth_type (cinterion_auth_type)); + if (username) + mm_bearer_properties_set_user (ctx->properties, username); + } + g_match_info_next (match_info, NULL); + } + + /* Go to next step */ + ctx->step++; + ctx->step_function (task); +} + +static void +modem_3gpp_load_initial_eps_step (GTask *task) +{ + MMIfaceModem3gpp *self; + InitialEpsContext *ctx; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + + switch (ctx->step) { + case INITIAL_EPS_CONTEXT_STEP_FIRST: + /* set defaults */ + ctx->cid = 1; + ctx->step++; + /* fall through */ + + case INITIAL_EPS_CONTEXT_STEP_CHECK_MODE: + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "+CFUN?", + 5, + FALSE, + (GAsyncReadyCallback)check_cfun_mode, + task); + return; + + case INITIAL_EPS_CONTEXT_STEP_RF_OFF: + ctx->step++; + /* fall through */ + + case INITIAL_EPS_CONTEXT_STEP_PROFILE: + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "^SCFG=\"MEopMode/Prov/Cfg\"", + 20, + FALSE, + (GAsyncReadyCallback)set_cid_from_mno_profile, + task); + return; + + case INITIAL_EPS_CONTEXT_STEP_APN: { + if (ctx->get_current_status) + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "+CGDCONT?", + 20, + FALSE, + (GAsyncReadyCallback)get_apn_from_cgdcont, + task); + else { + g_autofree gchar *cmd = NULL; + + cmd = g_strdup_printf ("+CGCONTRDP=%u", ctx->cid); + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "+CGCONTRDP", + 20, + FALSE, + (GAsyncReadyCallback)get_apn_from_cgcontrdp, + task); + } + return; + } + + case INITIAL_EPS_CONTEXT_STEP_AUTH: { + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "^SGAUTH?", + 20, + FALSE, + (GAsyncReadyCallback)get_auth_params, + task); + return; + } + + case INITIAL_EPS_CONTEXT_STEP_RF_ON: + ctx->step++; + /* fall through */ + + case INITIAL_EPS_CONTEXT_STEP_LAST: + g_task_return_pointer (task, ctx->properties, g_object_unref); + g_object_unref (task); + return; + default: + g_assert_not_reached (); + } +} + +static void +modem_3gpp_load_initial_eps_bearer (MMIfaceModem3gpp *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + InitialEpsContext *ctx; + MMBearerProperties *properties; + + task = g_task_new (self, NULL, callback, user_data); + ctx = g_slice_new0 (InitialEpsContext); + g_task_set_task_data (task, ctx, (GDestroyNotify) initial_eps_context_free); + properties = mm_bearer_properties_new (); + + /* Setup context */ + ctx->properties = g_object_ref (properties); + ctx->step = INITIAL_EPS_CONTEXT_STEP_FIRST; + ctx->step_function = modem_3gpp_load_initial_eps_step; + ctx-> get_current_status = TRUE; + + modem_3gpp_load_initial_eps_step (task); +} + +/*****************************************************************************/ +/* Initial EPS bearer settings loading -> set configuration */ + +static MMBearerProperties * +modem_3gpp_load_initial_eps_bearer_settings_finish (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error) +{ + return MM_BEARER_PROPERTIES (g_task_propagate_pointer (G_TASK (res), error)); +} + +static void +modem_3gpp_load_initial_eps_bearer_settings (MMIfaceModem3gpp *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + InitialEpsContext *ctx; + MMBearerProperties *properties; + + task = g_task_new (self, NULL, callback, user_data); + ctx = g_slice_new0 (InitialEpsContext); + g_task_set_task_data (task, ctx, (GDestroyNotify) initial_eps_context_free); + properties = mm_bearer_properties_new (); + + /* Setup context */ + ctx->properties = g_object_ref (properties); + ctx->step = INITIAL_EPS_CONTEXT_STEP_FIRST; + ctx->step_function = modem_3gpp_load_initial_eps_step; + ctx-> get_current_status = FALSE; + + modem_3gpp_load_initial_eps_step (task); +} + /*****************************************************************************/ /* Load supported modes (Modem interface) */ @@ -1319,7 +1872,7 @@ scfg_set_ready_sequence (MMBaseModem *_self, self = g_task_get_source_object (task); for (i = 0; self->priv->cmds[i].command; i++) mm_base_modem_at_command_alloc_clear (&self->priv->cmds[i]); - g_free(self->priv->cmds); + g_free (self->priv->cmds); self->priv->cmds = NULL; mm_base_modem_at_sequence_finish (_self, res, &ctx, &error); @@ -2031,6 +2584,14 @@ iface_modem_3gpp_init (MMIfaceModem3gpp *iface) iface->setup_unsolicited_events_finish = modem_3gpp_setup_cleanup_unsolicited_events_finish; iface->cleanup_unsolicited_events = modem_3gpp_cleanup_unsolicited_events; iface->cleanup_unsolicited_events_finish = modem_3gpp_setup_cleanup_unsolicited_events_finish; + + iface->load_initial_eps_bearer = modem_3gpp_load_initial_eps_bearer; + iface->load_initial_eps_bearer_finish = modem_3gpp_load_initial_eps_bearer_finish; + iface->load_initial_eps_bearer_settings = modem_3gpp_load_initial_eps_bearer_settings; + iface->load_initial_eps_bearer_settings_finish = modem_3gpp_load_initial_eps_bearer_settings_finish; + iface->set_initial_eps_bearer_settings = modem_3gpp_set_initial_eps_bearer_settings; + iface->set_initial_eps_bearer_settings_finish = modem_3gpp_set_initial_eps_bearer_settings_finish; + } static void diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index 095e396c..bff03a90 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -1398,3 +1398,55 @@ mm_cinterion_smoni_response_to_signal_info (const gchar *response, return TRUE; } + +/*****************************************************************************/ +/* provider cfg information to CID number for EPS initial settings */ + +/* + * at^scfg="MEopMode/Prov/Cfg" + * ^SCFG: "MEopMode/Prov/Cfg","vdfde" + * ^SCFG: "MEopMode/Prov/Cfg","attus" + * ^SCFG: "MEopMode/Prov/Cfg","2" -> PLS8-X vzw + * ^SCFG: "MEopMode/Prov/Cfg","vzwdcus" -> PLAS9-x vzw + * ^SCFG: "MEopMode/Prov/Cfg","tmode" -> t-mob germany + * OK + */ +void +mm_cinterion_provcfg_response_to_cid (const gchar *response, + MMCinterionModemFamily modem_family, + MMModemCharset charset, + gpointer log_object, + guint *cid) +{ + g_autoptr(GRegex) r = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + g_autofree GError *inner_error = NULL; + + r = g_regex_new ("\\^SCFG:\\s*\"MEopMode/Prov/Cfg\",\\s*\"([0-9a-zA-Z]*)\"", 0, 0, NULL); + g_assert (r != NULL); + g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); + if (inner_error) + return; + if (g_match_info_matches (match_info)) { + g_autofree gchar *mno = NULL; + + mno = mm_get_string_unquoted_from_match_info (match_info, 1); + if (mno && modem_family == MM_CINTERION_MODEM_FAMILY_IMT) { + mno = mm_charset_take_and_convert_to_utf8 (mno, charset); + mm_obj_dbg (log_object, "current mno: %s", mno); + } + + /* for Cinterion LTE modules, some CID numbers have special meaning. + * This is dictated by the chipset and by the MNO: + * - the chipset uses a special one, CID 1, as a LTE combined attach chipset + * - the MNOs can define the sequence and number of APN to be used for their network. + * This takes priority over the chipset preferences, and therefore for some of them + * the CID for the initial EPS context must be changed. + */ + if (g_strcmp0 (mno, "2") == 0 || g_strcmp0 (mno, "vzwdcus") == 0) + *cid = 3; + else if (g_strcmp0 (mno, "tmode") == 0) + *cid = 2; + /* in all other cases no change to the preset value */ + } +} diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.h b/plugins/cinterion/mm-modem-helpers-cinterion.h index c35c5b3c..76e0d43e 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.h +++ b/plugins/cinterion/mm-modem-helpers-cinterion.h @@ -163,4 +163,13 @@ gboolean mm_cinterion_smoni_response_to_signal_info (const gchar *response, MMSignal **out_lte, GError **error); +/*****************************************************************************/ +/* ^SCFG="MEopMode/Prov/Cfg" helper */ + +void mm_cinterion_provcfg_response_to_cid (const gchar *response, + MMCinterionModemFamily modem_family, + MMModemCharset charset, + gpointer log_object, + guint *cid); + #endif /* MM_MODEM_HELPERS_CINTERION_H */ diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c index 35123283..14ce4c38 100644 --- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c +++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c @@ -1596,6 +1596,71 @@ test_smoni_response_to_signal (void) } } +/*****************************************************************************/ +/* Test ^SCFG="MEopMode/Prov/Cfg" responses */ + +typedef struct { + const gchar *str; + MMCinterionModemFamily modem_family; + guint initial_cid; + gdouble expected_cid; +} ProvcfgResponseTest; + + +static const ProvcfgResponseTest provcfg_response_tests[] = { + { + + .str = "^SCFG: \"MEopMode/Prov/Cfg\",\"vdfde\"", + .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .initial_cid = 1, + .expected_cid = 1, + }, + { + + .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"attus\"", + .modem_family = MM_CINTERION_MODEM_FAMILY_IMT, + .initial_cid = 1, + .expected_cid = 1, + }, + { + + .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"2\"", + .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .initial_cid = 1, + .expected_cid = 3, + }, + { + + .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"vzwdcus\"", + .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .initial_cid = 1, + .expected_cid = 3, + }, + { + + .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"tmode\"", + .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .initial_cid = 1, + .expected_cid = 2, + } +}; + +static void +test_provcfg_response (void) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (provcfg_response_tests); i++) { + guint cid = provcfg_response_tests[i].initial_cid; + + mm_cinterion_provcfg_response_to_cid (provcfg_response_tests[i].str, + provcfg_response_tests[i].modem_family, + MM_MODEM_CHARSET_GSM, + NULL, + &cid); + g_assert_cmpuint (cid, ==, provcfg_response_tests[i].expected_cid); + } +} /*****************************************************************************/ @@ -1629,6 +1694,7 @@ int main (int argc, char **argv) g_test_add_func ("/MM/cinterion/ctzu/urc/full", test_ctzu_urc_full); g_test_add_func ("/MM/cinterion/smoni/query_response", test_smoni_response); g_test_add_func ("/MM/cinterion/smoni/query_response_to_signal", test_smoni_response_to_signal); + g_test_add_func ("/MM/cinterion/scfg/provcfg", test_provcfg_response); return g_test_run (); } From a36beb0a958f65bcaa5939e04bf340d98d4180a1 Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Tue, 11 Aug 2020 07:10:36 +0200 Subject: [PATCH 335/675] cinterion: clarify role of the AT ports for the ELS61/PLS62 family --- plugins/cinterion/77-mm-cinterion-port-types.rules | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/cinterion/77-mm-cinterion-port-types.rules b/plugins/cinterion/77-mm-cinterion-port-types.rules index f5ceee3a..51caf221 100644 --- a/plugins/cinterion/77-mm-cinterion-port-types.rules +++ b/plugins/cinterion/77-mm-cinterion-port-types.rules @@ -25,9 +25,11 @@ ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{ID_MM_CINTERION_MODEM_FAM # PLS62 family non-mbim enumeration # ttyACM0 (if #0): AT port # ttyACM1 (if #2): AT port -# ttyACM2 (if #4): unknown +# ttyACM2 (if #4): can be AT or GNSS in some models, best left ignored # ttyACM3 (if #6): unknown # ttyACM4 (if #8): unknown +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_IGNORE}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1" @@ -35,12 +37,12 @@ ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="08", ENV{ # PLS62 family mbim enumeration # ttyACM0 (if #0): AT port # ttyACM1 (if #2): AT port -# ttyACM2 (if #4): AT port +# ttyACM2 (if #4): can be AT or GNSS in some models, best left ignored # ttyACM3 (if #6): unknown # ttyACM4 (if #8): unknown ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" -ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_IGNORE}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1" From 2f684ce92ea9cc772a36db2e7bd9d48e677d3935 Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Tue, 11 Aug 2020 14:26:13 +0200 Subject: [PATCH 336/675] cinterion: remove limitation to IPv4 only PDP contexts There was a limitation in the past in the plugin, because one of the steps during the dial (CONNECT_3GPP_CONTEXT_STEP_PDP_CTX) was to reconfigure a specific CID hardcoding the IP type to IPv4. That logic was removed in commit af2d6c1c4b7f815862313bf0f84b1ff0e91ccd60, but we didn't remove the IPv4 limitation at that point. --- plugins/cinterion/mm-broadband-bearer-cinterion.c | 8 -------- plugins/cinterion/mm-broadband-modem-cinterion.c | 7 ------- 2 files changed, 15 deletions(-) diff --git a/plugins/cinterion/mm-broadband-bearer-cinterion.c b/plugins/cinterion/mm-broadband-bearer-cinterion.c index ceeb49be..794fe15f 100644 --- a/plugins/cinterion/mm-broadband-bearer-cinterion.c +++ b/plugins/cinterion/mm-broadband-bearer-cinterion.c @@ -413,7 +413,6 @@ dial_3gpp_context_step (GTask *task) case DIAL_3GPP_CONTEXT_STEP_FIRST: { MMBearerIpFamily ip_family; - /* Only IPv4 supported by this bearer implementation for now */ ip_family = mm_bearer_properties_get_ip_type (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self))); if (ip_family == MM_BEARER_IP_FAMILY_NONE || ip_family == MM_BEARER_IP_FAMILY_ANY) { gchar *ip_family_str; @@ -424,13 +423,6 @@ dial_3gpp_context_step (GTask *task) g_free (ip_family_str); } - if (ip_family != MM_BEARER_IP_FAMILY_IPV4) { - g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, - "Only IPv4 is supported by this modem"); - g_object_unref (task); - return; - } - ctx->step++; } /* fall through */ diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 95b9ed0d..f0bc5a66 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -1174,13 +1174,6 @@ modem_3gpp_set_initial_eps_bearer_settings_step (GTask *task) if (ip_family == MM_BEARER_IP_FAMILY_NONE || ip_family == MM_BEARER_IP_FAMILY_ANY) ip_family = MM_BEARER_IP_FAMILY_IPV4; - if (ip_family != MM_BEARER_IP_FAMILY_IPV4) { - /* we must have the same settings as in dial_3gpp_context_step() - * for the case when the CID is re-used for the connection PDN */ - mm_obj_dbg (self, "Only IPv4 is supported by this modem"); - ip_family = MM_BEARER_IP_FAMILY_IPV4; - } - ip_family_str = mm_3gpp_get_pdp_type_from_ip_family (ip_family); apn = mm_bearer_properties_get_apn (ctx->properties); mm_obj_dbg (self, "context CID=%d with APN '%s' and PDP type '%s'", ctx->cid, apn, ip_family_str); From 16e3bb892d25e3cb7796889082943b073924a695 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 4 Aug 2020 14:13:45 +0200 Subject: [PATCH 337/675] iface-modem: avoid connection status flapping if briefly unregistered If the modem is connected and we receive indications of a quick unregistration cycle (i.e. unregistered, then registered again) we should not end up flagging the modem as disconnected. We already had some logic to avoid this with the "deferred 3GPP unregistration" logic in the base bearer object, but this logic only took into account the status of the bearer, not the status of the modem. Wed Jul 29 15:35:44 2020 daemon.info [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: 3GPP Registration state changed (home -> idle) Wed Jul 29 15:35:44 2020 daemon.debug [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: 3GPP location updated (MCC: '0', MNC: '0', Location area code: '0', Tracking area code: '1CE8', Cell ID: '68F832') Wed Jul 29 15:35:44 2020 daemon.debug [1567]: Connected bearer not registered in 3GPP network Wed Jul 29 15:35:44 2020 daemon.info [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: state changed (connected -> enabled) Wed Jul 29 15:35:44 2020 daemon.debug [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: signal quality updated (0) Wed Jul 29 15:35:44 2020 daemon.debug [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: access technology changed (lte -> unknown) Wed Jul 29 15:35:44 2020 daemon.debug [1567]: Periodic signal checks disabled Wed Jul 29 15:35:44 2020 daemon.info [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: 3GPP Registration state changed (idle -> registering) Wed Jul 29 15:35:44 2020 daemon.debug [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: 3GPP location updated (MCC: '0', MNC: '0', Location area code: '0', Tracking area code: '1C84', Cell ID: 'A3E050') Wed Jul 29 15:35:44 2020 daemon.debug [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: 3GPP location updated (MCC: '238', MNC: '1', Location area code: '0', Tracking area code: '1C84', Cell ID: 'A3E050') Wed Jul 29 15:35:44 2020 daemon.info [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: 3GPP Registration state changed (registering -> home) Wed Jul 29 15:35:44 2020 daemon.info [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: state changed (enabled -> registered) We now try to improve this situation by also considering the case where modem is supposed to get into "enabled" state (i.e. not registered, not searching), but we still consider the amount of connected bearers to decide the final state reported by the modem. In other words, a modem with the 3GPP registration reported as 'idle' will still be reported as 'connected' if there is at least one bearer in connected state. This situation will end as soon as the 'deferred 3GPP unregistration' timeout expires, as that will force the bearer to be disconnected. --- src/mm-iface-modem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 9b3f2223..8a4a00af 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -1509,7 +1509,8 @@ __iface_modem_update_state_internal (MMIfaceModem *self, /* While connected we don't want registration status changes to change * the modem's state away from CONNECTED. */ - if ((new_state == MM_MODEM_STATE_SEARCHING || + if ((new_state == MM_MODEM_STATE_ENABLED || + new_state == MM_MODEM_STATE_SEARCHING || new_state == MM_MODEM_STATE_REGISTERED) && bearer_list && old_state > MM_MODEM_STATE_REGISTERED) { From 7cd373589cb7d81633a5df279e0b63c405cc2bb6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 4 Aug 2020 16:33:11 +0200 Subject: [PATCH 338/675] bearer-qmi: if connection aborted, ensure network handles are released If the connection attempt is aborted before finishing (either network triggered or user triggered), we need to make sure that we run a 'Stop Network' request for every 'Start Network' that had succeeded until then, or otherwise we'll no longer be able to re-run a 'Start Network' with the same settings and get a proper packet data handle. E.g. in this sequence we attempt a IPv4v6 connection. The logic starts setting up the IPv4 path: Wed Jul 29 14:44:06 2020 daemon.info [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: state changed (registered -> connecting) Wed Jul 29 14:44:06 2020 daemon.debug [1567]: Launching connection with QMI port (usb/cdc-wdm0) and data port (net/wwan0) Wed Jul 29 14:44:06 2020 daemon.debug [1567]: Defaulting to use static IP method Wed Jul 29 14:44:06 2020 daemon.debug [1567]: Running IPv4 connection setup ... The 'Start Network' for IPv4 succeeds and we get a proper packet data handle: Wed Jul 29 14:44:07 2020 daemon.debug [1567]: [/dev/cdc-wdm0] sent generic request (translated)... <<<<<< QMUX: <<<<<< length = 23 <<<<<< flags = 0x00 <<<<<< service = "wds" <<<<<< client = 20 <<<<<< QMI: <<<<<< flags = "none" <<<<<< transaction = 3075 <<<<<< tlv_length = 11 <<<<<< message = "Start Network" (0x0020) <<<<<< TLV: <<<<<< type = "APN" (0x14) <<<<<< length = 8 <<<<<< value = 69:6E:74:65:72:6E:65:74 <<<<<< translated = internet Wed Jul 29 14:44:07 2020 daemon.debug [1567]: [/dev/cdc-wdm0] received generic response (translated)... <<<<<< QMUX: <<<<<< length = 26 <<<<<< flags = 0x80 <<<<<< service = "wds" <<<<<< client = 20 <<<<<< QMI: <<<<<< flags = "response" <<<<<< transaction = 3075 <<<<<< tlv_length = 14 <<<<<< message = "Start Network" (0x0020) <<<<<< TLV: <<<<<< type = "Result" (0x02) <<<<<< length = 4 <<<<<< value = 00:00:00:00 <<<<<< translated = SUCCESS <<<<<< TLV: <<<<<< type = "Packet Data Handle" (0x01) <<<<<< length = 4 <<<<<< value = 80:CD:AD:81 <<<<<< translated = 2175651200 Then, we start the IPv6 connection path: Wed Jul 29 14:44:07 2020 daemon.debug [1567]: Running IPv6 connection setup ... But, because we suddenly are not registered in the network, the connection is aborted, and we don't cleanup the IPv4 path at this point, as this patch wasn't available. Wed Jul 29 14:44:07 2020 daemon.debug [1567]: Bearer not allowed to connect, not registered in 3GPP network Wed Jul 29 14:44:07 2020 daemon.debug [1567]: Forcing disconnection of bearer '/org/freedesktop/ModemManager1/Bearer/56' Wed Jul 29 14:44:07 2020 daemon.debug [1567]: transaction 0xe1 aborted, but message is not abortable Wed Jul 29 14:44:07 2020 daemon.info [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: state changed (connecting -> enabled) Wed Jul 29 14:44:07 2020 daemon.debug [1567]: Couldn't connect bearer '/org/freedesktop/ModemManager1/Bearer/56': 'operation cancelled' We then attempt a new connection request with the same settings: Wed Jul 29 14:44:22 2020 daemon.info [1567]: Modem /org/freedesktop/ModemManager1/Modem/0: state changed (registered -> connecting) Wed Jul 29 14:44:22 2020 daemon.debug [1567]: Launching connection with QMI port (usb/cdc-wdm0) and data port (net/wwan0) Wed Jul 29 14:44:22 2020 daemon.debug [1567]: Defaulting to use static IP method Wed Jul 29 14:44:22 2020 daemon.debug [1567]: Running IPv4 connection setup And we see how the 'Start Network' command fails with a 'No Effect' error, as the IPv4 was left connected earlier. Due to this, the modem is assumed connected, but we won't have a valid packet data handle to stop the connection cleanly: Wed Jul 29 14:44:22 2020 daemon.debug [1567]: [/dev/cdc-wdm0] sent generic request (translated)... <<<<<< QMUX: <<<<<< length = 23 <<<<<< flags = 0x00 <<<<<< service = "wds" <<<<<< client = 20 <<<<<< QMI: <<<<<< flags = "none" <<<<<< transaction = 3080 <<<<<< tlv_length = 11 <<<<<< message = "Start Network" (0x0020) <<<<<< TLV: <<<<<< type = "APN" (0x14) <<<<<< length = 8 <<<<<< value = 69:6E:74:65:72:6E:65:74 <<<<<< translated = internet Wed Jul 29 14:44:23 2020 daemon.debug [1567]: [/dev/cdc-wdm0] received generic response (translated)... <<<<<< QMUX: <<<<<< length = 26 <<<<<< flags = 0x80 <<<<<< service = "wds" <<<<<< client = 20 <<<<<< QMI: <<<<<< flags = "response" <<<<<< transaction = 3080 <<<<<< tlv_length = 14 <<<<<< message = "Start Network" (0x0020) <<<<<< TLV: <<<<<< type = "Result" (0x02) <<<<<< length = 4 <<<<<< value = 01:00:1A:00 <<<<<< translated = FAILURE: NoEffect <<<<<< TLV: <<<<<< type = "Packet Data Handle" (0x01) <<<<<< length = 4 <<<<<< value = 00:00:00:00 <<<<<< translated = 0 --- src/mm-bearer-qmi.c | 65 ++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/src/mm-bearer-qmi.c b/src/mm-bearer-qmi.c index 91cb71d9..45185c6a 100644 --- a/src/mm-bearer-qmi.c +++ b/src/mm-bearer-qmi.c @@ -463,27 +463,48 @@ connect_context_free (ConnectContext *ctx) g_free (ctx->user); g_free (ctx->password); - if (ctx->packet_service_status_ipv4_indication_id) { - common_setup_cleanup_packet_service_status_unsolicited_events (ctx->self, - ctx->client_ipv4, - FALSE, - &ctx->packet_service_status_ipv4_indication_id); - } - if (ctx->event_report_ipv4_indication_id) { - cleanup_event_report_unsolicited_events (ctx->self, - ctx->client_ipv4, - &ctx->event_report_ipv4_indication_id); - } - if (ctx->packet_service_status_ipv6_indication_id) { - common_setup_cleanup_packet_service_status_unsolicited_events (ctx->self, - ctx->client_ipv6, - FALSE, - &ctx->packet_service_status_ipv6_indication_id); + if (ctx->client_ipv4) { + if (ctx->packet_service_status_ipv4_indication_id) { + common_setup_cleanup_packet_service_status_unsolicited_events (ctx->self, + ctx->client_ipv4, + FALSE, + &ctx->packet_service_status_ipv4_indication_id); + } + if (ctx->event_report_ipv4_indication_id) { + cleanup_event_report_unsolicited_events (ctx->self, + ctx->client_ipv4, + &ctx->event_report_ipv4_indication_id); + } + if (ctx->packet_data_handle_ipv4) { + g_autoptr(QmiMessageWdsStopNetworkInput) input = NULL; + + input = qmi_message_wds_stop_network_input_new (); + qmi_message_wds_stop_network_input_set_packet_data_handle (input, ctx->packet_data_handle_ipv4, NULL); + qmi_client_wds_stop_network (ctx->client_ipv4, input, 30, NULL, NULL, NULL); + } + g_clear_object (&ctx->client_ipv4); } - if (ctx->event_report_ipv6_indication_id) { - cleanup_event_report_unsolicited_events (ctx->self, - ctx->client_ipv6, - &ctx->event_report_ipv6_indication_id); + + if (ctx->client_ipv6) { + if (ctx->packet_service_status_ipv6_indication_id) { + common_setup_cleanup_packet_service_status_unsolicited_events (ctx->self, + ctx->client_ipv6, + FALSE, + &ctx->packet_service_status_ipv6_indication_id); + } + if (ctx->event_report_ipv6_indication_id) { + cleanup_event_report_unsolicited_events (ctx->self, + ctx->client_ipv6, + &ctx->event_report_ipv6_indication_id); + } + if (ctx->packet_data_handle_ipv6) { + g_autoptr(QmiMessageWdsStopNetworkInput) input = NULL; + + input = qmi_message_wds_stop_network_input_new (); + qmi_message_wds_stop_network_input_set_packet_data_handle (input, ctx->packet_data_handle_ipv6, NULL); + qmi_client_wds_stop_network (ctx->client_ipv6, input, 30, NULL, NULL, NULL); + } + g_clear_object (&ctx->client_ipv6); } if (ctx->explicit_qmi_open) @@ -491,8 +512,6 @@ connect_context_free (ConnectContext *ctx) g_clear_error (&ctx->error_ipv4); g_clear_error (&ctx->error_ipv6); - g_clear_object (&ctx->client_ipv4); - g_clear_object (&ctx->client_ipv6); g_clear_object (&ctx->ipv4_config); g_clear_object (&ctx->ipv6_config); g_object_unref (ctx->data); @@ -1558,6 +1577,7 @@ connect_context_step (GTask *task) g_assert (ctx->self->priv->client_ipv4 == NULL); if (ctx->packet_data_handle_ipv4) { ctx->self->priv->packet_data_handle_ipv4 = ctx->packet_data_handle_ipv4; + ctx->packet_data_handle_ipv4 = 0; ctx->self->priv->packet_service_status_ipv4_indication_id = ctx->packet_service_status_ipv4_indication_id; ctx->packet_service_status_ipv4_indication_id = 0; ctx->self->priv->event_report_ipv4_indication_id = ctx->event_report_ipv4_indication_id; @@ -1569,6 +1589,7 @@ connect_context_step (GTask *task) g_assert (ctx->self->priv->client_ipv6 == NULL); if (ctx->packet_data_handle_ipv6) { ctx->self->priv->packet_data_handle_ipv6 = ctx->packet_data_handle_ipv6; + ctx->packet_data_handle_ipv6 = 0; ctx->self->priv->packet_service_status_ipv6_indication_id = ctx->packet_service_status_ipv6_indication_id; ctx->packet_service_status_ipv6_indication_id = 0; ctx->self->priv->event_report_ipv6_indication_id = ctx->event_report_ipv6_indication_id; From d9a64c74ff0244b96a44fa27abcdc411d29f4874 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 13 Aug 2020 11:25:59 +0800 Subject: [PATCH 339/675] quectel: allow MBIM devices --- plugins/quectel/mm-plugin-quectel.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/quectel/mm-plugin-quectel.c b/plugins/quectel/mm-plugin-quectel.c index 12e4612e..7d0988b2 100644 --- a/plugins/quectel/mm-plugin-quectel.c +++ b/plugins/quectel/mm-plugin-quectel.c @@ -27,6 +27,10 @@ #include "mm-broadband-modem-qmi-quectel.h" #endif +#if defined WITH_MBIM +#include "mm-broadband-modem-mbim.h" +#endif + G_DEFINE_TYPE (MMPluginQuectel, mm_plugin_quectel, MM_TYPE_PLUGIN) MM_PLUGIN_DEFINE_MAJOR_VERSION @@ -54,6 +58,17 @@ create_modem (MMPlugin *self, } #endif +#if defined WITH_MBIM + if (mm_port_probe_list_has_mbim_port (probes)) { + mm_obj_dbg (self, "MBIM-powered Quectel modem found..."); + return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); + } +#endif + return MM_BASE_MODEM (mm_broadband_modem_quectel_new (uid, drivers, mm_plugin_get_name (self), @@ -79,6 +94,7 @@ mm_plugin_create (void) MM_PLUGIN_ALLOWED_AT, TRUE, MM_PLUGIN_ALLOWED_QCDM, TRUE, MM_PLUGIN_ALLOWED_QMI, TRUE, + MM_PLUGIN_ALLOWED_MBIM, TRUE, NULL)); } From 55ae47a3bb874991ca621e4aa17cf16b08d28139 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 16 Aug 2020 11:06:57 +0200 Subject: [PATCH 340/675] quectel: add udev rules unit tester --- plugins/Makefile.am | 5 +++-- plugins/tests/test-udev-rules.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index f7ca2ac4..d4e5387a 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1155,8 +1155,6 @@ endif if ENABLE_PLUGIN_QUECTEL -dist_udevrules_DATA += quectel/77-mm-quectel-port-types.rules - pkglib_LTLIBRARIES += libmm-plugin-quectel.la libmm_plugin_quectel_la_SOURCES = \ quectel/mm-plugin-quectel.c \ @@ -1178,6 +1176,9 @@ libmm_plugin_quectel_la_CPPFLAGS = \ $(NULL) libmm_plugin_quectel_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) +dist_udevrules_DATA += quectel/77-mm-quectel-port-types.rules +AM_CFLAGS += -DTESTUDEVRULESDIR_QUECTEL=\"${srcdir}/quectel\" + endif ################################################################################ diff --git a/plugins/tests/test-udev-rules.c b/plugins/tests/test-udev-rules.c index 36cc4120..651e02fa 100644 --- a/plugins/tests/test-udev-rules.c +++ b/plugins/tests/test-udev-rules.c @@ -160,6 +160,14 @@ test_fibocom (void) } #endif +#if defined ENABLE_PLUGIN_QUECTEL +static void +test_quectel (void) +{ + common_test (TESTUDEVRULESDIR_QUECTEL); +} +#endif + /************************************************************/ int main (int argc, char **argv) @@ -208,6 +216,9 @@ int main (int argc, char **argv) #if defined ENABLE_PLUGIN_FIBOCOM g_test_add_func ("/MM/test-udev-rules/fibocom", test_fibocom); #endif +#if defined ENABLE_PLUGIN_QUECTEL + g_test_add_func ("/MM/test-udev-rules/quectel", test_quectel); +#endif return g_test_run (); } From de23b53ee4d91367b50a960f8b19b2e29449e49a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 16 Aug 2020 11:13:26 +0200 Subject: [PATCH 341/675] modem-helpers: ensure error is set in mm_3gpp_parse_cpms_test_response() If splitting the +CPMS=? response in groups fails, make sure we set the GError when returning FALSE. --- src/mm-modem-helpers.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index f319a925..d080e010 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -2888,8 +2888,11 @@ mm_3gpp_parse_cpms_test_response (const gchar *reply, #define N_EXPECTED_GROUPS 3 split = mm_split_string_groups (mm_strip_tag (reply, "+CPMS:")); - if (!split) + if (!split) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't split +CPMS test response in groups"); return FALSE; + } if (g_strv_length (split) != N_EXPECTED_GROUPS) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, From 5346d3c55c7ffc38af58c879fd426a2c3accd489 Mon Sep 17 00:00:00 2001 From: carlyin Date: Sun, 16 Aug 2020 16:55:25 +0800 Subject: [PATCH 342/675] quectel: add port type hints for the Quectel 5G RM500 --- plugins/quectel/77-mm-quectel-port-types.rules | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/quectel/77-mm-quectel-port-types.rules b/plugins/quectel/77-mm-quectel-port-types.rules index caa7b10e..54778d24 100644 --- a/plugins/quectel/77-mm-quectel-port-types.rules +++ b/plugins/quectel/77-mm-quectel-port-types.rules @@ -57,4 +57,14 @@ ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", ENV{.MM_USBIFNUM}=="01", ENV{ ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +# Quectel RM500 +# ttyUSB0 (if #0): QCDM/DIAG port +# ttyUSB1 (if #1): GPS data port +# ttyUSB2 (if #2): AT primary port +# ttyUSB3 (if #3): AT secondary port +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0800", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_QCDM}="1" +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0800", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_PORT_TYPE_GPS}="1" +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0800", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0800", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" + LABEL="mm_quectel_port_types_end" From 65f56122b53f52dfd9b5ffdcce53d829d80b31e7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 19 Aug 2020 14:59:01 +0200 Subject: [PATCH 343/675] ci: add build test for WITH_NEWEST_QMI_COMMANDS We keep this logic around, so lets add a build test as well. --- .gitlab-ci.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8c3e7b1b..136b6105 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,6 +63,27 @@ build-no-qmi-no-mbim: - make check - make install +build-qmi-newest-commands: + stage: build + only: + - master + - merge_requests + - tags + - schedules + script: + - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git + - pushd libqmi + - NOCONFIGURE=1 ./autogen.sh + - ./configure --prefix=/usr --disable-mbim-qmux --enable-collection=basic + - make + - make install + - popd + - NOCONFIGURE=1 ./autogen.sh + - ./configure --prefix=/tmp/build-qmi-newest-commands --disable-gtk-doc --without-mbim CFLAGS="-DWITH_NEWEST_QMI_COMMANDS" + - make + - make check + - make install + build-single-plugins: stage: build only: From 9b8fb447b0b2b967fe7fbb980ed2debd12be67ed Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 19 Aug 2020 14:48:12 +0200 Subject: [PATCH 344/675] broadband-modem-qmi: fix type comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only applicable when building with WITH_NEWEST_QMI_COMMANDS. mm-broadband-modem-qmi.c: In function ‘process_common_info’: mm-broadband-modem-qmi.c:2924:20: error: comparison is always false due to limited range of data type [-Werror=type-limits] 2924 | if (mnc[2] == 0xFF) { | ^~ --- src/mm-broadband-modem-qmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index d57bab94..50050b8f 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -2921,7 +2921,7 @@ process_common_info (QmiNasServiceStatus service_status, if (network_id_valid) { *mm_operator_id = g_malloc (7); memcpy (*mm_operator_id, mcc, 3); - if (mnc[2] == 0xFF) { + if ((guint8)mnc[2] == 0xFF) { memcpy (&((*mm_operator_id)[3]), mnc, 2); (*mm_operator_id)[5] = '\0'; } else { From d43d595c0270ff5fdbe62626679493d97824c668 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 19 Aug 2020 14:55:41 +0200 Subject: [PATCH 345/675] broadband-modem-qmi: avoid unused functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only applicable when building with WITH_NEWEST_QMI_COMMANDS. mm-broadband-modem-qmi.c:4741:1: error: ‘common_enable_disable_unsolicited_events_signal_strength’ defined but not used [-Werror=unused-function] 4741 | common_enable_disable_unsolicited_events_signal_strength (GTask *task) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm-broadband-modem-qmi.c:4528:1: error: ‘serving_system_indication_cb’ defined but not used [-Werror=unused-function] 4528 | serving_system_indication_cb (QmiClientNas *client, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm-broadband-modem-qmi.c:3468:1: error: ‘common_enable_disable_unsolicited_registration_events_serving_system’ defined but not used [-Werror=unused-function] 3468 | common_enable_disable_unsolicited_registration_events_serving_system (GTask *task) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm-broadband-modem-qmi.c:2812:1: error: ‘get_serving_system_3gpp_ready’ defined but not used [-Werror=unused-function] 2812 | get_serving_system_3gpp_ready (QmiClientNas *client, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm-broadband-modem-qmi.c:1652:1: error: ‘get_signal_strength_ready’ defined but not used [-Werror=unused-function] 1652 | get_signal_strength_ready (QmiClientNas *client, --- src/mm-broadband-modem-qmi.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 50050b8f..11b3fb31 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -1589,7 +1589,7 @@ get_signal_info_ready (QmiClientNas *client, qmi_message_nas_get_signal_info_output_unref (output); } -#endif /* WITH_NEWEST_QMI_COMMANDS */ +#else /* WITH_NEWEST_QMI_COMMANDS */ static gboolean signal_strength_get_quality_and_access_tech (MMBroadbandModemQmi *self, @@ -1698,6 +1698,8 @@ get_signal_strength_ready (QmiClientNas *client, qmi_message_nas_get_signal_strength_output_unref (output); } +#endif /* WITH_NEWEST_QMI_COMMANDS */ + static void load_signal_quality (MMIfaceModem *self, GAsyncReadyCallback callback, @@ -2586,6 +2588,8 @@ modem_3gpp_run_registration_checks_finish (MMIfaceModem3gpp *self, return g_task_propagate_boolean (G_TASK (res), error); } +#if !defined WITH_NEWEST_QMI_COMMANDS + static void common_process_serving_system_3gpp (MMBroadbandModemQmi *self, QmiMessageNasGetServingSystemOutput *response_output, @@ -2842,7 +2846,7 @@ get_serving_system_3gpp_ready (QmiClientNas *client, qmi_message_nas_get_serving_system_output_unref (output); } -#if defined WITH_NEWEST_QMI_COMMANDS +#else /* WITH_NEWEST_QMI_COMMANDS */ static gboolean process_common_info (QmiNasServiceStatus service_status, @@ -3464,6 +3468,8 @@ ri_serving_system_or_system_info_ready (QmiClientNas *client, g_object_unref (task); } +#if !defined WITH_NEWEST_QMI_COMMANDS + static void common_enable_disable_unsolicited_registration_events_serving_system (GTask *task) { @@ -3482,7 +3488,8 @@ common_enable_disable_unsolicited_registration_events_serving_system (GTask *tas task); } -#if defined WITH_NEWEST_QMI_COMMANDS +#else /* WITH_NEWEST_QMI_COMMANDS */ + static void common_enable_disable_unsolicited_registration_events_system_info (GTask *task) { @@ -3500,6 +3507,7 @@ common_enable_disable_unsolicited_registration_events_system_info (GTask *task) (GAsyncReadyCallback)ri_serving_system_or_system_info_ready, task); } + #endif /* WITH_NEWEST_QMI_COMMANDS */ static void @@ -4522,7 +4530,8 @@ system_info_indication_cb (QmiClientNas *client, if (mm_iface_modem_is_3gpp (MM_IFACE_MODEM (self))) common_process_system_info_3gpp (self, NULL, output); } -#endif + +#else /* WITH_NEWEST_QMI_COMMANDS */ static void serving_system_indication_cb (QmiClientNas *client, @@ -4535,6 +4544,8 @@ serving_system_indication_cb (QmiClientNas *client, common_process_serving_system_cdma (self, NULL, output); } +#endif + static void common_setup_cleanup_unsolicited_registration_events (MMBroadbandModemQmi *self, gboolean enable, @@ -4714,6 +4725,8 @@ common_enable_disable_unsolicited_events_finish (MMBroadbandModemQmi *self, return g_task_propagate_boolean (G_TASK (res), error); } +#if !defined WITH_NEWEST_QMI_COMMANDS + static void ser_signal_strength_ready (QmiClientNas *client, GAsyncResult *res, @@ -4771,7 +4784,7 @@ common_enable_disable_unsolicited_events_signal_strength (GTask *task) task); } -#if defined WITH_NEWEST_QMI_COMMANDS +#else /* WITH_NEWEST_QMI_COMMANDS */ static void ri_signal_info_ready (QmiClientNas *client, From 93686510d737bc373100beaeeb3edb7ca091a3f0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 20 Aug 2020 10:57:01 +0200 Subject: [PATCH 346/675] sms-part-3gpp: minor refactor in text split logic --- src/mm-sms-part-3gpp.c | 167 +++++++++++++++++++++++------------------ 1 file changed, 94 insertions(+), 73 deletions(-) diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index c4f6154f..9e1862d1 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -1063,22 +1063,103 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, return NULL; } +static gchar ** +util_split_text_gsm7 (const gchar *text, + gsize text_len, + gpointer log_object) +{ + gchar **out; + guint n_chunks; + guint i; + guint j; + + /* No splitting needed? */ + if (text_len <= 160) { + out = g_new0 (gchar *, 2); + out[0] = g_strdup (text); + return out; + } + + /* Compute number of chunks needed */ + n_chunks = text_len / 153; + if (text_len % 153 != 0) + n_chunks++; + + /* Fill in all chunks */ + out = g_new0 (gchar *, n_chunks + 1); + for (i = 0, j = 0; i < n_chunks; i++, j += 153) + out[i] = g_strndup (&text[j], 153); + + return out; +} + +static gchar ** +util_split_text_ucs2 (const gchar *text, + gsize text_len, + gpointer log_object) +{ + g_autoptr(GByteArray) array = NULL; + g_autoptr(GError) error = NULL; + gchar **out; + guint n_chunks; + guint i; + guint j; + + /* Guess the size of the output array to avoid multiple allocations */ + array = g_byte_array_sized_new (text_len * 2); + if (!mm_modem_charset_byte_array_append (array, + text, + FALSE, + MM_MODEM_CHARSET_UCS2, + &error)) { + mm_obj_warn (log_object, "failed to append UCS2: %s", error->message); + return NULL; + } + + /* Our bytearray has it in UCS-2 now. + * UCS-2 is a fixed-size encoding, which means that the text has exactly + * 2 bytes for each unicode point. We can now split this array into + * chunks of 67 UCS-2 characters (134 bytes). + * + * Note that UCS-2 covers unicode points between U+0000 and U+FFFF, which + * means that there is no direct relationship between the size of the + * input text in UTF-8 and the size of the text in UCS-2. A 3-byte UTF-8 + * encoded character will still be represented with 2 bytes in UCS-2. + */ + + /* No splitting needed? */ + if (array->len <= 140) { + out = g_new0 (gchar *, 2); + out[0] = g_strdup (text); + return out; + } + + /* Compute number of chunks needed */ + n_chunks = array->len / 134; + if (array->len % 134 != 0) + n_chunks++; + + /* Fill in all chunks */ + out = g_new0 (gchar *, n_chunks + 1); + for (i = 0, j = 0; i < n_chunks; i++, j += 134) { + out[i] = sms_decode_text (&array->data[j], + MIN (array->len - j, 134), + MM_SMS_ENCODING_UCS2, + 0, + log_object); + } + + return out; +} + gchar ** mm_sms_part_3gpp_util_split_text (const gchar *text, MMSmsEncoding *encoding, gpointer log_object) { - gchar **out; - guint n_chunks; - guint i; - guint j; - gsize in_len; - if (!text) return NULL; - in_len = strlen (text); - /* Some info about the rules for splitting. * * The User Data can be up to 140 bytes in the SMS part: @@ -1099,74 +1180,14 @@ mm_sms_part_3gpp_util_split_text (const gchar *text, */ /* Check if we can do GSM encoding */ - if (!mm_charset_can_convert_to (text, MM_MODEM_CHARSET_GSM)) { - /* If cannot do it in GSM encoding, do it in UCS-2 */ - g_autoptr(GByteArray) array = NULL; - g_autoptr(GError) error = NULL; - - *encoding = MM_SMS_ENCODING_UCS2; - - /* Guess more or less the size of the output array to avoid multiple - * allocations */ - array = g_byte_array_sized_new (in_len * 2); - if (!mm_modem_charset_byte_array_append (array, - text, - FALSE, - MM_MODEM_CHARSET_UCS2, - &error)) { - mm_obj_warn (log_object, "failed to append UCS2: %s", error->message); - return NULL; - } - - /* Our bytearray has it in UCS-2 now. - * UCS-2 is a fixed-size encoding, which means that the text has exactly - * 2 bytes for each unicode point. We can now split this array into - * chunks of 67 UCS-2 characters (134 bytes). - * - * Note that UCS-2 covers unicode points between U+0000 and U+FFFF, which - * means that there is no direct relationship between the size of the - * input text in UTF-8 and the size of the text in UCS-2. A 3-byte UTF-8 - * encoded character will still be represented with 2 bytes in UCS-2. - */ - if (array->len <= 140) { - out = g_new (gchar *, 2); - out[0] = g_strdup (text); - out[1] = NULL; - } else { - n_chunks = array->len / 134; - if (array->len % 134 != 0) - n_chunks++; - - out = g_new0 (gchar *, n_chunks + 1); - for (i = 0, j = 0; i < n_chunks; i++, j += 134) { - out[i] = sms_decode_text (&array->data[j], - MIN (array->len - j, 134), - MM_SMS_ENCODING_UCS2, - 0, - log_object); - } - } - } else { - /* Do it with GSM encoding */ + if (mm_charset_can_convert_to (text, MM_MODEM_CHARSET_GSM)) { *encoding = MM_SMS_ENCODING_GSM7; - - if (in_len <= 160) { - out = g_new (gchar *, 2); - out[0] = g_strdup (text); - out[1] = NULL; - } else { - n_chunks = in_len / 153; - if (in_len % 153 != 0) - n_chunks++; - - out = g_new0 (gchar *, n_chunks + 1); - for (i = 0, j = 0; i < n_chunks; i++, j += 153) { - out[i] = g_strndup (&text[j], 153); - } - } + return util_split_text_gsm7 (text, strlen (text), log_object); } - return out; + /* Otherwise, fallback to UCS2 encoding */ + *encoding = MM_SMS_ENCODING_UCS2; + return util_split_text_ucs2 (text, strlen (text), log_object); } GByteArray ** From eb5443b197464e55c85d7a8af67a28f2088506a3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 20 Aug 2020 10:58:24 +0200 Subject: [PATCH 347/675] charsets: add UTF-16BE as a possible modem charset Just as an implementation detail to be taken as an extension of UCS2BE, never really to be used as a real modem charset. --- src/mm-charsets.c | 16 ++++++++++++++-- src/mm-charsets.h | 3 ++- src/tests/test-charsets.c | 18 ++++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index e48cec3e..46b3c68c 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -43,6 +43,7 @@ static CharsetEntry charset_map[] = { { "PCCP437", "CP437", "CP437", "CP437//TRANSLIT", MM_MODEM_CHARSET_PCCP437 }, { "PCDN", "CP850", "CP850", "CP850//TRANSLIT", MM_MODEM_CHARSET_PCDN }, { "HEX", NULL, NULL, NULL, MM_MODEM_CHARSET_HEX }, + { "UTF-16", "UTF16", "UTF-16BE", "UTF-16BE//TRANSLIT", MM_MODEM_CHARSET_UTF16 }, { NULL, NULL, NULL, NULL, MM_MODEM_CHARSET_UNKNOWN } }; @@ -535,6 +536,14 @@ ucs2_is_subset (gunichar c, const char *utf8, gsize ulen) return (c <= 0xFFFF); } +static gboolean +utf16_is_subset (gunichar c, + const gchar *utf8, + gsize ulen) +{ + return TRUE; +} + static gboolean iso88591_is_subset (gunichar c, const char *utf8, gsize ulen) { @@ -613,6 +622,7 @@ SubsetEntry subset_table[] = { { MM_MODEM_CHARSET_GSM, gsm_is_subset }, { MM_MODEM_CHARSET_IRA, ira_is_subset }, { MM_MODEM_CHARSET_UCS2, ucs2_is_subset }, + { MM_MODEM_CHARSET_UTF16, utf16_is_subset }, { MM_MODEM_CHARSET_8859_1, iso88591_is_subset }, { MM_MODEM_CHARSET_PCCP437, pccp437_is_subset }, { MM_MODEM_CHARSET_PCDN, pcdn_is_subset }, @@ -786,7 +796,8 @@ mm_charset_take_and_convert_to_utf8 (gchar *str, MMModemCharset charset) break; } - case MM_MODEM_CHARSET_UCS2: { + case MM_MODEM_CHARSET_UCS2: + case MM_MODEM_CHARSET_UTF16: { gsize len; gboolean possibly_hex = TRUE; gsize bread = 0, bwritten = 0; @@ -914,7 +925,8 @@ mm_utf8_take_and_convert_to_charset (gchar *str, break; } - case MM_MODEM_CHARSET_UCS2: { + case MM_MODEM_CHARSET_UCS2: + case MM_MODEM_CHARSET_UTF16: { const gchar *iconv_to; gsize encoded_len = 0; GError *error = NULL; diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 9e9215d5..e81674c4 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -27,7 +27,8 @@ typedef enum { MM_MODEM_CHARSET_UCS2 = 0x00000010, MM_MODEM_CHARSET_PCCP437 = 0x00000020, MM_MODEM_CHARSET_PCDN = 0x00000040, - MM_MODEM_CHARSET_HEX = 0x00000080 + MM_MODEM_CHARSET_HEX = 0x00000080, + MM_MODEM_CHARSET_UTF16 = 0x00000100, } MMModemCharset; const char *mm_modem_charset_to_string (MMModemCharset charset); diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c index 0931d7e8..a15e0332 100644 --- a/src/tests/test-charsets.c +++ b/src/tests/test-charsets.c @@ -369,6 +369,7 @@ struct charset_can_convert_to_test_s { gboolean to_ira; gboolean to_8859_1; gboolean to_ucs2; + gboolean to_utf16; gboolean to_pccp437; gboolean to_pcdn; }; @@ -379,35 +380,35 @@ test_charset_can_covert_to (void) static const struct charset_can_convert_to_test_s charset_can_convert_to_test[] = { { .utf8 = "", - .to_gsm = TRUE, .to_ira = TRUE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, + .to_gsm = TRUE, .to_ira = TRUE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_utf16 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, }, { .utf8 = " ", - .to_gsm = TRUE, .to_ira = TRUE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, + .to_gsm = TRUE, .to_ira = TRUE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_utf16 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, }, { .utf8 = "some basic ascii", - .to_gsm = TRUE, .to_ira = TRUE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, + .to_gsm = TRUE, .to_ira = TRUE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_utf16 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, }, { .utf8 = "ホモ・サピエンス 喂人类 katakana, chinese, english: UCS2 takes it all", - .to_gsm = FALSE, .to_ira = FALSE, .to_8859_1 = FALSE, .to_ucs2 = TRUE, .to_pccp437 = FALSE, .to_pcdn = FALSE, + .to_gsm = FALSE, .to_ira = FALSE, .to_8859_1 = FALSE, .to_ucs2 = TRUE, .to_utf16 = TRUE, .to_pccp437 = FALSE, .to_pcdn = FALSE, }, { .utf8 = "Some from the GSM7 basic set: a % Ψ Ω ñ ö è æ", - .to_gsm = TRUE, .to_ira = FALSE, .to_8859_1 = FALSE, .to_ucs2 = TRUE, .to_pccp437 = FALSE, .to_pcdn = FALSE, + .to_gsm = TRUE, .to_ira = FALSE, .to_8859_1 = FALSE, .to_ucs2 = TRUE, .to_utf16 = TRUE, .to_pccp437 = FALSE, .to_pcdn = FALSE, }, { .utf8 = "More from the GSM7 extended set: {} [] ~ € |", - .to_gsm = TRUE, .to_ira = FALSE, .to_8859_1 = FALSE, .to_ucs2 = TRUE, .to_pccp437 = FALSE, .to_pcdn = FALSE, + .to_gsm = TRUE, .to_ira = FALSE, .to_8859_1 = FALSE, .to_ucs2 = TRUE, .to_utf16 = TRUE, .to_pccp437 = FALSE, .to_pcdn = FALSE, }, { .utf8 = "patín cannot be encoded in GSM7 or IRA, but is valid UCS2, ISO-8859-1, CP437 and CP850", - .to_gsm = FALSE, .to_ira = FALSE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, + .to_gsm = FALSE, .to_ira = FALSE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_utf16 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, }, { .utf8 = "ècole can be encoded in multiple ways, but not in IRA", - .to_gsm = TRUE, .to_ira = FALSE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, + .to_gsm = TRUE, .to_ira = FALSE, .to_8859_1 = TRUE, .to_ucs2 = TRUE, .to_utf16 = TRUE, .to_pccp437 = TRUE, .to_pcdn = TRUE, }, }; guint i; @@ -418,6 +419,7 @@ test_charset_can_covert_to (void) g_assert (mm_charset_can_convert_to (charset_can_convert_to_test[i].utf8, MM_MODEM_CHARSET_IRA) == charset_can_convert_to_test[i].to_ira); g_assert (mm_charset_can_convert_to (charset_can_convert_to_test[i].utf8, MM_MODEM_CHARSET_8859_1) == charset_can_convert_to_test[i].to_8859_1); g_assert (mm_charset_can_convert_to (charset_can_convert_to_test[i].utf8, MM_MODEM_CHARSET_UCS2) == charset_can_convert_to_test[i].to_ucs2); + g_assert (mm_charset_can_convert_to (charset_can_convert_to_test[i].utf8, MM_MODEM_CHARSET_UTF16) == charset_can_convert_to_test[i].to_utf16); g_assert (mm_charset_can_convert_to (charset_can_convert_to_test[i].utf8, MM_MODEM_CHARSET_PCCP437) == charset_can_convert_to_test[i].to_pccp437); g_assert (mm_charset_can_convert_to (charset_can_convert_to_test[i].utf8, MM_MODEM_CHARSET_PCDN) == charset_can_convert_to_test[i].to_pcdn); } From 81162df15dc9a409d0979ff8d472a026f31ed883 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 20 Aug 2020 11:32:18 +0200 Subject: [PATCH 348/675] charsets: refactor coding style Mostly to use GLib types like gchar or gint, and also to use G_N_ELEMENTS() instead of custom end of array terminating items. --- src/mm-charsets.c | 290 +++++++++++++++++++++++----------------------- src/mm-charsets.h | 42 +++---- 2 files changed, 170 insertions(+), 162 deletions(-) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index 46b3c68c..19d1874c 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -27,89 +27,80 @@ #include "mm-log.h" typedef struct { - const char *gsm_name; - const char *other_name; - const char *iconv_from_name; - const char *iconv_to_name; - MMModemCharset charset; + const gchar *gsm_name; + const gchar *other_name; + const gchar *iconv_from_name; + const gchar *iconv_to_name; + MMModemCharset charset; } CharsetEntry; -static CharsetEntry charset_map[] = { - { "UTF-8", "UTF8", "UTF-8", "UTF-8//TRANSLIT", MM_MODEM_CHARSET_UTF8 }, - { "UCS2", NULL, "UCS-2BE", "UCS-2BE//TRANSLIT", MM_MODEM_CHARSET_UCS2 }, - { "IRA", "ASCII", "ASCII", "ASCII//TRANSLIT", MM_MODEM_CHARSET_IRA }, - { "GSM", NULL, NULL, NULL, MM_MODEM_CHARSET_GSM }, - { "8859-1", NULL, "ISO8859-1", "ISO8859-1//TRANSLIT", MM_MODEM_CHARSET_8859_1 }, +static const CharsetEntry charset_map[] = { + { "UTF-8", "UTF8", "UTF-8", "UTF-8//TRANSLIT", MM_MODEM_CHARSET_UTF8 }, + { "UCS2", NULL, "UCS-2BE", "UCS-2BE//TRANSLIT", MM_MODEM_CHARSET_UCS2 }, + { "IRA", "ASCII", "ASCII", "ASCII//TRANSLIT", MM_MODEM_CHARSET_IRA }, + { "GSM", NULL, NULL, NULL, MM_MODEM_CHARSET_GSM }, + { "8859-1", NULL, "ISO8859-1", "ISO8859-1//TRANSLIT", MM_MODEM_CHARSET_8859_1 }, { "PCCP437", "CP437", "CP437", "CP437//TRANSLIT", MM_MODEM_CHARSET_PCCP437 }, - { "PCDN", "CP850", "CP850", "CP850//TRANSLIT", MM_MODEM_CHARSET_PCDN }, - { "HEX", NULL, NULL, NULL, MM_MODEM_CHARSET_HEX }, - { "UTF-16", "UTF16", "UTF-16BE", "UTF-16BE//TRANSLIT", MM_MODEM_CHARSET_UTF16 }, - { NULL, NULL, NULL, NULL, MM_MODEM_CHARSET_UNKNOWN } + { "PCDN", "CP850", "CP850", "CP850//TRANSLIT", MM_MODEM_CHARSET_PCDN }, + { "HEX", NULL, NULL, NULL, MM_MODEM_CHARSET_HEX }, + { "UTF-16", "UTF16", "UTF-16BE", "UTF-16BE//TRANSLIT", MM_MODEM_CHARSET_UTF16 }, }; -const char * -mm_modem_charset_to_string (MMModemCharset charset) -{ - CharsetEntry *iter = &charset_map[0]; - - g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); - - while (iter->gsm_name) { - if (iter->charset == charset) - return iter->gsm_name; - iter++; - } - g_warn_if_reached (); - return NULL; -} - MMModemCharset -mm_modem_charset_from_string (const char *string) +mm_modem_charset_from_string (const gchar *string) { - CharsetEntry *iter = &charset_map[0]; + guint i; g_return_val_if_fail (string != NULL, MM_MODEM_CHARSET_UNKNOWN); - while (iter->gsm_name) { - if (strcasestr (string, iter->gsm_name)) - return iter->charset; - if (iter->other_name && strcasestr (string, iter->other_name)) - return iter->charset; - iter++; + for (i = 0; i < G_N_ELEMENTS (charset_map); i++) { + if (strcasestr (string, charset_map[i].gsm_name)) + return charset_map[i].charset; + if (charset_map[i].other_name && strcasestr (string, charset_map[i].other_name)) + return charset_map[i].charset; } return MM_MODEM_CHARSET_UNKNOWN; } -static const char * -charset_iconv_to (MMModemCharset charset) +static const CharsetEntry * +lookup_charset_by_id (MMModemCharset charset) { - CharsetEntry *iter = &charset_map[0]; + guint i; g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); - - while (iter->gsm_name) { - if (iter->charset == charset) - return iter->iconv_to_name; - iter++; + for (i = 0; i < G_N_ELEMENTS (charset_map); i++) { + if (charset_map[i].charset == charset) + return &charset_map[i]; } g_warn_if_reached (); return NULL; } -static const char * -charset_iconv_from (MMModemCharset charset) +const gchar * +mm_modem_charset_to_string (MMModemCharset charset) { - CharsetEntry *iter = &charset_map[0]; + const CharsetEntry *entry; - g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); + entry = lookup_charset_by_id (charset); + return entry ? entry->gsm_name : NULL; +} - while (iter->gsm_name) { - if (iter->charset == charset) - return iter->iconv_from_name; - iter++; - } - g_warn_if_reached (); - return NULL; +static const gchar * +charset_iconv_to (MMModemCharset charset) +{ + const CharsetEntry *entry; + + entry = lookup_charset_by_id (charset); + return entry ? entry->iconv_to_name : NULL; +} + +static const gchar * +charset_iconv_from (MMModemCharset charset) +{ + const CharsetEntry *entry; + + entry = lookup_charset_by_id (charset); + return entry ? entry->iconv_from_name : NULL; } gboolean @@ -149,9 +140,9 @@ gchar * mm_modem_charset_byte_array_to_utf8 (GByteArray *array, MMModemCharset charset) { - char *converted; - const char *iconv_from; - GError *error = NULL; + const gchar *iconv_from; + g_autofree gchar *converted = NULL; + g_autoptr(GError) error = NULL; g_return_val_if_fail (array != NULL, NULL); g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); @@ -162,21 +153,21 @@ mm_modem_charset_byte_array_to_utf8 (GByteArray *array, converted = g_convert ((const gchar *)array->data, array->len, "UTF-8//TRANSLIT", iconv_from, NULL, NULL, &error); - if (!converted || error) { - g_clear_error (&error); - converted = NULL; - } + if (!converted || error) + return NULL; - return converted; + return g_steal_pointer (&converted); } -char * -mm_modem_charset_hex_to_utf8 (const char *src, MMModemCharset charset) +gchar * +mm_modem_charset_hex_to_utf8 (const gchar *src, + MMModemCharset charset) { - char *unconverted, *converted; - const char *iconv_from; - gsize unconverted_len = 0; - GError *error = NULL; + const gchar *iconv_from; + g_autofree gchar *unconverted = NULL; + g_autofree gchar *converted = NULL; + g_autoptr(GError) error = NULL; + gsize unconverted_len = 0; g_return_val_if_fail (src != NULL, NULL); g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); @@ -189,29 +180,25 @@ mm_modem_charset_hex_to_utf8 (const char *src, MMModemCharset charset) return NULL; if (charset == MM_MODEM_CHARSET_UTF8 || charset == MM_MODEM_CHARSET_IRA) - return unconverted; + return g_steal_pointer (&unconverted); converted = g_convert (unconverted, unconverted_len, "UTF-8//TRANSLIT", iconv_from, NULL, NULL, &error); - if (!converted || error) { - g_clear_error (&error); - converted = NULL; - } - - g_free (unconverted); + if (!converted || error) + return NULL; - return converted; + return g_steal_pointer (&converted); } -char * -mm_modem_charset_utf8_to_hex (const char *src, MMModemCharset charset) +gchar * +mm_modem_charset_utf8_to_hex (const gchar *src, + MMModemCharset charset) { - gsize converted_len = 0; - char *converted; - const char *iconv_to; - GError *error = NULL; - gchar *hex; + const gchar *iconv_to; + g_autofree gchar *converted = NULL; + g_autoptr(GError) error = NULL; + gsize converted_len = 0; g_return_val_if_fail (src != NULL, NULL); g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); @@ -225,16 +212,11 @@ mm_modem_charset_utf8_to_hex (const char *src, MMModemCharset charset) converted = g_convert (src, strlen (src), iconv_to, "UTF-8//TRANSLIT", NULL, &converted_len, &error); - if (!converted || error) { - g_clear_error (&error); - g_free (converted); + if (!converted || error) return NULL; - } /* Get hex representation of the string */ - hex = mm_utils_bin2hexstr ((guint8 *)converted, converted_len); - g_free (converted); - return hex; + return mm_utils_bin2hexstr ((guint8 *)converted, converted_len); } /* GSM 03.38 encoding conversion stuff */ @@ -243,7 +225,7 @@ mm_modem_charset_utf8_to_hex (const char *src, MMModemCharset charset) #define GSM_EXT_ALPHABET_SIZE 10 typedef struct GsmUtf8Mapping { - gchar chars[3]; + gchar chars[3]; guint8 len; guint8 gsm; /* only used for extended GSM charset */ } GsmUtf8Mapping; @@ -327,7 +309,8 @@ static const GsmUtf8Mapping gsm_def_utf8_alphabet[GSM_DEF_ALPHABET_SIZE] = { }; static guint8 -gsm_def_char_to_utf8 (const guint8 gsm, guint8 out_utf8[2]) +gsm_def_char_to_utf8 (const guint8 gsm, + guint8 out_utf8[2]) { g_return_val_if_fail (gsm < GSM_DEF_ALPHABET_SIZE, 0); memcpy (&out_utf8[0], &gsm_def_utf8_alphabet[gsm].chars[0], gsm_def_utf8_alphabet[gsm].len); @@ -335,9 +318,11 @@ gsm_def_char_to_utf8 (const guint8 gsm, guint8 out_utf8[2]) } static gboolean -utf8_to_gsm_def_char (const char *utf8, guint32 len, guint8 *out_gsm) +utf8_to_gsm_def_char (const gchar *utf8, + guint32 len, + guint8 *out_gsm) { - int i; + gint i; if (len > 0 && len < 4) { for (i = 0; i < GSM_DEF_ALPHABET_SIZE; i++) { @@ -374,7 +359,8 @@ static const GsmUtf8Mapping gsm_ext_utf8_alphabet[GSM_EXT_ALPHABET_SIZE] = { #define GSM_ESCAPE_CHAR 0x1b static guint8 -gsm_ext_char_to_utf8 (const guint8 gsm, guint8 out_utf8[3]) +gsm_ext_char_to_utf8 (const guint8 gsm, + guint8 out_utf8[3]) { int i; @@ -388,7 +374,9 @@ gsm_ext_char_to_utf8 (const guint8 gsm, guint8 out_utf8[3]) } static gboolean -utf8_to_gsm_ext_char (const char *utf8, guint32 len, guint8 *out_gsm) +utf8_to_gsm_ext_char (const gchar *utf8, + guint32 len, + guint8 *out_gsm) { int i; @@ -406,9 +394,10 @@ utf8_to_gsm_ext_char (const char *utf8, guint32 len, guint8 *out_gsm) } guint8 * -mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, guint32 len) +mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, + guint32 len) { - guint i; + guint i; GByteArray *utf8; g_return_val_if_fail (gsm != NULL, NULL); @@ -465,12 +454,13 @@ mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, guint32 len) } guint8 * -mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len) +mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, + guint32 *out_len) { - GByteArray *gsm; - const char *c = utf8, *next = c; - static const guint8 gesc = GSM_ESCAPE_CHAR; - int i = 0; + GByteArray *gsm; + const gchar *c; + const gchar *next; + static const guint8 gesc = GSM_ESCAPE_CHAR; g_return_val_if_fail (utf8 != NULL, NULL); g_return_val_if_fail (g_utf8_validate (utf8, -1, NULL), NULL); @@ -486,6 +476,8 @@ mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len) return g_byte_array_free (gsm, FALSE); } + next = utf8; + c = utf8; while (next && *next) { guint8 gch = 0x3f; /* 0x3f == '?' */ @@ -500,7 +492,6 @@ mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len) g_byte_array_append (gsm, &gch, 1); c = next; - i++; } /* Output length doesn't consider terminating NUL byte */ @@ -513,7 +504,9 @@ mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len) } static gboolean -gsm_is_subset (gunichar c, const char *utf8, gsize ulen) +gsm_is_subset (gunichar c, + const gchar *utf8, + gsize ulen) { guint8 gsm; @@ -525,13 +518,17 @@ gsm_is_subset (gunichar c, const char *utf8, gsize ulen) } static gboolean -ira_is_subset (gunichar c, const char *utf8, gsize ulen) +ira_is_subset (gunichar c, + const gchar *utf8, + gsize ulen) { return (ulen == 1); } static gboolean -ucs2_is_subset (gunichar c, const char *utf8, gsize ulen) +ucs2_is_subset (gunichar c, + const gchar *utf8, + gsize ulen) { return (c <= 0xFFFF); } @@ -545,13 +542,17 @@ utf16_is_subset (gunichar c, } static gboolean -iso88591_is_subset (gunichar c, const char *utf8, gsize ulen) +iso88591_is_subset (gunichar c, + const gchar *utf8, + gsize ulen) { return (c <= 0xFF); } static gboolean -pccp437_is_subset (gunichar c, const char *utf8, gsize ulen) +pccp437_is_subset (gunichar c, + const gchar *utf8, + gsize ulen) { static const gunichar t[] = { 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, @@ -582,7 +583,9 @@ pccp437_is_subset (gunichar c, const char *utf8, gsize ulen) } static gboolean -pcdn_is_subset (gunichar c, const char *utf8, gsize ulen) +pcdn_is_subset (gunichar c, + const gchar *utf8, + gsize ulen) { static const gunichar t[] = { 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, @@ -614,19 +617,19 @@ pcdn_is_subset (gunichar c, const char *utf8, gsize ulen) typedef struct { MMModemCharset cs; - gboolean (*func) (gunichar c, const char *utf8, gsize ulen); - guint charsize; + gboolean (*func) (gunichar c, + const gchar *utf8, + gsize ulen); } SubsetEntry; -SubsetEntry subset_table[] = { - { MM_MODEM_CHARSET_GSM, gsm_is_subset }, - { MM_MODEM_CHARSET_IRA, ira_is_subset }, - { MM_MODEM_CHARSET_UCS2, ucs2_is_subset }, - { MM_MODEM_CHARSET_UTF16, utf16_is_subset }, +const SubsetEntry subset_table[] = { + { MM_MODEM_CHARSET_GSM, gsm_is_subset }, + { MM_MODEM_CHARSET_IRA, ira_is_subset }, + { MM_MODEM_CHARSET_UCS2, ucs2_is_subset }, + { MM_MODEM_CHARSET_UTF16, utf16_is_subset }, { MM_MODEM_CHARSET_8859_1, iso88591_is_subset }, - { MM_MODEM_CHARSET_PCCP437, pccp437_is_subset }, - { MM_MODEM_CHARSET_PCDN, pcdn_is_subset }, - { MM_MODEM_CHARSET_UNKNOWN, NULL }, + { MM_MODEM_CHARSET_PCCP437, pccp437_is_subset }, + { MM_MODEM_CHARSET_PCDN, pcdn_is_subset }, }; /** @@ -637,11 +640,11 @@ SubsetEntry subset_table[] = { * Returns: %TRUE if the conversion is possible without errors, %FALSE otherwise. */ gboolean -mm_charset_can_convert_to (const char *utf8, - MMModemCharset charset) +mm_charset_can_convert_to (const gchar *utf8, + MMModemCharset charset) { - const char *p = utf8; - SubsetEntry *e; + const gchar *p; + guint i; g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, FALSE); g_return_val_if_fail (utf8 != NULL, FALSE); @@ -650,11 +653,13 @@ mm_charset_can_convert_to (const char *utf8, return TRUE; /* Find the charset in our subset table */ - for (e = &subset_table[0]; - e->cs != charset && e->cs != MM_MODEM_CHARSET_UNKNOWN; - e++); - g_return_val_if_fail (e->cs != MM_MODEM_CHARSET_UNKNOWN, FALSE); + for (i = 0; i < G_N_ELEMENTS (subset_table); i++) { + if (subset_table[i].cs == charset) + break; + } + g_return_val_if_fail (i < G_N_ELEMENTS (subset_table), FALSE); + p = utf8; while (*p) { gunichar c; const char *end; @@ -668,7 +673,7 @@ mm_charset_can_convert_to (const char *utf8, while (*++end); } - if (!e->func (c, p, (end - p))) + if (!subset_table[i].func (c, p, (end - p))) return FALSE; p = end; @@ -679,9 +684,9 @@ mm_charset_can_convert_to (const char *utf8, guint8 * mm_charset_gsm_unpack (const guint8 *gsm, - guint32 num_septets, - guint8 start_offset, /* in _bits_ */ - guint32 *out_unpacked_len) + guint32 num_septets, + guint8 start_offset, /* in _bits_ */ + guint32 *out_unpacked_len) { GByteArray *unpacked; guint i; @@ -715,9 +720,9 @@ mm_charset_gsm_unpack (const guint8 *gsm, guint8 * mm_charset_gsm_pack (const guint8 *src, - guint32 src_len, - guint8 start_offset, - guint32 *out_packed_len) + guint32 src_len, + guint8 start_offset, + guint32 *out_packed_len) { guint8 *packed; guint octet = 0, lshift, plen; @@ -754,7 +759,8 @@ mm_charset_gsm_pack (const guint8 *src, * the hex representation of the charset-encoded string, so we need to cope with * that case. */ gchar * -mm_charset_take_and_convert_to_utf8 (gchar *str, MMModemCharset charset) +mm_charset_take_and_convert_to_utf8 (gchar *str, + MMModemCharset charset) { gchar *utf8 = NULL; @@ -876,8 +882,8 @@ mm_charset_take_and_convert_to_utf8 (gchar *str, MMModemCharset charset) * representation of the charset-encoded string, so we need to cope with that * case. */ gchar * -mm_utf8_take_and_convert_to_charset (gchar *str, - MMModemCharset charset) +mm_utf8_take_and_convert_to_charset (gchar *str, + MMModemCharset charset) { gchar *encoded = NULL; diff --git a/src/mm-charsets.h b/src/mm-charsets.h index e81674c4..c064eef5 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -31,9 +31,8 @@ typedef enum { MM_MODEM_CHARSET_UTF16 = 0x00000100, } MMModemCharset; -const char *mm_modem_charset_to_string (MMModemCharset charset); - -MMModemCharset mm_modem_charset_from_string (const char *string); +const gchar *mm_modem_charset_to_string (MMModemCharset charset); +MMModemCharset mm_modem_charset_from_string (const gchar *string); /* Append the given string to the given byte array but re-encode it * into the given charset first. The original string is assumed to be @@ -53,34 +52,37 @@ gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array, /* Take a string in hex representation ("00430052" or "A4BE11" for example) * and convert it from the given character set to UTF-8. */ -char *mm_modem_charset_hex_to_utf8 (const char *src, MMModemCharset charset); +gchar *mm_modem_charset_hex_to_utf8 (const gchar *src, + MMModemCharset charset); /* Take a string in UTF-8 and convert it to the given charset in hex * representation. */ -char *mm_modem_charset_utf8_to_hex (const char *src, MMModemCharset charset); - -guint8 *mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len); +gchar *mm_modem_charset_utf8_to_hex (const gchar *src, + MMModemCharset charset); -guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, guint32 len); +guint8 *mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, + guint32 *out_len); +guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, + guint32 len); /* Checks whether conversion to the given charset may be done without errors */ -gboolean mm_charset_can_convert_to (const char *utf8, - MMModemCharset charset); +gboolean mm_charset_can_convert_to (const gchar *utf8, + MMModemCharset charset); guint8 *mm_charset_gsm_unpack (const guint8 *gsm, - guint32 num_septets, - guint8 start_offset, /* in bits */ - guint32 *out_unpacked_len); + guint32 num_septets, + guint8 start_offset, /* in bits */ + guint32 *out_unpacked_len); guint8 *mm_charset_gsm_pack (const guint8 *src, - guint32 src_len, - guint8 start_offset, /* in bits */ - guint32 *out_packed_len); - -gchar *mm_charset_take_and_convert_to_utf8 (gchar *str, MMModemCharset charset); + guint32 src_len, + guint8 start_offset, /* in bits */ + guint32 *out_packed_len); -gchar *mm_utf8_take_and_convert_to_charset (gchar *str, - MMModemCharset charset); +gchar *mm_charset_take_and_convert_to_utf8 (gchar *str, + MMModemCharset charset); +gchar *mm_utf8_take_and_convert_to_charset (gchar *str, + MMModemCharset charset); #endif /* MM_CHARSETS_H */ From 599f545c0d905505516c6546ff77caced2aa14f1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 20 Aug 2020 12:18:05 +0200 Subject: [PATCH 349/675] sms-part-3gpp: allow sending UTF-16 as if it were UCS-2 Despite 3GPP TS 23.038 specifies that Unicode SMS messages are encoded in UCS-2, UTF-16 encoding is commonly used instead on many modern platforms to allow encoding code points that fall outside the Basic Multilingual Plane (BMP), such as Emoji. Update the logic to always use UTF-16 instead of UCS-2 when creating or parsing PDUs (even if we always report as sending or receiving UCS-2). For all purposes, UCS-2 is considered a subset of UTF-16 (assuming that code points out of the [U+0000,U+D7FF] and [U+E000,U+FFFF] ranges are not applicable in UCS-2). Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/250 --- src/mm-sms-part-3gpp.c | 159 +++++++++++++++++---------------- src/mm-sms-part.h | 18 +++- src/tests/test-sms-part-3gpp.c | 78 +++++++++++++--- 3 files changed, 165 insertions(+), 90 deletions(-) diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index 9e1862d1..c18aaa75 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -246,38 +246,25 @@ sms_decode_text (const guint8 *text, int bit_offset, gpointer log_object) { - char *utf8; - guint8 *unpacked; - guint32 unpacked_len; + gchar *utf8; if (encoding == MM_SMS_ENCODING_GSM7) { + g_autofree guint8 *unpacked = NULL; + guint32 unpacked_len; + mm_obj_dbg (log_object, "converting SMS part text from GSM-7 to UTF-8..."); unpacked = mm_charset_gsm_unpack ((const guint8 *) text, len, bit_offset, &unpacked_len); utf8 = (char *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len); mm_obj_dbg (log_object, " got UTF-8 text: '%s'", utf8); - g_free (unpacked); } else if (encoding == MM_SMS_ENCODING_UCS2) { - /* Despite 3GPP TS 23.038 specifies that Unicode SMS messages are - * encoded in UCS-2, UTF-16 encoding is commonly used instead on many - * modern platforms to allow encoding code points that fall outside the - * Basic Multilingual Plane (BMP), such as Emoji. Most of the UCS-2 - * code points are identical to their equivalent UTF-16 code points. - * In UTF-16, non-BMP code points are encoded in a pair of surrogate - * code points (i.e. a high surrogate in 0xD800..0xDBFF, followed by a - * low surrogate in 0xDC00..0xDFFF). An isolated surrogate code point - * has no general interpretation in UTF-16, but could be a valid - * (though unmapped) code point in UCS-2. Here we first try to decode - * the SMS message in UTF-16BE, and if that fails, fall back to decode - * in UCS-2BE. - */ + g_autoptr(GByteArray) bytearray = NULL; + mm_obj_dbg (log_object, "converting SMS part text from UTF-16BE to UTF-8..."); - utf8 = g_convert ((const gchar *) text, len, "UTF-8", "UTF-16BE", NULL, NULL, NULL); - if (!utf8) { - mm_obj_dbg (log_object, "converting SMS part text from UCS-2BE to UTF-8..."); - utf8 = g_convert ((const gchar *) text, len, "UTF-8", "UCS-2BE", NULL, NULL, NULL); - } + bytearray = g_byte_array_append (g_byte_array_sized_new (len), (const guint8 *)text, len); + /* Always assume UTF-16 instead of UCS-2! */ + utf8 = mm_modem_charset_byte_array_to_utf8 (bytearray, MM_MODEM_CHARSET_UTF16); if (!utf8) { - mm_obj_warn (log_object, "couldn't convert SMS part contents from UTF-16BE/UCS-2BE to UTF-8: not decoding any text"); + mm_obj_warn (log_object, "couldn't convert SMS part contents from UTF-16BE to UTF-8: not decoding any text"); utf8 = g_strdup (""); } else mm_obj_dbg (log_object, " got UTF-8 text: '%s'", utf8); @@ -625,9 +612,11 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, mm_obj_dbg (log_object, " user data encoding is 8bit"); break; case MM_SMS_ENCODING_UNKNOWN: - default: mm_obj_dbg (log_object, " user data encoding is unknown"); break; + default: + g_assert_not_reached (); + } mm_sms_part_set_encoding (sms_part, user_data_encoding); @@ -829,6 +818,7 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, guint len, offset = 0; guint shift = 0; guint8 *udl_ptr; + MMSmsEncoding encoding; g_return_val_if_fail (mm_sms_part_get_number (part) != NULL, NULL); g_return_val_if_fail (mm_sms_part_get_text (part) != NULL || mm_sms_part_get_data (part) != NULL, NULL); @@ -923,7 +913,9 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, pdu[offset] |= mm_sms_part_get_class (part); } - switch (mm_sms_part_get_encoding (part)) { + encoding = mm_sms_part_get_encoding (part); + + switch (encoding) { case MM_SMS_ENCODING_UCS2: mm_obj_dbg (log_object, " using UCS2 encoding..."); pdu[offset] |= SMS_DCS_CODING_UCS2; @@ -976,7 +968,7 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, shift = 1; } - if (mm_sms_part_get_encoding (part) == MM_SMS_ENCODING_GSM7) { + if (encoding == MM_SMS_ENCODING_GSM7) { guint8 *unpacked, *packed; guint32 unlen = 0, packlen = 0; @@ -1012,17 +1004,19 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, memcpy (&pdu[offset], packed, packlen); g_free (packed); offset += packlen; - } else if (mm_sms_part_get_encoding (part) == MM_SMS_ENCODING_UCS2) { + } else if (encoding == MM_SMS_ENCODING_UCS2) { g_autoptr(GByteArray) array = NULL; g_autoptr(GError) inner_error = NULL; /* Try to guess a good value for the array */ array = g_byte_array_sized_new (strlen (mm_sms_part_get_text (part)) * 2); - if (!mm_modem_charset_byte_array_append (array, mm_sms_part_get_text (part), FALSE, MM_MODEM_CHARSET_UCS2, &inner_error)) { + /* Always assume UTF-16 instead of UCS-2! */ + if (!mm_modem_charset_byte_array_append (array, mm_sms_part_get_text (part), FALSE, MM_MODEM_CHARSET_UTF16, &inner_error)) { g_set_error (error, MM_MESSAGE_ERROR, MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER, - "Failed to convert message text to UCS2: %s", inner_error->message); + "Failed to convert message text to UTF-16: %s", + inner_error->message); goto error; } @@ -1094,62 +1088,68 @@ util_split_text_gsm7 (const gchar *text, } static gchar ** -util_split_text_ucs2 (const gchar *text, - gsize text_len, - gpointer log_object) +util_split_text_utf16_or_ucs2 (const gchar *text, + gsize text_len, + gpointer log_object) { - g_autoptr(GByteArray) array = NULL; - g_autoptr(GError) error = NULL; - gchar **out; - guint n_chunks; - guint i; - guint j; - - /* Guess the size of the output array to avoid multiple allocations */ - array = g_byte_array_sized_new (text_len * 2); - if (!mm_modem_charset_byte_array_append (array, - text, - FALSE, - MM_MODEM_CHARSET_UCS2, - &error)) { - mm_obj_warn (log_object, "failed to append UCS2: %s", error->message); - return NULL; + g_autoptr(GPtrArray) chunks = NULL; + const gchar *walker; + const gchar *chunk_start; + glong encoded_chunk_length; + glong total_encoded_chunk_length; + + chunks = g_ptr_array_new_with_free_func ((GDestroyNotify)g_free); + + walker = text; + chunk_start = text; + encoded_chunk_length = 0; + total_encoded_chunk_length = 0; + while (walker && *walker) { + g_autofree gunichar2 *unichar2 = NULL; + glong unichar2_written = 0; + glong unichar2_written_bytes = 0; + gunichar single; + + single = g_utf8_get_char (walker); + unichar2 = g_ucs4_to_utf16 (&single, 1, NULL, &unichar2_written, NULL); + g_assert (unichar2_written > 0); + + /* When splitting for UCS-2 encoding, only one single unichar2 will be + * written, because all codepoints represented in UCS2 fit in the BMP. + * When splitting for UTF-16, though, we may end up writing one or two + * unichar2 (without or with surrogate pairs), because UTF-16 covers the + * whole Unicode spectrum. */ + unichar2_written_bytes = (unichar2_written * sizeof (gunichar2)); + if ((encoded_chunk_length + unichar2_written_bytes) > 134) { + g_ptr_array_add (chunks, g_strndup (chunk_start, walker - chunk_start)); + chunk_start = walker; + encoded_chunk_length = unichar2_written_bytes; + } else + encoded_chunk_length += unichar2_written_bytes; + + total_encoded_chunk_length += unichar2_written_bytes; + walker = g_utf8_next_char (walker); } - /* Our bytearray has it in UCS-2 now. - * UCS-2 is a fixed-size encoding, which means that the text has exactly - * 2 bytes for each unicode point. We can now split this array into - * chunks of 67 UCS-2 characters (134 bytes). - * - * Note that UCS-2 covers unicode points between U+0000 and U+FFFF, which - * means that there is no direct relationship between the size of the - * input text in UTF-8 and the size of the text in UCS-2. A 3-byte UTF-8 - * encoded character will still be represented with 2 bytes in UCS-2. - */ + /* We have split the original string in chunks, where each chunk + * does not require more than 134 bytes when encoded in UTF-16. + * As a special case now, we consider the case that no splitting + * is necessary, i.e. if the total amount of bytes after encoding + * in UTF-16 is less or equal than 140. */ + if (total_encoded_chunk_length <= 140) { + gchar **out; - /* No splitting needed? */ - if (array->len <= 140) { out = g_new0 (gchar *, 2); out[0] = g_strdup (text); return out; } - /* Compute number of chunks needed */ - n_chunks = array->len / 134; - if (array->len % 134 != 0) - n_chunks++; + /* Otherwise, we do need the splitted chunks. Add the last one + * with contents plus the last trailing NULL */ + g_ptr_array_add (chunks, g_strndup (chunk_start, walker - chunk_start)); + g_ptr_array_add (chunks, NULL); - /* Fill in all chunks */ - out = g_new0 (gchar *, n_chunks + 1); - for (i = 0, j = 0; i < n_chunks; i++, j += 134) { - out[i] = sms_decode_text (&array->data[j], - MIN (array->len - j, 134), - MM_SMS_ENCODING_UCS2, - 0, - log_object); - } - - return out; + return (gchar **) g_ptr_array_free (g_steal_pointer (&chunks), FALSE); } gchar ** @@ -1174,6 +1174,11 @@ mm_sms_part_3gpp_util_split_text (const gchar *text, * 134 * 8 = 1072; 1072/7=153.14 * 2) If we're using UCS2 encoding, we can pack up to 70 characters in * 140 bytes (each with 2 bytes), or up to 67 characters in 134 bytes. + * 3) If we're using UTF-16 encoding (instead of UCS2), the amount of + * characters we can pack is variable, depends on how the characters + * are encoded in UTF-16 (e.g. if there are characters out of the BMP + * we'll need surrogate pairs and a single character will need 4 bytes + * instead of 2). * * This method does the split of the input string into N strings, so that * each of the strings can be placed in a SMS part. @@ -1185,9 +1190,9 @@ mm_sms_part_3gpp_util_split_text (const gchar *text, return util_split_text_gsm7 (text, strlen (text), log_object); } - /* Otherwise, fallback to UCS2 encoding */ + /* Otherwise fallback to report UCS-2 and split supporting UTF-16 */ *encoding = MM_SMS_ENCODING_UCS2; - return util_split_text_ucs2 (text, strlen (text), log_object); + return util_split_text_utf16_or_ucs2 (text, strlen (text), log_object); } GByteArray ** diff --git a/src/mm-sms-part.h b/src/mm-sms-part.h index 92f39b11..2ee7f308 100644 --- a/src/mm-sms-part.h +++ b/src/mm-sms-part.h @@ -20,11 +20,27 @@ #include #include +/* Despite 3GPP TS 23.038 specifies that Unicode SMS messages are + * encoded in UCS-2, UTF-16 encoding is commonly used instead on many + * modern platforms to allow encoding code points that fall outside the + * Basic Multilingual Plane (BMP), such as Emoji. Most of the UCS-2 + * code points are identical to their equivalent UTF-16 code points. + * In UTF-16, non-BMP code points are encoded in a pair of surrogate + * code points (i.e. a high surrogate in 0xD800..0xDBFF, followed by a + * low surrogate in 0xDC00..0xDFFF). An isolated surrogate code point + * has no general interpretation in UTF-16, but could be a valid + * (though unmapped) code point in UCS-2. + * + * The current implementation in ModemManager just assumes that whenever + * possible (i.e. when parsing received PDUs or when creating submit + * PDUs) UTF-16 will be used instead of plain UCS-2 (even if the PDUs + * report the encoding as UCS-2). + */ typedef enum { /*< underscore_name=mm_sms_encoding >*/ MM_SMS_ENCODING_UNKNOWN = 0x0, MM_SMS_ENCODING_GSM7, MM_SMS_ENCODING_8BIT, - MM_SMS_ENCODING_UCS2 + MM_SMS_ENCODING_UCS2, } MMSmsEncoding; typedef struct _MMSmsPart MMSmsPart; diff --git a/src/tests/test-sms-part-3gpp.c b/src/tests/test-sms-part-3gpp.c index c3d59d87..db6aa7a0 100644 --- a/src/tests/test-sms-part-3gpp.c +++ b/src/tests/test-sms-part-3gpp.c @@ -553,8 +553,7 @@ common_test_create_pdu (const gchar *smsc, g_assert_no_error (error); g_assert (pdu != NULL); - g_assert_cmpuint (len, ==, expected_size); - g_assert_cmpint (memcmp (pdu, expected, len), ==, 0); + g_assert_cmpmem (pdu, len, expected, expected_size); g_assert_cmpint (msgstart, ==, expected_msgstart); g_free (pdu); @@ -735,7 +734,7 @@ common_test_text_split (const gchar *text, } static void -test_text_split_short (void) +test_text_split_short_gsm7 (void) { const gchar *text = "Hello"; const gchar *expected [] = { @@ -749,7 +748,7 @@ test_text_split_short (void) static void test_text_split_short_ucs2 (void) { - const gchar *text = "你好"; + const gchar *text = "你好"; /* (UTF-8) e4 bd a0 e5 a5 bd */ const gchar *expected [] = { "你好", NULL @@ -759,7 +758,19 @@ test_text_split_short_ucs2 (void) } static void -test_text_split_max_single_pdu (void) +test_text_split_short_utf16 (void) +{ + const gchar *text = "😉"; /* U+1F609, winking face */ + const gchar *expected [] = { + "😉", + NULL + }; + + common_test_text_split (text, expected, MM_SMS_ENCODING_UCS2); +} + +static void +test_text_split_max_single_pdu_gsm7 (void) { const gchar *text = "0123456789012345678901234567890123456789" @@ -798,7 +809,23 @@ test_text_split_max_single_pdu_ucs2 (void) } static void -test_text_split_two_pdu (void) +test_text_split_max_single_pdu_utf16 (void) +{ + /* NOTE: this string contains 35 Bhaiksuki characters, each of + * them requiring 4 bytes both in UTF-8 and in UTF-16 (140 bytes + * in total). */ + const gchar *text = + "𑰀𑰁𑰂𑰃𑰄𑰅𑰆𑰇𑰈𑰊𑰋𑰌𑰍𑰎𑰏𑰐𑰑𑰒𑰓𑰔𑰕𑰖𑰗𑰘𑰙𑰚𑰛𑰜𑰝𑰞𑰟𑰠𑰡𑰢𑰣"; + const gchar *expected [] = { + "𑰀𑰁𑰂𑰃𑰄𑰅𑰆𑰇𑰈𑰊𑰋𑰌𑰍𑰎𑰏𑰐𑰑𑰒𑰓𑰔𑰕𑰖𑰗𑰘𑰙𑰚𑰛𑰜𑰝𑰞𑰟𑰠𑰡𑰢𑰣", + NULL + }; + + common_test_text_split (text, expected, MM_SMS_ENCODING_UCS2); +} + +static void +test_text_split_two_pdu_gsm7 (void) { const gchar *text = "0123456789012345678901234567890123456789" @@ -839,6 +866,30 @@ test_text_split_two_pdu_ucs2 (void) common_test_text_split (text, expected, MM_SMS_ENCODING_UCS2); } +static void +test_text_split_two_pdu_utf16 (void) +{ + /* NOTE: this string contains 35 Bhaiksuki characters, each of + * them requiring 4 bytes both in UTF-8 and in UTF-16 (140 bytes + * in total) plus one ASCII char (encoded with 1 byte in UTF-8 and + * 2 bytes in UTF-16), making it a total of 142 bytes when in + * UTF-16 (so not fitting in one single PDU) + * + * When split in chunks, the last chunk will hold 2 Bhaiksuki + * characters plus the last ASCII one (9 bytes in UTF-16) so that + * the first chunk contains the leading 33 Bhaiksuki characters + * (132 characters, less than 134) */ + const gchar *text = + "𑰀𑰁𑰂𑰃𑰄𑰅𑰆𑰇𑰈𑰊𑰋𑰌𑰍𑰎𑰏𑰐𑰑𑰒𑰓𑰔𑰕𑰖𑰗𑰘𑰙𑰚𑰛𑰜𑰝𑰞𑰟𑰠𑰡𑰢𑰣a"; + const gchar *expected [] = { + "𑰀𑰁𑰂𑰃𑰄𑰅𑰆𑰇𑰈𑰊𑰋𑰌𑰍𑰎𑰏𑰐𑰑𑰒𑰓𑰔𑰕𑰖𑰗𑰘𑰙𑰚𑰛𑰜𑰝𑰞𑰟𑰠𑰡", + "𑰢𑰣a", + NULL + }; + + common_test_text_split (text, expected, MM_SMS_ENCODING_UCS2); +} + /************************************************************/ int main (int argc, char **argv) @@ -874,12 +925,15 @@ int main (int argc, char **argv) g_test_add_func ("/MM/SMS/3GPP/PDU-Creator/GSM-3", test_create_pdu_gsm_3); g_test_add_func ("/MM/SMS/3GPP/PDU-Creator/GSM-no-validity", test_create_pdu_gsm_no_validity); - g_test_add_func ("/MM/SMS/3GPP/Text-Split/short", test_text_split_short); - g_test_add_func ("/MM/SMS/3GPP/Text-Split/short-UCS2", test_text_split_short_ucs2); - g_test_add_func ("/MM/SMS/3GPP/Text-Split/max-single-pdu", test_text_split_max_single_pdu); - g_test_add_func ("/MM/SMS/3GPP/Text-Split/max-single-pdu-UCS2", test_text_split_max_single_pdu_ucs2); - g_test_add_func ("/MM/SMS/3GPP/Text-Split/two-pdu", test_text_split_two_pdu); - g_test_add_func ("/MM/SMS/3GPP/Text-Split/two-pdu-UCS2", test_text_split_two_pdu_ucs2); + g_test_add_func ("/MM/SMS/3GPP/Text-Split/gsm7/short", test_text_split_short_gsm7); + g_test_add_func ("/MM/SMS/3GPP/Text-Split/ucs2/short", test_text_split_short_ucs2); + g_test_add_func ("/MM/SMS/3GPP/Text-Split/utf16/short", test_text_split_short_utf16); + g_test_add_func ("/MM/SMS/3GPP/Text-Split/gsm7/max-single-pdu", test_text_split_max_single_pdu_gsm7); + g_test_add_func ("/MM/SMS/3GPP/Text-Split/ucs2/max-single-pdu", test_text_split_max_single_pdu_ucs2); + g_test_add_func ("/MM/SMS/3GPP/Text-Split/utf16/max-single-pdu", test_text_split_max_single_pdu_utf16); + g_test_add_func ("/MM/SMS/3GPP/Text-Split/gsm7/two-pdu", test_text_split_two_pdu_gsm7); + g_test_add_func ("/MM/SMS/3GPP/Text-Split/ucs2/two-pdu", test_text_split_two_pdu_ucs2); + g_test_add_func ("/MM/SMS/3GPP/Text-Split/utf16/two-pdu", test_text_split_two_pdu_utf16); return g_test_run (); } From 48973e3d72307ca84375d1c7811eb0b04def91ce Mon Sep 17 00:00:00 2001 From: David Leonard Date: Wed, 26 Aug 2020 14:37:10 +1000 Subject: [PATCH 350/675] sms: fix CMDA SMS UTF-8 translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes incoming SMS translation issue seen on MC7354 when translating contents from Latin-1 encoding to UTF-8, because the encoding parameter "ISO−8859−1" used U+2212 (MINUS SIGN) instead of U+002D (HYPHEN-MINUS). [mm-sms-part-cdma.c:873] read_bearer_data_user_data(): text/data: ignored (latin to UTF-8 conversion error): 0: Conversion from character set 'ISO−8859−1' to 'UTF-8' is not supported Fix thanks to Peter Hunt --- src/mm-sms-part-cdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index 2903e846..6e3f1179 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -874,7 +874,7 @@ read_bearer_data_user_data (MMSmsPart *sms_part, } latin[i] = '\0'; - text = g_convert (latin, -1, "UTF-8", "ISO−8859−1", NULL, NULL, NULL); + text = g_convert (latin, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); if (!text) { mm_obj_dbg (log_object, " text/data: ignored (latin to UTF-8 conversion error)"); } else { From 86a183778b5b123f6556ecbe53ec7d06d6e7c575 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 1 Aug 2020 09:59:13 +0200 Subject: [PATCH 351/675] api,sim: new 'Active' property In preparation for the multi-SIM setup, we need a way to tell whether a given SIM card is active or not in the system. On systems with one single SIM slot, the available SIM card will always be active. On Multi-SIM Single-Standby setups we may have multiple SIM slots with multiple SIM cards, but only one of them will be active at any given time. On Multi-SIM Multi-Standby setups we may have multiple SIM slots with multiple SIM cards that may be active at the same time. E.g. the QMI protocol allows up to 5 different active SIM cards (primary, secondary, tertiary...). --- cli/mmcli-output.c | 1 + cli/mmcli-output.h | 1 + cli/mmcli-sim.c | 1 + .../libmm-glib/libmm-glib-sections.txt | 3 +++ .../org.freedesktop.ModemManager1.Sim.xml | 13 ++++++++++++ libmm-glib/mm-sim.c | 20 +++++++++++++++++++ libmm-glib/mm-sim.h | 2 ++ plugins/huawei/mm-sim-huawei.c | 1 + plugins/iridium/mm-sim-iridium.c | 1 + plugins/mbm/mm-sim-mbm.c | 1 + plugins/nokia/mm-sim-nokia.c | 1 + plugins/novatel/mm-sim-novatel-lte.c | 1 + plugins/pantech/mm-sim-pantech.c | 1 + plugins/sierra/mm-sim-sierra.c | 1 + plugins/ublox/mm-sim-ublox.c | 1 + src/mm-base-sim.c | 1 + src/mm-sim-mbim.c | 1 + src/mm-sim-qmi.c | 1 + 18 files changed, 52 insertions(+) diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c index 81a402ac..7f68e812 100644 --- a/cli/mmcli-output.c +++ b/cli/mmcli-output.c @@ -264,6 +264,7 @@ static FieldInfo field_infos[] = { [MMC_F_SMS_PROPERTIES_DELIVERY_STATE] = { "sms.properties.delivery-state", "delivery state", MMC_S_SMS_PROPERTIES, }, [MMC_F_SMS_PROPERTIES_DISCH_TIMESTAMP] = { "sms.properties.discharge-timestamp", "discharge timestamp", MMC_S_SMS_PROPERTIES, }, [MMC_F_SIM_GENERAL_DBUS_PATH] = { "sim.dbus-path", "path", MMC_S_SIM_GENERAL, }, + [MMC_F_SIM_PROPERTIES_ACTIVE] = { "sim.properties.active", "active", MMC_S_SIM_PROPERTIES, }, [MMC_F_SIM_PROPERTIES_IMSI] = { "sim.properties.imsi", "imsi", MMC_S_SIM_PROPERTIES, }, [MMC_F_SIM_PROPERTIES_ICCID] = { "sim.properties.iccid", "iccid", MMC_S_SIM_PROPERTIES, }, [MMC_F_SIM_PROPERTIES_OPERATOR_ID] = { "sim.properties.operator-code", "operator id", MMC_S_SIM_PROPERTIES, }, diff --git a/cli/mmcli-output.h b/cli/mmcli-output.h index e350b340..0bf40a41 100644 --- a/cli/mmcli-output.h +++ b/cli/mmcli-output.h @@ -281,6 +281,7 @@ typedef enum { MMC_F_SMS_PROPERTIES_DELIVERY_STATE, MMC_F_SMS_PROPERTIES_DISCH_TIMESTAMP, MMC_F_SIM_GENERAL_DBUS_PATH, + MMC_F_SIM_PROPERTIES_ACTIVE, MMC_F_SIM_PROPERTIES_IMSI, MMC_F_SIM_PROPERTIES_ICCID, MMC_F_SIM_PROPERTIES_OPERATOR_ID, diff --git a/cli/mmcli-sim.c b/cli/mmcli-sim.c index efb15df3..e5501ca9 100644 --- a/cli/mmcli-sim.c +++ b/cli/mmcli-sim.c @@ -159,6 +159,7 @@ static void print_sim_info (MMSim *sim) { mmcli_output_string (MMC_F_SIM_GENERAL_DBUS_PATH, mm_sim_get_path (sim)); + mmcli_output_string (MMC_F_SIM_PROPERTIES_ACTIVE, mm_sim_get_active (sim) ? "yes" : "no"); mmcli_output_string (MMC_F_SIM_PROPERTIES_IMSI, mm_sim_get_imsi (sim)); mmcli_output_string (MMC_F_SIM_PROPERTIES_ICCID, mm_sim_get_identifier (sim)); mmcli_output_string (MMC_F_SIM_PROPERTIES_OPERATOR_ID, mm_sim_get_operator_identifier (sim)); diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 32524e7a..3ffd8c87 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -1209,6 +1209,7 @@ MMSim mm_sim_get_path mm_sim_dup_path +mm_sim_get_active mm_sim_get_identifier mm_sim_dup_identifier mm_sim_get_imsi @@ -3088,6 +3089,7 @@ mm_gdbus_object_manager_client_get_type MmGdbusSim MmGdbusSimIface +mm_gdbus_sim_get_active mm_gdbus_sim_get_imsi mm_gdbus_sim_dup_imsi mm_gdbus_sim_get_sim_identifier @@ -3112,6 +3114,7 @@ mm_gdbus_sim_call_change_pin mm_gdbus_sim_call_change_pin_finish mm_gdbus_sim_call_change_pin_sync +mm_gdbus_sim_set_active mm_gdbus_sim_set_imsi mm_gdbus_sim_set_operator_identifier mm_gdbus_sim_set_operator_name diff --git a/introspection/org.freedesktop.ModemManager1.Sim.xml b/introspection/org.freedesktop.ModemManager1.Sim.xml index ceba2629..f214ba5f 100644 --- a/introspection/org.freedesktop.ModemManager1.Sim.xml +++ b/introspection/org.freedesktop.ModemManager1.Sim.xml @@ -65,6 +65,19 @@ + + + + + + + + + + + + + '%s'", - mm_modem_3gpp_registration_state_get_string (priv->state_cs), - mm_modem_3gpp_registration_state_get_string (priv->state_ps), - mm_modem_3gpp_registration_state_get_string (priv->state_eps), - mm_modem_3gpp_registration_state_get_string (priv->state_5gs), - mm_modem_3gpp_registration_state_get_string (consolidated)); - - return consolidated; + return MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN; } /*****************************************************************************/ @@ -1433,8 +1403,14 @@ update_registration_reload_current_registration_info_ready (MMIfaceModem3gpp *se new_state = GPOINTER_TO_UINT (user_data); - mm_obj_info (self, "3GPP Registration state changed (registering -> %s)", + mm_obj_info (self, "3GPP registration state changed (registering -> %s)", mm_modem_3gpp_registration_state_get_string (new_state)); + mm_obj_dbg (self, "consolidated registration state: cs '%s', ps '%s', eps '%s', 5gs '%s' --> '%s'", + mm_modem_3gpp_registration_state_get_string (priv->state_cs), + mm_modem_3gpp_registration_state_get_string (priv->state_ps), + mm_modem_3gpp_registration_state_get_string (priv->state_eps), + mm_modem_3gpp_registration_state_get_string (priv->state_5gs), + mm_modem_3gpp_registration_state_get_string (new_state)); /* The property in the interface is bound to the property * in the skeleton, so just updating here is enough */ @@ -1513,7 +1489,7 @@ update_registration_state (MMIfaceModem3gpp *self, return; } - mm_obj_info (self, "3GPP Registration state changed (%s -> registering)", + mm_obj_info (self, "3GPP registration state changed (%s -> registering)", mm_modem_3gpp_registration_state_get_string (old_state)); /* Reload current registration info. ONLY update the state to REGISTERED @@ -1526,9 +1502,15 @@ update_registration_state (MMIfaceModem3gpp *self, return; } - mm_obj_info (self, "3GPP Registration state changed (%s -> %s)", + mm_obj_info (self, "3GPP registration state changed (%s -> %s)", mm_modem_3gpp_registration_state_get_string (old_state), mm_modem_3gpp_registration_state_get_string (new_state)); + mm_obj_dbg (self, "consolidated registration state: cs '%s', ps '%s', eps '%s', 5gs '%s' --> '%s'", + mm_modem_3gpp_registration_state_get_string (priv->state_cs), + mm_modem_3gpp_registration_state_get_string (priv->state_ps), + mm_modem_3gpp_registration_state_get_string (priv->state_eps), + mm_modem_3gpp_registration_state_get_string (priv->state_5gs), + mm_modem_3gpp_registration_state_get_string (new_state)); update_non_registered_state (self, old_state, new_state); } From 135d484501dbf641b51b02033377871100323049 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 9 Oct 2020 12:50:49 +0200 Subject: [PATCH 407/675] iface-modem-location: allow Cell ID only updates The "Serving System" indications reported via QMI when the device is moving may contain LAC/TAC+CID updates or just CID updates. E.g. this one has "CID 3GPP" (0x1e): Mon Aug 3 11:22:42 2020 daemon.debug [1567]: [/dev/cdc-wdm0] received generic indication (translated)... <<<<<< QMUX: <<<<<< length = 33 <<<<<< flags = 0x80 <<<<<< service = "nas" <<<<<< client = 3 <<<<<< QMI: <<<<<< flags = "indication" <<<<<< transaction = 4512 <<<<<< tlv_length = 21 <<<<<< message = "Serving System" (0x0024) <<<<<< TLV: <<<<<< type = "Serving System" (0x01) <<<<<< length = 6 <<<<<< value = 01:01:01:02:01:08 <<<<<< translated = [ registration_state = 'registered' cs_attach_state = 'attached' ps_attach_state = 'attached' selected_network = '3gpp' radio_interfaces = '{ [0] = 'lte '}' ] <<<<<< TLV: <<<<<< type = "Data Service Capability" (0x11) <<<<<< length = 2 <<<<<< value = 01:0B <<<<<< translated = { [0] = 'lte '} <<<<<< TLV: <<<<<< type = "CID 3GPP" (0x1e) <<<<<< length = 4 <<<<<< value = 14:C2:A8:00 <<<<<< translated = 11059732 And this one has both "CID 3GPP" (0x1e) and "LTE TAC" (0x25): Mon Aug 3 11:23:05 2020 daemon.debug [1567]: [/dev/cdc-wdm0] received generic indication (translated)... <<<<<< QMUX: <<<<<< length = 38 <<<<<< flags = 0x80 <<<<<< service = "nas" <<<<<< client = 3 <<<<<< QMI: <<<<<< flags = "indication" <<<<<< transaction = 4513 <<<<<< tlv_length = 26 <<<<<< message = "Serving System" (0x0024) <<<<<< TLV: <<<<<< type = "Serving System" (0x01) <<<<<< length = 6 <<<<<< value = 01:01:01:02:01:08 <<<<<< translated = [ registration_state = 'registered' cs_attach_state = 'attached' ps_attach_state = 'attached' selected_network = '3gpp' radio_interfaces = '{ [0] = 'lte '}' ] <<<<<< TLV: <<<<<< type = "Data Service Capability" (0x11) <<<<<< length = 2 <<<<<< value = 01:0B <<<<<< translated = { [0] = 'lte '} <<<<<< TLV: <<<<<< type = "CID 3GPP" (0x1e) <<<<<< length = 4 <<<<<< value = 32:36:BC:00 <<<<<< translated = 12334642 <<<<<< TLV: <<<<<< type = "LTE TAC" (0x25) <<<<<< length = 2 <<< We should therefore allow changes only in the CID, maintaining whatever LAC/TAC value we had before. --- src/mm-broadband-modem-qmi.c | 2 +- src/mm-iface-modem-3gpp.c | 8 ++++---- src/mm-iface-modem-location.c | 26 ++++++++++++++++++++------ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 9a1a1e64..8fc5660b 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -2668,7 +2668,7 @@ common_process_serving_system_3gpp (MMBroadbandModemQmi *self, qmi_indication_nas_serving_system_output_get_cid_3gpp (indication_output, &cid, NULL); } /* Only update info in the interface if we get something */ - if (cid && (lac || tac)) + if (cid || lac || tac) mm_iface_modem_3gpp_update_location (MM_IFACE_MODEM_3GPP (self), lac, tac, cid); /* request to reload operator info explicitly, so that the new diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index 08006709..b933064e 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -1359,9 +1359,9 @@ mm_iface_modem_3gpp_update_access_technologies (MMIfaceModem3gpp *self, void mm_iface_modem_3gpp_update_location (MMIfaceModem3gpp *self, - gulong location_area_code, - gulong tracking_area_code, - gulong cell_id) + gulong location_area_code, + gulong tracking_area_code, + gulong cell_id) { Private *priv; MMModem3gppRegistrationState state; @@ -1380,7 +1380,7 @@ mm_iface_modem_3gpp_update_location (MMIfaceModem3gpp *self, * where we're registering (loading current registration info after a state * change to registered), we also allow LAC/CID updates. */ if (REG_STATE_IS_REGISTERED (state) || priv->reloading_registration_info) { - if ((location_area_code > 0 || tracking_area_code > 0) && cell_id > 0) + if (location_area_code || tracking_area_code || cell_id) mm_iface_modem_location_3gpp_update_lac_tac_ci (MM_IFACE_MODEM_LOCATION (self), location_area_code, tracking_area_code, diff --git a/src/mm-iface-modem-location.c b/src/mm-iface-modem-location.c index ce307ccb..da78a1ff 100644 --- a/src/mm-iface-modem-location.c +++ b/src/mm-iface-modem-location.c @@ -396,9 +396,9 @@ mm_iface_modem_location_3gpp_update_mcc_mnc (MMIfaceModemLocation *self, void mm_iface_modem_location_3gpp_update_lac_tac_ci (MMIfaceModemLocation *self, - gulong location_area_code, - gulong tracking_area_code, - gulong cell_id) + gulong location_area_code, + gulong tracking_area_code, + gulong cell_id) { MmGdbusModemLocation *skeleton; LocationContext *ctx; @@ -414,9 +414,23 @@ mm_iface_modem_location_3gpp_update_lac_tac_ci (MMIfaceModemLocation *self, guint changed = 0; g_assert (ctx->location_3gpp != NULL); - changed += mm_location_3gpp_set_location_area_code (ctx->location_3gpp, location_area_code); - changed += mm_location_3gpp_set_tracking_area_code (ctx->location_3gpp, tracking_area_code); - changed += mm_location_3gpp_set_cell_id (ctx->location_3gpp, cell_id); + + /* Update LAC if given, and clear TAC unless a TAC is also given */ + if (location_area_code) { + changed += mm_location_3gpp_set_location_area_code (ctx->location_3gpp, location_area_code); + if (!tracking_area_code) + changed += mm_location_3gpp_set_tracking_area_code (ctx->location_3gpp, 0); + } + /* Update TAC if given, and clear LAC unless a LAC is also given */ + if (tracking_area_code) { + changed += mm_location_3gpp_set_tracking_area_code (ctx->location_3gpp, tracking_area_code); + if (!location_area_code) + changed += mm_location_3gpp_set_location_area_code (ctx->location_3gpp, 0); + } + /* Cell ID only updated if given. It is assumed that if LAC or TAC are given, CID is also given */ + if (cell_id) + changed += mm_location_3gpp_set_cell_id (ctx->location_3gpp, cell_id); + if (changed) notify_3gpp_location_update (self, skeleton, ctx->location_3gpp); } From df9cb4a8f6f0abaad8052e36c10874bfbea2ac76 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 10 Oct 2020 14:38:24 +0200 Subject: [PATCH 408/675] iface-modem-location: log old and new 3GPP location ids when updating --- src/mm-iface-modem-location.c | 74 +++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/src/mm-iface-modem-location.c b/src/mm-iface-modem-location.c index da78a1ff..b45a3405 100644 --- a/src/mm-iface-modem-location.c +++ b/src/mm-iface-modem-location.c @@ -400,42 +400,66 @@ mm_iface_modem_location_3gpp_update_lac_tac_ci (MMIfaceModemLocation *self, gulong tracking_area_code, gulong cell_id) { - MmGdbusModemLocation *skeleton; - LocationContext *ctx; + g_autoptr(MmGdbusModemLocationSkeleton) skeleton = NULL; + LocationContext *ctx; + guint changed = 0; + gulong old_location_area_code; + gulong old_tracking_area_code; + gulong old_cell_id; - ctx = get_location_context (self); g_object_get (self, MM_IFACE_MODEM_LOCATION_DBUS_SKELETON, &skeleton, NULL); - if (!skeleton) + if (!skeleton || !(mm_gdbus_modem_location_get_enabled (MM_GDBUS_MODEM_LOCATION (skeleton)) & MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI)) return; - if (mm_gdbus_modem_location_get_enabled (skeleton) & MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI) { - guint changed = 0; - - g_assert (ctx->location_3gpp != NULL); - - /* Update LAC if given, and clear TAC unless a TAC is also given */ - if (location_area_code) { - changed += mm_location_3gpp_set_location_area_code (ctx->location_3gpp, location_area_code); - if (!tracking_area_code) - changed += mm_location_3gpp_set_tracking_area_code (ctx->location_3gpp, 0); + ctx = get_location_context (self); + g_assert (ctx->location_3gpp != NULL); + + old_location_area_code = mm_location_3gpp_get_location_area_code (ctx->location_3gpp); + old_tracking_area_code = mm_location_3gpp_get_tracking_area_code (ctx->location_3gpp); + old_cell_id = mm_location_3gpp_get_cell_id (ctx->location_3gpp); + + /* Update LAC if given, and clear TAC unless a TAC is also given */ + if (location_area_code) { + if (old_location_area_code != location_area_code) { + mm_obj_dbg (self, "3GPP location area code updated: '%lX->%lX'", old_location_area_code, location_area_code); + mm_location_3gpp_set_location_area_code (ctx->location_3gpp, location_area_code); + changed++; } - /* Update TAC if given, and clear LAC unless a LAC is also given */ - if (tracking_area_code) { - changed += mm_location_3gpp_set_tracking_area_code (ctx->location_3gpp, tracking_area_code); - if (!location_area_code) - changed += mm_location_3gpp_set_location_area_code (ctx->location_3gpp, 0); + if (!tracking_area_code) { + if (old_tracking_area_code != 0) { + mm_obj_dbg (self, "3GPP tracking area code cleared: '%lX->%lX'", old_tracking_area_code, tracking_area_code); + mm_location_3gpp_set_tracking_area_code (ctx->location_3gpp, 0); + changed++; + } + } + } + /* Update TAC if given, and clear LAC unless a LAC is also given */ + if (tracking_area_code) { + if (old_tracking_area_code != tracking_area_code) { + mm_obj_dbg (self, "3GPP tracking area code updated: '%lX->%lX'", old_tracking_area_code, tracking_area_code); + mm_location_3gpp_set_tracking_area_code (ctx->location_3gpp, tracking_area_code); + changed++; + } + if (!location_area_code) { + if (old_location_area_code != 0) { + mm_obj_dbg (self, "3GPP location area code cleared: '%lX->%lX'", old_location_area_code, location_area_code); + mm_location_3gpp_set_location_area_code (ctx->location_3gpp, 0); + changed++; + } } - /* Cell ID only updated if given. It is assumed that if LAC or TAC are given, CID is also given */ - if (cell_id) - changed += mm_location_3gpp_set_cell_id (ctx->location_3gpp, cell_id); + } - if (changed) - notify_3gpp_location_update (self, skeleton, ctx->location_3gpp); + /* Cell ID only updated if given. It is assumed that if LAC or TAC are given, CID is also given */ + if (cell_id && (old_cell_id != cell_id)) { + mm_obj_dbg (self, "3GPP cell id updated: '%lX->%lX'", old_cell_id, cell_id); + mm_location_3gpp_set_cell_id (ctx->location_3gpp, cell_id); + changed++; } - g_object_unref (skeleton); + if (changed) + notify_3gpp_location_update (self, MM_GDBUS_MODEM_LOCATION (skeleton), ctx->location_3gpp); } void From 50c1550c9f808ddd080f7992bf2d7f4dfae6e0ec Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 14 Oct 2020 14:38:40 +0200 Subject: [PATCH 409/675] cinterion: fix missing GError initialization --- plugins/cinterion/mm-shared-cinterion.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/cinterion/mm-shared-cinterion.c b/plugins/cinterion/mm-shared-cinterion.c index 9ad03a75..5b7a360f 100644 --- a/plugins/cinterion/mm-shared-cinterion.c +++ b/plugins/cinterion/mm-shared-cinterion.c @@ -470,7 +470,7 @@ parent_disable_location_gathering_ready (MMIfaceModemLocation *self, GAsyncResult *res, GTask *task) { - GError *error; + GError *error = NULL; Private *priv; priv = get_private (MM_SHARED_CINTERION (self)); @@ -727,7 +727,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self, GAsyncResult *res, GTask *task) { - GError *error; + GError *error = NULL; Private *priv; priv = get_private (MM_SHARED_CINTERION (self)); From 3b6176cbe2bc64bbf19fa0378b1c65b646bb6d13 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 14 Oct 2020 14:38:52 +0200 Subject: [PATCH 410/675] simtech: fix missing GError initialization --- plugins/simtech/mm-shared-simtech.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/simtech/mm-shared-simtech.c b/plugins/simtech/mm-shared-simtech.c index 0d3da877..f6921b61 100644 --- a/plugins/simtech/mm-shared-simtech.c +++ b/plugins/simtech/mm-shared-simtech.c @@ -304,7 +304,7 @@ parent_disable_location_gathering_ready (MMIfaceModemLocation *self, GAsyncResult *res, GTask *task) { - GError *error; + GError *error = NULL; Private *priv; priv = get_private (MM_SHARED_SIMTECH (self)); @@ -436,7 +436,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self, GAsyncResult *res, GTask *task) { - GError *error; + GError *error = NULL; Private *priv; priv = get_private (MM_SHARED_SIMTECH (self)); From f013e94ff89680d1acd7dba12ff4a6a0fa7b58bf Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 14 Oct 2020 14:40:00 +0200 Subject: [PATCH 411/675] xmm: fix missing GError initialization --- plugins/xmm/mm-shared-xmm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/xmm/mm-shared-xmm.c b/plugins/xmm/mm-shared-xmm.c index e2203942..2bf5e8e2 100644 --- a/plugins/xmm/mm-shared-xmm.c +++ b/plugins/xmm/mm-shared-xmm.c @@ -1225,7 +1225,7 @@ parent_disable_location_gathering_ready (MMIfaceModemLocation *self, GAsyncResult *res, GTask *task) { - GError *error; + GError *error = NULL; Private *priv; priv = get_private (MM_SHARED_XMM (self)); @@ -1324,7 +1324,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self, GAsyncResult *res, GTask *task) { - GError *error; + GError *error = NULL; Private *priv; priv = get_private (MM_SHARED_XMM (self)); From 1800983b6c77b495a97eb4335541561456abfed5 Mon Sep 17 00:00:00 2001 From: Eric Caruso Date: Fri, 16 Oct 2020 11:22:37 -0700 Subject: [PATCH 412/675] mm-modem-helpers: add low_nybble_first argument to mm_bcd_to_string All BCD-encoded strings used by MM currently have the low nybble of each byte come before the high nybble, but some strings (such as the EID string returned by QMI Get Slot Status) are meant to be read in order with the high nybble before the low one. As such, extend mm_bcd_to_string to decode both. --- src/mm-modem-helpers.c | 9 ++++++--- src/mm-modem-helpers.h | 4 +++- src/mm-shared-qmi.c | 9 ++++++--- src/mm-sim-qmi.c | 6 ++++-- src/tests/test-modem-helpers.c | 35 +++++++++++++++++++++------------- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index d080e010..3ee12aaa 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -473,7 +473,7 @@ mm_filter_supported_modes (const GArray *all, static const gchar bcd_chars[] = "0123456789\0\0\0\0\0\0"; gchar * -mm_bcd_to_string (const guint8 *bcd, gsize bcd_len) +mm_bcd_to_string (const guint8 *bcd, gsize bcd_len, gboolean low_nybble_first) { GString *str; gsize i; @@ -482,8 +482,11 @@ mm_bcd_to_string (const guint8 *bcd, gsize bcd_len) str = g_string_sized_new (bcd_len * 2 + 1); for (i = 0 ; i < bcd_len; i++) { - str = g_string_append_c (str, bcd_chars[bcd[i] & 0xF]); + if (low_nybble_first) + str = g_string_append_c (str, bcd_chars[bcd[i] & 0xF]); str = g_string_append_c (str, bcd_chars[(bcd[i] >> 4) & 0xF]); + if (!low_nybble_first) + str = g_string_append_c (str, bcd_chars[bcd[i] & 0xF]); } return g_string_free (str, FALSE); } @@ -4301,7 +4304,7 @@ mm_3gpp_parse_emergency_numbers (const char *raw, GError **error) for (i = 0; i < max_items; i++) { gchar *number; - number = mm_bcd_to_string (&bin[i*3], 3); + number = mm_bcd_to_string (&bin[i*3], 3, TRUE /* low_nybble_first */); if (number && number[0]) g_ptr_array_add (out, number); else diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index c1a1b2c9..fb556543 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -84,7 +84,9 @@ GArray *mm_filter_supported_modes (const GArray *all, const GArray *supported_combinations, gpointer log_object); -gchar *mm_bcd_to_string (const guint8 *bcd, gsize bcd_len); +gchar *mm_bcd_to_string (const guint8 *bcd, + gsize bcd_len, + gboolean low_nybble_first); /*****************************************************************************/ /* VOICE specific helpers and utilities */ diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index bea47a39..4530057a 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -3423,7 +3423,8 @@ uim_get_slot_status_ready (QmiClientUim *client, continue; } - raw_iccid = mm_bcd_to_string ((const guint8 *)slot_status->iccid->data, slot_status->iccid->len); + raw_iccid = mm_bcd_to_string ((const guint8 *)slot_status->iccid->data, slot_status->iccid->len, + TRUE /* low_nybble_first */); if (!raw_iccid) { mm_obj_warn (self, "not creating SIM object: failed to convert ICCID from BCD"); g_ptr_array_add (ctx->sim_slots, NULL); @@ -3765,8 +3766,10 @@ uim_slot_status_indication_cb (QmiClientUim *client, if (slot_status->physical_slot_status == QMI_UIM_SLOT_STATE_ACTIVE) { g_autofree gchar *iccid = NULL; - if (slot_status->iccid && slot_status->iccid->len > 0) - iccid = mm_bcd_to_string ((const guint8 *) slot_status->iccid->data, slot_status->iccid->len); + if (slot_status->iccid && slot_status->iccid->len > 0) { + iccid = mm_bcd_to_string ((const guint8 *) slot_status->iccid->data, slot_status->iccid->len, + TRUE /* low_nybble_first */); + } mm_iface_modem_check_for_sim_swap (MM_IFACE_MODEM (self), i + 1, /* Slot index */ diff --git a/src/mm-sim-qmi.c b/src/mm-sim-qmi.c index 52bf0792..bbe2352c 100644 --- a/src/mm-sim-qmi.c +++ b/src/mm-sim-qmi.c @@ -344,7 +344,8 @@ uim_get_iccid_ready (QmiClientUim *client, return; } - iccid = mm_bcd_to_string ((const guint8 *) read_result->data, read_result->len); + iccid = mm_bcd_to_string ((const guint8 *) read_result->data, read_result->len, + TRUE /* low_nybble_first */); g_assert (iccid); g_task_return_pointer (task, iccid, g_free); g_object_unref (task); @@ -458,7 +459,8 @@ uim_get_imsi_ready (QmiClientUim *client, return; } - imsi = mm_bcd_to_string ((const guint8 *) read_result->data, read_result->len); + imsi = mm_bcd_to_string ((const guint8 *) read_result->data, read_result->len, + TRUE /* low_nybble_first */); g_assert (imsi); if (strlen (imsi) < 3) g_task_return_new_error (task, diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 78b3cd11..a6bc72d2 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -4429,20 +4429,22 @@ test_parse_uint_list (void) typedef struct { const guint8 bcd[10]; gsize bcd_len; - const gchar *str; + const gchar *low_nybble_first_str; + const gchar *high_nybble_first_str; } BcdToStringTest; static const BcdToStringTest bcd_to_string_tests[] = { - { { }, 0, "" }, - { { 0x01 }, 1, "10" }, - { { 0x1F }, 1, "" }, - { { 0xE2 }, 1, "2" }, - { { 0xD3 }, 1, "3" }, - { { 0xC4 }, 1, "4" }, - { { 0xB1, 0x23 }, 2, "1" }, - { { 0x01, 0x23, 0x45, 0x67 }, 4, "10325476" }, - { { 0x01, 0x23, 0x45, 0xA7 }, 4, "1032547" }, - { { 0x01, 0x23, 0x45, 0x67 }, 2, "1032" }, + { { }, 0, "", "" }, + { { 0x01 }, 1, "10", "01" }, + { { 0x1F }, 1, "", "1" }, + { { 0xE2 }, 1, "2", "" }, + { { 0xD3 }, 1, "3", "" }, + { { 0xC4 }, 1, "4", "" }, + { { 0xB1, 0x23 }, 2, "1", "" }, + { { 0x01, 0x2A }, 2, "10", "012" }, + { { 0x01, 0x23, 0x45, 0x67 }, 4, "10325476", "01234567" }, + { { 0x01, 0x23, 0x45, 0xA7 }, 4, "1032547", "012345" }, + { { 0x01, 0x23, 0x45, 0x67 }, 2, "1032", "0123" }, }; static void @@ -4454,8 +4456,15 @@ test_bcd_to_string (void *f, gpointer d) gchar *str; str = mm_bcd_to_string (bcd_to_string_tests[i].bcd, - bcd_to_string_tests[i].bcd_len); - g_assert_cmpstr (str, ==, bcd_to_string_tests[i].str); + bcd_to_string_tests[i].bcd_len, + TRUE /* low_nybble_first */); + g_assert_cmpstr (str, ==, bcd_to_string_tests[i].low_nybble_first_str); + g_free (str); + + str = mm_bcd_to_string (bcd_to_string_tests[i].bcd, + bcd_to_string_tests[i].bcd_len, + FALSE /* low_nybble_first */); + g_assert_cmpstr (str, ==, bcd_to_string_tests[i].high_nybble_first_str); g_free (str); } } From 1ed9f7e94e5948f408d1d09ad8c219a594669066 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 19 Oct 2020 22:11:02 +0200 Subject: [PATCH 413/675] broadband-modem-qmi: minor coding style fixes --- src/mm-broadband-modem-qmi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 8fc5660b..8a11318f 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -9070,7 +9070,7 @@ qmi_device_removed_cb (QmiDevice *device, static void track_qmi_device_removed (MMBroadbandModemQmi *self, - MMPortQmi* qmi) + MMPortQmi *qmi) { QmiDevice *device; @@ -9086,7 +9086,7 @@ track_qmi_device_removed (MMBroadbandModemQmi *self, static void untrack_qmi_device_removed (MMBroadbandModemQmi *self, - MMPortQmi* qmi) + MMPortQmi *qmi) { QmiDevice *device; @@ -9289,7 +9289,7 @@ dispose (GObject *object) MMPortQmi *qmi; /* If any port cleanup is needed, it must be done during dispose(), as - * the modem object will be affected by an explciit g_object_run_dispose() + * the modem object will be affected by an explicit g_object_run_dispose() * that will remove all port references right away */ qmi = mm_base_modem_peek_port_qmi (MM_BASE_MODEM (self)); if (qmi) { From 9fca0467801d41598666dd63e9394ed806c5a399 Mon Sep 17 00:00:00 2001 From: Eric Caruso Date: Fri, 12 Jun 2020 15:16:50 -0700 Subject: [PATCH 414/675] mm-base-sim: add EID D-Bus property This provides a new D-Bus property on the Sim object that exposes the EID of the SIM, if available. --- .../libmm-glib/libmm-glib-sections.txt | 2 ++ .../org.freedesktop.ModemManager1.Sim.xml | 7 +++++++ src/mm-base-sim.c | 19 +++++++++++++++++++ src/mm-base-sim.h | 8 ++++++++ 4 files changed, 36 insertions(+) diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 1e283f2c..107cd94d 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -3110,6 +3110,8 @@ MmGdbusSimIface mm_gdbus_sim_get_active mm_gdbus_sim_get_imsi mm_gdbus_sim_dup_imsi +mm_gdbus_sim_get_eid +mm_gdbus_sim_dup_eid mm_gdbus_sim_get_sim_identifier mm_gdbus_sim_dup_sim_identifier mm_gdbus_sim_get_operator_identifier diff --git a/introspection/org.freedesktop.ModemManager1.Sim.xml b/introspection/org.freedesktop.ModemManager1.Sim.xml index f214ba5f..87891e31 100644 --- a/introspection/org.freedesktop.ModemManager1.Sim.xml +++ b/introspection/org.freedesktop.ModemManager1.Sim.xml @@ -95,6 +95,13 @@ --> + + + */ /* Properties */ - GObject *modem_firmware_dbus_skeleton; + GObject *modem_firmware_dbus_skeleton; + gboolean modem_firmware_ignore_carrier; }; /*****************************************************************************/ @@ -12110,6 +12112,9 @@ set_property (GObject *object, case PROP_MODEM_CARRIER_CONFIG_MAPPING: self->priv->carrier_config_mapping = g_value_dup_string (value); break; + case PROP_MODEM_FIRMWARE_IGNORE_CARRIER: + self->priv->modem_firmware_ignore_carrier = g_value_get_boolean (value); + break; case PROP_FLOW_CONTROL: self->priv->flow_control = g_value_get_flags (value); break; @@ -12248,6 +12253,9 @@ get_property (GObject *object, case PROP_MODEM_CARRIER_CONFIG_MAPPING: g_value_set_string (value, self->priv->carrier_config_mapping); break; + case PROP_MODEM_FIRMWARE_IGNORE_CARRIER: + g_value_set_boolean (value, self->priv->modem_firmware_ignore_carrier); + break; case PROP_FLOW_CONTROL: g_value_set_flags (value, self->priv->flow_control); break; @@ -12843,6 +12851,10 @@ mm_broadband_modem_class_init (MMBroadbandModemClass *klass) PROP_MODEM_CARRIER_CONFIG_MAPPING, MM_IFACE_MODEM_CARRIER_CONFIG_MAPPING); + g_object_class_override_property (object_class, + PROP_MODEM_FIRMWARE_IGNORE_CARRIER, + MM_IFACE_MODEM_FIRMWARE_IGNORE_CARRIER); + properties[PROP_FLOW_CONTROL] = g_param_spec_flags (MM_BROADBAND_MODEM_FLOW_CONTROL, "Flow control", diff --git a/src/mm-iface-modem-firmware.c b/src/mm-iface-modem-firmware.c index 5cd710b2..d363f929 100644 --- a/src/mm-iface-modem-firmware.c +++ b/src/mm-iface-modem-firmware.c @@ -297,18 +297,23 @@ add_generic_version (MMBaseModem *self, MMFirmwareUpdateSettings *update_settings, GError **error) { - const gchar *firmware_revision; - const gchar *carrier_revision; - gchar *combined; + const gchar *firmware_revision; + const gchar *carrier_revision = NULL; + g_autofree gchar *combined = NULL; + gboolean ignore_carrier = FALSE; firmware_revision = mm_iface_modem_get_revision (MM_IFACE_MODEM (self)); if (!firmware_revision) { - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Unknown revision"); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Unknown revision"); return FALSE; } - mm_iface_modem_get_carrier_config (MM_IFACE_MODEM (self), NULL, &carrier_revision); + g_object_get (self, + MM_IFACE_MODEM_FIRMWARE_IGNORE_CARRIER, &ignore_carrier, + NULL); + + if (!ignore_carrier) + mm_iface_modem_get_carrier_config (MM_IFACE_MODEM (self), NULL, &carrier_revision); if (!carrier_revision) { mm_firmware_update_settings_set_version (update_settings, firmware_revision); @@ -317,7 +322,6 @@ add_generic_version (MMBaseModem *self, combined = g_strdup_printf ("%s - %s", firmware_revision, carrier_revision); mm_firmware_update_settings_set_version (update_settings, combined); - g_free (combined); return TRUE; } @@ -332,9 +336,10 @@ add_generic_device_ids (MMBaseModem *self, guint16 rid; MMPort *primary = NULL; const gchar *subsystem; - const gchar *aux; + const gchar *carrier_config = NULL; g_autoptr(GPtrArray) ids = NULL; guint i; + gboolean ignore_carrier = FALSE; vid = mm_base_modem_get_vendor_id (self); pid = mm_base_modem_get_product_id (self); @@ -370,16 +375,20 @@ add_generic_device_ids (MMBaseModem *self, return FALSE; } - mm_iface_modem_get_carrier_config (MM_IFACE_MODEM (self), &aux, NULL); + g_object_get (self, + MM_IFACE_MODEM_FIRMWARE_IGNORE_CARRIER, &ignore_carrier, + NULL); + + if (!ignore_carrier) + mm_iface_modem_get_carrier_config (MM_IFACE_MODEM (self), &carrier_config, NULL); ids = g_ptr_array_new_with_free_func (g_free); - if (aux) { - gchar *carrier; + if (carrier_config) { + g_autofree gchar *carrier = NULL; - carrier = g_ascii_strup (aux, -1); + carrier = g_ascii_strup (carrier_config, -1); g_ptr_array_add (ids, g_strdup_printf ("%s\\VID_%04X&PID_%04X&REV_%04X&CARRIER_%s", supported_subsystems[i], vid, pid, rid, carrier)); - g_free (carrier); } g_ptr_array_add (ids, g_strdup_printf ("%s\\VID_%04X&PID_%04X&REV_%04X", supported_subsystems[i], vid, pid, rid)); @@ -563,6 +572,14 @@ iface_modem_firmware_init (gpointer g_iface) MM_GDBUS_TYPE_MODEM_FIRMWARE_SKELETON, G_PARAM_READWRITE)); + g_object_interface_install_property + (g_iface, + g_param_spec_boolean (MM_IFACE_MODEM_FIRMWARE_IGNORE_CARRIER, + "Ignore carrier info in firmware details", + "Whether carrier info (version, name) should be ignored when showing the firmware details", + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + initialized = TRUE; } diff --git a/src/mm-iface-modem-firmware.h b/src/mm-iface-modem-firmware.h index 6ce894a0..365bfb15 100644 --- a/src/mm-iface-modem-firmware.h +++ b/src/mm-iface-modem-firmware.h @@ -27,7 +27,8 @@ #define MM_IS_IFACE_MODEM_FIRMWARE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_IFACE_MODEM_FIRMWARE)) #define MM_IFACE_MODEM_FIRMWARE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_IFACE_MODEM_FIRMWARE, MMIfaceModemFirmware)) -#define MM_IFACE_MODEM_FIRMWARE_DBUS_SKELETON "iface-modem-firmware-dbus-skeleton" +#define MM_IFACE_MODEM_FIRMWARE_DBUS_SKELETON "iface-modem-firmware-dbus-skeleton" +#define MM_IFACE_MODEM_FIRMWARE_IGNORE_CARRIER "iface-modem-firmware-ignore-carrier" typedef struct _MMIfaceModemFirmware MMIfaceModemFirmware; From c3bc515b8a8eb77b3517cc96827fa48573459dd8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 19 Nov 2020 15:52:20 +0100 Subject: [PATCH 481/675] base-manager: never create kernel device objects for remove events There is no point in creating a new kernel device object just to process a remove event; instead, do any matching with existing kernel device objects by subsystem and name, which is what the generic backend already did anyway. This avoids unnecessary lookup of information in sysfs during removal events, because the port is anyway already gone when we try to look those up. --- src/mm-base-manager.c | 104 ++++++++++++++++++++++++++---------------- src/mm-device.c | 73 +++++++++++++++++++++++------ src/mm-device.h | 21 +++++---- 3 files changed, 138 insertions(+), 60 deletions(-) diff --git a/src/mm-base-manager.c b/src/mm-base-manager.c index 071d92e2..130e5ad1 100644 --- a/src/mm-base-manager.c +++ b/src/mm-base-manager.c @@ -136,6 +136,24 @@ find_device_by_port (MMBaseManager *manager, return NULL; } +static MMDevice * +find_device_by_port_name (MMBaseManager *manager, + const gchar *subsystem, + const gchar *name) +{ + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, manager->priv->devices); + while (g_hash_table_iter_next (&iter, &key, &value)) { + MMDevice *candidate = MM_DEVICE (value); + + if (mm_device_owns_port_name (candidate, subsystem, name)) + return candidate; + } + return NULL; +} + static MMDevice * find_device_by_physdev_uid (MMBaseManager *self, const gchar *physdev_uid) @@ -208,24 +226,24 @@ static void device_inhibited_track_port (MMBaseManager *self, MMKernelDevice *port, gboolean manual_scan); static void device_inhibited_untrack_port (MMBaseManager *self, - MMKernelDevice *port); + const gchar *subsystem, + const gchar *name); static void -device_removed (MMBaseManager *self, - MMKernelDevice *kernel_device) +device_removed (MMBaseManager *self, + const gchar *subsystem, + const gchar *name) { - g_autoptr(MMDevice) device = NULL; - const gchar *name; - - g_return_if_fail (kernel_device != NULL); + g_autoptr(MMDevice) device = NULL; - device = find_device_by_port (self, kernel_device); + g_assert (subsystem && name); + device = find_device_by_port_name (self, subsystem, name); if (!device) { /* If the device was inhibited and the port is gone, untrack it. * This is only needed for ports that were tracked out of device objects. * In this case we don't rely on the physdev uid, as API-reported * remove kernel events may not include uid. */ - device_inhibited_untrack_port (self, kernel_device); + device_inhibited_untrack_port (self, subsystem, name); return; } @@ -236,9 +254,8 @@ device_removed (MMBaseManager *self, * ourselves. */ g_object_ref (device); - name = mm_kernel_device_get_name (kernel_device); mm_obj_info (self, "port %s released by device '%s'", name, mm_device_get_uid (device)); - mm_device_release_port (device, kernel_device); + mm_device_release_port_name (device, subsystem, name); /* If port probe list gets empty, remove the device object iself */ if (!mm_device_peek_port_probe_list (device)) { @@ -283,7 +300,7 @@ device_added (MMBaseManager *self, /* This could mean that device changed, losing its candidate * flags (such as Bluetooth RFCOMM devices upon disconnect. * Try to forget it. */ - device_removed (self, port); + device_removed (self, mm_kernel_device_get_subsystem (port), name); mm_obj_dbg (self, "port %s not candidate", name); return; } @@ -346,11 +363,10 @@ handle_kernel_event (MMBaseManager *self, MMKernelEventProperties *properties, GError **error) { - MMKernelDevice *kernel_device; - const gchar *action; - const gchar *subsystem; - const gchar *name; - const gchar *uid; + const gchar *action; + const gchar *subsystem; + const gchar *name; + const gchar *uid; action = mm_kernel_event_properties_get_action (properties); if (!action) { @@ -387,25 +403,27 @@ handle_kernel_event (MMBaseManager *self, mm_obj_dbg (self, " name: %s", name); mm_obj_dbg (self, " uid: %s", uid ? uid : "n/a"); + if (g_strcmp0 (action, "add") == 0) { + g_autoptr(MMKernelDevice) kernel_device = NULL; #if defined WITH_UDEV - if (!mm_context_get_test_no_udev ()) - kernel_device = mm_kernel_device_udev_new_from_properties (properties, error); - else + if (!mm_context_get_test_no_udev ()) + kernel_device = mm_kernel_device_udev_new_from_properties (properties, error); + else #endif - kernel_device = mm_kernel_device_generic_new (properties, error); - - if (!kernel_device) - return FALSE; + kernel_device = mm_kernel_device_generic_new (properties, error); + if (!kernel_device) + return FALSE; - if (g_strcmp0 (action, "add") == 0) device_added (self, kernel_device, TRUE, TRUE); - else if (g_strcmp0 (action, "remove") == 0) - device_removed (self, kernel_device); - else - g_assert_not_reached (); - g_object_unref (kernel_device); + return TRUE; + } - return TRUE; + if (g_strcmp0 (action, "remove") == 0) { + device_removed (self, subsystem, name); + return TRUE; + } + + g_assert_not_reached (); } #if defined WITH_UDEV @@ -415,13 +433,18 @@ handle_uevent (MMBaseManager *self, const gchar *action, GUdevDevice *device) { - g_autoptr(MMKernelDevice) kernel_device = NULL; + if (g_str_equal (action, "add") || g_str_equal (action, "move") || g_str_equal (action, "change")) { + g_autoptr(MMKernelDevice) kernel_device = NULL; - kernel_device = mm_kernel_device_udev_new (device); - if (g_str_equal (action, "add") || g_str_equal (action, "move") || g_str_equal (action, "change")) + kernel_device = mm_kernel_device_udev_new (device); device_added (self, kernel_device, TRUE, FALSE); - else if (g_str_equal (action, "remove")) - device_removed (self, kernel_device); + return; + } + + if (g_str_equal (action, "remove")) { + device_removed (self, g_udev_device_get_subsystem (device), g_udev_device_get_name (device)); + return; + } } typedef struct { @@ -886,7 +909,8 @@ is_device_inhibited (MMBaseManager *self, static void device_inhibited_untrack_port (MMBaseManager *self, - MMKernelDevice *kernel_port) + const gchar *subsystem, + const gchar *name) { GHashTableIter iter; gchar *uid; @@ -900,8 +924,10 @@ device_inhibited_untrack_port (MMBaseManager *self, InhibitedDevicePortInfo *port_info; port_info = (InhibitedDevicePortInfo *)(l->data); - if (mm_kernel_device_cmp (port_info->kernel_port, kernel_port)) { - mm_obj_dbg (self, "released port %s while inhibited", mm_kernel_device_get_name (kernel_port)); + + if ((g_strcmp0 (subsystem, mm_kernel_device_get_subsystem (port_info->kernel_port)) == 0) && + (g_strcmp0 (name, mm_kernel_device_get_name (port_info->kernel_port)) == 0)) { + mm_obj_dbg (self, "released port %s while inhibited", name); inhibited_device_port_info_free (port_info); info->port_infos = g_list_delete_link (info->port_infos, l); return; diff --git a/src/mm-device.c b/src/mm-device.c index a128d63e..ddd420fe 100644 --- a/src/mm-device.c +++ b/src/mm-device.c @@ -97,32 +97,56 @@ struct _MMDevicePrivate { /*****************************************************************************/ static MMPortProbe * -device_find_probe_with_device (MMDevice *self, - MMKernelDevice *kernel_port, - gboolean lookup_ignored) +probe_list_lookup_by_device (GList *port_probes, + MMKernelDevice *kernel_port) { GList *l; - for (l = self->priv->port_probes; l; l = g_list_next (l)) { + for (l = port_probes; l; l = g_list_next (l)) { MMPortProbe *probe = MM_PORT_PROBE (l->data); if (mm_kernel_device_cmp (mm_port_probe_peek_port (probe), kernel_port)) return probe; } + return NULL; +} - if (!lookup_ignored) - return NULL; +static MMPortProbe * +probe_list_lookup_by_name (GList *port_probes, + const gchar *subsystem, + const gchar *name) +{ + GList *l; - for (l = self->priv->ignored_port_probes; l; l = g_list_next (l)) { - MMPortProbe *probe = MM_PORT_PROBE (l->data); + for (l = port_probes; l; l = g_list_next (l)) { + MMPortProbe *probe = MM_PORT_PROBE (l->data); + MMKernelDevice *probe_device; - if (mm_kernel_device_cmp (mm_port_probe_peek_port (probe), kernel_port)) + probe_device = mm_port_probe_peek_port (probe); + if ((g_strcmp0 (subsystem, mm_kernel_device_get_subsystem (probe_device)) == 0) && + (g_strcmp0 (name, mm_kernel_device_get_name (probe_device)) == 0)) return probe; } - return NULL; } +static MMPortProbe * +device_find_probe_with_device (MMDevice *self, + MMKernelDevice *kernel_port, + gboolean lookup_ignored) +{ + MMPortProbe *probe; + + probe = probe_list_lookup_by_device (self->priv->port_probes, kernel_port); + if (probe) + return probe; + + if (!lookup_ignored) + return NULL; + + return probe_list_lookup_by_device (self->priv->ignored_port_probes, kernel_port); +} + gboolean mm_device_owns_port (MMDevice *self, MMKernelDevice *kernel_port) @@ -130,6 +154,28 @@ mm_device_owns_port (MMDevice *self, return !!device_find_probe_with_device (self, kernel_port, TRUE); } +static MMPortProbe * +device_find_probe_with_name (MMDevice *self, + const gchar *subsystem, + const gchar *name) +{ + MMPortProbe *probe; + + probe = probe_list_lookup_by_name (self->priv->port_probes, subsystem, name); + if (probe) + return probe; + + return probe_list_lookup_by_name (self->priv->ignored_port_probes, subsystem, name); +} + +gboolean +mm_device_owns_port_name (MMDevice *self, + const gchar *subsystem, + const gchar *name) +{ + return !!device_find_probe_with_name (self, subsystem, name); +} + static void add_port_driver (MMDevice *self, MMKernelDevice *kernel_port) @@ -190,12 +236,13 @@ mm_device_grab_port (MMDevice *self, } void -mm_device_release_port (MMDevice *self, - MMKernelDevice *kernel_port) +mm_device_release_port_name (MMDevice *self, + const gchar *subsystem, + const gchar *name) { MMPortProbe *probe; - probe = device_find_probe_with_device (self, kernel_port, TRUE); + probe = device_find_probe_with_name (self, subsystem, name); if (probe) { /* Found, remove from lists and destroy probe */ if (g_list_find (self->priv->port_probes, probe)) diff --git a/src/mm-device.h b/src/mm-device.h index d78a97c9..00d5977a 100644 --- a/src/mm-device.h +++ b/src/mm-device.h @@ -67,14 +67,19 @@ MMDevice *mm_device_new (const gchar *uid, gboolean virtual, GDBusObjectManagerServer *object_manager); -void mm_device_grab_port (MMDevice *self, - MMKernelDevice *kernel_port); -void mm_device_release_port (MMDevice *self, - MMKernelDevice *kernel_port); -gboolean mm_device_owns_port (MMDevice *self, - MMKernelDevice *kernel_port); -void mm_device_ignore_port (MMDevice *self, - MMKernelDevice *kernel_port); +void mm_device_grab_port (MMDevice *self, + MMKernelDevice *kernel_port); +gboolean mm_device_owns_port (MMDevice *self, + MMKernelDevice *kernel_port); +void mm_device_ignore_port (MMDevice *self, + MMKernelDevice *kernel_port); + +gboolean mm_device_owns_port_name (MMDevice *self, + const gchar *subsystem, + const gchar *name); +void mm_device_release_port_name (MMDevice *self, + const gchar *subsystem, + const gchar *name); gboolean mm_device_create_modem (MMDevice *self, GError **error); From 7ac42e76482acd687464f9dca2ef3ac7b67825a1 Mon Sep 17 00:00:00 2001 From: David Leonard Date: Wed, 26 Aug 2020 14:19:28 +1000 Subject: [PATCH 482/675] sms: fix 7-bit ASCII SMS decoding Fixes an issue where (5+8n)-character long SMS messages received on a CDMA network would be dropped with a "cannot read user data" error, while other length SMS messages would be delivered fine. Fix thanks to Peter Hunt --- src/mm-sms-part-cdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index 6e3f1179..e08193cf 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -846,7 +846,7 @@ read_bearer_data_user_data (MMSmsPart *sms_part, gchar *text; guint i; - SUBPARAMETER_SIZE_CHECK (byte_offset + 1 + ((bit_offset + (num_fields * 7)) / 8)); + SUBPARAMETER_SIZE_CHECK (byte_offset + ((bit_offset + (num_fields * 7)) / 8)); text = g_malloc (num_fields + 1); for (i = 0; i < num_fields; i++) { From 3be07bb38db2f1295d5ef240232ac046a579808b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 20 Nov 2020 00:36:04 +0100 Subject: [PATCH 483/675] tests,cdma: test CDMA SMS with different text lengths --- src/tests/test-sms-part-cdma.c | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/tests/test-sms-part-cdma.c b/src/tests/test-sms-part-cdma.c index af01b5f5..df6e982c 100644 --- a/src/tests/test-sms-part-cdma.c +++ b/src/tests/test-sms-part-cdma.c @@ -500,6 +500,42 @@ test_create_pdu_text_unicode_encoding (void) expected, sizeof (expected)); } +static void +test_create_parse_pdu_text_ascii_encoding (void) +{ +#define MAX_TEXT_LEN 100 + guint i; + gchar text[MAX_TEXT_LEN + 1]; + + memset (text, 0, sizeof (text)); + + for (i = 0; i < MAX_TEXT_LEN; i++) { + MMSmsPart *part; + guint8 *pdu; + guint len = 0; + GError *error = NULL; + + text[i]='A'; + + part = mm_sms_part_new (0, MM_SMS_PDU_TYPE_CDMA_SUBMIT); + mm_sms_part_set_cdma_teleservice_id (part, MM_SMS_CDMA_TELESERVICE_ID_WMT); + mm_sms_part_set_number (part, "123456789"); + mm_sms_part_set_text (part, text); + pdu = mm_sms_part_cdma_get_submit_pdu (part, &len, NULL, &error); + g_assert_no_error (error); + g_assert (pdu != NULL); + mm_sms_part_free (part); + + part = mm_sms_part_cdma_new_from_binary_pdu (0, pdu, len, NULL, &error); + g_assert_no_error (error); + g_assert (part != NULL); + g_assert_cmpuint (MM_SMS_CDMA_TELESERVICE_ID_WMT, ==, mm_sms_part_get_cdma_teleservice_id (part)); + g_assert_cmpstr ("123456789", ==, mm_sms_part_get_number (part)); + g_assert_cmpstr (text, ==, mm_sms_part_get_text (part)); + mm_sms_part_free (part); + } +} + /************************************************************/ int main (int argc, char **argv) @@ -520,5 +556,7 @@ int main (int argc, char **argv) g_test_add_func ("/MM/SMS/CDMA/PDU-Creator/latin-encoding", test_create_pdu_text_latin_encoding); g_test_add_func ("/MM/SMS/CDMA/PDU-Creator/unicode-encoding", test_create_pdu_text_unicode_encoding); + g_test_add_func ("/MM/SMS/CDMA/PDU-Creator-Parser/ascii-encoding", test_create_parse_pdu_text_ascii_encoding); + return g_test_run (); } From 399a042dad2e2c5cca9e0cfe0af6d41ae1fb0c35 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 25 Oct 2020 15:11:02 +0100 Subject: [PATCH 484/675] bearer-qmi: support binding to data port Allow plugins to specify a QmiSioPort value to bind to. This is used e.g. in the RPMSG+BAM-DMUX setup in order to allow any RPMSG port to control all the available net ports. --- src/mm-bearer-qmi.c | 73 +++++++++++++++++++++++++++++++++++- src/mm-broadband-modem-qmi.c | 9 ++++- src/mm-broadband-modem-qmi.h | 3 ++ 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/src/mm-bearer-qmi.c b/src/mm-bearer-qmi.c index e29414f4..670fb804 100644 --- a/src/mm-bearer-qmi.c +++ b/src/mm-bearer-qmi.c @@ -410,12 +410,14 @@ typedef enum { CONNECT_STEP_IPV4, CONNECT_STEP_WDS_CLIENT_IPV4, CONNECT_STEP_IP_FAMILY_IPV4, + CONNECT_STEP_BIND_DATA_PORT_IPV4, CONNECT_STEP_ENABLE_INDICATIONS_IPV4, CONNECT_STEP_START_NETWORK_IPV4, CONNECT_STEP_GET_CURRENT_SETTINGS_IPV4, CONNECT_STEP_IPV6, CONNECT_STEP_WDS_CLIENT_IPV6, CONNECT_STEP_IP_FAMILY_IPV6, + CONNECT_STEP_BIND_DATA_PORT_IPV6, CONNECT_STEP_ENABLE_INDICATIONS_IPV6, CONNECT_STEP_START_NETWORK_IPV6, CONNECT_STEP_GET_CURRENT_SETTINGS_IPV6, @@ -427,6 +429,7 @@ typedef struct { ConnectStep step; MMPort *data; MMPortQmi *qmi; + QmiSioPort sio_port; gboolean explicit_qmi_open; gchar *user; gchar *password; @@ -988,6 +991,32 @@ get_current_settings (GTask *task, QmiClientWds *client) qmi_message_wds_get_current_settings_input_unref (input); } +static void +bind_data_port_ready (QmiClientWds *client, + GAsyncResult *res, + GTask *task) +{ + ConnectContext *ctx; + GError *error = NULL; + g_autoptr(QmiMessageWdsBindDataPortOutput) output = NULL; + + ctx = g_task_get_task_data (task); + + g_assert (ctx->running_ipv4 || ctx->running_ipv6); + g_assert (!(ctx->running_ipv4 && ctx->running_ipv6)); + + output = qmi_client_wds_bind_data_port_finish (client, res, &error); + if (!output || !qmi_message_wds_bind_data_port_output_get_result (output, &error)) { + g_prefix_error (&error, "Couldn't bind data port: "); + complete_connect (task, NULL, error); + return; + } + + /* Keep on */ + ctx->step++; + connect_context_step (task); +} + static void set_ip_family_ready (QmiClientWds *client, GAsyncResult *res, @@ -1401,6 +1430,26 @@ connect_context_step (GTask *task) ctx->step++; /* fall through */ + case CONNECT_STEP_BIND_DATA_PORT_IPV4: + /* If SIO port given, bind client to it */ + if (ctx->sio_port != QMI_SIO_PORT_NONE) { + g_autoptr(QmiMessageWdsBindDataPortInput) input = NULL; + + mm_obj_dbg (self, "binding to data port: %s", qmi_sio_port_get_string (ctx->sio_port)); + input = qmi_message_wds_bind_data_port_input_new (); + qmi_message_wds_bind_data_port_input_set_data_port (input, ctx->sio_port, NULL); + qmi_client_wds_bind_data_port (ctx->client_ipv4, + input, + 10, + g_task_get_cancellable (task), + (GAsyncReadyCallback)bind_data_port_ready, + task); + return; + } + + ctx->step++; + /* fall through */ + case CONNECT_STEP_ENABLE_INDICATIONS_IPV4: common_setup_cleanup_packet_service_status_unsolicited_events (ctx->self, ctx->client_ipv4, @@ -1492,6 +1541,26 @@ connect_context_step (GTask *task) return; } + case CONNECT_STEP_BIND_DATA_PORT_IPV6: + /* If SIO port given, bind client to it */ + if (ctx->sio_port != QMI_SIO_PORT_NONE) { + g_autoptr(QmiMessageWdsBindDataPortInput) input = NULL; + + mm_obj_dbg (self, "binding to data port: %s", qmi_sio_port_get_string (ctx->sio_port)); + input = qmi_message_wds_bind_data_port_input_new (); + qmi_message_wds_bind_data_port_input_set_data_port (input, ctx->sio_port, NULL); + qmi_client_wds_bind_data_port (ctx->client_ipv6, + input, + 10, + g_task_get_cancellable (task), + (GAsyncReadyCallback)bind_data_port_ready, + task); + return; + } + + ctx->step++; + /* fall through */ + case CONNECT_STEP_ENABLE_INDICATIONS_IPV6: common_setup_cleanup_packet_service_status_unsolicited_events (ctx->self, ctx->client_ipv6, @@ -1617,6 +1686,7 @@ _connect (MMBaseBearer *_self, MMBaseModem *modem = NULL; MMPort *data = NULL; MMPortQmi *qmi = NULL; + QmiSioPort sio_port = QMI_SIO_PORT_NONE; GError *error = NULL; const gchar *apn; GTask *task; @@ -1642,7 +1712,7 @@ _connect (MMBaseBearer *_self, } /* Each data port has a single QMI port associated */ - qmi = mm_broadband_modem_qmi_get_port_qmi_for_data (MM_BROADBAND_MODEM_QMI (modem), data, &error); + qmi = mm_broadband_modem_qmi_get_port_qmi_for_data (MM_BROADBAND_MODEM_QMI (modem), data, &sio_port, &error); if (!qmi) { g_task_report_error ( self, @@ -1689,6 +1759,7 @@ _connect (MMBaseBearer *_self, ctx = g_slice_new0 (ConnectContext); ctx->self = g_object_ref (self); ctx->qmi = g_object_ref (qmi); + ctx->sio_port = sio_port; ctx->data = g_object_ref (data); ctx->step = CONNECT_STEP_FIRST; ctx->ip_method = MM_BEARER_IP_METHOD_UNKNOWN; diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 8ac469fa..d61e4365 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -213,13 +213,14 @@ mm_broadband_modem_qmi_peek_port_qmi (MMBroadbandModemQmi *self) MMPortQmi * mm_broadband_modem_qmi_get_port_qmi_for_data (MMBroadbandModemQmi *self, MMPort *data, + QmiSioPort *out_sio_port, GError **error) { MMPortQmi *qmi_port; g_assert (MM_IS_BROADBAND_MODEM_QMI (self)); - qmi_port = mm_broadband_modem_qmi_peek_port_qmi_for_data (self, data, error); + qmi_port = mm_broadband_modem_qmi_peek_port_qmi_for_data (self, data, out_sio_port, error); return (qmi_port ? MM_PORT_QMI (g_object_ref (qmi_port)) : NULL); @@ -228,6 +229,7 @@ mm_broadband_modem_qmi_get_port_qmi_for_data (MMBroadbandModemQmi *self, static MMPortQmi * peek_port_qmi_for_data (MMBroadbandModemQmi *self, MMPort *data, + QmiSioPort *out_sio_port, GError **error) { GList *cdc_wdm_qmi_ports; @@ -282,6 +284,8 @@ peek_port_qmi_for_data (MMBroadbandModemQmi *self, MM_CORE_ERROR_NOT_FOUND, "Couldn't find associated QMI port for 'net/%s'", mm_port_get_device (data)); + else + *out_sio_port = QMI_SIO_PORT_NONE; return found; } @@ -289,11 +293,12 @@ peek_port_qmi_for_data (MMBroadbandModemQmi *self, MMPortQmi * mm_broadband_modem_qmi_peek_port_qmi_for_data (MMBroadbandModemQmi *self, MMPort *data, + QmiSioPort *out_sio_port, GError **error) { g_assert (MM_BROADBAND_MODEM_QMI_GET_CLASS (self)->peek_port_qmi_for_data); - return MM_BROADBAND_MODEM_QMI_GET_CLASS (self)->peek_port_qmi_for_data (self, data, error); + return MM_BROADBAND_MODEM_QMI_GET_CLASS (self)->peek_port_qmi_for_data (self, data, out_sio_port, error); } /*****************************************************************************/ diff --git a/src/mm-broadband-modem-qmi.h b/src/mm-broadband-modem-qmi.h index 9972cde8..9b712109 100644 --- a/src/mm-broadband-modem-qmi.h +++ b/src/mm-broadband-modem-qmi.h @@ -39,6 +39,7 @@ struct _MMBroadbandModemQmiClass{ MMPortQmi * (* peek_port_qmi_for_data) (MMBroadbandModemQmi *self, MMPort *data, + QmiSioPort *out_sio_port, GError **error); }; @@ -54,10 +55,12 @@ MMBroadbandModemQmi *mm_broadband_modem_qmi_new (const gchar *device, MMPortQmi *mm_broadband_modem_qmi_peek_port_qmi (MMBroadbandModemQmi *self); MMPortQmi *mm_broadband_modem_qmi_peek_port_qmi_for_data (MMBroadbandModemQmi *self, MMPort *data, + QmiSioPort *out_sio_port, GError **error); MMPortQmi *mm_broadband_modem_qmi_get_port_qmi (MMBroadbandModemQmi *self); MMPortQmi *mm_broadband_modem_qmi_get_port_qmi_for_data (MMBroadbandModemQmi *self, MMPort *data, + QmiSioPort *out_sio_port, GError **error); #endif /* MM_BROADBAND_MODEM_QMI_H */ From 3d12272d183061c11cd80bfe96ae89898f4c081c Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 30 Oct 2020 10:05:24 +0100 Subject: [PATCH 485/675] kerneldevice: allow loading port attributes In addition to loading port and device properties, we now also allow loading sysfs properties that are assumed to be static (i.e. their values won't change since loaded the first time). --- src/kerneldevice/mm-kernel-device-generic.c | 37 ++++++++++++++ src/kerneldevice/mm-kernel-device-udev.c | 30 ++++++++++++ src/kerneldevice/mm-kernel-device.c | 54 +++++++++++++++++++++ src/kerneldevice/mm-kernel-device.h | 9 ++++ 4 files changed, 130 insertions(+) diff --git a/src/kerneldevice/mm-kernel-device-generic.c b/src/kerneldevice/mm-kernel-device-generic.c index 90228f17..b1a3bf97 100644 --- a/src/kerneldevice/mm-kernel-device-generic.c +++ b/src/kerneldevice/mm-kernel-device-generic.c @@ -963,6 +963,41 @@ kernel_device_get_property (MMKernelDevice *self, /*****************************************************************************/ +static gchar * +build_attribute_data_key (const gchar *attribute) +{ + return g_strdup_printf ("ATTR:%s", attribute); +} + +static gboolean +kernel_device_has_attribute (MMKernelDevice *self, + const gchar *attribute) +{ + return has_sysfs_attribute (MM_KERNEL_DEVICE_GENERIC (self)->priv->sysfs_path, attribute); +} + +static const gchar * +kernel_device_get_attribute (MMKernelDevice *_self, + const gchar *attribute) +{ + MMKernelDeviceGeneric *self; + g_autofree gchar *key = NULL; + gchar *value = NULL; + + self = MM_KERNEL_DEVICE_GENERIC (_self); + + key = build_attribute_data_key (attribute); + value = g_object_get_data (G_OBJECT (self), key); + if (!value) { + value = read_sysfs_attribute_as_string (self->priv->sysfs_path, attribute); + if (value) + g_object_set_data_full (G_OBJECT (self), key, value, g_free); + } + return (const gchar *) value; +} + +/*****************************************************************************/ + MMKernelDevice * mm_kernel_device_generic_new_with_rules (MMKernelEventProperties *props, GArray *rules, @@ -1145,6 +1180,8 @@ mm_kernel_device_generic_class_init (MMKernelDeviceGenericClass *klass) kernel_device_class->cmp = kernel_device_cmp; kernel_device_class->has_property = kernel_device_has_property; kernel_device_class->get_property = kernel_device_get_property; + kernel_device_class->has_attribute = kernel_device_has_attribute; + kernel_device_class->get_attribute = kernel_device_get_attribute; /* Device-wide properties are stored per-port in the generic backend */ kernel_device_class->has_global_property = kernel_device_has_property; diff --git a/src/kerneldevice/mm-kernel-device-udev.c b/src/kerneldevice/mm-kernel-device-udev.c index 44fdd074..f75104bd 100644 --- a/src/kerneldevice/mm-kernel-device-udev.c +++ b/src/kerneldevice/mm-kernel-device-udev.c @@ -527,6 +527,34 @@ kernel_device_get_global_property (MMKernelDevice *_self, /*****************************************************************************/ +static gboolean +kernel_device_has_attribute (MMKernelDevice *_self, + const gchar *attribute) +{ + MMKernelDeviceUdev *self; + + self = MM_KERNEL_DEVICE_UDEV (_self); + if (!self->priv->device) + return FALSE; + + return g_udev_device_has_sysfs_attr (self->priv->device, attribute); +} + +static const gchar * +kernel_device_get_attribute (MMKernelDevice *_self, + const gchar *attribute) +{ + MMKernelDeviceUdev *self; + + self = MM_KERNEL_DEVICE_UDEV (_self); + if (!self->priv->device) + return NULL; + + return g_udev_device_get_sysfs_attr (self->priv->device, attribute); +} + +/*****************************************************************************/ + MMKernelDevice * mm_kernel_device_udev_new (GUdevDevice *udev_device) { @@ -725,6 +753,8 @@ mm_kernel_device_udev_class_init (MMKernelDeviceUdevClass *klass) kernel_device_class->get_property = kernel_device_get_property; kernel_device_class->has_global_property = kernel_device_has_global_property; kernel_device_class->get_global_property = kernel_device_get_global_property; + kernel_device_class->has_attribute = kernel_device_has_attribute; + kernel_device_class->get_attribute = kernel_device_get_attribute; properties[PROP_UDEV_DEVICE] = g_param_spec_object ("udev-device", diff --git a/src/kerneldevice/mm-kernel-device.c b/src/kerneldevice/mm-kernel-device.c index a0717cc2..464a3800 100644 --- a/src/kerneldevice/mm-kernel-device.c +++ b/src/kerneldevice/mm-kernel-device.c @@ -277,6 +277,60 @@ mm_kernel_device_get_global_property_as_int_hex (MMKernelDevice *self, return ((value && mm_get_uint_from_hex_str (value, &aux)) ? aux : 0); } +gboolean +mm_kernel_device_has_attribute (MMKernelDevice *self, + const gchar *attribute) +{ + g_return_val_if_fail (MM_IS_KERNEL_DEVICE (self), FALSE); + + return (MM_KERNEL_DEVICE_GET_CLASS (self)->has_attribute ? + MM_KERNEL_DEVICE_GET_CLASS (self)->has_attribute (self, attribute) : + FALSE); +} + +const gchar * +mm_kernel_device_get_attribute (MMKernelDevice *self, + const gchar *attribute) +{ + g_return_val_if_fail (MM_IS_KERNEL_DEVICE (self), NULL); + + return (MM_KERNEL_DEVICE_GET_CLASS (self)->get_attribute ? + MM_KERNEL_DEVICE_GET_CLASS (self)->get_attribute (self, attribute) : + NULL); +} + +gboolean +mm_kernel_device_get_attribute_as_boolean (MMKernelDevice *self, + const gchar *attribute) +{ + const gchar *value; + + value = mm_kernel_device_get_attribute (self, attribute); + return (value && mm_common_get_boolean_from_string (value, NULL)); +} + +gint +mm_kernel_device_get_attribute_as_int (MMKernelDevice *self, + const gchar *attribute) +{ + const gchar *value; + gint aux; + + value = mm_kernel_device_get_attribute (self, attribute); + return ((value && mm_get_int_from_str (value, &aux)) ? aux : 0); +} + +guint +mm_kernel_device_get_attribute_as_int_hex (MMKernelDevice *self, + const gchar *attribute) +{ + const gchar *value; + guint aux; + + value = mm_kernel_device_get_attribute (self, attribute); + return ((value && mm_get_uint_from_hex_str (value, &aux)) ? aux : 0); +} + /*****************************************************************************/ static gchar * diff --git a/src/kerneldevice/mm-kernel-device.h b/src/kerneldevice/mm-kernel-device.h index adf6da82..45b270d5 100644 --- a/src/kerneldevice/mm-kernel-device.h +++ b/src/kerneldevice/mm-kernel-device.h @@ -62,6 +62,8 @@ struct _MMKernelDeviceClass { const gchar * (* get_property) (MMKernelDevice *self, const gchar *property); gboolean (* has_global_property) (MMKernelDevice *self, const gchar *property); const gchar * (* get_global_property) (MMKernelDevice *self, const gchar *property); + gboolean (* has_attribute) (MMKernelDevice *self, const gchar *attribute); + const gchar * (* get_attribute) (MMKernelDevice *self, const gchar *attribute); }; GType mm_kernel_device_get_type (void); @@ -103,4 +105,11 @@ gboolean mm_kernel_device_get_global_property_as_boolean (MMKernelDevice *se gint mm_kernel_device_get_global_property_as_int (MMKernelDevice *self, const gchar *property); guint mm_kernel_device_get_global_property_as_int_hex (MMKernelDevice *self, const gchar *property); +/* Attributes in sysfs */ +gboolean mm_kernel_device_has_attribute (MMKernelDevice *self, const gchar *attribute); +const gchar *mm_kernel_device_get_attribute (MMKernelDevice *self, const gchar *attribute); +gboolean mm_kernel_device_get_attribute_as_boolean (MMKernelDevice *self, const gchar *attribute); +gint mm_kernel_device_get_attribute_as_int (MMKernelDevice *self, const gchar *attribute); +guint mm_kernel_device_get_attribute_as_int_hex (MMKernelDevice *self, const gchar *attribute); + #endif /* MM_KERNEL_DEVICE_H */ From cab4b54ad106caadb7f70025348f0aab5522bde4 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 25 Oct 2020 14:23:29 +0100 Subject: [PATCH 486/675] core: new 'rpmsg' subsystem Most older Qualcomm SoCs (e.g. MSM8916, MSM8974, ...) communicate with the integrated modem via shared memory (SMD channels). This is similar to QRTR on newer SoCs, but without the "network" layer. In fact, the older SoCs also have QRTR, but the modem QMI services are not exposed there. The mainline Linux kernel exposes SMD channels via the "remote processor messaging bus" (rpmsg). Through special IOCTL calls it is possible to create a char device for a rpmsg/SMD channel. We can then use these to send QMI/AT messages to the modem, much like the ordinary serial char devices when using a Qualcomm modem through USB. This commit introduces support for the new 'rpmsg' subsystem, which allows exporting QMI-capable and AT-capable ports. By default NO rpmsg port is flagged as candidate, it is assumed that the plugin adding support for the rpmsg subsystem will add specific rules to do so (e.g. so that non-modem ports are explicitly not flagged as candidate). All rpmsg ports will be probed for AT or QMI capabilities, unless explicit port type hints (e.g. ID_MM_PORT_TYPE_QMI or ID_MM_PORT_TYPE_AT_PRIMARY) are set. These changes are highly based on the initial integration work done by Stephan Gerhold in postmarketOS, see: https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/363 --- cli/mmcli-manager.c | 2 +- src/mm-base-modem.c | 18 ++++++++++++++++-- src/mm-filter.c | 7 +++++++ src/mm-filter.h | 23 ++++++++++++++--------- src/mm-plugin.c | 5 +++++ src/mm-port-probe.c | 26 +++++++++++++++++--------- src/mm-port.h | 4 ++-- 7 files changed, 62 insertions(+), 23 deletions(-) diff --git a/cli/mmcli-manager.c b/cli/mmcli-manager.c index 950617b6..01d2972c 100644 --- a/cli/mmcli-manager.c +++ b/cli/mmcli-manager.c @@ -444,7 +444,7 @@ get_manager_ready (GObject *source, #if defined WITH_UDEV if (report_kernel_event_auto_scan) { - const gchar *subsys[] = { "tty", "usbmisc", "net", NULL }; + const gchar *subsys[] = { "tty", "usbmisc", "net", "rpmsg", NULL }; guint i; ctx->udev = g_udev_client_new (subsys); diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index 09227da5..29256f7d 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -237,6 +237,20 @@ base_modem_create_usbmisc_port (MMBaseModem *self, return NULL; } +static MMPort * +base_modem_create_rpmsg_port (MMBaseModem *self, + const gchar *name, + MMPortType ptype) +{ +#if defined WITH_QMI + if (ptype == MM_PORT_TYPE_QMI) + return MM_PORT (mm_port_qmi_new (name, MM_PORT_SUBSYS_RPMSG)); +#endif + if (ptype == MM_PORT_TYPE_AT) + return MM_PORT (mm_port_serial_at_new (name, MM_PORT_SUBSYS_RPMSG)); + return NULL; +} + static MMPort * base_modem_create_virtual_port (MMBaseModem *self, const gchar *name) @@ -278,6 +292,8 @@ mm_base_modem_grab_port (MMBaseModem *self, port = base_modem_create_tty_port (self, name, kernel_device, ptype); else if (g_str_equal (subsys, "usbmisc")) port = base_modem_create_usbmisc_port (self, name, ptype); + else if (g_str_equal (subsys, "rpmsg")) + port = base_modem_create_rpmsg_port (self, name, ptype); else if (g_str_equal (subsys, "virtual")) port = base_modem_create_virtual_port (self, name); @@ -327,8 +343,6 @@ mm_base_modem_grab_port (MMBaseModem *self, return TRUE; } -/******************************************************************************/ - gboolean mm_base_modem_disable_finish (MMBaseModem *self, GAsyncResult *res, diff --git a/src/mm-filter.c b/src/mm-filter.c index c5a15312..52575a1c 100644 --- a/src/mm-filter.c +++ b/src/mm-filter.c @@ -199,6 +199,13 @@ mm_filter_port (MMFilter *self, return TRUE; } + /* If this is a rpmsg channel device, we always allow it */ + if ((self->priv->enabled_rules & MM_FILTER_RULE_RPMSG) && + (g_strcmp0 (subsystem, "rpmsg") == 0)) { + mm_obj_dbg (self, "(%s/%s) port allowed: rpmsg device", subsystem, name); + return TRUE; + } + /* If this is a tty device, we may allow it */ if ((self->priv->enabled_rules & MM_FILTER_RULE_TTY) && (g_strcmp0 (subsystem, "tty") == 0)) { diff --git a/src/mm-filter.h b/src/mm-filter.h index dc5f2bff..8d2e0e22 100644 --- a/src/mm-filter.h +++ b/src/mm-filter.h @@ -53,15 +53,16 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_VIRTUAL = 1 << 3, MM_FILTER_RULE_NET = 1 << 4, MM_FILTER_RULE_USBMISC = 1 << 5, - MM_FILTER_RULE_TTY = 1 << 6, - MM_FILTER_RULE_TTY_BLACKLIST = 1 << 7, - MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY = 1 << 8, - MM_FILTER_RULE_TTY_PLATFORM_DRIVER = 1 << 9, - MM_FILTER_RULE_TTY_DEFAULT_ALLOWED = 1 << 10, - MM_FILTER_RULE_TTY_DRIVER = 1 << 11, - MM_FILTER_RULE_TTY_ACM_INTERFACE = 1 << 12, - MM_FILTER_RULE_TTY_WITH_NET = 1 << 13, - MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN = 1 << 14, + MM_FILTER_RULE_RPMSG = 1 << 6, + MM_FILTER_RULE_TTY = 1 << 7, + MM_FILTER_RULE_TTY_BLACKLIST = 1 << 8, + MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY = 1 << 9, + MM_FILTER_RULE_TTY_PLATFORM_DRIVER = 1 << 10, + MM_FILTER_RULE_TTY_DEFAULT_ALLOWED = 1 << 11, + MM_FILTER_RULE_TTY_DRIVER = 1 << 12, + MM_FILTER_RULE_TTY_ACM_INTERFACE = 1 << 13, + MM_FILTER_RULE_TTY_WITH_NET = 1 << 14, + MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN = 1 << 15, } MMFilterRule; #define MM_FILTER_RULE_ALL \ @@ -71,6 +72,7 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_VIRTUAL | \ MM_FILTER_RULE_NET | \ MM_FILTER_RULE_USBMISC | \ + MM_FILTER_RULE_RPMSG | \ MM_FILTER_RULE_TTY | \ MM_FILTER_RULE_TTY_BLACKLIST | \ MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY | \ @@ -89,6 +91,7 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_VIRTUAL | \ MM_FILTER_RULE_NET | \ MM_FILTER_RULE_USBMISC | \ + MM_FILTER_RULE_RPMSG | \ MM_FILTER_RULE_TTY | \ MM_FILTER_RULE_TTY_BLACKLIST | \ MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY | \ @@ -104,6 +107,7 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_VIRTUAL | \ MM_FILTER_RULE_NET | \ MM_FILTER_RULE_USBMISC | \ + MM_FILTER_RULE_RPMSG | \ MM_FILTER_RULE_TTY | \ MM_FILTER_RULE_TTY_PLATFORM_DRIVER | \ MM_FILTER_RULE_TTY_DRIVER | \ @@ -120,6 +124,7 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_VIRTUAL | \ MM_FILTER_RULE_NET | \ MM_FILTER_RULE_USBMISC | \ + MM_FILTER_RULE_RPMSG | \ MM_FILTER_RULE_TTY | \ MM_FILTER_RULE_TTY_BLACKLIST | \ MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY | \ diff --git a/src/mm-plugin.c b/src/mm-plugin.c index be6e39ff..13b46a75 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -781,6 +781,11 @@ mm_plugin_supports_port (MMPlugin *self, probe_run_flags |= MM_PORT_PROBE_MBIM; else probe_run_flags |= MM_PORT_PROBE_AT; + } else if (g_str_equal (mm_kernel_device_get_subsystem (port), "rpmsg")) { + if (self->priv->at) + probe_run_flags |= MM_PORT_PROBE_AT; + if (self->priv->qmi) + probe_run_flags |= MM_PORT_PROBE_QMI; } /* For potential AT ports, check for more things */ diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c index c6b535b5..d4bffb3e 100644 --- a/src/mm-port-probe.c +++ b/src/mm-port-probe.c @@ -491,16 +491,22 @@ wdm_probe_qmi (MMPortProbe *self) ctx = g_task_get_task_data (self->priv->task); #if defined WITH_QMI - mm_obj_dbg (self, "probing QMI..."); + { + MMPortSubsys subsys = MM_PORT_SUBSYS_USBMISC; - /* Create a port and try to open it */ - ctx->port_qmi = mm_port_qmi_new (mm_kernel_device_get_name (self->priv->port), - MM_PORT_SUBSYS_USBMISC); - mm_port_qmi_open (ctx->port_qmi, - FALSE, - NULL, - (GAsyncReadyCallback) port_qmi_open_ready, - self); + mm_obj_dbg (self, "probing QMI..."); + + if (g_str_equal (mm_kernel_device_get_subsystem (self->priv->port), "rpmsg")) + subsys = MM_PORT_SUBSYS_RPMSG; + + /* Create a port and try to open it */ + ctx->port_qmi = mm_port_qmi_new (mm_kernel_device_get_name (self->priv->port), subsys); + mm_port_qmi_open (ctx->port_qmi, + FALSE, + NULL, + (GAsyncReadyCallback) port_qmi_open_ready, + self); + } #else /* If not compiled with QMI support, just assume we won't have any QMI port */ mm_port_probe_set_result_qmi (self, FALSE); @@ -1273,6 +1279,8 @@ serial_open_at (MMPortProbe *self) if (g_str_equal (mm_kernel_device_get_subsystem (self->priv->port), "usbmisc")) subsys = MM_PORT_SUBSYS_USBMISC; + else if (g_str_equal (mm_kernel_device_get_subsystem (self->priv->port), "rpmsg")) + subsys = MM_PORT_SUBSYS_RPMSG; ctx->serial = MM_PORT_SERIAL (mm_port_serial_at_new (mm_kernel_device_get_name (self->priv->port), subsys)); if (!ctx->serial) { diff --git a/src/mm-port.h b/src/mm-port.h index 2d8d1ad6..8295d264 100644 --- a/src/mm-port.h +++ b/src/mm-port.h @@ -28,8 +28,8 @@ typedef enum { /*< underscore_name=mm_port_subsys >*/ MM_PORT_SUBSYS_NET, MM_PORT_SUBSYS_USBMISC, MM_PORT_SUBSYS_UNIX, - - MM_PORT_SUBSYS_LAST = MM_PORT_SUBSYS_UNIX /*< skip >*/ + MM_PORT_SUBSYS_RPMSG, + MM_PORT_SUBSYS_LAST = MM_PORT_SUBSYS_RPMSG /*< skip >*/ } MMPortSubsys; typedef enum { /*< underscore_name=mm_port_type >*/ From 8fc60754dd1df91560a3123454df1ad0ecf0ac92 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 22 Oct 2020 12:48:35 +0200 Subject: [PATCH 487/675] qcom-soc: new plugin for Qualcomm SoCs This plugin implements support for old Qualcomm SoCs like the MSM8916 or the MSM8974, where: * control ports are available via RPMSG channels exported as devices e.g. with rpmsgexport: https://github.com/andersson/rpmsgexport * network ports are exposed by the bam-dmux kernel driver: https://github.com/msm8916-mainline/linux/commits/bam-dmux Adding support for newer Qualcomm SoCs (e.g. QRTR+IPA) could be done in a similar way on this very same plugin. This plugin is the first and only one that implements support for a modem device that is "built in" the system, as opposed to external modems that may be available via USB or PCI. The ID_MM_PHYSDEV_UID based udev tags provided by the plugin provide the logic to bind all the SoC ports together in the same modem object, and therefore ID_MM_PHYSDEV_UID should not be used by users to override the ones set by the plugin. All "rpmsg[0-9]*" ports that are considered part of the modem are flagged as candidate, ignoring the parent "rpmsg_ctrl[0-9]*" ports on purpose. This setup therefore assumes that the channels have been exported already as devices (e.g. using rpmsgexport). libqmi 1.27.2 is required to support the "WDS Bind Data Port" message. --- .gitlab-ci.yml | 2 +- configure.ac | 4 +- plugins/Makefile.am | 25 ++++ plugins/qcom-soc/77-mm-qcom-soc.rules | 46 ++++++ .../mm-broadband-modem-qmi-qcom-soc.c | 133 ++++++++++++++++++ .../mm-broadband-modem-qmi-qcom-soc.h | 49 +++++++ plugins/qcom-soc/mm-plugin-qcom-soc.c | 92 ++++++++++++ plugins/qcom-soc/mm-plugin-qcom-soc.h | 40 ++++++ plugins/tests/test-udev-rules.c | 11 ++ 9 files changed, 400 insertions(+), 2 deletions(-) create mode 100644 plugins/qcom-soc/77-mm-qcom-soc.rules create mode 100644 plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.c create mode 100644 plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.h create mode 100644 plugins/qcom-soc/mm-plugin-qcom-soc.c create mode 100644 plugins/qcom-soc/mm-plugin-qcom-soc.h diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index af67083f..e429af6c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -108,7 +108,7 @@ build-single-plugins: dell dlink fibocom foxconn gosuncn haier huawei iridium linktop longcheer mbm motorola mtk nokia nokia-icera novatel novatel-lte option option-hso pantech - quectel samsung sierra-legacy sierra simtech + qcom-soc quectel samsung sierra-legacy sierra simtech telit thuraya tplink ublox via wavecom x22x zte; do ./configure --prefix=/usr --disable-gtk-doc --disable-all-plugins --enable-plugin-$plugin; make; diff --git a/configure.ac b/configure.ac index 069f0d83..9718c480 100644 --- a/configure.ac +++ b/configure.ac @@ -400,7 +400,7 @@ dnl----------------------------------------------------------------------------- dnl QMI support (enabled by default) dnl -LIBQMI_VERSION=1.27.1 +LIBQMI_VERSION=1.27.2 AC_ARG_WITH(qmi, AS_HELP_STRING([--without-qmi], [Build without QMI support]), [], [with_qmi=yes]) AM_CONDITIONAL(WITH_QMI, test "x$with_qmi" = "xyes") @@ -490,6 +490,7 @@ MM_ENABLE_PLUGIN([option], MM_ENABLE_PLUGIN([option-hso], [with_shared_option]) MM_ENABLE_PLUGIN([pantech]) +MM_ENABLE_PLUGIN([qcom-soc]) MM_ENABLE_PLUGIN([quectel]) MM_ENABLE_PLUGIN([samsung], [with_shared_icera]) @@ -627,6 +628,7 @@ echo " option: ${enable_plugin_option} option hso: ${enable_plugin_option_hso} pantech: ${enable_plugin_pantech} + qcom-soc: ${enable_plugin_qcom_soc} quectel: ${enable_plugin_quectel} samsung: ${enable_plugin_samsung} sierra legacy: ${enable_plugin_sierra_legacy} diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 7e08bfd2..df78beb3 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1208,6 +1208,31 @@ libmm_plugin_pantech_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) endif +################################################################################ +# plugin: qcom-soc +################################################################################ + +if ENABLE_PLUGIN_QCOM_SOC +if WITH_QMI +pkglib_LTLIBRARIES += libmm-plugin-qcom-soc.la +libmm_plugin_qcom_soc_la_SOURCES = \ + qcom-soc/mm-plugin-qcom-soc.c \ + qcom-soc/mm-plugin-qcom-soc.h \ + qcom-soc/mm-broadband-modem-qmi-qcom-soc.c \ + qcom-soc/mm-broadband-modem-qmi-qcom-soc.h \ + $(NULL) +libmm_plugin_qcom_soc_la_CPPFLAGS = \ + $(PLUGIN_COMMON_COMPILER_FLAGS) \ + -DMM_MODULE_NAME=\"qcom-soc\" \ + $(NULL) +libmm_plugin_qcom_soc_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) + +dist_udevrules_DATA += qcom-soc/77-mm-qcom-soc.rules + +AM_CFLAGS += -DTESTUDEVRULESDIR_QCOM_SOC=\"${srcdir}/qcom-soc/\" +endif +endif + ################################################################################ # plugin: quectel ################################################################################ diff --git a/plugins/qcom-soc/77-mm-qcom-soc.rules b/plugins/qcom-soc/77-mm-qcom-soc.rules new file mode 100644 index 00000000..772f498c --- /dev/null +++ b/plugins/qcom-soc/77-mm-qcom-soc.rules @@ -0,0 +1,46 @@ +# do not edit this file, it will be overwritten on update + +ACTION!="add|change|move|bind", GOTO="mm_qcom_soc_end" + +# Process only known net and rpmsg ports +SUBSYSTEM=="net", DRIVERS=="bam-dmux", GOTO="mm_qcom_soc_process" +SUBSYSTEM=="rpmsg", DRIVERS=="qcom-q6v5-mss", GOTO="mm_qcom_soc_process" +GOTO="mm_qcom_soc_end" + +LABEL="mm_qcom_soc_process" + +# +# Add a common physdev UID to all ports in the Qualcomm SoC, so that they +# are all bound together to the same modem object. +# +# The MSM8916, MSM8974, .... Qualcomm SoCs use the combination of RPMSG +# based control ports plus BAM-DMUX based network ports. +# +ENV{ID_MM_PHYSDEV_UID}="qcom-soc" + +# port type hints for the rpmsgexport-ed ports +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA5_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA6_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA7_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA8_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA9_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA12_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA13_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA14_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA15_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA16_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA1", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA2", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA3", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA4", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" + +# ignore every other port without explicit hints +SUBSYSTEM=="rpmsg", ENV{ID_MM_PORT_TYPE_QMI}!="1", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}!="1", ENV{ID_MM_PORT_IGNORE}="1" + +# explicitly ignore bam-dmux network ports like rmnet_usb0 +KERNEL=="rmnet_usb[0-9]*", ENV{ID_MM_PORT_IGNORE}="1" + +# flag all rpmsg ports under this plugin as candidate +KERNEL=="rpmsg[0-9]*", SUBSYSTEM=="rpmsg", ENV{ID_MM_CANDIDATE}="1" + +LABEL="mm_qcom_soc_end" diff --git a/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.c b/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.c new file mode 100644 index 00000000..58a6e5e3 --- /dev/null +++ b/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.c @@ -0,0 +1,133 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2020 Aleksander Morgado + */ + +#include + +#include +#include +#include +#include +#include + +#include "ModemManager.h" +#include "mm-log.h" +#include "mm-broadband-modem-qmi-qcom-soc.h" + +G_DEFINE_TYPE (MMBroadbandModemQmiQcomSoc, mm_broadband_modem_qmi_qcom_soc, MM_TYPE_BROADBAND_MODEM_QMI) + +/*****************************************************************************/ + +static const QmiSioPort sio_port_per_port_number[] = { + QMI_SIO_PORT_A2_MUX_RMNET0, + QMI_SIO_PORT_A2_MUX_RMNET1, + QMI_SIO_PORT_A2_MUX_RMNET2, + QMI_SIO_PORT_A2_MUX_RMNET3, + QMI_SIO_PORT_A2_MUX_RMNET4, + QMI_SIO_PORT_A2_MUX_RMNET5, + QMI_SIO_PORT_A2_MUX_RMNET6, + QMI_SIO_PORT_A2_MUX_RMNET7 +}; + +static MMPortQmi * +peek_port_qmi_for_data (MMBroadbandModemQmi *self, + MMPort *data, + QmiSioPort *out_sio_port, + GError **error) +{ + GList *rpmsg_qmi_ports; + MMPortQmi *found = NULL; + MMKernelDevice *net_port; + const gchar *net_port_driver; + gint net_port_number; + + g_assert (MM_IS_BROADBAND_MODEM_QMI (self)); + g_assert (mm_port_get_subsys (data) == MM_PORT_SUBSYS_NET); + + net_port = mm_port_peek_kernel_device (data); + net_port_driver = mm_kernel_device_get_driver (net_port); + if (g_strcmp0 (net_port_driver, "bam-dmux") != 0) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Unsupported QMI kernel driver for 'net/%s': %s", + mm_port_get_device (data), + net_port_driver); + return NULL; + } + + /* The dev_port notified by the bam-dmux driver indicates which SIO port we should be using */ + net_port_number = mm_kernel_device_get_attribute_as_int (net_port, "dev_port"); + if (net_port_number < 0 || net_port_number >= (gint) G_N_ELEMENTS (sio_port_per_port_number)) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_NOT_FOUND, + "Couldn't find SIO port number for 'net/%s'", + mm_port_get_device (data)); + return NULL; + } + + /* Find one QMI port, we don't care which one */ + rpmsg_qmi_ports = mm_base_modem_find_ports (MM_BASE_MODEM (self), + MM_PORT_SUBSYS_RPMSG, + MM_PORT_TYPE_QMI, + NULL); + if (!rpmsg_qmi_ports) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_NOT_FOUND, + "Couldn't find any QMI port for 'net/%s'", + mm_port_get_device (data)); + return NULL; + } + + /* Set outputs */ + *out_sio_port = sio_port_per_port_number[net_port_number]; + found = MM_PORT_QMI (rpmsg_qmi_ports->data); + + g_list_free_full (rpmsg_qmi_ports, g_object_unref); + + return found; +} + +/*****************************************************************************/ + +MMBroadbandModemQmiQcomSoc * +mm_broadband_modem_qmi_qcom_soc_new (const gchar *device, + const gchar **drivers, + const gchar *plugin, + guint16 vendor_id, + guint16 product_id) +{ + return g_object_new (MM_TYPE_BROADBAND_MODEM_QMI_QCOM_SOC, + MM_BASE_MODEM_DEVICE, device, + MM_BASE_MODEM_DRIVERS, drivers, + MM_BASE_MODEM_PLUGIN, plugin, + MM_BASE_MODEM_VENDOR_ID, vendor_id, + MM_BASE_MODEM_PRODUCT_ID, product_id, + NULL); +} + +static void +mm_broadband_modem_qmi_qcom_soc_init (MMBroadbandModemQmiQcomSoc *self) +{ +} + +static void +mm_broadband_modem_qmi_qcom_soc_class_init (MMBroadbandModemQmiQcomSocClass *klass) +{ + MMBroadbandModemQmiClass *broadband_modem_qmi_class = MM_BROADBAND_MODEM_QMI_CLASS (klass); + + broadband_modem_qmi_class->peek_port_qmi_for_data = peek_port_qmi_for_data; +} diff --git a/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.h b/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.h new file mode 100644 index 00000000..92c37beb --- /dev/null +++ b/plugins/qcom-soc/mm-broadband-modem-qmi-qcom-soc.h @@ -0,0 +1,49 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2020 Aleksander Morgado + */ + +#ifndef MM_BROADBAND_MODEM_QMI_QCOM_SOC_H +#define MM_BROADBAND_MODEM_QMI_QCOM_SOC_H + +#include "mm-broadband-modem-qmi.h" + +#define MM_TYPE_BROADBAND_MODEM_QMI_QCOM_SOC (mm_broadband_modem_qmi_qcom_soc_get_type ()) +#define MM_BROADBAND_MODEM_QMI_QCOM_SOC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_QMI_QCOM_SOC, MMBroadbandModemQmiQcomSoc)) +#define MM_BROADBAND_MODEM_QMI_QCOM_SOC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_QMI_QCOM_SOC, MMBroadbandModemQmiQcomSocClass)) +#define MM_IS_BROADBAND_MODEM_QMI_QCOM_SOC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_QMI_QCOM_SOC)) +#define MM_IS_BROADBAND_MODEM_QMI_QCOM_SOC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_QMI_QCOM_SOC)) +#define MM_BROADBAND_MODEM_QMI_QCOM_SOC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_QMI_QCOM_SOC, MMBroadbandModemQmiQcomSocClass)) + +typedef struct _MMBroadbandModemQmiQcomSoc MMBroadbandModemQmiQcomSoc; +typedef struct _MMBroadbandModemQmiQcomSocClass MMBroadbandModemQmiQcomSocClass; +typedef struct _MMBroadbandModemQmiQcomSocPrivate MMBroadbandModemQmiQcomSocPrivate; + +struct _MMBroadbandModemQmiQcomSoc { + MMBroadbandModemQmi parent; + MMBroadbandModemQmiQcomSocPrivate *priv; +}; + +struct _MMBroadbandModemQmiQcomSocClass{ + MMBroadbandModemQmiClass parent; +}; + +GType mm_broadband_modem_qmi_qcom_soc_get_type (void); + +MMBroadbandModemQmiQcomSoc *mm_broadband_modem_qmi_qcom_soc_new (const gchar *device, + const gchar **drivers, + const gchar *plugin, + guint16 vendor_id, + guint16 product_id); + +#endif /* MM_BROADBAND_MODEM_QMI_QCOM_SOC_H */ diff --git a/plugins/qcom-soc/mm-plugin-qcom-soc.c b/plugins/qcom-soc/mm-plugin-qcom-soc.c new file mode 100644 index 00000000..6f2fac90 --- /dev/null +++ b/plugins/qcom-soc/mm-plugin-qcom-soc.c @@ -0,0 +1,92 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2020 Aleksander Morgado + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define _LIBMM_INSIDE_MM +#include + +#include "mm-plugin-qcom-soc.h" +#include "mm-broadband-modem-qmi-qcom-soc.h" +#include "mm-log-object.h" + +G_DEFINE_TYPE (MMPluginQcomSoc, mm_plugin_qcom_soc, MM_TYPE_PLUGIN) + +MM_PLUGIN_DEFINE_MAJOR_VERSION +MM_PLUGIN_DEFINE_MINOR_VERSION + +/*****************************************************************************/ + +static MMBaseModem * +create_modem (MMPlugin *self, + const gchar *uid, + const gchar **drivers, + guint16 vendor, + guint16 product, + GList *probes, + GError **error) +{ + if (!mm_port_probe_list_has_qmi_port (probes)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Unsupported device: at least a QMI port is required"); + return NULL; + } + + mm_obj_dbg (self, "Qualcomm SoC modem found..."); + return MM_BASE_MODEM (mm_broadband_modem_qmi_qcom_soc_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); +} + +/*****************************************************************************/ + +G_MODULE_EXPORT MMPlugin * +mm_plugin_create (void) +{ + static const gchar *subsystems[] = { "rpmsg", "net", NULL }; + + return MM_PLUGIN ( + g_object_new (MM_TYPE_PLUGIN_QCOM_SOC, + MM_PLUGIN_NAME, MM_MODULE_NAME, + MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, + MM_PLUGIN_ALLOWED_AT, TRUE, + MM_PLUGIN_ALLOWED_QMI, TRUE, + NULL)); +} + +static void +mm_plugin_qcom_soc_init (MMPluginQcomSoc *self) +{ +} + +static void +mm_plugin_qcom_soc_class_init (MMPluginQcomSocClass *klass) +{ + MMPluginClass *plugin_class = MM_PLUGIN_CLASS (klass); + + plugin_class->create_modem = create_modem; +} diff --git a/plugins/qcom-soc/mm-plugin-qcom-soc.h b/plugins/qcom-soc/mm-plugin-qcom-soc.h new file mode 100644 index 00000000..54da154f --- /dev/null +++ b/plugins/qcom-soc/mm-plugin-qcom-soc.h @@ -0,0 +1,40 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2020 Aleksander Morgado + */ + +#ifndef MM_PLUGIN_QCOM_SOC_H +#define MM_PLUGIN_QCOM_SOC_H + +#include "mm-plugin.h" + +#define MM_TYPE_PLUGIN_QCOM_SOC (mm_plugin_qcom_soc_get_type ()) +#define MM_PLUGIN_QCOM_SOC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_QCOM_SOC, MMPluginQcomSoc)) +#define MM_PLUGIN_QCOM_SOC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_QCOM_SOC, MMPluginQcomSocClass)) +#define MM_IS_PLUGIN_QCOM_SOC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_QCOM_SOC)) +#define MM_IS_PLUGIN_QCOM_SOC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_QCOM_SOC)) +#define MM_PLUGIN_QCOM_SOC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_QCOM_SOC, MMPluginQcomSocClass)) + +typedef struct { + MMPlugin parent; +} MMPluginQcomSoc; + +typedef struct { + MMPluginClass parent; +} MMPluginQcomSocClass; + +GType mm_plugin_qcom_soc_get_type (void); + +G_MODULE_EXPORT MMPlugin *mm_plugin_create (void); + +#endif /* MM_PLUGIN_QCOM_SOC_H */ diff --git a/plugins/tests/test-udev-rules.c b/plugins/tests/test-udev-rules.c index e1b38a9e..2f7190f1 100644 --- a/plugins/tests/test-udev-rules.c +++ b/plugins/tests/test-udev-rules.c @@ -176,6 +176,14 @@ test_gosuncn (void) } #endif +#if defined ENABLE_PLUGIN_QCOM_SOC && defined WITH_QMI +static void +test_qcom_soc (void) +{ + common_test (TESTUDEVRULESDIR_QCOM_SOC); +} +#endif + /************************************************************/ int main (int argc, char **argv) @@ -230,6 +238,9 @@ int main (int argc, char **argv) #if defined ENABLE_PLUGIN_GOSUNCN g_test_add_func ("/MM/test-udev-rules/gosuncn", test_gosuncn); #endif +#if defined ENABLE_PLUGIN_QCOM_SOC && defined WITH_QMI + g_test_add_func ("/MM/test-udev-rules/qcom-soc", test_qcom_soc); +#endif return g_test_run (); } From 9065e3b22777c5c811a2239de6353ecd3baade5d Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Wed, 4 Nov 2020 18:20:39 +0100 Subject: [PATCH 488/675] qcom-soc: simplify port type hint rules --- plugins/qcom-soc/77-mm-qcom-soc.rules | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/plugins/qcom-soc/77-mm-qcom-soc.rules b/plugins/qcom-soc/77-mm-qcom-soc.rules index 772f498c..6c1178ae 100644 --- a/plugins/qcom-soc/77-mm-qcom-soc.rules +++ b/plugins/qcom-soc/77-mm-qcom-soc.rules @@ -19,25 +19,14 @@ LABEL="mm_qcom_soc_process" ENV{ID_MM_PHYSDEV_UID}="qcom-soc" # port type hints for the rpmsgexport-ed ports -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA5_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA6_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA7_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA8_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA9_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA12_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA13_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA14_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA15_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA16_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA1", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA2", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA3", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" -SUBSYSTEM=="rpmsg", ATTR{name}=="DATA4", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA[0-9]*_CNTL", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA[0-9]", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" # ignore every other port without explicit hints SUBSYSTEM=="rpmsg", ENV{ID_MM_PORT_TYPE_QMI}!="1", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}!="1", ENV{ID_MM_PORT_IGNORE}="1" -# explicitly ignore bam-dmux network ports like rmnet_usb0 +# explicitly ignore ports intended for USB tethering (DATA40, DATA40_CNTL) +SUBSYSTEM=="rpmsg", ATTR{name}=="DATA40*", ENV{ID_MM_PORT_IGNORE}="1" KERNEL=="rmnet_usb[0-9]*", ENV{ID_MM_PORT_IGNORE}="1" # flag all rpmsg ports under this plugin as candidate From 65560dd8854f01eec1b28587c37d544bfff360d3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 19 Nov 2020 12:00:34 +0100 Subject: [PATCH 489/675] build: qcom-soc plugin by default disabled It will not be automatically enabled by the implicit --enable-all-plugins; instead, it must be explicitly enabled with --enable-plugin-qcom-soc. This plugin only makes sense under very specific SoC builds, so there is no point in always building it by default. It should be explicitly requested only in those SoC builds that are really going to make use of it (e.g. postmarketOS). --- configure.ac | 2 +- m4/mm-enable-plugin.m4 | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 9718c480..e3c9a4f8 100644 --- a/configure.ac +++ b/configure.ac @@ -490,7 +490,7 @@ MM_ENABLE_PLUGIN([option], MM_ENABLE_PLUGIN([option-hso], [with_shared_option]) MM_ENABLE_PLUGIN([pantech]) -MM_ENABLE_PLUGIN([qcom-soc]) +MM_ENABLE_PLUGIN_DISABLED([qcom-soc]) MM_ENABLE_PLUGIN([quectel]) MM_ENABLE_PLUGIN([samsung], [with_shared_icera]) diff --git a/m4/mm-enable-plugin.m4 b/m4/mm-enable-plugin.m4 index 0ea09da2..4f92a744 100644 --- a/m4/mm-enable-plugin.m4 +++ b/m4/mm-enable-plugin.m4 @@ -20,18 +20,18 @@ AC_ARG_ENABLE(all-plugins, ]) dnl Usage: -dnl MM_ENABLE_PLUGIN([NAME],[WITH_SHARED_NAME_1,WITH_SHARED_NAME_2,...]) -AC_DEFUN([MM_ENABLE_PLUGIN], +dnl MM_ENABLE_PLUGIN_FULL([NAME],[DEFAULT],[WITH_SHARED_NAME_1,WITH_SHARED_NAME_2,...]) +AC_DEFUN([MM_ENABLE_PLUGIN_FULL], [dnl m4_pushdef([var_enable_plugin], patsubst([enable_plugin_$1], -, _))dnl m4_pushdef([VAR_ENABLE_PLUGIN], patsubst(translit([enable_plugin_$1], [a-z], [A-Z]), -, _))dnl AC_ARG_ENABLE(plugin-$1, AS_HELP_STRING([--enable-plugin-$1], [Build $1 plugin]), [], - [var_enable_plugin=$enable_all_plugins]) + [var_enable_plugin=$2]) if test "x$var_enable_plugin" = "xyes"; then AC_DEFINE([VAR_ENABLE_PLUGIN], 1, [Define if $1 plugin is enabled]) -m4_ifval([$2],[m4_foreach(with_shared,[$2],[dnl +m4_ifval([$3],[m4_foreach(with_shared,[$3],[dnl with_shared="yes" ])])dnl fi @@ -40,6 +40,20 @@ m4_popdef([VAR_ENABLE_PLUGIN])dnl m4_popdef([var_enable_plugin])dnl ]) +dnl Usage: +dnl MM_ENABLE_PLUGIN([NAME],[WITH_SHARED_NAME_1,WITH_SHARED_NAME_2,...]) +AC_DEFUN([MM_ENABLE_PLUGIN], +[dnl +MM_ENABLE_PLUGIN_FULL($1,$enable_all_plugins,$2) +]) + +dnl Usage: +dnl MM_ENABLE_PLUGIN_DISABLED([NAME],[WITH_SHARED_NAME_1,WITH_SHARED_NAME_2,...]) +AC_DEFUN([MM_ENABLE_PLUGIN_DISABLED], +[dnl +MM_ENABLE_PLUGIN_FULL($1,"no",$2) +]) + dnl Usage: dnl MM_BUILD_SHARED([NAME]) AC_DEFUN([MM_BUILD_SHARED], From 6e0380c165cb7ab2a464ee4cf117e8e6caa4fe25 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 19 Nov 2020 12:51:58 +0100 Subject: [PATCH 490/675] base-modem: order ports by name by default When there are multiple ports with the same purpose (e.g. multiple net data ports, or multiple QMI control ports), sort them by name by default. The port order does not make any difference for ports that have flagged with a specific purpose (e.g. AT primary). The sorting is done both in the internal lists and when looking up ports with find_ports(). --- src/mm-base-modem.c | 141 ++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index 29256f7d..cdef6990 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -813,6 +813,14 @@ mm_base_modem_get_port_infos (MMBaseModem *self, return (MMModemPortInfo *) g_array_free (port_infos, FALSE); } +static gint +port_cmp (MMPort *a, + MMPort *b) +{ + /* default to alphabetical sorting on the port name */ + return g_strcmp0 (mm_port_get_device (a), mm_port_get_device (b)); +} + GList * mm_base_modem_find_ports (MMBaseModem *self, MMPortSubsys subsys, @@ -845,7 +853,7 @@ mm_base_modem_find_ports (MMBaseModem *self, out = g_list_append (out, g_object_ref (port)); } - return out; + return g_list_sort (out, (GCompareFunc) port_cmp); } static void @@ -903,14 +911,13 @@ mm_base_modem_organize_ports (MMBaseModem *self, MMPortSerialAt *gps_control = NULL; MMPortSerialGps *gps = NULL; MMPortSerial *audio = NULL; - MMPort *data_primary = NULL; - GList *data = NULL; + MMPortSerialAt *data_at_primary = NULL; + GList *data_at = NULL; + GList *data_net = NULL; #if defined WITH_QMI - MMPort *qmi_primary = NULL; GList *qmi = NULL; #endif #if defined WITH_MBIM - MMPort *mbim_primary = NULL; GList *mbim = NULL; #endif GList *l; @@ -942,10 +949,10 @@ mm_base_modem_organize_ports (MMBaseModem *self, } if (flags & MM_PORT_SERIAL_AT_FLAG_PPP) { - if (!data_primary) - data_primary = candidate; + if (!data_at_primary) + data_at_primary = MM_PORT_SERIAL_AT (candidate); else - data = g_list_append (data, candidate); + data_at = g_list_append (data_at, candidate); } /* Explicitly flagged secondary ports trump NONE ports for secondary */ @@ -975,16 +982,7 @@ mm_base_modem_organize_ports (MMBaseModem *self, break; case MM_PORT_TYPE_NET: - if (!data_primary) - data_primary = candidate; - else if (MM_IS_PORT_SERIAL_AT (data_primary)) { - /* Net device (if any) is the preferred data port */ - data = g_list_append (data, data_primary); - data_primary = candidate; - } - else - /* All non-primary net ports get added to the list of data ports */ - data = g_list_append (data, candidate); + data_net = g_list_append (data_net, candidate); break; case MM_PORT_TYPE_GPS: @@ -1001,21 +999,13 @@ mm_base_modem_organize_ports (MMBaseModem *self, #if defined WITH_QMI case MM_PORT_TYPE_QMI: - if (!qmi_primary) - qmi_primary = candidate; - else - /* All non-primary QMI ports get added to the list of QMI ports */ - qmi = g_list_append (qmi, candidate); + qmi = g_list_append (qmi, candidate); break; #endif #if defined WITH_MBIM case MM_PORT_TYPE_MBIM: - if (!mbim_primary) - mbim_primary = candidate; - else - /* All non-primary MBIM ports get added to the list of MBIM ports */ - mbim = g_list_append (mbim, candidate); + mbim = g_list_append (mbim, candidate); break; #endif @@ -1040,20 +1030,20 @@ mm_base_modem_organize_ports (MMBaseModem *self, secondary = NULL; } /* Fallback to a data port if no primary or secondary */ - else if (data_primary && MM_IS_PORT_SERIAL_AT (data_primary)) { - primary = MM_PORT_SERIAL_AT (data_primary); - data_primary = NULL; + else if (data_at_primary) { + primary = data_at_primary; + data_at_primary = NULL; } else { gboolean allow_modem_without_at_port = FALSE; #if defined WITH_QMI - if (qmi_primary) + if (qmi) allow_modem_without_at_port = TRUE; #endif #if defined WITH_MBIM - if (mbim_primary) + if (mbim) allow_modem_without_at_port = TRUE; #endif @@ -1075,7 +1065,7 @@ mm_base_modem_organize_ports (MMBaseModem *self, #if defined WITH_QMI /* On QMI-based modems, we need to have at least a net port */ - if (qmi_primary && !data_primary) { + if (qmi && !data_net) { g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, @@ -1086,7 +1076,7 @@ mm_base_modem_organize_ports (MMBaseModem *self, #if defined WITH_MBIM /* On MBIM-based modems, we need to have at least a net port */ - if (mbim_primary && !data_primary) { + if (mbim && !data_net) { g_set_error_literal (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, @@ -1096,73 +1086,84 @@ mm_base_modem_organize_ports (MMBaseModem *self, #endif /* Data port defaults to primary AT port */ - if (!data_primary) - data_primary = MM_PORT (primary); - g_assert (data_primary); + if (primary && !data_at_primary) + data_at_primary = primary; /* Reset flags on all ports; clear data port first since it might also * be the primary or secondary port. */ - if (MM_IS_PORT_SERIAL_AT (data_primary)) - mm_port_serial_at_set_flags (MM_PORT_SERIAL_AT (data_primary), MM_PORT_SERIAL_AT_FLAG_NONE); - + if (data_at_primary) + mm_port_serial_at_set_flags (data_at_primary, MM_PORT_SERIAL_AT_FLAG_NONE); if (primary) mm_port_serial_at_set_flags (primary, MM_PORT_SERIAL_AT_FLAG_PRIMARY); if (secondary) mm_port_serial_at_set_flags (secondary, MM_PORT_SERIAL_AT_FLAG_SECONDARY); - - if (MM_IS_PORT_SERIAL_AT (data_primary)) { - flags = mm_port_serial_at_get_flags (MM_PORT_SERIAL_AT (data_primary)); - mm_port_serial_at_set_flags (MM_PORT_SERIAL_AT (data_primary), flags | MM_PORT_SERIAL_AT_FLAG_PPP); + if (data_at_primary) { + flags = mm_port_serial_at_get_flags (data_at_primary); + mm_port_serial_at_set_flags (data_at_primary, flags | MM_PORT_SERIAL_AT_FLAG_PPP); } - log_port (self, MM_PORT (primary), "at (primary)"); - log_port (self, MM_PORT (secondary), "at (secondary)"); - log_port (self, MM_PORT (data_primary), "data (primary)"); - for (l = data; l; l = g_list_next (l)) - log_port (self, MM_PORT (l->data), "data (secondary)"); - log_port (self, MM_PORT (qcdm), "qcdm"); - log_port (self, MM_PORT (gps_control), "gps (control)"); - log_port (self, MM_PORT (gps), "gps (nmea)"); - log_port (self, MM_PORT (audio), "audio"); + /* sort ports by name */ +#if defined WITH_QMI + qmi = g_list_sort (qmi, (GCompareFunc) port_cmp); +#endif +#if defined WITH_MBIM + mbim = g_list_sort (mbim, (GCompareFunc) port_cmp); +#endif + data_net = g_list_sort (data_net, (GCompareFunc) port_cmp); + data_at = g_list_sort (data_at, (GCompareFunc) port_cmp); + + log_port (self, MM_PORT (primary), "at (primary)"); + log_port (self, MM_PORT (secondary), "at (secondary)"); + log_port (self, MM_PORT (data_at_primary), "at (data primary)"); + for (l = data_at; l; l = g_list_next (l)) + log_port (self, MM_PORT (l->data), "at (data secondary)"); + for (l = data_net; l; l = g_list_next (l)) + log_port (self, MM_PORT (l->data), "net (data)"); + log_port (self, MM_PORT (qcdm), "qcdm"); + log_port (self, MM_PORT (gps_control), "gps (control)"); + log_port (self, MM_PORT (gps), "gps (nmea)"); + log_port (self, MM_PORT (audio), "audio"); #if defined WITH_QMI - log_port (self, MM_PORT (qmi_primary), "qmi (primary)"); for (l = qmi; l; l = g_list_next (l)) - log_port (self, MM_PORT (l->data), "qmi (secondary)"); + log_port (self, MM_PORT (l->data), "qmi"); #endif #if defined WITH_MBIM - log_port (self, MM_PORT (mbim_primary), "mbim (primary)"); for (l = mbim; l; l = g_list_next (l)) - log_port (self, MM_PORT (l->data), "mbim (secondary)"); + log_port (self, MM_PORT (l->data), "mbim"); #endif /* We keep new refs to the objects here */ + self->priv->primary = (primary ? g_object_ref (primary) : NULL); self->priv->secondary = (secondary ? g_object_ref (secondary) : NULL); self->priv->qcdm = (qcdm ? g_object_ref (qcdm) : NULL); self->priv->gps_control = (gps_control ? g_object_ref (gps_control) : NULL); self->priv->gps = (gps ? g_object_ref (gps) : NULL); - /* Build the final list of data ports, primary port first */ - self->priv->data = g_list_append (self->priv->data, g_object_ref (data_primary)); - g_list_foreach (data, (GFunc)g_object_ref, NULL); - self->priv->data = g_list_concat (self->priv->data, data); + /* Build the final list of data ports, NET ports preferred */ + if (data_net) { + g_list_foreach (data_net, (GFunc)g_object_ref, NULL); + self->priv->data = g_list_concat (self->priv->data, data_net); + } + if (data_at_primary) + self->priv->data = g_list_append (self->priv->data, g_object_ref (data_at_primary)); + if (data_at) { + g_list_foreach (data_at, (GFunc)g_object_ref, NULL); + self->priv->data = g_list_concat (self->priv->data, data_at); + } #if defined WITH_QMI - /* Build the final list of QMI ports, primary port first */ - if (qmi_primary) { - self->priv->qmi = g_list_append (self->priv->qmi, g_object_ref (qmi_primary)); + if (qmi) { g_list_foreach (qmi, (GFunc)g_object_ref, NULL); - self->priv->qmi = g_list_concat (self->priv->qmi, qmi); + self->priv->qmi = qmi; } #endif #if defined WITH_MBIM - /* Build the final list of MBIM ports, primary port first */ - if (mbim_primary) { - self->priv->mbim = g_list_append (self->priv->mbim, g_object_ref (mbim_primary)); + if (mbim) { g_list_foreach (mbim, (GFunc)g_object_ref, NULL); - self->priv->mbim = g_list_concat (self->priv->mbim, mbim); + self->priv->mbim = mbim; } #endif From 935e73c8dfc8ad557100005baa506439526a702e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 22 Nov 2020 14:34:07 +0100 Subject: [PATCH 491/675] build: fix build with single plugins We need to quote arguments with [] so that lists are not expanded as different arguments. Fixes 65560dd8854f01eec1b28587c37d544bfff360d3 --- m4/mm-enable-plugin.m4 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/m4/mm-enable-plugin.m4 b/m4/mm-enable-plugin.m4 index 4f92a744..774c881d 100644 --- a/m4/mm-enable-plugin.m4 +++ b/m4/mm-enable-plugin.m4 @@ -44,14 +44,14 @@ dnl Usage: dnl MM_ENABLE_PLUGIN([NAME],[WITH_SHARED_NAME_1,WITH_SHARED_NAME_2,...]) AC_DEFUN([MM_ENABLE_PLUGIN], [dnl -MM_ENABLE_PLUGIN_FULL($1,$enable_all_plugins,$2) +MM_ENABLE_PLUGIN_FULL([$1],[$enable_all_plugins],[$2]) ]) dnl Usage: dnl MM_ENABLE_PLUGIN_DISABLED([NAME],[WITH_SHARED_NAME_1,WITH_SHARED_NAME_2,...]) AC_DEFUN([MM_ENABLE_PLUGIN_DISABLED], [dnl -MM_ENABLE_PLUGIN_FULL($1,"no",$2) +MM_ENABLE_PLUGIN_FULL([$1],["no"],[$2]) ]) dnl Usage: From 92c86e2b1bcdaab991d89bdd8f670b248c246bae Mon Sep 17 00:00:00 2001 From: Thomas Dendale Date: Mon, 23 Nov 2020 09:04:50 +0000 Subject: [PATCH 492/675] huawei: add GPS port type hints for Huawei ME906e --- plugins/huawei/77-mm-huawei-net-port-types.rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/huawei/77-mm-huawei-net-port-types.rules b/plugins/huawei/77-mm-huawei-net-port-types.rules index b8bcc94d..d0e591f8 100644 --- a/plugins/huawei/77-mm-huawei-net-port-types.rules +++ b/plugins/huawei/77-mm-huawei-net-port-types.rules @@ -18,6 +18,8 @@ SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="02" SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="01", ATTRS{bInterfaceProtocol}=="05", ENV{ID_MM_PORT_TYPE_GPS}="1" # GPS NMEA port on MU909 SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="01", ATTRS{bInterfaceProtocol}=="14", ENV{ID_MM_PORT_TYPE_GPS}="1" +# GPS NMEA port on MU906e +SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="06", ATTRS{bInterfaceProtocol}=="14", ENV{ID_MM_PORT_TYPE_GPS}="1" # Only the standard ECM or NCM port can support dial-up with AT NDISDUP through AT port SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="02", ATTRS{bInterfaceSubClass}=="06",ATTRS{bInterfaceProtocol}=="00", ENV{ID_MM_HUAWEI_NDISDUP_SUPPORTED}="1" From 38f6704fa1d6f602be84bcbf016b3386ac82c426 Mon Sep 17 00:00:00 2001 From: Pavan Holla Date: Mon, 23 Nov 2020 17:52:17 +0000 Subject: [PATCH 493/675] base-sim: Reprobe modem if lock status cannot be read after sending puk If the lock status cannot be read during a puk unblock attempt, reprobe the modem. It is likely that the SIM was permanently blocked if the lock status cannot be read. --- src/mm-base-modem.c | 2 +- src/mm-base-modem.h | 2 +- src/mm-base-sim.c | 37 ++++++++++++++++++++++++++----------- src/mm-broadband-modem.c | 2 +- src/mm-device.c | 1 + src/mm-iface-modem.c | 5 ++++- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index cdef6990..e5030dcb 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -1285,7 +1285,7 @@ after_sim_switch_disable_ready (MMBaseModem *self, } void -mm_base_modem_process_sim_switch (MMBaseModem *self) +mm_base_modem_process_sim_event (MMBaseModem *self) { mm_base_modem_set_reprobe (self, TRUE); mm_base_modem_disable (self, (GAsyncReadyCallback) after_sim_switch_disable_ready, NULL); diff --git a/src/mm-base-modem.h b/src/mm-base-modem.h index 7b00b568..24634814 100644 --- a/src/mm-base-modem.h +++ b/src/mm-base-modem.h @@ -199,6 +199,6 @@ gboolean mm_base_modem_disable_finish (MMBaseModem *self, GAsyncResult *res, GError **error); -void mm_base_modem_process_sim_switch (MMBaseModem *self); +void mm_base_modem_process_sim_event (MMBaseModem *self); #endif /* MM_BASE_MODEM_H */ diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index b8570a3c..106a0a95 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -584,17 +584,17 @@ update_lock_info_ready (MMIfaceModem *modem, const GError *saved_error; /* Device is locked. Now: + * - If we got an error during update_lock_info, report it. The sim might have been blocked. * - If we got an error in the original send-pin action, report it. - * - If we got an error in the pin-check action, report it. * - Otherwise, build our own error from the lock code. */ - saved_error = g_task_get_task_data (task); - if (saved_error) { - g_clear_error (&error); - error = g_error_copy (saved_error); - } else if (!error) - error = error_for_unlock_check (lock); - + if (!error) { + saved_error = g_task_get_task_data (task); + if (saved_error) + error = g_error_copy (saved_error); + else + error = error_for_unlock_check (lock); + } g_task_return_error (task, error); } else g_task_return_boolean (task, TRUE); @@ -869,12 +869,27 @@ handle_send_puk_ready (MMBaseSim *self, HandleSendPukContext *ctx) { GError *error = NULL; - - if (!mm_base_sim_send_puk_finish (self, res, &error)) + gboolean sim_error = FALSE; + + if (!mm_base_sim_send_puk_finish (self, res, &error)) { + sim_error = g_error_matches (error, + MM_MOBILE_EQUIPMENT_ERROR, + MM_MOBILE_EQUIPMENT_ERROR_SIM_NOT_INSERTED) || + g_error_matches (error, + MM_MOBILE_EQUIPMENT_ERROR, + MM_MOBILE_EQUIPMENT_ERROR_SIM_FAILURE) || + g_error_matches (error, + MM_MOBILE_EQUIPMENT_ERROR, + MM_MOBILE_EQUIPMENT_ERROR_SIM_WRONG); g_dbus_method_invocation_take_error (ctx->invocation, error); - else + } else mm_gdbus_sim_complete_send_puk (MM_GDBUS_SIM (self), ctx->invocation); + if (sim_error) { + mm_obj_info (self, "Received critical sim error. SIM might be permanently blocked. Reprobing..."); + mm_base_modem_process_sim_event (self->priv->modem); + } + handle_send_puk_context_free (ctx); } diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 5fb72cc9..97c60b68 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -11946,7 +11946,7 @@ mm_broadband_modem_sim_hot_swap_detected (MMBroadbandModem *self) self->priv->sim_hot_swap_ports_ctx = NULL; } - mm_base_modem_process_sim_switch (MM_BASE_MODEM (self)); + mm_base_modem_process_sim_event (MM_BASE_MODEM (self)); } /*****************************************************************************/ diff --git a/src/mm-device.c b/src/mm-device.c index ddd420fe..488ee5e2 100644 --- a/src/mm-device.c +++ b/src/mm-device.c @@ -383,6 +383,7 @@ reprobe (MMDevice *self) { GError *error = NULL; + mm_obj_dbg (self, "Reprobing modem..."); if (!mm_device_create_modem (self, &error)) { mm_obj_warn (self, "could not recreate modem: %s", error->message); g_error_free (error); diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 0ddc0a29..5bb9dd2c 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -1076,7 +1076,7 @@ set_primary_sim_slot_ready (MMIfaceModem *self, /* Notify about the SIM swap, which will disable and reprobe the device. * There is no need to update the PrimarySimSlot property, as this value will be * reloaded automatically during the reprobe. */ - mm_base_modem_process_sim_switch (MM_BASE_MODEM (self)); + mm_base_modem_process_sim_event (MM_BASE_MODEM (self)); } mm_gdbus_modem_complete_set_primary_sim_slot (ctx->skeleton, ctx->invocation); @@ -3314,6 +3314,8 @@ set_lock_status (MMIfaceModem *self, old_lock = mm_gdbus_modem_get_unlock_required (skeleton); mm_gdbus_modem_set_unlock_required (skeleton, lock); + if (lock == MM_MODEM_LOCK_UNKNOWN) + mm_gdbus_modem_set_unlock_retries (skeleton, 0); /* We don't care about SIM-PIN2/SIM-PUK2 since the device is * operational without it. */ @@ -3639,6 +3641,7 @@ update_lock_info_context_step (GTask *task) case UPDATE_LOCK_INFO_CONTEXT_STEP_LAST: if (ctx->saved_error) { + set_lock_status (self, ctx->skeleton, MM_MODEM_LOCK_UNKNOWN); /* Return saved error */ g_task_return_error (task, ctx->saved_error); ctx->saved_error = NULL; From 1f0c04644dd48b086bc00f9765f94342f3badc3f Mon Sep 17 00:00:00 2001 From: Pavan Holla Date: Mon, 23 Nov 2020 20:24:05 +0000 Subject: [PATCH 494/675] base-sim: Reprobe modem if puk lock is discovered after sending pin1 Enabling/Disabling/Changing/Sending the PIN1 lock is usually limited to 3 retries. If these attempts are exhausted, the modem is puk_locked. We reprobe the modem to get rid of any unwanted interfaces and move to a locked state. --- src/mm-base-sim.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 106a0a95..85051191 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -87,6 +87,21 @@ mm_base_sim_export (MMBaseSim *self) g_free (path); } +/*****************************************************************************/ +/* Reprobe when a puk lock is discovered after pin1_retries are exhausted */ + +static void +reprobe_if_puk_discovered (MMBaseSim *self, + GError *error) +{ + if (g_error_matches (error, + MM_MOBILE_EQUIPMENT_ERROR, + MM_MOBILE_EQUIPMENT_ERROR_SIM_PUK)) { + mm_obj_dbg (self, "Discovered PUK lock, discarding old modem..."); + mm_base_modem_process_sim_event (self->priv->modem); + } +} + /*****************************************************************************/ /* CHANGE PIN (Generic implementation) */ @@ -171,8 +186,9 @@ after_change_update_lock_info_ready (MMIfaceModem *modem, mm_iface_modem_update_lock_info_finish (modem, res, NULL); if (ctx->save_error) { - g_dbus_method_invocation_take_error (ctx->invocation, ctx->save_error); - ctx->save_error = NULL; + g_dbus_method_invocation_return_gerror (ctx->invocation, ctx->save_error); + reprobe_if_puk_discovered (ctx->self, ctx->save_error); + g_clear_error (&ctx->save_error); } else { mm_gdbus_sim_complete_change_pin (MM_GDBUS_SIM (ctx->self), ctx->invocation); } @@ -349,8 +365,9 @@ after_enable_update_lock_info_ready (MMIfaceModem *modem, mm_iface_modem_update_lock_info_finish (modem, res, NULL); if (ctx->save_error) { - g_dbus_method_invocation_take_error (ctx->invocation, ctx->save_error); - ctx->save_error = NULL; + g_dbus_method_invocation_return_gerror (ctx->invocation, ctx->save_error); + reprobe_if_puk_discovered (ctx->self, ctx->save_error); + g_clear_error (&ctx->save_error); } else { /* Signal about the new lock state */ g_signal_emit (ctx->self, signals[SIGNAL_PIN_LOCK_ENABLED], 0, ctx->enabled); @@ -786,9 +803,11 @@ handle_send_pin_ready (MMBaseSim *self, { GError *error = NULL; - if (!mm_base_sim_send_pin_finish (self, res, &error)) - g_dbus_method_invocation_take_error (ctx->invocation, error); - else + if (!mm_base_sim_send_pin_finish (self, res, &error)) { + g_dbus_method_invocation_return_gerror (ctx->invocation, error); + reprobe_if_puk_discovered (self, error); + g_clear_error (&error); + } else mm_gdbus_sim_complete_send_pin (MM_GDBUS_SIM (self), ctx->invocation); handle_send_pin_context_free (ctx); From 756894bc7682250821c3b80e96fea66d73a3e837 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Fri, 27 Nov 2020 18:07:02 +0100 Subject: [PATCH 495/675] build: Allow elogind for suspend/resume support --- configure.ac | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index e3c9a4f8..032c4c4c 100644 --- a/configure.ac +++ b/configure.ac @@ -248,13 +248,14 @@ dnl PKG_CHECK_MODULES(LIBSYSTEMD, [libsystemd >= 209],[have_libsystemd=yes],[have_libsystemd=no]) PKG_CHECK_MODULES(LIBSYSTEMD_LOGIN, [libsystemd-login >= 183],[have_libsystemd_login=yes],[have_libsystemd_login=no]) +PKG_CHECK_MODULES(LIBELOGIND, [libelogind >= 209], [have_elogind=yes], [have_elogind=no]) AC_ARG_WITH(systemd-suspend-resume, AS_HELP_STRING([--with-systemd-suspend-resume=no|yes], [Enable systemd suspend/resume support [[default=auto]]]),, [with_systemd_suspend_resume=auto]) if test "x$with_systemd_suspend_resume" = "xauto"; then - if test "x$have_libsystemd" = "xyes" || test "x$have_libsystemd_login" = "xyes"; then + if test "x$have_libsystemd" = "xyes" || test "x$have_libsystemd_login" = "xyes" || test "x$have_elogind" = "xyes"; then with_systemd_suspend_resume=yes else with_systemd_suspend_resume=no @@ -263,8 +264,8 @@ fi case $with_systemd_suspend_resume in yes) - if test "x$have_libsystemd" = "xno" && test "x$have_libsystemd_login" = "xno"; then - AC_MSG_ERROR(libsystemd or libsystemd-login development headers are required) + if test "x$have_libsystemd" = "xno" && test "x$have_libsystemd_login" = "xno" && test "x$have_elogind" = "xno"; then + AC_MSG_WARN(libsystemd, libsystemd-login or elogind must be available at runtime for suspend/resume support) fi AC_DEFINE(WITH_SYSTEMD_SUSPEND_RESUME, 1, [Define if you have systemd suspend-resume support]) ;; From 446d497040f5e71a1d6a842b82cdab07ef54a0fa Mon Sep 17 00:00:00 2001 From: Eric Caruso Date: Mon, 30 Nov 2020 09:25:10 -0800 Subject: [PATCH 496/675] introspection: fix Bearer documentation If e.g. a bearer with IPv6 configuration has DNS servers but exports its link-local address, MM will avoid giving it the "static" method type, and instead fall back to the "dhcp" type. However, it may still have DNS information. Therefore, the comment that "method" is the only property on configuration with type DHCP is misleading. --- introspection/org.freedesktop.ModemManager1.Bearer.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/introspection/org.freedesktop.ModemManager1.Bearer.xml b/introspection/org.freedesktop.ModemManager1.Bearer.xml index a07ee057..fb008797 100644 --- a/introspection/org.freedesktop.ModemManager1.Bearer.xml +++ b/introspection/org.freedesktop.ModemManager1.Bearer.xml @@ -120,7 +120,7 @@ If the bearer specifies configuration via PPP or DHCP, only the - "method" item will be present. + "method" item is guaranteed to be present. Additional items which are only applicable when using the MM_BEARER_IP_METHOD_STATIC From 750fb2bc4ab9bdc779a9e3919d74c64059b9e963 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Wed, 25 Nov 2020 19:58:25 +0100 Subject: [PATCH 497/675] serial-parsers: also match OK responses that are not at end of line Do not fail to detect a valid response with a call or text incoming. This happens also during port probing when there's no URC parsers installed in the serial port. This probably will not happen when the serial port was managed by the modem object. --- src/mm-serial-parsers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-serial-parsers.c b/src/mm-serial-parsers.c index b511302e..248cc685 100644 --- a/src/mm-serial-parsers.c +++ b/src/mm-serial-parsers.c @@ -108,7 +108,7 @@ mm_serial_parser_v1_new (void) parser = g_slice_new (MMSerialParserV1); - parser->regex_ok = g_regex_new ("\\r\\nOK(\\r\\n)+$", flags, 0, NULL); + parser->regex_ok = g_regex_new ("\\r\\nOK(\\r\\n)+", flags, 0, NULL); parser->regex_connect = g_regex_new ("\\r\\nCONNECT.*\\r\\n", flags, 0, NULL); parser->regex_sms = g_regex_new ("\\r\\n>\\s*$", flags, 0, NULL); parser->regex_cme_error = g_regex_new ("\\r\\n\\+CME ERROR:\\s*(\\d+)\\r\\n$", flags, 0, NULL); From c05580ca9a69b491042921d2fe40383fde1657ea Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Fri, 27 Nov 2020 18:46:42 +0100 Subject: [PATCH 498/675] tests: added parse OK response test --- src/tests/test-at-serial-port.c | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/tests/test-at-serial-port.c b/src/tests/test-at-serial-port.c index 2147df4d..dadb6340 100644 --- a/src/tests/test-at-serial-port.c +++ b/src/tests/test-at-serial-port.c @@ -18,6 +18,7 @@ #include #include "mm-port-serial-at.h" +#include "mm-serial-parsers.h" #include "mm-log-test.h" typedef struct { @@ -25,6 +26,11 @@ typedef struct { const gchar *without_echo; } EchoRemovalTest; +typedef struct { + const gchar *response; + const gboolean found; +} ParseOkTest; + static const EchoRemovalTest echo_removal_tests[] = { { "\r\n", "\r\n" }, { "\r", "\r" }, @@ -41,6 +47,13 @@ static const EchoRemovalTest echo_removal_tests[] = { { "\r\nthis is valid\r\nand so is this\r\n", "\r\nthis is valid\r\nand so is this\r\n" }, }; +static const ParseOkTest parse_ok_tests[] = { + { "\r\nOK\r\n", TRUE}, + { "\r\nOK\r\n\r\n+CMTI: \"ME\",1\r\n", TRUE}, + { "\r\nOK\r\n\r\n+CIEV: 7,1\r\n\r\n+CRING: VOICE\r\n\r\n+CLIP: \"+0123456789\",145,,,,0\r\n", TRUE}, + { "\r\nERROR\r\n", FALSE} +}; + static void at_serial_echo_removal (void) { @@ -64,11 +77,40 @@ at_serial_echo_removal (void) } } +static void +at_serial_parse_ok (void) +{ + guint i; + gpointer parser; + GError *error = NULL; + gboolean found = FALSE; + GString *response; + + for (i = 0; i < G_N_ELEMENTS (parse_ok_tests); i++) { + parser = mm_serial_parser_v1_new (); + response = g_string_new (parse_ok_tests[i].response); + found = mm_serial_parser_v1_parse (parser, response, NULL, &error); + + /* Match found */ + if (parse_ok_tests[i].found) { + g_assert_cmpint (found, ==, parse_ok_tests[i].found); + g_assert_no_error (error); + } + /* Not found: error */ + else { + g_assert (error != NULL); + } + + g_string_free (response, TRUE); + } +} + int main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/ModemManager/AT-serial/echo-removal", at_serial_echo_removal); + g_test_add_func ("/ModemManager/AT-serial/parse-ok", at_serial_parse_ok); return g_test_run (); } From c15d103ca62cec7287764f1b5d0d3316ac891ce5 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 29 Nov 2020 15:59:21 +0100 Subject: [PATCH 499/675] serial-parsers: also match ERROR responses that are not at end of line Do not fail to detect an error response with a call or text incoming. This happens during port probing when there's no URC parsers installed in the serial port. This probably will not happen when the serial port was managed by the modem object.w --- src/mm-serial-parsers.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mm-serial-parsers.c b/src/mm-serial-parsers.c index 248cc685..0b60d607 100644 --- a/src/mm-serial-parsers.c +++ b/src/mm-serial-parsers.c @@ -111,13 +111,13 @@ mm_serial_parser_v1_new (void) parser->regex_ok = g_regex_new ("\\r\\nOK(\\r\\n)+", flags, 0, NULL); parser->regex_connect = g_regex_new ("\\r\\nCONNECT.*\\r\\n", flags, 0, NULL); parser->regex_sms = g_regex_new ("\\r\\n>\\s*$", flags, 0, NULL); - parser->regex_cme_error = g_regex_new ("\\r\\n\\+CME ERROR:\\s*(\\d+)\\r\\n$", flags, 0, NULL); - parser->regex_cms_error = g_regex_new ("\\r\\n\\+CMS ERROR:\\s*(\\d+)\\r\\n$", flags, 0, NULL); - parser->regex_cme_error_str = g_regex_new ("\\r\\n\\+CME ERROR:\\s*([^\\n\\r]+)\\r\\n$", flags, 0, NULL); - parser->regex_cms_error_str = g_regex_new ("\\r\\n\\+CMS ERROR:\\s*([^\\n\\r]+)\\r\\n$", flags, 0, NULL); - parser->regex_ezx_error = g_regex_new ("\\r\\n\\MODEM ERROR:\\s*(\\d+)\\r\\n$", flags, 0, NULL); - parser->regex_unknown_error = g_regex_new ("\\r\\n(ERROR)|(COMMAND NOT SUPPORT)\\r\\n$", flags, 0, NULL); - parser->regex_connect_failed = g_regex_new ("\\r\\n(NO CARRIER)|(BUSY)|(NO ANSWER)|(NO DIALTONE)\\r\\n$", flags, 0, NULL); + parser->regex_cme_error = g_regex_new ("\\r\\n\\+CME ERROR:\\s*(\\d+)\\r\\n", flags, 0, NULL); + parser->regex_cms_error = g_regex_new ("\\r\\n\\+CMS ERROR:\\s*(\\d+)\\r\\n", flags, 0, NULL); + parser->regex_cme_error_str = g_regex_new ("\\r\\n\\+CME ERROR:\\s*([^\\n\\r]+)\\r\\n", flags, 0, NULL); + parser->regex_cms_error_str = g_regex_new ("\\r\\n\\+CMS ERROR:\\s*([^\\n\\r]+)\\r\\n", flags, 0, NULL); + parser->regex_ezx_error = g_regex_new ("\\r\\n\\MODEM ERROR:\\s*(\\d+)\\r\\n", flags, 0, NULL); + parser->regex_unknown_error = g_regex_new ("\\r\\n(ERROR)|(COMMAND NOT SUPPORT)\\r\\n", flags, 0, NULL); + parser->regex_connect_failed = g_regex_new ("\\r\\n(NO CARRIER)|(BUSY)|(NO ANSWER)|(NO DIALTONE)\\r\\n", flags, 0, NULL); /* Samsung Z810 may reply "NA" to report a not-available error */ parser->regex_na = g_regex_new ("\\r\\nNA\\r\\n", flags, 0, NULL); From d531992897fe4a99005da03e83c818dd138a06d5 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 29 Nov 2020 15:59:49 +0100 Subject: [PATCH 500/675] tests: added parse ERROR response test --- src/tests/test-at-serial-port.c | 75 ++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/src/tests/test-at-serial-port.c b/src/tests/test-at-serial-port.c index dadb6340..5372c478 100644 --- a/src/tests/test-at-serial-port.c +++ b/src/tests/test-at-serial-port.c @@ -29,7 +29,8 @@ typedef struct { typedef struct { const gchar *response; const gboolean found; -} ParseOkTest; + const gboolean expected_error; +} ParseResponseTest; static const EchoRemovalTest echo_removal_tests[] = { { "\r\n", "\r\n" }, @@ -47,11 +48,39 @@ static const EchoRemovalTest echo_removal_tests[] = { { "\r\nthis is valid\r\nand so is this\r\n", "\r\nthis is valid\r\nand so is this\r\n" }, }; -static const ParseOkTest parse_ok_tests[] = { - { "\r\nOK\r\n", TRUE}, - { "\r\nOK\r\n\r\n+CMTI: \"ME\",1\r\n", TRUE}, - { "\r\nOK\r\n\r\n+CIEV: 7,1\r\n\r\n+CRING: VOICE\r\n\r\n+CLIP: \"+0123456789\",145,,,,0\r\n", TRUE}, - { "\r\nERROR\r\n", FALSE} +static const ParseResponseTest parse_ok_tests[] = { + { "\r\nOK\r\n", TRUE, FALSE}, + { "\r\nOK\r\n\r\n+CMTI: \"ME\",1\r\n", TRUE, FALSE}, + { "\r\nOK\r\n\r\n+CIEV: 7,1\r\n\r\n+CRING: VOICE\r\n\r\n+CLIP: \"+0123456789\",145,,,,0\r\n", TRUE, FALSE}, + { "\r\nUNKNOWN COMMAND\r\n", FALSE, FALSE} +}; + +static const ParseResponseTest parse_error_tests[] = { + { "\r\nUNKNOWN COMMAND\r\n", FALSE, FALSE}, + { "\r\nERROR\r\n", TRUE, TRUE}, + { "\r\nERROR\r\n\r\noooops\r\n", TRUE, TRUE}, + { "\r\n+CME ERROR: raspberry\r\n", TRUE, TRUE}, + { "\r\n+CME ERROR: 123\r\n", TRUE, TRUE}, + { "\r\n+CME ERROR: \r\n", TRUE, TRUE}, + { "\r\n+CME ERROR:\r\n", FALSE, FALSE}, + { "\r\n+CMS ERROR: bananas\r\n", TRUE, TRUE}, + { "\r\n+CMS ERROR: 456\r\n", TRUE, TRUE}, + { "\r\n+CMS ERROR: \r\n", TRUE, TRUE}, + { "\r\n+CMS ERROR:\r\n", FALSE, FALSE}, + { "\r\nMODEM ERROR: 5\r\n", TRUE, TRUE}, + { "\r\nMODEM ERROR: apple\r\n", FALSE, FALSE}, + { "\r\nMODEM ERROR: \r\n", FALSE, FALSE}, + { "\r\nMODEM ERROR:\r\n", FALSE, FALSE}, + { "\r\nCOMMAND NOT SUPPORT\r\n", TRUE, TRUE}, + { "\r\nCOMMAND NOT SUPPORT\r\n\r\nSomething extra\r\n", TRUE, TRUE}, + { "\r\nNO CARRIER\r\n", TRUE, TRUE}, + { "\r\nNO CARRIER\r\n\r\nSomething extra\r\n", TRUE, TRUE}, + { "\r\nBUSY\r\n", TRUE, TRUE}, + { "\r\nBUSY\r\n\r\nSomething extra\r\n", TRUE, TRUE}, + { "\r\nNO ANSWER\r\n", TRUE, TRUE}, + { "\r\nNO ANSWER\r\n\r\nSomething extra\r\n", TRUE, TRUE}, + { "\r\nNO DIALTONE\r\n", TRUE, TRUE}, + { "\r\nNO DIALTONE\r\n\r\nSomething extra\r\n", TRUE, TRUE} }; static void @@ -78,7 +107,7 @@ at_serial_echo_removal (void) } static void -at_serial_parse_ok (void) +_run_parse_test (const ParseResponseTest tests[], guint number_of_tests) { guint i; gpointer parser; @@ -86,31 +115,47 @@ at_serial_parse_ok (void) gboolean found = FALSE; GString *response; - for (i = 0; i < G_N_ELEMENTS (parse_ok_tests); i++) { + for (i = 0; i < number_of_tests; i++) { parser = mm_serial_parser_v1_new (); - response = g_string_new (parse_ok_tests[i].response); + response = g_string_new (tests[i].response); found = mm_serial_parser_v1_parse (parser, response, NULL, &error); - /* Match found */ - if (parse_ok_tests[i].found) { - g_assert_cmpint (found, ==, parse_ok_tests[i].found); - g_assert_no_error (error); + /* Verify if we expect a match or not */ + g_assert_cmpint (found, ==, tests[i].found); + + /* Error expected */ + if (tests[i].expected_error) { + g_assert (error != NULL); } - /* Not found: error */ + /* No error expected */ else { - g_assert (error != NULL); + g_assert_no_error (error); } g_string_free (response, TRUE); + error = NULL ; } } +static void +at_serial_parse_ok (void) +{ + _run_parse_test (parse_ok_tests, G_N_ELEMENTS(parse_ok_tests)); +} + +static void +at_serial_parse_error (void) +{ + _run_parse_test (parse_error_tests, G_N_ELEMENTS(parse_error_tests)); +} + int main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/ModemManager/AT-serial/echo-removal", at_serial_echo_removal); g_test_add_func ("/ModemManager/AT-serial/parse-ok", at_serial_parse_ok); + g_test_add_func ("/ModemManager/AT-serial/parse-error", at_serial_parse_error); return g_test_run (); } From f80c8d8be6a22accb71f06b33f53daed3d255bec Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 1 Dec 2020 22:59:32 +0100 Subject: [PATCH 501/675] broadband-modem-qmi: fix reporting of signal strength indications We had all the logic in place... but we were never actually enabling the signal strength indications because the `enable` flag in the context was never set. The bug was introduced back in May 2018, and released with 1.10.0. Fixes baefe53ab9c0ea0612d2bf7da64b6f6cf9753bcd --- src/mm-broadband-modem-qmi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index d61e4365..d5af5065 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -4909,6 +4909,7 @@ common_enable_disable_unsolicited_events (MMBroadbandModemQmi *self, } ctx = g_new0 (EnableUnsolicitedEventsContext, 1); + ctx->enable = enable; ctx->client = g_object_ref (client); g_task_set_task_data (task, ctx, (GDestroyNotify)enable_unsolicited_events_context_free); From 8072ed2d6f4240ceb7b66f5e618192fd54ea94b2 Mon Sep 17 00:00:00 2001 From: Torsten Hilbrich Date: Wed, 2 Dec 2020 12:46:32 +0100 Subject: [PATCH 502/675] broadband-modem-mbim: Add MM_BROADBAND_MODEM_MBIM_QMI_UNSUPPORTED This property (initially set to FALSE) controls whether QMI over MBIM should never be considered. This property is set to TRUE for XMM-based MBIM devices as they don't support QMI. This fixes a probing delay of 15s on a Fibocom L850-GL device (2cb7:0007) found in the Lenovo T14 Gen 1. The establishing of a QMI connection was refused multiple time with MBIM error OperationNotAllowed. Only the timeout of 15s for this connection resumed the probing. The properties in the MMBroadbandModemMbim are only installed when WITH_QMI and QMI_MBIM_QMUX_SUPPORTED are set. Actually, this should only disable the PROP_QMI_UNSUPPORTED but as this is the only property this avoids the "unused variable 'self'" warnings/errors when trying to compile set_property and get_property without QMI support. This can be changed once other properties are needed. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/284 --- plugins/xmm/mm-broadband-modem-mbim-xmm.c | 3 + src/mm-broadband-modem-mbim.c | 71 ++++++++++++++++++++++- src/mm-broadband-modem-mbim.h | 2 + 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/plugins/xmm/mm-broadband-modem-mbim-xmm.c b/plugins/xmm/mm-broadband-modem-mbim-xmm.c index 781d7e4f..4a6cd93d 100644 --- a/plugins/xmm/mm-broadband-modem-mbim-xmm.c +++ b/plugins/xmm/mm-broadband-modem-mbim-xmm.c @@ -56,6 +56,9 @@ mm_broadband_modem_mbim_xmm_new (const gchar *device, MM_IFACE_MODEM_SIM_HOT_SWAP_SUPPORTED, TRUE, MM_IFACE_MODEM_SIM_HOT_SWAP_CONFIGURED, FALSE, MM_IFACE_MODEM_PERIODIC_SIGNAL_CHECK_DISABLED, TRUE, +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED + MM_BROADBAND_MODEM_MBIM_QMI_UNSUPPORTED, TRUE, +#endif NULL); } diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index f18189b0..19f9dc78 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -86,6 +86,14 @@ typedef enum { PROCESS_NOTIFICATION_FLAG_LTE_ATTACH_STATUS = 1 << 8, } ProcessNotificationFlag; +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED +enum { + PROP_0, + PROP_QMI_UNSUPPORTED, + PROP_LAST +}; +#endif + struct _MMBroadbandModemMbimPrivate { /* Queried and cached capabilities */ MbimCellularClass caps_cellular_class; @@ -128,6 +136,7 @@ struct _MMBroadbandModemMbimPrivate { gulong mbim_device_removed_id; #if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED + gboolean qmi_unsupported; /* Flag when QMI-based capability/mode switching is in use */ gboolean qmi_capability_and_mode_switching; #endif @@ -2429,6 +2438,9 @@ initialization_started (MMBroadbandModem *self, { InitializationStartedContext *ctx; GTask *task; +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED + gboolean qmi_unsupported = FALSE; +#endif ctx = g_slice_new0 (InitializationStartedContext); ctx->mbim = mm_broadband_modem_mbim_get_port_mbim (MM_BROADBAND_MODEM_MBIM (self)); @@ -2454,10 +2466,16 @@ initialization_started (MMBroadbandModem *self, return; } +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED + g_object_get (self, + MM_BROADBAND_MODEM_MBIM_QMI_UNSUPPORTED, &qmi_unsupported, + NULL); +#endif + /* Now open our MBIM port */ mm_port_mbim_open (ctx->mbim, #if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED - TRUE, /* With QMI over MBIM support if available */ + ! qmi_unsupported, /* With QMI over MBIM support if available */ #endif NULL, (GAsyncReadyCallback)mbim_port_open_ready, @@ -5506,6 +5524,44 @@ messaging_create_sms (MMIfaceModemMessaging *self) /*****************************************************************************/ +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED +static void +set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MMBroadbandModemMbim *self = MM_BROADBAND_MODEM_MBIM (object); + + switch (prop_id) { + case PROP_QMI_UNSUPPORTED: + self->priv->qmi_unsupported = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MMBroadbandModemMbim *self = MM_BROADBAND_MODEM_MBIM (object); + + switch (prop_id) { + case PROP_QMI_UNSUPPORTED: + g_value_set_boolean (value, self->priv->qmi_unsupported); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} +#endif + MMBroadbandModemMbim * mm_broadband_modem_mbim_new (const gchar *device, const gchar **drivers, @@ -5835,6 +5891,10 @@ mm_broadband_modem_mbim_class_init (MMBroadbandModemMbimClass *klass) klass->peek_port_mbim_for_data = peek_port_mbim_for_data; +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED + object_class->set_property = set_property; + object_class->get_property = get_property; +#endif object_class->dispose = dispose; object_class->finalize = finalize; @@ -5845,4 +5905,13 @@ mm_broadband_modem_mbim_class_init (MMBroadbandModemMbimClass *klass) /* Do not initialize the MBIM modem through AT commands */ broadband_modem_class->enabling_modem_init = NULL; broadband_modem_class->enabling_modem_init_finish = NULL; + +#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED + g_object_class_install_property (object_class, PROP_QMI_UNSUPPORTED, + g_param_spec_boolean (MM_BROADBAND_MODEM_MBIM_QMI_UNSUPPORTED, + "QMI over MBIM unsupported", + "TRUE when QMI over MBIM should not be considered.", + FALSE, + G_PARAM_READWRITE)); +#endif } diff --git a/src/mm-broadband-modem-mbim.h b/src/mm-broadband-modem-mbim.h index 2d241fed..66a12f2a 100644 --- a/src/mm-broadband-modem-mbim.h +++ b/src/mm-broadband-modem-mbim.h @@ -29,6 +29,8 @@ typedef struct _MMBroadbandModemMbim MMBroadbandModemMbim; typedef struct _MMBroadbandModemMbimClass MMBroadbandModemMbimClass; typedef struct _MMBroadbandModemMbimPrivate MMBroadbandModemMbimPrivate; +#define MM_BROADBAND_MODEM_MBIM_QMI_UNSUPPORTED "broadband-modem-mbim-qmi-unsupported" + struct _MMBroadbandModemMbim { MMBroadbandModem parent; MMBroadbandModemMbimPrivate *priv; From bee8a391bf46e33f8378504f71c4e087d7a82fb5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 13 Dec 2020 17:33:11 +0100 Subject: [PATCH 503/675] broadband-modem-mbim: ignore MS SAR notifications explicitly SAR service will be introduced in the stable libmbim 1.26.0, but it's been flagged in the dev 1.25.1 version already. --- src/mm-broadband-modem-mbim.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 19f9dc78..765a267f 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -3608,6 +3608,9 @@ device_notification_cb (MbimDevice *device, case MBIM_SERVICE_QMI: case MBIM_SERVICE_ATDS: case MBIM_SERVICE_INTEL_FIRMWARE_UPDATE: +#if MBIM_CHECK_VERSION (1,25,1) + case MBIM_SERVICE_MS_SAR: +#endif default: /* Ignore */ break; From 067b09c8358ad92ff0ca3c266d0229e9518069d0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 14 Dec 2020 09:35:02 +0100 Subject: [PATCH 504/675] cinterion: add PLS83 port type hints --- plugins/cinterion/77-mm-cinterion-port-types.rules | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/cinterion/77-mm-cinterion-port-types.rules b/plugins/cinterion/77-mm-cinterion-port-types.rules index 51caf221..8916303c 100644 --- a/plugins/cinterion/77-mm-cinterion-port-types.rules +++ b/plugins/cinterion/77-mm-cinterion-port-types.rules @@ -46,4 +46,14 @@ ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="04", ENV{ ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1" +# PLS83 +# ttyACM0 (if #0): AT port +# ttyACM1 (if #2): AT port +# ttyACM2 (if #4): GPS data port +# ttyACM3 (if #6): DIAG/QCDM +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="006F", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="006F", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="006F", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_TYPE_GPS}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="006F", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_TYPE_QCDM}="1" + LABEL="mm_cinterion_port_types_end" From ba4b3f60b7605441bb127be231eab49450c29404 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 14 Dec 2020 09:58:15 +0100 Subject: [PATCH 505/675] cinterion: add QCDM and GPS port type hints for PLS62 --- .../77-mm-cinterion-port-types.rules | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/cinterion/77-mm-cinterion-port-types.rules b/plugins/cinterion/77-mm-cinterion-port-types.rules index 8916303c..5770c004 100644 --- a/plugins/cinterion/77-mm-cinterion-port-types.rules +++ b/plugins/cinterion/77-mm-cinterion-port-types.rules @@ -25,26 +25,26 @@ ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{ID_MM_CINTERION_MODEM_FAM # PLS62 family non-mbim enumeration # ttyACM0 (if #0): AT port # ttyACM1 (if #2): AT port -# ttyACM2 (if #4): can be AT or GNSS in some models, best left ignored -# ttyACM3 (if #6): unknown -# ttyACM4 (if #8): unknown +# ttyACM2 (if #4): can be AT or GNSS in some models +# ttyACM3 (if #6): AT port (but just ignore) +# ttyACM4 (if #8): DIAG/QCDM ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" -ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_IGNORE}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_TYPE_GPS}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1" -ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005b", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_TYPE_QCDM}="1" # PLS62 family mbim enumeration # ttyACM0 (if #0): AT port # ttyACM1 (if #2): AT port -# ttyACM2 (if #4): can be AT or GNSS in some models, best left ignored -# ttyACM3 (if #6): unknown -# ttyACM4 (if #8): unknown +# ttyACM2 (if #4): can be AT or GNSS in some models +# ttyACM3 (if #6): AT port (but just ignore) +# ttyACM4 (if #8): DIAG/QCDM ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" -ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_IGNORE}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_TYPE_GPS}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1" -ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="005d", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_TYPE_QCDM}="1" # PLS83 # ttyACM0 (if #0): AT port From 243272c11178e68914d7cc2dcfdc28248edb2aa7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 14 Dec 2020 09:58:59 +0100 Subject: [PATCH 506/675] cinterion: add AT primary/secondary port type hints for PLS8 --- plugins/cinterion/77-mm-cinterion-port-types.rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/cinterion/77-mm-cinterion-port-types.rules b/plugins/cinterion/77-mm-cinterion-port-types.rules index 5770c004..f9324053 100644 --- a/plugins/cinterion/77-mm-cinterion-port-types.rules +++ b/plugins/cinterion/77-mm-cinterion-port-types.rules @@ -16,6 +16,8 @@ ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="0053", ENV{.MM_USBIFNUM}=="01", ENV{ # ttyACM2 (if #4): GPS data port # ttyACM3 (if #6): unknown # ttyACM4 (if #8): unknown +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="0061", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="0061", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_TYPE_AT_SECONDARY}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="0061", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_TYPE_GPS}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="0061", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1" ATTRS{idVendor}=="1e2d", ATTRS{idProduct}=="0061", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1" From 7f88280929c350b087751e71e56e81b9b88d3495 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 22 Nov 2020 16:55:22 +0100 Subject: [PATCH 507/675] altair: make sure parse_vendor_pco_info() always returns an error The parse_vendor_pco_info() method was returning NULL without error if the pco info string was empty. Under this situation, the code would have tried to add a NULL MMPco into the pco_list list, which is not desired. Avoid this, by making sure a NULL return always sets an error. --- plugins/altair/mm-broadband-modem-altair-lte.c | 6 +++++- plugins/altair/mm-modem-helpers-altair-lte.c | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/altair/mm-broadband-modem-altair-lte.c b/plugins/altair/mm-broadband-modem-altair-lte.c index 9e555f5b..d26335f7 100644 --- a/plugins/altair/mm-broadband-modem-altair-lte.c +++ b/plugins/altair/mm-broadband-modem-altair-lte.c @@ -1105,9 +1105,13 @@ altair_pco_info_changed (MMPortSerialAt *port, pco_info = g_match_info_fetch (match_info, 0); + /* ignore if empty */ + if (!pco_info || !pco_info[0]) + return; + mm_obj_dbg (self, "parsing vendor PCO info: %s", pco_info); pco = mm_altair_parse_vendor_pco_info (pco_info, &error); - if (error) { + if (!pco) { mm_obj_warn (self, "error parsing vendor PCO info: %s", error->message); return; } diff --git a/plugins/altair/mm-modem-helpers-altair-lte.c b/plugins/altair/mm-modem-helpers-altair-lte.c index d1b2aa5c..278f31e8 100644 --- a/plugins/altair/mm-modem-helpers-altair-lte.c +++ b/plugins/altair/mm-modem-helpers-altair-lte.c @@ -140,9 +140,11 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error) MMPco *pco = NULL; gint num_matches; - if (!pco_info[0]) - /* No APNs configured, all done */ + if (!pco_info || !pco_info[0]) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "No PCO info given"); return NULL; + } /* Expected %PCOINFO response: * From 0729ba5c88eb038e60ffbe3faf9431e9650f7ca1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 26 Nov 2020 23:30:56 +0100 Subject: [PATCH 508/675] broadband-modem-mbim: plug memleak when processing USSD in GSM7 --- src/mm-broadband-modem-mbim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 765a267f..a3633120 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4812,8 +4812,8 @@ ussd_decode (guint32 scheme, gchar *decoded = NULL; if (scheme == MM_MODEM_GSM_USSD_SCHEME_7BIT) { - guint8 *unpacked; - guint32 unpacked_len; + g_autofree guint8 *unpacked = NULL; + guint32 unpacked_len; unpacked = mm_charset_gsm_unpack ((const guint8 *)data->data, (data->len * 8) / 7, 0, &unpacked_len); decoded = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len); From 7b52efda3421f09ddb5dd4ae65d3d03b7e952490 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 30 Nov 2020 10:35:32 +0100 Subject: [PATCH 509/675] build: require libqmi 1.27.3 to support initial EPS management --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 032c4c4c..c96e4b76 100644 --- a/configure.ac +++ b/configure.ac @@ -401,7 +401,7 @@ dnl----------------------------------------------------------------------------- dnl QMI support (enabled by default) dnl -LIBQMI_VERSION=1.27.2 +LIBQMI_VERSION=1.27.3 AC_ARG_WITH(qmi, AS_HELP_STRING([--without-qmi], [Build without QMI support]), [], [with_qmi=yes]) AM_CONDITIONAL(WITH_QMI, test "x$with_qmi" = "xyes") From 295400688acc4d670a1f7c58d45359bb891bf44d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Nov 2020 21:55:48 +0100 Subject: [PATCH 510/675] broadband-modem-qmi: allocate a generic WDS client For generic WDS operations not tied to any connection attempt. --- src/mm-broadband-modem-qmi.c | 79 +++++++----------------------------- 1 file changed, 15 insertions(+), 64 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index d5af5065..f544bc48 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -8926,22 +8926,6 @@ signal_load_values (MMIfaceModemSignal *self, /*****************************************************************************/ /* First enabling step */ -typedef struct { - MMPortQmi *qmi; - QmiClientWds *wds; -} EnablingStartedContext; - -static void -enabling_started_context_free (EnablingStartedContext *ctx) -{ - if (ctx->wds) { - mm_port_qmi_release_client (ctx->qmi, QMI_SERVICE_WDS, MM_PORT_QMI_FLAG_DEFAULT); - g_clear_object (&ctx->wds); - } - g_clear_object (&ctx->qmi); - g_slice_free (EnablingStartedContext, ctx); -} - static gboolean enabling_started_finish (MMBroadbandModem *self, GAsyncResult *res, @@ -9011,45 +8995,13 @@ wds_get_autoconnect_settings_ready (QmiClientWds *client, task); } -static void -enabling_wds_client_ready (MMPortQmi *qmi, - GAsyncResult *res, - GTask *task) -{ - MMBroadbandModemQmi *self; - EnablingStartedContext *ctx; - g_autoptr(GError) error = NULL; - - self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); - - if (!mm_port_qmi_allocate_client_finish (qmi, res, &error)) { - mm_obj_warn (self, "cannot check whether autoconnect is disabled or not: " - "couldn't allocate client for WDS service: %s", error->message); - g_task_return_boolean (task, TRUE); - g_object_unref (task); - return; - } - - ctx->wds = QMI_CLIENT_WDS (mm_port_qmi_get_client (ctx->qmi, - QMI_SERVICE_WDS, - MM_PORT_QMI_FLAG_DEFAULT)); - - qmi_client_wds_get_autoconnect_settings (ctx->wds, - NULL, - 5, - NULL, - (GAsyncReadyCallback) wds_get_autoconnect_settings_ready, - task); -} - static void parent_enabling_started_ready (MMBroadbandModem *_self, GAsyncResult *res, GTask *task) { MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); - EnablingStartedContext *ctx; + QmiClient *client = NULL; g_autoptr(GError) error = NULL; if (!MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_qmi_parent_class)->enabling_started_finish (_self, res, &error)) { @@ -9070,28 +9022,26 @@ parent_enabling_started_ready (MMBroadbandModem *_self, mm_obj_dbg (self, "need to check whether autoconnect is disabled or not..."); self->priv->autoconnect_checked = TRUE; - /* Setup context */ - ctx = g_slice_new0 (EnablingStartedContext); - g_task_set_task_data (task, ctx, (GDestroyNotify)enabling_started_context_free); + /* Use default WDS client to query autoconnect settings */ + client = mm_shared_qmi_peek_client (MM_SHARED_QMI (self), + QMI_SERVICE_WDS, + MM_PORT_QMI_FLAG_DEFAULT, + NULL); - /* Keep a full port reference around */ - ctx->qmi = mm_broadband_modem_qmi_get_port_qmi (MM_BROADBAND_MODEM_QMI (self)); - if (!ctx->qmi) { - mm_obj_warn (self, "cannot check whether autoconnect is disabled or not: couldn't peek QMI port"); + if (!client) { + mm_obj_warn (self, "cannot check whether autoconnect is disabled or not: couldn't peek default WDS client"); /* not fatal, just assume autoconnect is disabled */ g_task_return_boolean (task, TRUE); g_object_unref (task); return; } - /* By default there is no generic WDS client preallocated in the QMI port, - * so explicitly allocate one ourselves */ - mm_port_qmi_allocate_client (ctx->qmi, - QMI_SERVICE_WDS, - MM_PORT_QMI_FLAG_DEFAULT, - NULL, - (GAsyncReadyCallback)enabling_wds_client_ready, - task); + qmi_client_wds_get_autoconnect_settings (QMI_CLIENT_WDS (client), + NULL, + 5, + NULL, + (GAsyncReadyCallback) wds_get_autoconnect_settings_ready, + task); } static void @@ -9115,6 +9065,7 @@ enabling_started (MMBroadbandModem *self, static const QmiService qmi_services[] = { QMI_SERVICE_DMS, QMI_SERVICE_NAS, + QMI_SERVICE_WDS, QMI_SERVICE_WMS, QMI_SERVICE_PDS, QMI_SERVICE_OMA, From 527b4e3232a611bde1cab6e6302924fb65f453a7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Nov 2020 22:08:04 +0100 Subject: [PATCH 511/675] broadband-modem-qmi: implement initial EPS bearer info loading --- src/mm-broadband-modem-qmi.c | 75 ++++++++++++++++++++++++++++++++++++ src/mm-modem-helpers-qmi.c | 15 ++++++++ src/mm-modem-helpers-qmi.h | 1 + 3 files changed, 91 insertions(+) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index f544bc48..1dff318c 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -7645,6 +7645,79 @@ modem_3gpp_ussd_cancel (MMIfaceModem3gppUssd *_self, task); } +/*****************************************************************************/ +/* Initial EPS bearer info loading */ + +static MMBearerProperties * +modem_3gpp_load_initial_eps_bearer_finish (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error) +{ + return MM_BEARER_PROPERTIES (g_task_propagate_pointer (G_TASK (res), error)); +} + +static void +get_lte_attach_parameters_ready (QmiClientWds *client, + GAsyncResult *res, + GTask *task) +{ + g_autoptr(QmiMessageWdsGetLteAttachParametersOutput) output = NULL; + GError *error = NULL; + MMBearerProperties *properties; + const gchar *apn; + QmiWdsIpSupportType ip_support_type; + + output = qmi_client_wds_get_lte_attach_parameters_finish (client, res, &error); + if (!output) { + g_prefix_error (&error, "QMI operation failed: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + if (!qmi_message_wds_get_lte_attach_parameters_output_get_result (output, &error)) { + g_prefix_error (&error, "Couldn't get LTE attach parameters: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + properties = mm_bearer_properties_new (); + if (qmi_message_wds_get_lte_attach_parameters_output_get_apn (output, &apn, NULL)) + mm_bearer_properties_set_apn (properties, apn); + if (qmi_message_wds_get_lte_attach_parameters_output_get_ip_support_type (output, &ip_support_type, NULL)) { + MMBearerIpFamily ip_family; + + ip_family = mm_bearer_ip_family_from_qmi_ip_support_type (ip_support_type); + if (ip_family != MM_BEARER_IP_FAMILY_NONE) + mm_bearer_properties_set_ip_type (properties, ip_family); + } + g_task_return_pointer (task, properties, g_object_unref); + g_object_unref (task); +} + +static void +modem_3gpp_load_initial_eps_bearer (MMIfaceModem3gpp *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + QmiClient *client; + + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_WDS, &client, + callback, user_data)) + return; + + task = g_task_new (self, NULL, callback, user_data); + qmi_client_wds_get_lte_attach_parameters (QMI_CLIENT_WDS (client), + NULL, + 10, + NULL, + (GAsyncReadyCallback) get_lte_attach_parameters_ready, + task); +} + /*****************************************************************************/ /* Check firmware support (Firmware interface) */ @@ -9537,6 +9610,8 @@ iface_modem_3gpp_init (MMIfaceModem3gpp *iface) iface->load_operator_code_finish = modem_3gpp_load_operator_code_finish; iface->load_operator_name = modem_3gpp_load_operator_name; iface->load_operator_name_finish = modem_3gpp_load_operator_name_finish; + iface->load_initial_eps_bearer = modem_3gpp_load_initial_eps_bearer; + iface->load_initial_eps_bearer_finish = modem_3gpp_load_initial_eps_bearer_finish; } static void diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 584d0618..e7f93914 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1472,6 +1472,21 @@ mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth) return out; } +MMBearerIpFamily +mm_bearer_ip_family_from_qmi_ip_support_type (QmiWdsIpSupportType ip_support_type) +{ + switch (ip_support_type) { + case QMI_WDS_IP_SUPPORT_TYPE_IPV4: + return MM_BEARER_IP_FAMILY_IPV4; + case QMI_WDS_IP_SUPPORT_TYPE_IPV6: + return MM_BEARER_IP_FAMILY_IPV6; + case QMI_WDS_IP_SUPPORT_TYPE_IPV4V6: + return MM_BEARER_IP_FAMILY_IPV4V6; + default: + return MM_BEARER_IP_FAMILY_NONE; + } +} + /*****************************************************************************/ /** diff --git a/src/mm-modem-helpers-qmi.h b/src/mm-modem-helpers-qmi.h index 9d69e99a..a7d835b6 100644 --- a/src/mm-modem-helpers-qmi.h +++ b/src/mm-modem-helpers-qmi.h @@ -114,6 +114,7 @@ MMSmsState mm_sms_state_from_qmi_message_tag (QmiWmsMessageTagType tag); /* QMI/WDS to MM translations */ QmiWdsAuthentication mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth); +MMBearerIpFamily mm_bearer_ip_family_from_qmi_ip_support_type (QmiWdsIpSupportType ip_support_type); /*****************************************************************************/ /* QMI/OMA to MM translations */ From 5613215db8e5b3d4bbd7d3e6ad937b342ccd4c76 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 29 Nov 2020 22:41:08 +0100 Subject: [PATCH 512/675] broadband-modem-qmi: implement initial EPS bearer settings loading and setting --- src/mm-broadband-modem-qmi.c | 469 +++++++++++++++++++++++++++++++++++ src/mm-modem-helpers-qmi.c | 51 ++++ src/mm-modem-helpers-qmi.h | 8 +- 3 files changed, 526 insertions(+), 2 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 1dff318c..1d3d02c4 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -97,6 +97,9 @@ struct _MMBroadbandModemQmiPrivate { * the device enabling */ gboolean autoconnect_checked; + /* Index of the WDS profile used as initial EPS bearer */ + guint16 default_attach_pdn; + /* 3GPP/CDMA registration helpers */ gchar *current_operator_id; gchar *current_operator_description; @@ -7718,6 +7721,468 @@ modem_3gpp_load_initial_eps_bearer (MMIfaceModem3gpp *self, task); } +/*****************************************************************************/ +/* Initial EPS bearer settings setting */ + +typedef enum { + SET_INITIAL_EPS_BEARER_SETTINGS_STEP_FIRST, + SET_INITIAL_EPS_BEARER_SETTINGS_STEP_LOAD_POWER_STATE, + SET_INITIAL_EPS_BEARER_SETTINGS_STEP_POWER_DOWN, + SET_INITIAL_EPS_BEARER_SETTINGS_STEP_MODIFY_PROFILE, + SET_INITIAL_EPS_BEARER_SETTINGS_STEP_POWER_UP, + SET_INITIAL_EPS_BEARER_SETTINGS_STEP_LAST_SETTING, +} SetInitialEpsBearerSettingsStep; + +typedef struct { + SetInitialEpsBearerSettingsStep step; + QmiClientWds *client; + MMBearerProperties *settings; + MMModemPowerState power_state; +} SetInitialEpsBearerSettingsContext; + +static void +set_initial_eps_bearer_settings_context_free (SetInitialEpsBearerSettingsContext *ctx) +{ + g_clear_object (&ctx->client); + g_clear_object (&ctx->settings); + g_slice_free (SetInitialEpsBearerSettingsContext, ctx); +} + +static gboolean +modem_3gpp_set_initial_eps_bearer_settings_finish (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void set_initial_eps_bearer_settings_step (GTask *task); + +static void +set_initial_eps_bearer_power_up_ready (MMIfaceModem *self, + GAsyncResult *res, + GTask *task) +{ + SetInitialEpsBearerSettingsContext *ctx; + GError *error = NULL; + + ctx = g_task_get_task_data (task); + + if (!modem_power_up_down_off_finish (self, res, &error)) { + g_prefix_error (&error, "Couldn't power up modem: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + ctx->step++; + set_initial_eps_bearer_settings_step (task); +} + +static void +set_initial_eps_bearer_modify_profile_ready (QmiClientWds *client, + GAsyncResult *res, + GTask *task) +{ + g_autoptr(QmiMessageWdsModifyProfileOutput) output = NULL; + GError *error = NULL; + SetInitialEpsBearerSettingsContext *ctx; + + ctx = g_task_get_task_data (task); + + output = qmi_client_wds_modify_profile_finish (client, res, &error); + if (!output) { + g_prefix_error (&error, "QMI operation failed: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + if (!qmi_message_wds_modify_profile_output_get_result (output, &error)) { + QmiWdsDsProfileError ds_profile_error; + + if (g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) && + qmi_message_wds_modify_profile_output_get_extended_error_code (output, &ds_profile_error, NULL)) { + g_prefix_error (&error, "DS profile error: %s: ", + qmi_wds_ds_profile_error_get_string (ds_profile_error)); + } + g_prefix_error (&error, "Couldn't modify default LTE attach PDN settings: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + ctx->step++; + set_initial_eps_bearer_settings_step (task); +} + +static void +set_initial_eps_bearer_modify_profile (GTask *task) +{ + g_autoptr(QmiMessageWdsModifyProfileInput) input = NULL; + MMBroadbandModemQmi *self; + SetInitialEpsBearerSettingsContext *ctx; + const gchar *str; + MMBearerIpFamily ip_family; + QmiWdsPdpType pdp_type; + MMBearerAllowedAuth allowed_auth; + QmiWdsAuthentication auth; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + + input = qmi_message_wds_modify_profile_input_new (); + qmi_message_wds_modify_profile_input_set_profile_identifier (input, + QMI_WDS_PROFILE_TYPE_3GPP, + self->priv->default_attach_pdn, + NULL); + + str = mm_bearer_properties_get_apn (ctx->settings); + qmi_message_wds_modify_profile_input_set_apn_name (input, str ? str : "", NULL); + + ip_family = mm_bearer_properties_get_ip_type (ctx->settings); + if (ip_family == MM_BEARER_IP_FAMILY_NONE || ip_family == MM_BEARER_IP_FAMILY_ANY) + ip_family = MM_BEARER_IP_FAMILY_IPV4; + if (mm_bearer_ip_family_to_qmi_pdp_type (ip_family, &pdp_type)) + qmi_message_wds_modify_profile_input_set_pdp_type (input, pdp_type, NULL); + + allowed_auth = mm_bearer_properties_get_allowed_auth (ctx->settings); + if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) + allowed_auth = MM_BEARER_ALLOWED_AUTH_NONE; + auth = mm_bearer_allowed_auth_to_qmi_authentication (allowed_auth); + qmi_message_wds_modify_profile_input_set_authentication (input, auth, NULL); + + str = mm_bearer_properties_get_user (ctx->settings); + qmi_message_wds_modify_profile_input_set_username (input, str ? str : "", NULL); + + str = mm_bearer_properties_get_password (ctx->settings); + qmi_message_wds_modify_profile_input_set_password (input, str ? str : "", NULL); + + qmi_client_wds_modify_profile (ctx->client, + input, + 10, + NULL, + (GAsyncReadyCallback)set_initial_eps_bearer_modify_profile_ready, + task); +} + +static void +set_initial_eps_bearer_power_down_ready (MMIfaceModem *self, + GAsyncResult *res, + GTask *task) +{ + SetInitialEpsBearerSettingsContext *ctx; + GError *error = NULL; + + ctx = g_task_get_task_data (task); + + if (!modem_power_up_down_off_finish (self, res, &error)) { + g_prefix_error (&error, "Couldn't power down modem: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + ctx->step++; + set_initial_eps_bearer_settings_step (task); +} + +static void +set_initial_eps_bearer_load_power_state_ready (MMIfaceModem *self, + GAsyncResult *res, + GTask *task) +{ + SetInitialEpsBearerSettingsContext *ctx; + GError *error = NULL; + + ctx = g_task_get_task_data (task); + + ctx->power_state = load_power_state_finish (self, res, &error); + if (ctx->power_state == MM_MODEM_POWER_STATE_UNKNOWN) { + g_prefix_error (&error, "Couldn't load power state: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + ctx->step++; + set_initial_eps_bearer_settings_step (task); +} + +static void +set_initial_eps_bearer_settings_step (GTask *task) +{ + SetInitialEpsBearerSettingsContext *ctx; + MMBroadbandModemQmi *self; + + self = g_task_get_source_object (task); + ctx = g_task_get_task_data (task); + + switch (ctx->step) { + case SET_INITIAL_EPS_BEARER_SETTINGS_STEP_FIRST: + ctx->step++; + /* fall through */ + + case SET_INITIAL_EPS_BEARER_SETTINGS_STEP_LOAD_POWER_STATE: + mm_obj_dbg (self, "querying current power state..."); + load_power_state (MM_IFACE_MODEM (self), + (GAsyncReadyCallback) set_initial_eps_bearer_load_power_state_ready, + task); + return; + + case SET_INITIAL_EPS_BEARER_SETTINGS_STEP_POWER_DOWN: + if (ctx->power_state == MM_MODEM_POWER_STATE_ON) { + mm_obj_dbg (self, "powering down before changing initial EPS bearer settings..."); + modem_power_down (MM_IFACE_MODEM (self), + (GAsyncReadyCallback) set_initial_eps_bearer_power_down_ready, + task); + return; + } + ctx->step++; + /* fall through */ + + case SET_INITIAL_EPS_BEARER_SETTINGS_STEP_MODIFY_PROFILE: + mm_obj_dbg (self, "modifying initial EPS bearer settings profile..."); + set_initial_eps_bearer_modify_profile (task); + return; + + case SET_INITIAL_EPS_BEARER_SETTINGS_STEP_POWER_UP: + if (ctx->power_state == MM_MODEM_POWER_STATE_ON) { + mm_obj_dbg (self, "powering up after changing initial EPS bearer settings..."); + modem_power_up (MM_IFACE_MODEM (self), + (GAsyncReadyCallback) set_initial_eps_bearer_power_up_ready, + task); + return; + } + ctx->step++; + /* fall through */ + + case SET_INITIAL_EPS_BEARER_SETTINGS_STEP_LAST_SETTING: + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + default: + g_assert_not_reached (); + } +} + +static void +modem_3gpp_set_initial_eps_bearer_settings (MMIfaceModem3gpp *_self, + MMBearerProperties *config, + GAsyncReadyCallback callback, + gpointer user_data) +{ + MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); + SetInitialEpsBearerSettingsContext *ctx; + GTask *task; + QmiClient *client; + + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_WDS, &client, + callback, user_data)) + return; + + task = g_task_new (self, NULL, callback, user_data); + + if (!self->priv->default_attach_pdn) { + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Unknown default LTE attach APN index"); + g_object_unref (task); + return; + } + + ctx = g_slice_new0 (SetInitialEpsBearerSettingsContext); + ctx->settings = g_object_ref (config);; + ctx->client = QMI_CLIENT_WDS (g_object_ref (client)); + ctx->step = SET_INITIAL_EPS_BEARER_SETTINGS_STEP_FIRST; + g_task_set_task_data (task, ctx, (GDestroyNotify) set_initial_eps_bearer_settings_context_free); + + set_initial_eps_bearer_settings_step (task); +} + +/*****************************************************************************/ +/* Initial EPS bearer settings loading */ + +static MMBearerProperties * +modem_3gpp_load_initial_eps_bearer_settings_finish (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error) +{ + return MM_BEARER_PROPERTIES (g_task_propagate_pointer (G_TASK (res), error)); +} + +static void +load_initial_eps_bearer_get_profile_settings_ready (QmiClientWds *client, + GAsyncResult *res, + GTask *task) +{ + g_autoptr(QmiMessageWdsGetProfileSettingsOutput) output = NULL; + GError *error = NULL; + const gchar *str; + QmiWdsPdpType pdp_type; + QmiWdsAuthentication auth; + gboolean flag; + MMBearerProperties *properties; + + output = qmi_client_wds_get_profile_settings_finish (client, res, &error); + if (!output) { + g_prefix_error (&error, "QMI operation failed: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + if (!qmi_message_wds_get_profile_settings_output_get_result (output, &error)) { + QmiWdsDsProfileError ds_profile_error; + + if (g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) && + qmi_message_wds_get_profile_settings_output_get_extended_error_code (output, &ds_profile_error, NULL)) { + g_prefix_error (&error, "DS profile error: %s: ", + qmi_wds_ds_profile_error_get_string (ds_profile_error)); + } + g_prefix_error (&error, "Couldn't get default LTE attach PDN settings: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + properties = mm_bearer_properties_new (); + if (qmi_message_wds_get_profile_settings_output_get_apn_name (output, &str, NULL)) + mm_bearer_properties_set_apn (properties, str); + + if (qmi_message_wds_get_profile_settings_output_get_pdp_type (output, &pdp_type, NULL)) { + MMBearerIpFamily ip_family; + + ip_family = mm_bearer_ip_family_from_qmi_pdp_type (pdp_type); + if (ip_family != MM_BEARER_IP_FAMILY_NONE) + mm_bearer_properties_set_ip_type (properties, ip_family); + } + + if (qmi_message_wds_get_profile_settings_output_get_username (output, &str, NULL)) + mm_bearer_properties_set_user (properties, str); + + if (qmi_message_wds_get_profile_settings_output_get_password (output, &str, NULL)) + mm_bearer_properties_set_password (properties, str); + + if (qmi_message_wds_get_profile_settings_output_get_authentication (output, &auth, NULL)) { + MMBearerAllowedAuth allowed_auth; + + allowed_auth = mm_bearer_allowed_auth_from_qmi_authentication (auth); + if (allowed_auth != MM_BEARER_ALLOWED_AUTH_UNKNOWN) + mm_bearer_properties_set_allowed_auth (properties, allowed_auth); + } + + if (qmi_message_wds_get_profile_settings_output_get_roaming_disallowed_flag (output, &flag, NULL)) + mm_bearer_properties_set_allow_roaming (properties, !flag); + + g_task_return_pointer (task, properties, g_object_unref); + g_object_unref (task); +} + +static void +load_initial_eps_bearer_get_profile_settings (GTask *task, + QmiClientWds *client) +{ + g_autoptr(QmiMessageWdsGetProfileSettingsInput) input = NULL; + MMBroadbandModemQmi *self; + + self = g_task_get_source_object (task); + g_assert (self->priv->default_attach_pdn); + + input = qmi_message_wds_get_profile_settings_input_new (); + qmi_message_wds_get_profile_settings_input_set_profile_id (input, + QMI_WDS_PROFILE_TYPE_3GPP, + self->priv->default_attach_pdn, + NULL); + mm_obj_dbg (self, "querying LTE attach PDN settings at index %u...", self->priv->default_attach_pdn); + qmi_client_wds_get_profile_settings (client, + input, + 10, + NULL, + (GAsyncReadyCallback)load_initial_eps_bearer_get_profile_settings_ready, + task); +} + +static void +load_initial_eps_bearer_get_lte_attach_pdn_list_ready (QmiClientWds *client, + GAsyncResult *res, + GTask *task) +{ + g_autoptr(QmiMessageWdsGetLteAttachPdnListOutput) output = NULL; + MMBroadbandModemQmi *self; + GError *error = NULL; + GArray *current_list = NULL; + guint i; + + self = g_task_get_source_object (task); + + output = qmi_client_wds_get_lte_attach_pdn_list_finish (client, res, &error); + if (!output) { + g_prefix_error (&error, "QMI operation failed: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + if (!qmi_message_wds_get_lte_attach_pdn_list_output_get_result (output, &error)) { + g_prefix_error (&error, "Couldn't get LTE attach PDN list: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + qmi_message_wds_get_lte_attach_pdn_list_output_get_current_list (output, ¤t_list, NULL); + if (!current_list || !current_list->len) { + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Undefined list of LTE attach PDN"); + g_object_unref (task); + return; + } + + mm_obj_dbg (self, "Found %u LTE attach PDNs defined", current_list->len); + for (i = 0; i < current_list->len; i++) { + if (i == 0) { + self->priv->default_attach_pdn = g_array_index (current_list, guint16, i); + mm_obj_dbg (self, "Default LTE attach PDN profile: %u", self->priv->default_attach_pdn); + } else + mm_obj_dbg (self, "Additional LTE attach PDN profile: %u", g_array_index (current_list, guint16, i)); + } + + load_initial_eps_bearer_get_profile_settings (task, client); +} + +static void +modem_3gpp_load_initial_eps_bearer_settings (MMIfaceModem3gpp *_self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + MMBroadbandModemQmi *self = MM_BROADBAND_MODEM_QMI (_self); + QmiClient *client; + GTask *task; + + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_WDS, &client, + callback, user_data)) + return; + + task = g_task_new (self, NULL, callback, user_data); + + /* Default attach PDN is assumed to never change during runtime + * (we don't change it) so just load it the first time */ + if (!self->priv->default_attach_pdn) { + mm_obj_dbg (self, "querying LTE attach PDN list..."); + qmi_client_wds_get_lte_attach_pdn_list (QMI_CLIENT_WDS (client), + NULL, + 10, + NULL, + (GAsyncReadyCallback)load_initial_eps_bearer_get_lte_attach_pdn_list_ready, + task); + return; + } + + load_initial_eps_bearer_get_profile_settings (task, QMI_CLIENT_WDS (client)); +} + /*****************************************************************************/ /* Check firmware support (Firmware interface) */ @@ -9612,6 +10077,10 @@ iface_modem_3gpp_init (MMIfaceModem3gpp *iface) iface->load_operator_name_finish = modem_3gpp_load_operator_name_finish; iface->load_initial_eps_bearer = modem_3gpp_load_initial_eps_bearer; iface->load_initial_eps_bearer_finish = modem_3gpp_load_initial_eps_bearer_finish; + iface->load_initial_eps_bearer_settings = modem_3gpp_load_initial_eps_bearer_settings; + iface->load_initial_eps_bearer_settings_finish = modem_3gpp_load_initial_eps_bearer_settings_finish; + iface->set_initial_eps_bearer_settings = modem_3gpp_set_initial_eps_bearer_settings; + iface->set_initial_eps_bearer_settings_finish = modem_3gpp_set_initial_eps_bearer_settings_finish; } static void diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index e7f93914..8d0e4b88 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1472,6 +1472,19 @@ mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth) return out; } +MMBearerAllowedAuth +mm_bearer_allowed_auth_from_qmi_authentication (QmiWdsAuthentication auth) +{ + MMBearerAllowedAuth out = 0; + + if (auth & QMI_WDS_AUTHENTICATION_PAP) + out |= MM_BEARER_ALLOWED_AUTH_PAP; + if (auth & QMI_WDS_AUTHENTICATION_CHAP) + out |= MM_BEARER_ALLOWED_AUTH_CHAP; + + return out; +} + MMBearerIpFamily mm_bearer_ip_family_from_qmi_ip_support_type (QmiWdsIpSupportType ip_support_type) { @@ -1487,6 +1500,44 @@ mm_bearer_ip_family_from_qmi_ip_support_type (QmiWdsIpSupportType ip_support_typ } } +MMBearerIpFamily +mm_bearer_ip_family_from_qmi_pdp_type (QmiWdsPdpType pdp_type) +{ + switch (pdp_type) { + case QMI_WDS_PDP_TYPE_IPV4: + return MM_BEARER_IP_FAMILY_IPV4; + case QMI_WDS_PDP_TYPE_IPV6: + return MM_BEARER_IP_FAMILY_IPV6; + case QMI_WDS_PDP_TYPE_IPV4_OR_IPV6: + return MM_BEARER_IP_FAMILY_IPV4V6; + case QMI_WDS_PDP_TYPE_PPP: + default: + return MM_BEARER_IP_FAMILY_NONE; + } +} + +gboolean +mm_bearer_ip_family_to_qmi_pdp_type (MMBearerIpFamily ip_family, + QmiWdsPdpType *out_pdp_type) +{ + switch (ip_family) { + case MM_BEARER_IP_FAMILY_IPV4: + *out_pdp_type = QMI_WDS_PDP_TYPE_IPV4; + return TRUE; + case MM_BEARER_IP_FAMILY_IPV6: + *out_pdp_type = QMI_WDS_PDP_TYPE_IPV6; + return TRUE; + case MM_BEARER_IP_FAMILY_IPV4V6: + *out_pdp_type = QMI_WDS_PDP_TYPE_IPV4_OR_IPV6; + return TRUE; + case MM_BEARER_IP_FAMILY_NONE: + case MM_BEARER_IP_FAMILY_ANY: + default: + /* there is no valid conversion, so just return FALSE to indicate it */ + return FALSE; + } +} + /*****************************************************************************/ /** diff --git a/src/mm-modem-helpers-qmi.h b/src/mm-modem-helpers-qmi.h index a7d835b6..829ac76e 100644 --- a/src/mm-modem-helpers-qmi.h +++ b/src/mm-modem-helpers-qmi.h @@ -113,8 +113,12 @@ MMSmsState mm_sms_state_from_qmi_message_tag (QmiWmsMessageTagType tag); /*****************************************************************************/ /* QMI/WDS to MM translations */ -QmiWdsAuthentication mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth); -MMBearerIpFamily mm_bearer_ip_family_from_qmi_ip_support_type (QmiWdsIpSupportType ip_support_type); +QmiWdsAuthentication mm_bearer_allowed_auth_to_qmi_authentication (MMBearerAllowedAuth auth); +MMBearerAllowedAuth mm_bearer_allowed_auth_from_qmi_authentication (QmiWdsAuthentication auth); +MMBearerIpFamily mm_bearer_ip_family_from_qmi_ip_support_type (QmiWdsIpSupportType ip_support_type); +MMBearerIpFamily mm_bearer_ip_family_from_qmi_pdp_type (QmiWdsPdpType pdp_type); +gboolean mm_bearer_ip_family_to_qmi_pdp_type (MMBearerIpFamily ip_family, + QmiWdsPdpType *out_pdp_type); /*****************************************************************************/ /* QMI/OMA to MM translations */ From c99cc9210e7a93be1b572d686f5acdeb0160dd3f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 30 Nov 2020 16:05:52 +0100 Subject: [PATCH 513/675] iface-modem-3gpp: log requested/updates initial EPS bearer settings --- src/mm-iface-modem-3gpp.c | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index b933064e..df8df272 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -972,6 +972,45 @@ handle_set_initial_eps_bearer_settings_context_free (HandleSetInitialEpsBearerSe g_slice_free (HandleSetInitialEpsBearerSettingsContext, ctx); } +static void +log_initial_eps_bearer_settings (MMIfaceModem3gpp *self, + MMBearerProperties *properties) +{ + const gchar *apn; + MMBearerAllowedAuth allowed_auth; + const gchar *user; + const gchar *password; + MMBearerIpFamily ip_family; + + apn = mm_bearer_properties_get_apn (properties); + if (apn) + mm_obj_dbg (self, " APN: '%s'", apn); + + allowed_auth = mm_bearer_properties_get_allowed_auth (properties); + if (allowed_auth != MM_BEARER_ALLOWED_AUTH_UNKNOWN) { + g_autofree gchar *allowed_auth_str = NULL; + + allowed_auth_str = mm_bearer_allowed_auth_build_string_from_mask (allowed_auth); + mm_obj_dbg (self, " allowed auth: '%s'", allowed_auth_str); + } + + user = mm_bearer_properties_get_user (properties); + if (user) + mm_obj_dbg (self, " user: '%s'", user); + + password = mm_bearer_properties_get_password (properties); + if (password) + mm_obj_dbg (self, " password: '%s'", password); + + ip_family = mm_bearer_properties_get_ip_type (properties); + if (ip_family != MM_BEARER_IP_FAMILY_NONE) { + g_autofree gchar *ip_family_str = NULL; + + ip_family_str = mm_bearer_ip_family_build_string_from_mask (ip_family); + mm_obj_dbg (self, " ip family: '%s'", ip_family_str); + } +} + static void after_set_load_initial_eps_bearer_settings_ready (MMIfaceModem3gpp *self, GAsyncResult *res, @@ -987,7 +1026,12 @@ after_set_load_initial_eps_bearer_settings_ready (MMIfaceModem3gpp return; } + mm_obj_dbg (self, "Updated initial EPS bearer settings:"); + log_initial_eps_bearer_settings (self, new_config); + if (!mm_bearer_properties_cmp (new_config, ctx->config)) { + mm_obj_dbg (self, "Requested initial EPS bearer settings:"); + log_initial_eps_bearer_settings (self, ctx->config); g_dbus_method_invocation_return_error_literal (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Initial EPS bearer settings were not updated"); } else { From 5629f47a59b48f2604fd8e9e4af7209b138aef21 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 30 Nov 2020 21:51:32 +0100 Subject: [PATCH 514/675] libmm-glib,bearer-properties: allow loose comparisons When comparing bearer properties provided by the user versus loaded from the modem, we shouldn't be very strict, e.g.: * Password or other fields may not be readable from the device. * Some fields may not apply at all (e.g. RM protocol for EPS bearers) * NULL strings could be assumed equal to empty strings. * If no explicit IP type specified, an IPv4 default may be assumed. * If no explicit allowed auth specified, 'none' default may be assumed. These loose comparisons are applied when managing the initial EPS bearer settings and status, and we keep the strict comparison only during the connection attempt lookup of a bearer with certain settings, as those bearer objects are all created in the same place with the same rules. --- libmm-glib/mm-bearer-properties.c | 101 +++++++++++++++++++++++++++--- libmm-glib/mm-bearer-properties.h | 13 +++- src/mm-bearer-list.c | 6 +- src/mm-iface-modem-3gpp.c | 23 ++++--- 4 files changed, 123 insertions(+), 20 deletions(-) diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c index 5ed4438e..904d1248 100644 --- a/libmm-glib/mm-bearer-properties.c +++ b/libmm-glib/mm-bearer-properties.c @@ -667,21 +667,102 @@ mm_bearer_properties_new_from_dictionary (GVariant *dictionary, /*****************************************************************************/ +static gboolean +cmp_str (const gchar *a, + const gchar *b, + MMBearerPropertiesCmpFlags flags) +{ + /* Strict match */ + if ((!a && !b) || (a && b && g_strcmp0 (a, b) == 0)) + return TRUE; + /* Additional loose match, consider NULL and EMPTY string equal */ + if (flags & MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE) { + if ((!a && !b[0]) || (!b && !a[0])) + return TRUE; + } + return FALSE; +} + +static gboolean +cmp_ip_type (MMBearerIpFamily a, + MMBearerIpFamily b, + MMBearerPropertiesCmpFlags flags) +{ + /* Strict match */ + if (a == b) + return TRUE; + /* Additional loose match NONE == IPV4 */ + if (flags & MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE) { + if ((a == MM_BEARER_IP_FAMILY_NONE && b == MM_BEARER_IP_FAMILY_IPV4) || + (b == MM_BEARER_IP_FAMILY_NONE && a == MM_BEARER_IP_FAMILY_IPV4)) + return TRUE; + } + return FALSE; +} + +static gboolean +cmp_allowed_auth (MMBearerAllowedAuth a, + MMBearerAllowedAuth b, + MMBearerPropertiesCmpFlags flags) +{ + /* Strict match */ + if (a == b) + return TRUE; + /* Additional loose match UNKNOWN == NONE */ + if (flags & MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE) { + if ((a == MM_BEARER_ALLOWED_AUTH_UNKNOWN && b == MM_BEARER_ALLOWED_AUTH_NONE) || + (b == MM_BEARER_ALLOWED_AUTH_UNKNOWN && a == MM_BEARER_ALLOWED_AUTH_NONE)) + return TRUE; + } + return FALSE; +} + +static gboolean +cmp_allow_roaming (gboolean a, + gboolean a_set, + gboolean b, + gboolean b_set, + MMBearerPropertiesCmpFlags flags) +{ + /* Strict match */ + if (a == b && a_set == b_set) + return TRUE; + /* Additional loose match UNSET == */ + if (flags & MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE) { + if ((a == MM_BEARER_ALLOWED_AUTH_UNKNOWN && b == MM_BEARER_ALLOWED_AUTH_NONE) || + (b == MM_BEARER_ALLOWED_AUTH_UNKNOWN && a == MM_BEARER_ALLOWED_AUTH_NONE)) + return TRUE; + } + return FALSE; +} + /** * mm_bearer_properties_cmp: (skip) */ gboolean -mm_bearer_properties_cmp (MMBearerProperties *a, - MMBearerProperties *b) +mm_bearer_properties_cmp (MMBearerProperties *a, + MMBearerProperties *b, + MMBearerPropertiesCmpFlags flags) { - return ((!g_strcmp0 (a->priv->apn, b->priv->apn)) && - (a->priv->ip_type == b->priv->ip_type) && - (a->priv->allowed_auth == b->priv->allowed_auth) && - (!g_strcmp0 (a->priv->user, b->priv->user)) && - (!g_strcmp0 (a->priv->password, b->priv->password)) && - (a->priv->allow_roaming == b->priv->allow_roaming) && - (a->priv->allow_roaming_set == b->priv->allow_roaming_set) && - (a->priv->rm_protocol == b->priv->rm_protocol)); + if (!cmp_str (a->priv->apn, b->priv->apn, flags)) + return FALSE; + if (!cmp_ip_type (a->priv->ip_type, b->priv->ip_type, flags)) + return FALSE; + if (!cmp_allowed_auth (a->priv->allowed_auth, a->priv->allowed_auth, flags)) + return FALSE; + if (!cmp_str (a->priv->user, b->priv->user, flags)) + return FALSE; + if (!(flags & MM_BEARER_PROPERTIES_CMP_FLAGS_NO_PASSWORD) && !cmp_str (a->priv->password, b->priv->password, flags)) + return FALSE; + if (!(flags & MM_BEARER_PROPERTIES_CMP_FLAGS_NO_ALLOW_ROAMING)) { + if (a->priv->allow_roaming != b->priv->allow_roaming) + return FALSE; + if (a->priv->allow_roaming_set != b->priv->allow_roaming) + return FALSE; + } + if (a->priv->rm_protocol != b->priv->rm_protocol) + return FALSE; + return TRUE; } /*****************************************************************************/ diff --git a/libmm-glib/mm-bearer-properties.h b/libmm-glib/mm-bearer-properties.h index 751185d9..340d9bf1 100644 --- a/libmm-glib/mm-bearer-properties.h +++ b/libmm-glib/mm-bearer-properties.h @@ -113,8 +113,17 @@ gboolean mm_bearer_properties_consume_variant (MMBearerProperties *properties, GVariant *mm_bearer_properties_get_dictionary (MMBearerProperties *self); -gboolean mm_bearer_properties_cmp (MMBearerProperties *a, - MMBearerProperties *b); +typedef enum { + MM_BEARER_PROPERTIES_CMP_FLAGS_NONE = 0, + MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE = 1 << 0, + MM_BEARER_PROPERTIES_CMP_FLAGS_NO_PASSWORD = 1 << 1, + MM_BEARER_PROPERTIES_CMP_FLAGS_NO_ALLOW_ROAMING = 1 << 2, + MM_BEARER_PROPERTIES_CMP_FLAGS_NO_RM_PROTOCOL = 1 << 3, +} MMBearerPropertiesCmpFlags; + +gboolean mm_bearer_properties_cmp (MMBearerProperties *a, + MMBearerProperties *b, + MMBearerPropertiesCmpFlags flags); #endif diff --git a/src/mm-bearer-list.c b/src/mm-bearer-list.c index 504b99ae..65717132 100644 --- a/src/mm-bearer-list.c +++ b/src/mm-bearer-list.c @@ -153,7 +153,11 @@ mm_bearer_list_find_by_properties (MMBearerList *self, GList *l; for (l = self->priv->bearers; l; l = g_list_next (l)) { - if (mm_bearer_properties_cmp (mm_base_bearer_peek_config (MM_BASE_BEARER (l->data)), props)) + /* always strict matching when comparing these bearer properties, as they're all + * built in the same place */ + if (mm_bearer_properties_cmp (mm_base_bearer_peek_config (MM_BASE_BEARER (l->data)), + props, + MM_BEARER_PROPERTIES_CMP_FLAGS_NONE)) return g_object_ref (l->data); } diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index df8df272..4e153c78 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -30,6 +30,16 @@ #define SUBSYSTEM_3GPP "3gpp" +/* When comparing EPS bearer settings take into account that PASSWORD may not always + * be readable, and apply very loose matching for all fields. Also, some implementations + * may allow configuring roaming allowance in the initial EPS bearer, but that is also + * not common. */ +#define MM_BEARER_PROPERTIES_CMP_FLAGS_EPS \ + (MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE | \ + MM_BEARER_PROPERTIES_CMP_FLAGS_NO_PASSWORD | \ + MM_BEARER_PROPERTIES_CMP_FLAGS_NO_ALLOW_ROAMING | \ + MM_BEARER_PROPERTIES_CMP_FLAGS_NO_RM_PROTOCOL) + /*****************************************************************************/ /* Private data context */ @@ -1029,7 +1039,7 @@ after_set_load_initial_eps_bearer_settings_ready (MMIfaceModem3gpp mm_obj_dbg (self, "Updated initial EPS bearer settings:"); log_initial_eps_bearer_settings (self, new_config); - if (!mm_bearer_properties_cmp (new_config, ctx->config)) { + if (!mm_bearer_properties_cmp (new_config, ctx->config, MM_BEARER_PROPERTIES_CMP_FLAGS_EPS)) { mm_obj_dbg (self, "Requested initial EPS bearer settings:"); log_initial_eps_bearer_settings (self, ctx->config); g_dbus_method_invocation_return_error_literal (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, @@ -1108,15 +1118,11 @@ set_initial_eps_bearer_settings_auth_ready (MMBaseModem return; } - /* If the user doesn't specify explicit auth settings, assume NONE as default */ - if (mm_bearer_properties_get_allowed_auth (ctx->config) == MM_BEARER_ALLOWED_AUTH_UNKNOWN) - mm_bearer_properties_set_allowed_auth (ctx->config, MM_BEARER_ALLOWED_AUTH_NONE); - old_dictionary = mm_gdbus_modem3gpp_get_initial_eps_bearer_settings (ctx->skeleton); if (old_dictionary) old_config = mm_bearer_properties_new_from_dictionary (old_dictionary, NULL); - if (old_config && mm_bearer_properties_cmp (ctx->config, old_config)) { + if (old_config && mm_bearer_properties_cmp (ctx->config, old_config, MM_BEARER_PROPERTIES_CMP_FLAGS_EPS)) { mm_gdbus_modem3gpp_complete_set_initial_eps_bearer_settings (ctx->skeleton, ctx->invocation); handle_set_initial_eps_bearer_settings_context_free (ctx); } else { @@ -1756,7 +1762,10 @@ mm_iface_modem_3gpp_update_initial_eps_bearer (MMIfaceModem3gpp *self, /* skip update? */ if ((!old_bearer && !properties) || - (old_bearer && properties && mm_bearer_properties_cmp (properties, mm_base_bearer_peek_config (MM_BASE_BEARER (old_bearer))))) + (old_bearer && properties && + mm_bearer_properties_cmp (properties, + mm_base_bearer_peek_config (MM_BASE_BEARER (old_bearer)), + MM_BEARER_PROPERTIES_CMP_FLAGS_EPS))) goto out; if (properties) { From 2d9b62d23b6abbeea4833bbcb431d0e2adaf04aa Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 1 Dec 2020 22:43:16 +0100 Subject: [PATCH 515/675] iface-modem-3gpp: allow requesting the reload of the initial EPS bearer --- src/mm-iface-modem-3gpp.c | 35 +++++++++++++++++++++++++++++++++++ src/mm-iface-modem-3gpp.h | 1 + 2 files changed, 36 insertions(+) diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index 4e153c78..93899355 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -1792,6 +1792,41 @@ mm_iface_modem_3gpp_update_initial_eps_bearer (MMIfaceModem3gpp *self, g_object_unref (skeleton); } +static void +reload_initial_eps_bearer_ready (MMIfaceModem3gpp *self, + GAsyncResult *res) +{ + g_autoptr(MMBearerProperties) properties = NULL; + g_autoptr(GError) error = NULL; + + properties = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer_finish (self, res, &error); + if (!properties) { + mm_obj_dbg (self, "couldn't load initial default bearer properties: %s", error->message); + return; + } + + mm_iface_modem_3gpp_update_initial_eps_bearer (self, properties); +} + +void +mm_iface_modem_3gpp_reload_initial_eps_bearer (MMIfaceModem3gpp *self) +{ + gboolean eps_supported = FALSE; + + g_object_get (self, + MM_IFACE_MODEM_3GPP_EPS_NETWORK_SUPPORTED, &eps_supported, + NULL); + + if (eps_supported && + MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer && + MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer_finish) { + MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_initial_eps_bearer ( + self, + (GAsyncReadyCallback)reload_initial_eps_bearer_ready, + NULL); + } +} + /*****************************************************************************/ typedef struct _DisablingContext DisablingContext; diff --git a/src/mm-iface-modem-3gpp.h b/src/mm-iface-modem-3gpp.h index 2bff383e..258e5c10 100644 --- a/src/mm-iface-modem-3gpp.h +++ b/src/mm-iface-modem-3gpp.h @@ -292,6 +292,7 @@ void mm_iface_modem_3gpp_update_pco_list (MMIfaceModem3gpp *self, const GList *pco_list); void mm_iface_modem_3gpp_update_initial_eps_bearer (MMIfaceModem3gpp *self, MMBearerProperties *properties); +void mm_iface_modem_3gpp_reload_initial_eps_bearer (MMIfaceModem3gpp *self); /* Run all registration checks */ void mm_iface_modem_3gpp_run_registration_checks (MMIfaceModem3gpp *self, From da159587992d91d61040544fe961a60ef756cf89 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 1 Dec 2020 22:43:35 +0100 Subject: [PATCH 516/675] broadband-modem-qmi: reload initial EPS bearer on data system updates --- src/mm-broadband-modem-qmi.c | 225 +++++++++++++++++++++++++---------- 1 file changed, 162 insertions(+), 63 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 1d3d02c4..cabbb5ae 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -85,9 +85,10 @@ struct _MMBroadbandModemQmiPrivate { /* 3GPP and CDMA share unsolicited events setup/enable/disable/cleanup */ gboolean unsolicited_events_enabled; gboolean unsolicited_events_setup; - guint event_report_indication_id; + guint nas_event_report_indication_id; + guint wds_event_report_indication_id; #if defined WITH_NEWEST_QMI_COMMANDS - guint signal_info_indication_id; + guint nas_signal_info_indication_id; #endif /* WITH_NEWEST_QMI_COMMANDS */ /* New devices may not support the legacy DMS UIM commands */ @@ -4704,14 +4705,16 @@ modem_cdma_load_esn (MMIfaceModemCdma *_self, /* Enabling/disabling unsolicited events (3GPP and CDMA interface) */ typedef struct { - QmiClientNas *client; + QmiClientNas *client_nas; + QmiClientWds *client_wds; gboolean enable; } EnableUnsolicitedEventsContext; static void enable_unsolicited_events_context_free (EnableUnsolicitedEventsContext *ctx) { - g_object_unref (ctx->client); + g_clear_object (&ctx->client_wds); + g_clear_object (&ctx->client_nas); g_free (ctx); } @@ -4723,6 +4726,44 @@ common_enable_disable_unsolicited_events_finish (MMBroadbandModemQmi *self, return g_task_propagate_boolean (G_TASK (res), error); } +static void +ser_data_system_status_ready (QmiClientWds *client, + GAsyncResult *res, + GTask *task) +{ + MMBroadbandModemQmi *self; + g_autoptr(QmiMessageWdsSetEventReportOutput) output = NULL; + g_autoptr(GError) error = NULL; + + self = g_task_get_source_object (task); + + output = qmi_client_wds_set_event_report_finish (client, res, &error); + if (!output || !qmi_message_wds_set_event_report_output_get_result (output, &error)) + mm_obj_dbg (self, "couldn't set event report: '%s'", error->message); + + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +common_enable_disable_unsolicited_events_data_system_status (GTask *task) +{ + EnableUnsolicitedEventsContext *ctx; + g_autoptr(QmiMessageWdsSetEventReportInput) input = NULL; + g_autoptr(GError) error = NULL; + + ctx = g_task_get_task_data (task); + + input = qmi_message_wds_set_event_report_input_new (); + qmi_message_wds_set_event_report_input_set_data_systems (input, ctx->enable, NULL); + qmi_client_wds_set_event_report (ctx->client_wds, + input, + 5, + NULL, + (GAsyncReadyCallback)ser_data_system_status_ready, + task); +} + #if !defined WITH_NEWEST_QMI_COMMANDS static void @@ -4742,10 +4783,13 @@ ser_signal_strength_ready (QmiClientNas *client, if (!output || !qmi_message_nas_set_event_report_output_get_result (output, &error)) mm_obj_dbg (self, "couldn't set event report: '%s'", error->message); - /* Just ignore errors for now */ - self->priv->unsolicited_events_enabled = ctx->enable; - g_task_return_boolean (task, TRUE); - g_object_unref (task); + if (!ctx->client_wds) { + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + + common_enable_disable_unsolicited_events_data_system_status (task); } static void @@ -4774,7 +4818,7 @@ common_enable_disable_unsolicited_events_signal_strength (GTask *task) thresholds, NULL); qmi_client_nas_set_event_report ( - ctx->client, + ctx->client_nas, input, 5, NULL, @@ -4801,10 +4845,13 @@ ri_signal_info_ready (QmiClientNas *client, if (!output || !qmi_message_nas_register_indications_output_get_result (output, &error)) mm_obj_dbg (self, "couldn't register indications: '%s'", error->message); - /* Just ignore errors for now */ - self->priv->unsolicited_events_enabled = ctx->enable; - g_task_return_boolean (task, TRUE); - g_object_unref (task); + if (!ctx->client_wds) { + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + + common_enable_disable_unsolicited_events_data_system_status (task); } static void @@ -4817,7 +4864,7 @@ common_enable_disable_unsolicited_events_signal_info (GTask *task) input = qmi_message_nas_register_indications_input_new (); qmi_message_nas_register_indications_input_set_signal_info (input, ctx->enable, NULL); qmi_client_nas_register_indications ( - ctx->client, + ctx->client_nas, input, 5, NULL, @@ -4876,7 +4923,7 @@ common_enable_disable_unsolicited_events_signal_info_config (GTask *task) } qmi_client_nas_config_signal_info ( - ctx->client, + ctx->client_nas, input, 5, NULL, @@ -4894,12 +4941,8 @@ common_enable_disable_unsolicited_events (MMBroadbandModemQmi *self, { EnableUnsolicitedEventsContext *ctx; GTask *task; - QmiClient *client = NULL; - - if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), - QMI_SERVICE_NAS, &client, - callback, user_data)) - return; + QmiClient *client_nas = NULL; + QmiClient *client_wds = NULL; task = g_task_new (self, NULL, callback, user_data); @@ -4910,18 +4953,40 @@ common_enable_disable_unsolicited_events (MMBroadbandModemQmi *self, g_object_unref (task); return; } + self->priv->unsolicited_events_enabled = enable; + + client_nas = mm_shared_qmi_peek_client (MM_SHARED_QMI (self), + QMI_SERVICE_NAS, + MM_PORT_QMI_FLAG_DEFAULT, + NULL); + client_wds = mm_shared_qmi_peek_client (MM_SHARED_QMI (self), + QMI_SERVICE_WDS, + MM_PORT_QMI_FLAG_DEFAULT, + NULL); ctx = g_new0 (EnableUnsolicitedEventsContext, 1); ctx->enable = enable; - ctx->client = g_object_ref (client); + ctx->client_nas = client_nas ? g_object_ref (client_nas) : NULL; + ctx->client_wds = client_wds ? g_object_ref (client_wds) : NULL; g_task_set_task_data (task, ctx, (GDestroyNotify)enable_unsolicited_events_context_free); + if (ctx->client_nas) { #if defined WITH_NEWEST_QMI_COMMANDS - common_enable_disable_unsolicited_events_signal_info_config (task); + common_enable_disable_unsolicited_events_signal_info_config (task); #else - common_enable_disable_unsolicited_events_signal_strength (task); + common_enable_disable_unsolicited_events_signal_strength (task); #endif /* WITH_NEWEST_QMI_COMMANDS */ + return; + } + + if (ctx->client_wds) { + common_enable_disable_unsolicited_events_data_system_status (task); + return; + } + + g_task_return_boolean (task, TRUE); + g_object_unref (task); } /*****************************************************************************/ @@ -5002,9 +5067,26 @@ common_setup_cleanup_unsolicited_events_finish (MMBroadbandModemQmi *self, } static void -event_report_indication_cb (QmiClientNas *client, - QmiIndicationNasEventReportOutput *output, - MMBroadbandModemQmi *self) +wds_event_report_indication_cb (QmiClientWds *client, + QmiIndicationWdsEventReportOutput *output, + MMBroadbandModemQmi *self) +{ + QmiWdsDataSystemNetworkType preferred_network; + + if (qmi_indication_wds_event_report_output_get_data_systems (output, &preferred_network, NULL, NULL)) { + mm_obj_dbg (self, "data systems update, preferred network: %s", + qmi_wds_data_system_network_type_get_string (preferred_network)); + if (preferred_network == QMI_WDS_DATA_SYSTEM_NETWORK_TYPE_3GPP) + mm_iface_modem_3gpp_reload_initial_eps_bearer (MM_IFACE_MODEM_3GPP (self)); + else + mm_iface_modem_3gpp_update_initial_eps_bearer (MM_IFACE_MODEM_3GPP (self), NULL); + } +} + +static void +nas_event_report_indication_cb (QmiClientNas *client, + QmiIndicationNasEventReportOutput *output, + MMBroadbandModemQmi *self) { gint8 signal_strength; QmiNasRadioInterface signal_strength_radio_interface; @@ -5041,9 +5123,9 @@ event_report_indication_cb (QmiClientNas *client, #if defined WITH_NEWEST_QMI_COMMANDS static void -signal_info_indication_cb (QmiClientNas *client, - QmiIndicationNasSignalInfoOutput *output, - MMBroadbandModemQmi *self) +nas_signal_info_indication_cb (QmiClientNas *client, + QmiIndicationNasSignalInfoOutput *output, + MMBroadbandModemQmi *self) { gint8 cdma1x_rssi = 0; gint8 evdo_rssi = 0; @@ -5083,13 +5165,9 @@ common_setup_cleanup_unsolicited_events (MMBroadbandModemQmi *self, GAsyncReadyCallback callback, gpointer user_data) { - GTask *task; - QmiClient *client = NULL; - - if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), - QMI_SERVICE_NAS, &client, - callback, user_data)) - return; + GTask *task; + QmiClient *client_nas = NULL; + QmiClient *client_wds = NULL; task = g_task_new (self, NULL, callback, user_data); @@ -5100,38 +5178,59 @@ common_setup_cleanup_unsolicited_events (MMBroadbandModemQmi *self, g_object_unref (task); return; } - - /* Store new state */ self->priv->unsolicited_events_setup = enable; + client_nas = mm_shared_qmi_peek_client (MM_SHARED_QMI (self), + QMI_SERVICE_NAS, + MM_PORT_QMI_FLAG_DEFAULT, + NULL); + client_wds = mm_shared_qmi_peek_client (MM_SHARED_QMI (self), + QMI_SERVICE_WDS, + MM_PORT_QMI_FLAG_DEFAULT, + NULL); + /* Connect/Disconnect "Event Report" indications */ - if (enable) { - g_assert (self->priv->event_report_indication_id == 0); - self->priv->event_report_indication_id = - g_signal_connect (client, - "event-report", - G_CALLBACK (event_report_indication_cb), - self); - } else { - g_assert (self->priv->event_report_indication_id != 0); - g_signal_handler_disconnect (client, self->priv->event_report_indication_id); - self->priv->event_report_indication_id = 0; - } + if (client_nas) { + if (enable) { + g_assert (self->priv->nas_event_report_indication_id == 0); + self->priv->nas_event_report_indication_id = + g_signal_connect (client_nas, + "event-report", + G_CALLBACK (nas_event_report_indication_cb), + self); + } else if (self->priv->nas_event_report_indication_id != 0) { + g_signal_handler_disconnect (client_nas, self->priv->nas_event_report_indication_id); + self->priv->nas_event_report_indication_id = 0; + } #if defined WITH_NEWEST_QMI_COMMANDS - if (enable) { - g_assert (self->priv->signal_info_indication_id == 0); - self->priv->signal_info_indication_id = - g_signal_connect (client, - "signal-info", - G_CALLBACK (signal_info_indication_cb), - self); - } else { - g_assert (self->priv->signal_info_indication_id != 0); - g_signal_handler_disconnect (client, self->priv->signal_info_indication_id); - self->priv->signal_info_indication_id = 0; - } + if (enable) { + g_assert (self->priv->nas_signal_info_indication_id == 0); + self->priv->nas_signal_info_indication_id = + g_signal_connect (client_nas, + "signal-info", + G_CALLBACK (nas_signal_info_indication_cb), + self); + } else if (self->priv->nas_signal_info_indication_id != 0) { + g_signal_handler_disconnect (client_nas, self->priv->nas_signal_info_indication_id); + self->priv->nas_signal_info_indication_id = 0; + } #endif /* WITH_NEWEST_QMI_COMMANDS */ + } + + if (client_wds) { + if (enable) { + g_assert (self->priv->wds_event_report_indication_id == 0); + self->priv->wds_event_report_indication_id = + g_signal_connect (client_wds, + "event-report", + G_CALLBACK (wds_event_report_indication_cb), + self); + } else if (self->priv->wds_event_report_indication_id != 0) { + g_signal_handler_disconnect (client_wds, self->priv->wds_event_report_indication_id); + self->priv->wds_event_report_indication_id = 0; + } + } g_task_return_boolean (task, TRUE); g_object_unref (task); From 47f39c9e1a9f37758027dd5072caafe224351089 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 1 Dec 2020 22:55:56 +0100 Subject: [PATCH 517/675] broadband-modem-qmi: fix disabling of signal strength events Attempting to disable the signal strength events was failing because the protocol handler expects a valid set of thresholds also during the disabling. So, just pass always the thresholds. ModemManager[274522]: [/dev/cdc-wdm1] sent generic request (translated)... <<<<<< QMUX: <<<<<< length = 17 <<<<<< flags = 0x00 <<<<<< service = "nas" <<<<<< client = 3 <<<<<< QMI: <<<<<< flags = "none" <<<<<< transaction = 7 <<<<<< tlv_length = 5 <<<<<< message = "Set Event Report" (0x0002) <<<<<< TLV: <<<<<< type = "Signal Strength Indicator" (0x10) <<<<<< length = 2 <<<<<< value = 00:00 <<<<<< translated = [ report = 'no' thresholds = '{}' ] ModemManager[274522]: [/dev/cdc-wdm1] received generic response (translated)... <<<<<< QMUX: <<<<<< length = 19 <<<<<< flags = 0x80 <<<<<< service = "nas" <<<<<< client = 3 <<<<<< QMI: <<<<<< flags = "response" <<<<<< transaction = 7 <<<<<< tlv_length = 7 <<<<<< message = "Set Event Report" (0x0002) <<<<<< TLV: <<<<<< type = "Result" (0x02) <<<<<< length = 4 <<<<<< value = 01:00:08:00 <<<<<< translated = FAILURE: NoThresholdsProvided --- src/mm-broadband-modem-qmi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index cabbb5ae..a6442a99 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -4805,11 +4805,10 @@ common_enable_disable_unsolicited_events_signal_strength (GTask *task) ctx = g_task_get_task_data (task); - /* Only set thresholds during enable, but always create the array anyway, - * as the TLV setter expects it */ + /* Always set thresholds, both in enable and disable, or otherwise the protocol will + * complain with FAILURE: NoThresholdsProvided */ thresholds = g_array_sized_new (FALSE, FALSE, sizeof (gint8), G_N_ELEMENTS (thresholds_data)); - if (ctx->enable) - g_array_append_vals (thresholds, thresholds_data, G_N_ELEMENTS (thresholds_data)); + g_array_append_vals (thresholds, thresholds_data, G_N_ELEMENTS (thresholds_data)); input = qmi_message_nas_set_event_report_input_new (); qmi_message_nas_set_event_report_input_set_signal_strength_indicator ( From 3d4dd64dd03622ae5d335f0111c54e184de120c7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 1 Dec 2020 23:26:42 +0100 Subject: [PATCH 518/675] broadband-modem-qmi: disable signal/access-tech polling if indications enabled We can rely on QMI indications when the signal quality and access tech changes happen, instead of doing explicit polling. The modem will run the signal quality retrieval once, and then just rely on indications, with polling disabled: ModemManager[278759]: [1606862198.230492] [modem1] signal strength (lte): -79 dBm ModemManager[278759]: [1606862198.230520] [modem1] signal strength: -79 dBm --> 55% ModemManager[278759]: [1606862198.230583] [modem1] access technology changed (unknown -> lte) ModemManager[278759]: [1606862198.230654] [modem1] signal quality updated (55) ModemManager[278759]: [1606862198.230675] [modem1] periodic signal quality and access technology checks not rescheduled: unneeded or unsupported ModemManager[278759]: [1606862198.230692] [modem1] periodic signal checks disabled Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/231 --- src/mm-broadband-modem-qmi.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index a6442a99..d161d96e 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -4781,7 +4781,15 @@ ser_signal_strength_ready (QmiClientNas *client, output = qmi_client_nas_set_event_report_finish (client, res, &error); if (!output || !qmi_message_nas_set_event_report_output_get_result (output, &error)) - mm_obj_dbg (self, "couldn't set event report: '%s'", error->message); + mm_obj_dbg (self, "couldn't enable signal strength indications: '%s'", error->message); + else { + /* Disable access technology and signal quality polling if we can use the indications */ + mm_obj_dbg (self, "signal strength indications enabled: polling disabled"); + g_object_set (self, + MM_IFACE_MODEM_PERIODIC_SIGNAL_CHECK_DISABLED, TRUE, + MM_IFACE_MODEM_PERIODIC_ACCESS_TECH_CHECK_DISABLED, TRUE, + NULL); + } if (!ctx->client_wds) { g_task_return_boolean (task, TRUE); @@ -4842,7 +4850,15 @@ ri_signal_info_ready (QmiClientNas *client, output = qmi_client_nas_register_indications_finish (client, res, &error); if (!output || !qmi_message_nas_register_indications_output_get_result (output, &error)) - mm_obj_dbg (self, "couldn't register indications: '%s'", error->message); + mm_obj_dbg (self, "couldn't register signal info indications: '%s'", error->message); + else { + /* Disable access technology and signal quality polling if we can use the indications */ + mm_obj_dbg (self, "signal strength indications enabled: polling disabled"); + g_object_set (self, + MM_IFACE_MODEM_PERIODIC_SIGNAL_CHECK_DISABLED, TRUE, + MM_IFACE_MODEM_PERIODIC_ACCESS_TECH_CHECK_DISABLED, TRUE, + NULL); + } if (!ctx->client_wds) { g_task_return_boolean (task, TRUE); From 2f53a08e5f1eef8c1892dc55f32fbacba85565a0 Mon Sep 17 00:00:00 2001 From: Frederic Martinsons Date: Sun, 20 Dec 2020 18:07:44 +0100 Subject: [PATCH 519/675] iface-modem: don't consider charset setup failure as fatal. On some modem (for example SORACOM SC-QGLC4-C1) , the character set setup step fails with "Unknown error" when the SIM card is missing or locked. This leads to not expose Modem interface and not being able to unlocked the SIM. We should not consider this step as fatal but just issue a warning to let other steps continue (which will let modem in failed state anyway). Closes #289 Signed-off-by: Frederic Martinsons --- src/mm-iface-modem.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 5bb9dd2c..7b6f6f0e 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -5087,12 +5087,7 @@ interface_initialization_step (GTask *task) return; } - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Failed to find a usable modem character set"); - g_object_unref (task); - return; + mm_obj_warn (self, "Failed to find usable modem character set, let it to UNKNOWN"); } ctx->step++; /* fall-through */ From 18b72a046e89d00d7e7b9f2d718c43d64e595de0 Mon Sep 17 00:00:00 2001 From: Frederic Martinsons Date: Sun, 20 Dec 2020 18:11:06 +0100 Subject: [PATCH 520/675] mmcli: don't assume that mm_object_peek_modem or mm_object_get_modem return non null This very peculiar case can happen when an intermediate initiliazition step of a modem fails. The ModemManager daemon should always expose the modem interface but let not assume that in mmcli and protect these calls. Signed-off-by: Frederic Martinsons --- cli/mmcli-common.c | 4 +++- cli/mmcli-manager.c | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/mmcli-common.c b/cli/mmcli-common.c index a5402431..4163f42f 100644 --- a/cli/mmcli-common.c +++ b/cli/mmcli-common.c @@ -205,7 +205,9 @@ find_modem (MMManager *manager, MMModem *modem; obj = MM_OBJECT (l->data); - modem = MM_MODEM (mm_object_get_modem (obj)); + modem = mm_object_get_modem (obj); + if (!modem) + continue; if (modem_any || (modem_path && g_str_equal (mm_object_get_path (obj), modem_path)) || diff --git a/cli/mmcli-manager.c b/cli/mmcli-manager.c index 01d2972c..011c8c11 100644 --- a/cli/mmcli-manager.c +++ b/cli/mmcli-manager.c @@ -332,9 +332,14 @@ output_modem_info (MMObject *obj, gchar *extra; const gchar *manufacturer; const gchar *model; + MMModem *modem; - manufacturer = mm_modem_get_manufacturer (mm_object_peek_modem (obj)); - model = mm_modem_get_model (mm_object_peek_modem (obj)); + modem = mm_object_peek_modem (obj); + if (!modem) + return; + + manufacturer = mm_modem_get_manufacturer (modem); + model = mm_modem_get_model (modem); extra = g_strdup_printf ("[%s] %s", manufacturer ? manufacturer : "manufacturer unknown", model ? model : "model unknown"); From 8ccd63ef64d8bcc39ac67457674b85c8fe42c265 Mon Sep 17 00:00:00 2001 From: Andrew Lassalle Date: Fri, 8 Jan 2021 10:49:34 -0800 Subject: [PATCH 521/675] test-sms-part-cdma: fix memory leak --- src/tests/test-sms-part-cdma.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/test-sms-part-cdma.c b/src/tests/test-sms-part-cdma.c index df6e982c..eb095f34 100644 --- a/src/tests/test-sms-part-cdma.c +++ b/src/tests/test-sms-part-cdma.c @@ -533,6 +533,8 @@ test_create_parse_pdu_text_ascii_encoding (void) g_assert_cmpstr ("123456789", ==, mm_sms_part_get_number (part)); g_assert_cmpstr (text, ==, mm_sms_part_get_text (part)); mm_sms_part_free (part); + + g_free (pdu); } } From 8f465d44a5f40e1594db4f06b98b2436539a47bf Mon Sep 17 00:00:00 2001 From: Timo Jyrinki Date: Fri, 8 Jan 2021 15:34:57 +0200 Subject: [PATCH 522/675] po: add Finnish translation Translation by JRfi: https://l10n.gnome.org/vertimus/ModemManager/master/po/fi/ --- po/LINGUAS | 1 + po/fi.po | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 po/fi.po diff --git a/po/LINGUAS b/po/LINGUAS index d09b7ccf..fdf80dfb 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -1,6 +1,7 @@ cs da de +fi fr fur hu diff --git a/po/fi.po b/po/fi.po new file mode 100644 index 00000000..e5d68cf3 --- /dev/null +++ b/po/fi.po @@ -0,0 +1,116 @@ +# Finnish translation for ModemManager. +# Copyright (C) 2020 ModemManager's COPYRIGHT HOLDER +# This file is distributed under the same license as the ModemManager package. +# JRfi , 2020. +# +msgid "" +msgstr "" +"Project-Id-Version: ModemManager master\n" +"Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/mobile-broadband/" +"ModemManager/issues\n" +"POT-Creation-Date: 2021-01-08 03:28+0000\n" +"PO-Revision-Date: 2020-08-08 18:58+0300\n" +"Last-Translator: JR-Fi \n" +"Language-Team: Finnish \n" +"Language: fi\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.0.6\n" + +#: data/org.freedesktop.ModemManager1.policy.in.in:13 +msgid "Control the Modem Manager daemon" +msgstr "Hallitse Modem Manager taustaprosessia" + +#: data/org.freedesktop.ModemManager1.policy.in.in:14 +msgid "System policy prevents controlling the Modem Manager." +msgstr "" +"Järjestelmän sääntö estää Modem Managerin hallinta-asetusten muuttamisen." + +#: data/org.freedesktop.ModemManager1.policy.in.in:22 +msgid "Unlock and control a mobile broadband device" +msgstr "Avaa ja hallitse mobiilia laajakaistalaitetta" + +#: data/org.freedesktop.ModemManager1.policy.in.in:23 +msgid "" +"System policy prevents unlocking or controlling the mobile broadband device." +msgstr "" +"Järjestelmän sääntö estää avaamasta tai hallitsemasta mobiilia " +"laajakaistalaitetta." + +#: data/org.freedesktop.ModemManager1.policy.in.in:31 +msgid "Add, modify, and delete mobile broadband contacts" +msgstr "Lisää, muuta ja poista mobiilin laajakaistan yhteystietoja" + +#: data/org.freedesktop.ModemManager1.policy.in.in:32 +msgid "" +"System policy prevents adding, modifying, or deleting this device's contacts." +msgstr "" +"Järjestelmän sääntö estää lisäämästä, muuttamasta tai poistamasta tämän " +"laitteen yhteystietoja." + +#: data/org.freedesktop.ModemManager1.policy.in.in:40 +msgid "Send, save, modify, and delete text messages" +msgstr "Lähetä, talleta, muuta ja poista tekstiviestejä" + +#: data/org.freedesktop.ModemManager1.policy.in.in:41 +msgid "" +"System policy prevents sending or manipulating this device's text messages." +msgstr "" +"Järjestelmän sääntö estää lähettämästä tai muokkaamasta tämän laitteen " +"tekstiviestejä." + +#: data/org.freedesktop.ModemManager1.policy.in.in:49 +msgid "Accept incoming voice calls or start outgoing voice calls." +msgstr "Hyväksy tulevat puhelut tai aloita (ääni)puheluita." + +#: data/org.freedesktop.ModemManager1.policy.in.in:50 +msgid "System policy prevents voice calls." +msgstr "Järjestelmän sääntö estää äänipuhelut." + +#: data/org.freedesktop.ModemManager1.policy.in.in:58 +msgid "Query network time and timezone information" +msgstr "Tarkista verkon aika ja aikavyöhyketiedot" + +#: data/org.freedesktop.ModemManager1.policy.in.in:59 +msgid "System policy prevents querying network time information." +msgstr "" +"Järjestelmän sääntö estää tarkastamasta verkon aikaa ja aikavyöhyketietoja." + +#: data/org.freedesktop.ModemManager1.policy.in.in:67 +msgid "Enable and view geographic location and positioning information" +msgstr "Salli ja katso sijainti- ja paikkatiedot" + +#: data/org.freedesktop.ModemManager1.policy.in.in:68 +msgid "" +"System policy prevents enabling or viewing geographic location information." +msgstr "" +"Järjestelmän sääntö estää sallimasta tai katsomasta sijainti- ja " +"paikkatietoja" + +#: data/org.freedesktop.ModemManager1.policy.in.in:76 +msgid "Query and utilize network information and services" +msgstr "Tarkista ja käytä verkon tietoja ja palveluita" + +#: data/org.freedesktop.ModemManager1.policy.in.in:77 +msgid "" +"System policy prevents querying or utilizing network information and " +"services." +msgstr "" +"Järjestelmän sääntö estää tarkistamasta tai käyttämästä verkon tietoja ja " +"palveluita." + +#: data/org.freedesktop.ModemManager1.policy.in.in:85 +msgid "Query and manage firmware on a mobile broadband device" +msgstr "Tarkista ja hallitse mobiilin laajakaistalaitteen laiteohjelmistoa" + +#: data/org.freedesktop.ModemManager1.policy.in.in:86 +msgid "System policy prevents querying or managing this device's firmware." +msgstr "" +"Järjestelmän sääntö estää tarkistamasta ja hallitsemasta tämän laitteen " +"laiteohjelmistoa." + +#: src/mm-sleep-monitor.c:125 +msgid "ModemManager needs to reset devices" +msgstr "Modem Managerin pitää uudelleen käynnistää laitteita" From 102de14c15b1c278988de376d03262bcb078211d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 11 Jan 2021 14:13:28 +0100 Subject: [PATCH 523/675] telit: plug GPS data port leak The _get_port_gps() returns a full reference, use _peek_port_gps() instead. See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/302 --- plugins/telit/mm-broadband-modem-telit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/telit/mm-broadband-modem-telit.c b/plugins/telit/mm-broadband-modem-telit.c index 11a86b12..daa7bddd 100644 --- a/plugins/telit/mm-broadband-modem-telit.c +++ b/plugins/telit/mm-broadband-modem-telit.c @@ -359,7 +359,7 @@ gpsp_test_ready (MMIfaceModemLocation *self, if (error) { mm_obj_dbg (self, "GPS controller not supported: %s", error->message); g_clear_error (&error); - } else if (mm_base_modem_get_port_gps (MM_BASE_MODEM (self))) + } else if (mm_base_modem_peek_port_gps (MM_BASE_MODEM (self))) sources |= (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED); From d12ab8a25a60323a753e3437c81a984a503deb40 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 11 Jan 2021 14:18:36 +0100 Subject: [PATCH 524/675] iface-modem: avoid leaking the MmGdbusModem when bearers are updated See See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/302 --- src/mm-iface-modem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 7b6f6f0e..2e9a3004 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -504,6 +504,7 @@ bearer_list_updated (MMBearerList *bearer_list, g_strfreev (paths); g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (skeleton)); + g_object_unref (skeleton); } /*****************************************************************************/ From 17ea1dfa130001599b7dff421a1b7d71c25faa34 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 10 Jan 2021 15:13:45 +0100 Subject: [PATCH 525/675] docs: add MMBearerPropertiesCmpFlags to ignored list --- docs/reference/libmm-glib/libmm-glib-sections.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 79baa939..7fc82f91 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -1194,6 +1194,7 @@ mm_bearer_properties_set_rm_protocol mm_bearer_properties_new_from_dictionary mm_bearer_properties_new_from_string +MMBearerPropertiesCmpFlags mm_bearer_properties_cmp mm_bearer_properties_consume_string mm_bearer_properties_consume_variant From 89cd1696c3a105f314b1a7e275c68377ed6df5e4 Mon Sep 17 00:00:00 2001 From: Frederic Martinsons Date: Thu, 12 Nov 2020 10:48:11 +0100 Subject: [PATCH 526/675] tools: add unit test for test-modemmanager-service.py The tests spawn the service via GTestDBus framework and make some test API call while checking libmm interface to verify that informations are well propagated. To be able to use the fresh built libmm typelib, I used a wrapper script to set GI_TYPELIB_PATH (because DBus activation process clean the environment so it is not possible to set it directly in the file). This requires also the install of libgirepository-dev and python3-gi in the CI docker. Signed-off-by: Frederic Martinsons --- .gitignore | 4 + .gitlab-ci.yml | 4 +- configure.ac | 2 + tools/Makefile.am | 2 + tools/tests/Makefile.am | 46 ++ .../org.freedesktop.ModemManager1.service.in | 3 + tools/tests/test-stub.c | 459 ++++++++++++++++++ tools/tests/test-wrapper.sh.in | 5 + 8 files changed, 523 insertions(+), 2 deletions(-) create mode 100644 tools/tests/Makefile.am create mode 100644 tools/tests/services/org.freedesktop.ModemManager1.service.in create mode 100644 tools/tests/test-stub.c create mode 100644 tools/tests/test-wrapper.sh.in diff --git a/.gitignore b/.gitignore index ea7705af..4a0e5fd7 100644 --- a/.gitignore +++ b/.gitignore @@ -175,5 +175,9 @@ Makefile.in /test/mmsmspdu /test/mmsmsmonitor +/tools/tests/services/org.freedesktop.ModemManager1.service +/tools/tests/test-stub +/tools/tests/test-wrapper.sh + /ModemManager-*-coverage.info /ModemManager-*-coverage/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e429af6c..a8371f75 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ stages: before_script: - apt update || true - - apt -y install autoconf automake libtool libglib2.0-dev libgudev-1.0-dev libgettextpo-dev autopoint xsltproc dbus autoconf-archive gettext + - apt -y install autoconf automake libtool libgettextpo-dev libgirepository1.0-dev libglib2.0-dev libgudev-1.0-dev python3-dbus python3-gi autopoint xsltproc dbus autoconf-archive gettext build-no-qmi: stage: build @@ -125,7 +125,7 @@ build-default: - schedules - pushes script: - - apt -y install gtk-doc-tools libglib2.0-doc gobject-introspection libgirepository1.0-dev libsystemd-dev libpolkit-gobject-1-dev valac + - apt -y install gtk-doc-tools libglib2.0-doc gobject-introspection libsystemd-dev libpolkit-gobject-1-dev valac - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git - pushd libmbim - NOCONFIGURE=1 ./autogen.sh diff --git a/configure.ac b/configure.ac index c96e4b76..8c2711f2 100644 --- a/configure.ac +++ b/configure.ac @@ -542,6 +542,8 @@ src/tests/Makefile plugins/Makefile test/Makefile tools/Makefile +tools/tests/Makefile +tools/tests/services/org.freedesktop.ModemManager1.service introspection/Makefile introspection/tests/Makefile po/Makefile.in diff --git a/tools/Makefile.am b/tools/Makefile.am index 8b1edd5f..af87c73b 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1 +1,3 @@ +SUBDIRS = . tests + EXTRA_DIST = test-modemmanager-service.py diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am new file mode 100644 index 00000000..c91675bf --- /dev/null +++ b/tools/tests/Makefile.am @@ -0,0 +1,46 @@ +include $(top_srcdir)/gtester.make + +################################################################################ +# common +################################################################################ + +AM_CFLAGS = \ + $(WARN_CFLAGS) \ + $(MM_CFLAGS) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/include \ + -I$(top_builddir)/include \ + -I$(top_srcdir)/libmm-glib \ + -I${top_srcdir}/libmm-glib/generated \ + -I${top_builddir}/libmm-glib/generated \ + $(NULL) + +LDADD = \ + $(top_builddir)/libmm-glib/libmm-glib.la \ + $(NULL) + +AM_LDFLAGS = \ + $(WARN_LDFLAGS) \ + $(MM_LIBS) \ + $(MM_LDFLAGS) \ + $(NULL) + +noinst_PROGRAMS = test-stub +test_stub_CPPFLAGS = \ + -DTEST_SERVICES=\""$(abs_top_builddir)/tools/tests/services"\" \ + $(NULL) + +TEST_PROGS += $(noinst_PROGRAMS) + +test-wrapper.sh: test-wrapper.sh.in + @sed \ + -e 's|@abs_top_builddir[@]|$(abs_top_builddir)|g' \ + -e 's|@abs_top_srcdir[@]|$(abs_top_srcdir)|g' \ + $< >$@ + @chmod +x $@ + +BUILT_SOURCES = test-wrapper.sh +CLEANFILES = test-wrapper.sh + +EXTRA_DIST += test-wrapper.sh.in services/org.freedesktop.ModemManager1.service.in diff --git a/tools/tests/services/org.freedesktop.ModemManager1.service.in b/tools/tests/services/org.freedesktop.ModemManager1.service.in new file mode 100644 index 00000000..f6113d1f --- /dev/null +++ b/tools/tests/services/org.freedesktop.ModemManager1.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.freedesktop.ModemManager1 +Exec=@abs_top_builddir@/tools/tests/test-wrapper.sh diff --git a/tools/tests/test-stub.c b/tools/tests/test-stub.c new file mode 100644 index 00000000..5687feca --- /dev/null +++ b/tools/tests/test-stub.c @@ -0,0 +1,459 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2020 Frederic Martinsons + */ + +#include +#include +#include +#include +#include +#define MM_LOG_NO_OBJECT +#include + +#define MM_TEST_IFACE_NAME "org.freedesktop.ModemManager1.LibmmGlibTest" + +typedef struct { + GMainLoop *loop; + MMManager *mm_manager; + GDBusConnection *gdbus_connection; + GDBusProxy *mm_proxy; + GDBusProxy *mm_modem_prop_proxy; + GTestDBus *test_bus; + gchar *modem_object_path; + guint timeout_id; + MMSim *sim; + gboolean pin_error; +} TestData; + +static void +setup (TestData **ptdata, + gconstpointer data) +{ + GError *error = NULL; + TestData *tdata = NULL; + + tdata = (TestData *)g_malloc0 (sizeof(TestData)); + *ptdata = tdata; + + tdata->loop = g_main_loop_new (NULL, FALSE); + g_assert_nonnull (tdata->loop); + + tdata->test_bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_assert_nonnull (tdata->test_bus); + + g_test_dbus_add_service_dir (tdata->test_bus, TEST_SERVICES); + g_test_dbus_up (tdata->test_bus); + + /* Grab a proxy to the fake NM service to trigger tests */ + tdata->mm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + MM_DBUS_SERVICE, + MM_DBUS_PATH, + MM_TEST_IFACE_NAME, + NULL, &error); + g_assert_no_error (error); + + tdata->gdbus_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + g_assert_no_error (error); + + tdata->mm_manager = mm_manager_new_sync (tdata->gdbus_connection, + G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, + NULL, + &error); + g_assert_no_error (error); + g_assert_nonnull (tdata->mm_manager); +} + +static void +teardown (TestData **ptdata, + gconstpointer data) +{ + TestData *tdata = NULL; + + tdata = *ptdata; + g_clear_object (&tdata->mm_modem_prop_proxy); + g_clear_object (&tdata->mm_proxy); + g_clear_object (&tdata->mm_manager); + g_clear_object (&tdata->gdbus_connection); + g_test_dbus_down (tdata->test_bus); + g_clear_object (&tdata->test_bus); + g_main_loop_unref (tdata->loop); + g_free (tdata); +} + +static gboolean +loop_timeout_cb (gpointer user_data) +{ + mm_err ("Timeout has elapsed"); + g_assert_not_reached (); + return G_SOURCE_REMOVE; +} + +static void +run_loop_for_ms (TestData *tdata, + guint32 timeout) +{ + mm_info ("Run loop for %u ms", timeout); + tdata->timeout_id = g_timeout_add (timeout, loop_timeout_cb, tdata); + g_main_loop_run (tdata->loop); +} + +static void +stop_loop (TestData *tdata) +{ + if (tdata->timeout_id) { + g_source_remove (tdata->timeout_id); + tdata->timeout_id = 0; + } + mm_info ("Stop the loop"); + g_main_loop_quit (tdata->loop); +} + +static void +add_modem_completion_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + GVariant *dbus_return = NULL; + GVariant *obj_path_variant = NULL; + TestData *tdata = NULL; + + tdata = (TestData*)user_data; + + mm_info ("AddModem DBus call completed"); + dbus_return = g_dbus_proxy_call_finish (tdata->mm_proxy, res, &error); + g_assert_no_error (error); + g_assert_nonnull (dbus_return); + g_assert_cmpstr (g_variant_get_type_string (dbus_return), == , "(o)"); + + obj_path_variant = g_variant_get_child_value (dbus_return, 0); + tdata->modem_object_path = g_variant_dup_string (obj_path_variant, NULL); + + g_assert_null (tdata->mm_modem_prop_proxy); + tdata->mm_modem_prop_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + MM_DBUS_SERVICE, + tdata->modem_object_path, + "org.freedesktop.DBus.Properties", + NULL, &error); + + g_assert_no_error (error); + g_assert_nonnull (tdata->mm_modem_prop_proxy); + + g_variant_unref (dbus_return); + g_variant_unref (obj_path_variant); + + stop_loop (tdata); +} + +static gchar* +add_modem (TestData *tdata, + gboolean add_sim, + const gchar *iccid) +{ + g_dbus_proxy_call (tdata->mm_proxy, + "AddModem", + g_variant_new ("(bs)", add_sim, iccid), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 1000, + NULL, + add_modem_completion_cb, + tdata); + + run_loop_for_ms (tdata, 1000); + return tdata->modem_object_path; +} + +static void +emit_state_changed_completion_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + GVariant *dbus_return = NULL; + TestData *tdata = NULL; + + tdata = (TestData*)user_data; + + mm_info ("EmitStateChanged DBus call completed"); + dbus_return = g_dbus_proxy_call_finish (tdata->mm_proxy, res, &error); + g_assert_no_error (error); + g_assert_nonnull (dbus_return); + g_variant_unref (dbus_return); + + stop_loop (tdata); +} + +static void +set_modem_state (TestData *tdata, + MMModemState state, + MMModemStateFailedReason reason) +{ + GError *error = NULL; + GVariant *ret = NULL; + GVariant *old_state_variant = NULL; + guint old_state = 0; + + g_assert_nonnull (tdata->mm_modem_prop_proxy); + + /* Get current state */ + ret = g_dbus_proxy_call_sync (tdata->mm_modem_prop_proxy, + "org.freedesktop.DBus.Properties.Get", + g_variant_new ("(ss)", + MM_DBUS_INTERFACE_MODEM, + MM_MODEM_PROPERTY_STATE), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, + NULL, + &error); + g_assert_no_error (error); + g_variant_get (ret, "(v)", &old_state_variant); + old_state = (guint)g_variant_get_int32 (old_state_variant); + g_variant_unref (ret); + g_variant_unref (old_state_variant); + + ret = g_dbus_proxy_call_sync (tdata->mm_modem_prop_proxy, + "org.freedesktop.DBus.Properties.Set", + g_variant_new ("(ssv)", + MM_DBUS_INTERFACE_MODEM, + MM_MODEM_PROPERTY_STATE, + g_variant_new_int32 (state)), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, + NULL, + &error); + g_assert_no_error (error); + g_variant_unref (ret); + + ret = g_dbus_proxy_call_sync (tdata->mm_modem_prop_proxy, + "org.freedesktop.DBus.Properties.Set", + g_variant_new ("(ssv)", + MM_DBUS_INTERFACE_MODEM, + MM_MODEM_PROPERTY_STATEFAILEDREASON, + g_variant_new_uint32 (reason)), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, + NULL, + &error); + + g_assert_no_error (error); + g_variant_unref (ret); + + /* Emit state change signal */ + g_dbus_proxy_call (tdata->mm_proxy, + "EmitStateChanged", + g_variant_new ("(uuu)", old_state, state, reason), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 1000, + NULL, + emit_state_changed_completion_cb, + tdata); + + run_loop_for_ms (tdata, 1000); +} + +static void +set_modem_unlock_completion_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + GVariant *dbus_return = NULL; + TestData *tdata = NULL; + + tdata = (TestData*)user_data; + + mm_info ("org.freedesktop.DBus.Properties.Set DBus call completed"); + dbus_return = g_dbus_proxy_call_finish (tdata->mm_modem_prop_proxy, res, &error); + g_assert_no_error (error); + g_assert_nonnull (dbus_return); + g_variant_unref (dbus_return); + + stop_loop (tdata); +} + +static void +set_modem_unlock (TestData *tdata, + MMModemLock lock_state) +{ + g_assert_nonnull (tdata->mm_modem_prop_proxy); + + g_dbus_proxy_call (tdata->mm_modem_prop_proxy, + "org.freedesktop.DBus.Properties.Set", + g_variant_new ("(ssv)", + MM_DBUS_INTERFACE_MODEM, + MM_MODEM_PROPERTY_UNLOCKREQUIRED, + g_variant_new_uint32 (lock_state)), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 1000, + NULL, + set_modem_unlock_completion_cb, + tdata); + + run_loop_for_ms (tdata, 1000); +} + +static void +set_modem_equipment_error (TestData *tdata, + MMMobileEquipmentError equipmentError, + gboolean clear) +{ + GError *error = NULL; + GVariant *ret = NULL; + + ret = g_dbus_proxy_call_sync (tdata->mm_proxy, + "SetMobileEquipmentError", + g_variant_new ("(ub)", equipmentError, clear), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + 3000, + NULL, + &error); + g_assert_no_error (error); + g_variant_unref (ret); +} + +static void +test_modem_interface (TestData **ptdata, + gconstpointer data) +{ + TestData *tdata = NULL; + GDBusObject *modem_object = NULL; + MMModem *mm_modem = NULL; + g_autofree gchar *modem_path = NULL; + + tdata = *ptdata; + /* Add a modem object (with no sim attached) */ + modem_path = add_modem (tdata, FALSE, ""); + modem_object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (tdata->mm_manager), modem_path); + g_assert_nonnull (modem_object); + + mm_modem = mm_object_get_modem (MM_OBJECT (modem_object)); + g_clear_object (&modem_object); + + /* Check the modem states */ + g_assert_cmpuint (mm_modem_get_state (mm_modem), ==, MM_MODEM_STATE_UNKNOWN); + g_assert_cmpuint (mm_modem_get_state_failed_reason (mm_modem), ==, MM_MODEM_STATE_FAILED_REASON_UNKNOWN); + + /* Set new state and check that it is propagated */ + set_modem_state (tdata, MM_MODEM_STATE_REGISTERED, MM_MODEM_STATE_FAILED_REASON_NONE); + + g_assert_cmpuint (mm_modem_get_state (mm_modem), ==, MM_MODEM_STATE_REGISTERED); + g_assert_cmpuint (mm_modem_get_state_failed_reason (mm_modem), ==, MM_MODEM_STATE_FAILED_REASON_NONE); + + g_clear_object (&mm_modem); +} + +static void +mm_sim_send_pin_completion_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + gboolean ret = FALSE; + TestData *tdata = NULL; + + tdata = (TestData*)user_data; + + mm_info("SendPin DBus method call completed"); + ret = mm_sim_send_pin_finish (tdata->sim, res, &error); + if (tdata->pin_error) { + g_assert_nonnull (error); + g_assert_false (ret); + g_clear_error (&error); + } else { + g_assert_no_error (error); + g_assert_true (ret); + } + stop_loop (tdata); +} + +static void +test_sim_interface (TestData **ptdata, + gconstpointer data) +{ + TestData *tdata = NULL; + GDBusObject *modem_object = NULL; + MMModem *mm_modem = NULL; + GError *error = NULL; + g_autofree gchar *modem_path = NULL; + + tdata = *ptdata; + /* Add a modem with a sim object */ + modem_path = add_modem (tdata, TRUE, "89330122503000800750"); + modem_object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (tdata->mm_manager), modem_path); + g_assert_nonnull (modem_object); + mm_modem = mm_object_get_modem (MM_OBJECT (modem_object)); + g_clear_object (&modem_object); + + g_assert_cmpuint (mm_modem_get_unlock_required (mm_modem), ==, MM_MODEM_LOCK_NONE); + /* Lock the modem */ + set_modem_unlock (tdata, MM_MODEM_LOCK_SIM_PIN); + g_assert_cmpuint (mm_modem_get_unlock_required (mm_modem), ==, MM_MODEM_LOCK_SIM_PIN); + + tdata->sim = mm_modem_get_sim_sync (mm_modem, NULL, &error); + g_assert_no_error (error); + g_assert_nonnull (tdata->sim); + g_assert_cmpstr (mm_sim_get_identifier(tdata->sim), ==, "89330122503000800750"); + + /* Send a pin code */ + tdata->pin_error = FALSE; + mm_sim_send_pin (tdata->sim, "1234", NULL, mm_sim_send_pin_completion_cb, tdata); + run_loop_for_ms (tdata, 1000); + + /* Check that the modem has been unlocked */ + g_assert_cmpuint (mm_modem_get_unlock_required (mm_modem), ==, MM_MODEM_LOCK_NONE); + + /* Re lock it */ + set_modem_unlock (tdata, MM_MODEM_LOCK_SIM_PIN); + g_assert_cmpuint (mm_modem_get_unlock_required (mm_modem), ==, MM_MODEM_LOCK_SIM_PIN); + + /* Set an error that will simulate wrong pin code */ + set_modem_equipment_error (tdata, MM_MOBILE_EQUIPMENT_ERROR_INCORRECT_PASSWORD, FALSE); + + tdata->pin_error = TRUE; + mm_sim_send_pin (tdata->sim, "0000", NULL, mm_sim_send_pin_completion_cb, tdata); + run_loop_for_ms (tdata, 1000); + + g_assert_cmpuint (mm_modem_get_unlock_required (mm_modem), ==, MM_MODEM_LOCK_SIM_PIN); + + /* Clear the error and retry the pin code */ + set_modem_equipment_error (tdata, 0, TRUE); + tdata->pin_error = FALSE; + mm_sim_send_pin (tdata->sim, "1234", NULL, mm_sim_send_pin_completion_cb, tdata); + run_loop_for_ms (tdata, 1000); + + g_assert_cmpuint (mm_modem_get_unlock_required (mm_modem), ==, MM_MODEM_LOCK_NONE); + + g_clear_object (&tdata->sim); + g_clear_object (&mm_modem); +} + +int main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add ("/MM/stub/modem/interface", + TestData *, NULL, setup, + test_modem_interface, + teardown); + g_test_add ("/MM/stub/sim/interface", + TestData *, NULL, setup, + test_sim_interface, + teardown); + return g_test_run (); +} diff --git a/tools/tests/test-wrapper.sh.in b/tools/tests/test-wrapper.sh.in new file mode 100644 index 00000000..d64ea4cb --- /dev/null +++ b/tools/tests/test-wrapper.sh.in @@ -0,0 +1,5 @@ +#!/bin/bash + +# For debugging behavior of test-modemmanager-service.py, you can modify +# this line to add --log-file option +GI_TYPELIB_PATH=@abs_top_builddir@/libmm-glib @abs_top_srcdir@/tools/test-modemmanager-service.py From 9c353cf6f0a7650cfe1b914d6881890de9dff0b0 Mon Sep 17 00:00:00 2001 From: Louis-Alexis Eyraud Date: Fri, 15 Jan 2021 15:14:58 +0100 Subject: [PATCH 527/675] zte: add 1 second delay after sim unlock to avoid IMSI reading issue Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/306 Signed-off-by: Louis-Alexis Eyraud --- plugins/zte/mm-broadband-modem-zte.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/zte/mm-broadband-modem-zte.c b/plugins/zte/mm-broadband-modem-zte.c index 64549cd8..08bbed83 100644 --- a/plugins/zte/mm-broadband-modem-zte.c +++ b/plugins/zte/mm-broadband-modem-zte.c @@ -187,6 +187,19 @@ modem_after_sim_unlock_context_step (GTask *task) task); } +static gboolean +after_sim_unlock_wait_cb (GTask *task) +{ + /* Attempt to disable floods of "+ZUSIMR:2" unsolicited responses that + * eventually fill up the device's buffers and make it crash. Normally + * done during probing, but if the device has a PIN enabled it won't + * accept the +CPMS? during the probe and we have to do it here. + */ + modem_after_sim_unlock_context_step (task); + + return G_SOURCE_REMOVE; +} + static void modem_after_sim_unlock (MMIfaceModem *self, GAsyncReadyCallback callback, @@ -201,12 +214,7 @@ modem_after_sim_unlock (MMIfaceModem *self, task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, ctx, g_free); - /* Attempt to disable floods of "+ZUSIMR:2" unsolicited responses that - * eventually fill up the device's buffers and make it crash. Normally - * done during probing, but if the device has a PIN enabled it won't - * accept the +CPMS? during the probe and we have to do it here. - */ - modem_after_sim_unlock_context_step (task); + g_timeout_add_seconds (1, (GSourceFunc)after_sim_unlock_wait_cb, task); } /*****************************************************************************/ From d1bc67936539b1cf59f07f8f168486263b0005f5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 16 Jan 2021 15:37:35 +0100 Subject: [PATCH 528/675] build: add new RELEASING doc explaining how releases are made --- RELEASING | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 RELEASING diff --git a/RELEASING b/RELEASING new file mode 100644 index 00000000..8ae9a6e1 --- /dev/null +++ b/RELEASING @@ -0,0 +1,37 @@ + + +The ModemManager releases are generated using the GNU autotools. + +1) Configure and build the whole project, making sure gtk-doc is enabled: + + $ NOCONFIGURE=1 ./autogen.sh + $ ./configure --enable-gtk-doc + $ make -j8 + +2) Run distcheck so that the source distribution tarball is generated, and the + project test suite is run on it: + + $ make distcheck + +3) Compute checksum of the tarball so that it can be referenced in the release + email: + + $ sha256sum ModemManager-${VERSION}.tar.xz + +4) Sign release tarball, and verify it (*): + + $ gpg --detach-sign --armor ModemManager-${VERSION}.tar.xz + $ gpg --verify ModemManager-${VERSION}.tar.xz.asc ModemManager-${VERSION}.tar.xz + +5) Upload source tarball (.tar.xz) and signature (.tar.xz.asc) to + freedesktop.org + +TODO: manpages and gtk-doc references + +------------------------------------------------------------------------------- + +*) Verifying the release signature requires the public key of the person who + signed it, e.g.: + + $ curl https://www.freedesktop.org/software/ModemManager/0x3CAD53398973FFFA.asc | gpg --import + From 38267952284ded86bb0ea7ca9139236bc80556a3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 16 Jan 2021 17:42:36 +0100 Subject: [PATCH 529/675] docs: add 'online-location' references So that the gtkdoc-rebase step fixes the URLs to contain the correct links; e.g.: $ make dist V=s make[8]: Entering directory '/home/aleksander/Development/foss/ModemManager/docs/reference/libmm-glib' make \ top_distdir="../../../ModemManager-1.15.0" distdir="../../../ModemManager-1.15.0/docs/reference/libmm-glib" \ dist-hook ../ModemManager/ -> https://www.freedesktop.org/software/ModemManager/doc/latest/ModemManager/ (914) ../gio/ -> https://developer.gnome.org/gio/unstable/ (2564) ../glib/ -> https://developer.gnome.org/glib/unstable/ (5534) ../gobject/ -> https://developer.gnome.org/gobject/unstable/ (499) make[8]: Leaving directory '/home/aleksander/Development/foss/ModemManager/docs/reference/libmm-glib' Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/298 --- docs/reference/api/ModemManager-docs.xml | 2 ++ docs/reference/libmm-glib/libmm-glib-docs.xml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/reference/api/ModemManager-docs.xml b/docs/reference/api/ModemManager-docs.xml index 61850603..f068d7a5 100644 --- a/docs/reference/api/ModemManager-docs.xml +++ b/docs/reference/api/ModemManager-docs.xml @@ -15,6 +15,8 @@ For ModemManager version &version; + The latest version of this documentation can be found on-line at + https://www.freedesktop.org/software/ModemManager/doc/latest/ModemManager/. diff --git a/docs/reference/libmm-glib/libmm-glib-docs.xml b/docs/reference/libmm-glib/libmm-glib-docs.xml index 878f1d3a..0b3dc9b7 100644 --- a/docs/reference/libmm-glib/libmm-glib-docs.xml +++ b/docs/reference/libmm-glib/libmm-glib-docs.xml @@ -15,6 +15,8 @@ For libmm-glib version &version; + The latest version of this documentation can be found on-line at + https://www.freedesktop.org/software/ModemManager/doc/latest/libmm-glib/. From 6c0c67d6f0a65af416448236f07cdccfd1993dd8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 16 Jan 2021 17:44:42 +0100 Subject: [PATCH 530/675] doc: skip running gtkdoc-rebase on local install step We can leave the relative paths to other books (e.g. '../glib' or '../ModemManager') because running gtkdoc-rebase seems to be broken since the 1.29 release, see: https://gitlab.gnome.org/GNOME/gtk-doc/-/issues/138 --- gtk-doc.make | 1 - 1 file changed, 1 deletion(-) diff --git a/gtk-doc.make b/gtk-doc.make index 7d9a27f3..913aa4f7 100644 --- a/gtk-doc.make +++ b/gtk-doc.make @@ -285,7 +285,6 @@ install-data-local: mv -f $${installdir}/$(DOC_MODULE).devhelp2 \ $${installdir}/$(DOC_MODULE)-$(DOC_MODULE_VERSION).devhelp2; \ fi; \ - $(GTKDOC_REBASE) --relative --dest-dir=$(DESTDIR) --html-dir=$${installdir}; \ fi uninstall-local: From 268bf4f98af0adeef703f02469e47259c73be91e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 17 Jan 2021 10:33:45 +0100 Subject: [PATCH 531/675] core: update copyright years to 2021 --- cli/mmcli.c | 2 +- docs/reference/api/ModemManager-docs.xml | 1 + docs/reference/libmm-glib/libmm-glib-docs.xml | 1 + src/mm-context.c | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/mmcli.c b/cli/mmcli.c index bf59867c..05644519 100644 --- a/cli/mmcli.c +++ b/cli/mmcli.c @@ -148,7 +148,7 @@ static void print_version_and_exit (void) { g_print (PROGRAM_NAME " " PROGRAM_VERSION "\n" - "Copyright (2011 - 2020) Aleksander Morgado\n" + "Copyright (2011 - 2021) Aleksander Morgado\n" "License GPLv2+: GNU GPL version 2 or later \n" "This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n" diff --git a/docs/reference/api/ModemManager-docs.xml b/docs/reference/api/ModemManager-docs.xml index f068d7a5..bbcab97a 100644 --- a/docs/reference/api/ModemManager-docs.xml +++ b/docs/reference/api/ModemManager-docs.xml @@ -54,6 +54,7 @@ 2018 2019 2020 + 2021 The ModemManager Authors diff --git a/docs/reference/libmm-glib/libmm-glib-docs.xml b/docs/reference/libmm-glib/libmm-glib-docs.xml index 0b3dc9b7..71e74405 100644 --- a/docs/reference/libmm-glib/libmm-glib-docs.xml +++ b/docs/reference/libmm-glib/libmm-glib-docs.xml @@ -42,6 +42,7 @@ 2018 2019 2020 + 2021 The ModemManager Authors diff --git a/src/mm-context.c b/src/mm-context.c index 79091e87..890734ea 100644 --- a/src/mm-context.c +++ b/src/mm-context.c @@ -298,7 +298,7 @@ static void print_version (void) { g_print ("ModemManager " MM_DIST_VERSION "\n" - "Copyright (C) 2008-2020 The ModemManager authors\n" + "Copyright (C) 2008-2021 The ModemManager authors\n" "License GPLv2+: GNU GPL version 2 or later \n" "This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n" From 66010ed17e71714f35bb34a66cc53e1102a28651 Mon Sep 17 00:00:00 2001 From: Lukas Senger Date: Thu, 14 Jan 2021 15:22:19 +0100 Subject: [PATCH 532/675] simtech: fix updating bitmask during gps disabling During disabling of gps sources the bitmask that keeps track of them is updated incorrectly. Instead of removing the current source, all other sources are removed from the mask. One problem that arises from this is, that when you enable GPS after it has been disabled completely (e.g. by disabling all GPS sources), the code will not send a "+CGPS=1,1" command because it incorrectly assumes that GPS is still enabled on the device. --- plugins/simtech/mm-shared-simtech.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/simtech/mm-shared-simtech.c b/plugins/simtech/mm-shared-simtech.c index f6921b61..99c2346e 100644 --- a/plugins/simtech/mm-shared-simtech.c +++ b/plugins/simtech/mm-shared-simtech.c @@ -293,7 +293,7 @@ disable_cgps_ready (MMBaseModem *self, if (error) g_task_return_error (task, error); else { - priv->enabled_sources &= source; + priv->enabled_sources &= ~source; g_task_return_boolean (task, TRUE); } g_object_unref (task); From 52b44aeb4956a223ce9edcb596a896413b4d69fc Mon Sep 17 00:00:00 2001 From: Andrew Lassalle Date: Tue, 2 Feb 2021 13:43:16 -0800 Subject: [PATCH 533/675] cinterion: remove unused variables --- plugins/cinterion/mm-broadband-modem-cinterion.c | 2 -- plugins/cinterion/mm-modem-helpers-cinterion.c | 1 - 2 files changed, 3 deletions(-) diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 35e20334..4986eea5 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -1311,8 +1311,6 @@ set_initial_eps_cfun_mode_load_ready (MMBaseModem *self, { GError *error = NULL; const gchar *response; - g_autoptr(GRegex) r = NULL; - g_autoptr(GMatchInfo) match_info = NULL; SetInitialEpsContext *ctx; guint mode; diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index 5ceb4529..05228815 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -1467,7 +1467,6 @@ mm_cinterion_provcfg_response_to_cid (const gchar *response, { g_autoptr(GRegex) r = NULL; g_autoptr(GMatchInfo) match_info = NULL; - g_autofree GError *inner_error = NULL; g_autofree gchar *mno = NULL; r = g_regex_new ("\\^SCFG:\\s*\"MEopMode/Prov/Cfg\",\\s*\"([0-9a-zA-Z]*)\"", 0, 0, NULL); From e732a9afcc8e662df14a7fb5c78a1023705d5ff1 Mon Sep 17 00:00:00 2001 From: Andrew Lassalle Date: Tue, 2 Feb 2021 13:50:51 -0800 Subject: [PATCH 534/675] broadband-modem-qmi: remove unused variables --- src/mm-broadband-modem-qmi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index d161d96e..0a63b596 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -4750,7 +4750,6 @@ common_enable_disable_unsolicited_events_data_system_status (GTask *task) { EnableUnsolicitedEventsContext *ctx; g_autoptr(QmiMessageWdsSetEventReportInput) input = NULL; - g_autoptr(GError) error = NULL; ctx = g_task_get_task_data (task); From 8838546631958d88ecd0c72c557102876f5b87e4 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 5 Feb 2021 14:56:59 +0100 Subject: [PATCH 535/675] README: add CoC info --- README | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README b/README index ade8b77f..d4c60d23 100644 --- a/README +++ b/README @@ -34,3 +34,11 @@ and need to add or change some public method, feel free to suggest it! License. The ModemManager and mmcli binaries are both GPLv2+. The libmm-glib library is LGPLv2+. + +Code of Conduct. +Please note that this project is released with a Contributor Code of Conduct. +By participating in this project you agree to abide by its terms, which you can +find in the following link: + https://www.freedesktop.org/wiki/CodeOfConduct +CoC issues may be raised to the project maintainers at the following address: + modemmanager-devel-owner@lists.freedesktop.org From 6107774bb21e55028b87a7d3f23762324410543b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 17 Jan 2021 14:13:40 +0100 Subject: [PATCH 536/675] filter: add missing reference to rpmsg filter --- src/mm-filter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mm-filter.c b/src/mm-filter.c index 52575a1c..870ae7b8 100644 --- a/src/mm-filter.c +++ b/src/mm-filter.c @@ -456,6 +456,7 @@ mm_filter_new (MMFilterRule enabled_rules, mm_obj_dbg (self, " virtual devices forbidden: %s", RULE_ENABLED_STR (MM_FILTER_RULE_VIRTUAL)); mm_obj_dbg (self, " net devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_NET)); mm_obj_dbg (self, " usbmisc devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_USBMISC)); + mm_obj_dbg (self, " rpmsg devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_RPMSG)); if (self->priv->enabled_rules & MM_FILTER_RULE_TTY) { mm_obj_dbg (self, " tty devices:"); mm_obj_dbg (self, " blacklist applied: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_BLACKLIST)); From 16d1cf33183d376fa6cb8925e42c77b2e86be2d9 Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Sat, 13 Feb 2021 09:40:05 +0100 Subject: [PATCH 537/675] examples: rework imports Remove unused imports and fix import sorting using isort utility. --- examples/modem-watcher-python/ModemWatcher.py | 6 +++--- examples/modem-watcher-python/modem-watcher-python | 6 ++++-- examples/network-scan-python/network-scan-python | 6 ++++-- examples/sms-python/sms-python | 6 ++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/examples/modem-watcher-python/ModemWatcher.py b/examples/modem-watcher-python/ModemWatcher.py index a18725b1..8091d9f3 100644 --- a/examples/modem-watcher-python/ModemWatcher.py +++ b/examples/modem-watcher-python/ModemWatcher.py @@ -18,10 +18,10 @@ # Copyright (C) 2014 Aleksander Morgado # -import os, sys, gi - +import gi gi.require_version('ModemManager', '1.0') -from gi.repository import GLib, GObject, Gio, ModemManager +from gi.repository import Gio, GLib, GObject, ModemManager + """ The ModemWatcher class is responsible for monitoring ModemManager diff --git a/examples/modem-watcher-python/modem-watcher-python b/examples/modem-watcher-python/modem-watcher-python index 40998588..4884beef 100755 --- a/examples/modem-watcher-python/modem-watcher-python +++ b/examples/modem-watcher-python/modem-watcher-python @@ -18,10 +18,12 @@ # Copyright (C) 2014 Aleksander Morgado # -import sys, signal -import ModemWatcher +import signal + from gi.repository import GLib +import ModemWatcher + main_loop = None watcher = None diff --git a/examples/network-scan-python/network-scan-python b/examples/network-scan-python/network-scan-python index ad377091..51b8077c 100755 --- a/examples/network-scan-python/network-scan-python +++ b/examples/network-scan-python/network-scan-python @@ -18,10 +18,12 @@ # Copyright (C) 2019 Aleksander Morgado # -import sys, signal, gi +import sys +import gi gi.require_version('ModemManager', '1.0') -from gi.repository import GLib, GObject, Gio, ModemManager +from gi.repository import Gio, GLib, GObject, ModemManager + if __name__ == "__main__": diff --git a/examples/sms-python/sms-python b/examples/sms-python/sms-python index 2d572f18..569db376 100755 --- a/examples/sms-python/sms-python +++ b/examples/sms-python/sms-python @@ -18,10 +18,12 @@ # Copyright (C) 2016 Aleksander Morgado # -import sys, signal, gi +import sys +import gi gi.require_version('ModemManager', '1.0') -from gi.repository import GLib, GObject, Gio, ModemManager +from gi.repository import Gio, GLib, GObject, ModemManager + if __name__ == "__main__": From dd3310132f135e57c4d45827c8750920f7dbe5ee Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 13 Feb 2021 11:12:49 +0100 Subject: [PATCH 538/675] examples,python: fix undefined NameError in modem watcher example $ ./modem-watcher-python [ModemWatcher] ModemManager 1.15.0 service is available in bus [ModemWatcher] QUALCOMM INCORPORATED (0) modem managed by ModemManager [863974040050058]: /org/freedesktop/ModemManager1/Modem/0 [ModemWatcher] Sierra Wireless Inc. (Sierra Wireless EM7345 4G LTE) modem managed by ModemManager [013937003110648]: /org/freedesktop/ModemManager1/Modem/1 Traceback (most recent call last): File "/home/aleksander/Development/foss/ModemManager/examples/modem-watcher-python/./modem-watcher-python", line 35, in watcher = ModemWatcher.ModemWatcher() File "/home/aleksander/Development/foss/ModemManager/examples/modem-watcher-python/ModemWatcher.py", line 48, in __init__ self.on_name_owner(self.manager, None) File "/home/aleksander/Development/foss/ModemManager/examples/modem-watcher-python/ModemWatcher.py", line 85, in on_name_owner self.set_available() File "/home/aleksander/Development/foss/ModemManager/examples/modem-watcher-python/ModemWatcher.py", line 64, in set_available self.on_object_added(self.manager, obj) File "/home/aleksander/Development/foss/ModemManager/examples/modem-watcher-python/ModemWatcher.py", line 101, in on_object_added modem_index(obj.get_object_path())) NameError: name 'modem_index' is not defined --- examples/modem-watcher-python/ModemWatcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/modem-watcher-python/ModemWatcher.py b/examples/modem-watcher-python/ModemWatcher.py index 8091d9f3..2311a8ad 100644 --- a/examples/modem-watcher-python/ModemWatcher.py +++ b/examples/modem-watcher-python/ModemWatcher.py @@ -97,8 +97,8 @@ def on_object_added(self, manager, obj): modem.get_equipment_identifier(), obj.get_object_path())) if modem.get_state() == ModemManager.ModemState.FAILED: - print('[ModemWatcher,%s] ignoring failed modem' % - modem_index(obj.get_object_path())) + print('[ModemWatcher] ignoring failed modem: %s' % + obj.get_object_path()) """ Object removed From 12329ac7880b5a43eed8b7b2c4b932c544f43898 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 13 Feb 2021 11:24:24 +0100 Subject: [PATCH 539/675] examples,python: ignore scan operation in modems without 3GPP interface Traceback (most recent call last): File "/home/aleksander/Development/foss/ModemManager/examples/network-scan-python/./network-scan-python", line 46, in modem3gpp.set_default_timeout(300000) AttributeError: 'NoneType' object has no attribute 'set_default_timeout' --- examples/network-scan-python/network-scan-python | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/network-scan-python/network-scan-python b/examples/network-scan-python/network-scan-python index 51b8077c..df295995 100755 --- a/examples/network-scan-python/network-scan-python +++ b/examples/network-scan-python/network-scan-python @@ -37,12 +37,15 @@ if __name__ == "__main__": connection = Gio.bus_get_sync (Gio.BusType.SYSTEM, None) manager = ModemManager.Manager.new_sync (connection, Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, None) if manager.get_name_owner() is None: - sys.stderr.write('ModemManager not found in bus') + sys.stderr.write('ModemManager not found in bus\n') sys.exit(2) # Iterate modems and scan network with each one by one for obj in manager.get_objects(): modem3gpp = obj.get_modem_3gpp() + if modem3gpp is None: + sys.stderr.write('%s: skipping unusable modem...\n' % obj.get_object_path()) + continue modem3gpp.set_default_timeout(300000) print('%s: starting network scan...' % modem3gpp.get_object_path()) networks = modem3gpp.scan_sync() From 7159b8e27ac47af706e0c2e4d4f77460dce7881e Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 31 Jan 2021 15:38:31 +0100 Subject: [PATCH 540/675] context: add test-no-suspend-resume cli parameter Disables suspend/resume support at runtime. This is useful for modems which are never turned off or suspended when the host suspends. --- src/main.c | 10 +++++++--- src/mm-context.c | 18 ++++++++++++++++++ src/mm-context.h | 11 +++++++---- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 9963c7cc..928078a3 100644 --- a/src/main.c +++ b/src/main.c @@ -195,9 +195,13 @@ main (int argc, char *argv[]) { MMSleepMonitor *sleep_monitor; - sleep_monitor = mm_sleep_monitor_get (); - g_signal_connect (sleep_monitor, MM_SLEEP_MONITOR_SLEEPING, G_CALLBACK (sleeping_cb), NULL); - g_signal_connect (sleep_monitor, MM_SLEEP_MONITOR_RESUMING, G_CALLBACK (resuming_cb), NULL); + if (mm_context_get_test_no_suspend_resume()) + mm_dbg ("Suspend/resume support disabled at runtime"); + else { + sleep_monitor = mm_sleep_monitor_get (); + g_signal_connect (sleep_monitor, MM_SLEEP_MONITOR_SLEEPING, G_CALLBACK (sleeping_cb), NULL); + g_signal_connect (sleep_monitor, MM_SLEEP_MONITOR_RESUMING, G_CALLBACK (resuming_cb), NULL); + } } #endif diff --git a/src/mm-context.c b/src/mm-context.c index 890734ea..6561127e 100644 --- a/src/mm-context.c +++ b/src/mm-context.c @@ -225,6 +225,9 @@ static gchar *test_plugin_dir; #if defined WITH_UDEV static gboolean test_no_udev; #endif +#if defined WITH_SYSTEMD_SUSPEND_RESUME +static gboolean test_no_suspend_resume; +#endif static const GOptionEntry test_entries[] = { { @@ -248,6 +251,13 @@ static const GOptionEntry test_entries[] = { "Run without udev support even if available", NULL }, +#endif +#if defined WITH_SYSTEMD_SUSPEND_RESUME + { + "test-no-suspend-resume", 0, 0, G_OPTION_ARG_NONE, &test_no_suspend_resume, + "Disable suspend/resume support at runtime even if available", + NULL + }, #endif { NULL } }; @@ -292,6 +302,14 @@ mm_context_get_test_no_udev (void) } #endif +#if defined WITH_SYSTEMD_SUSPEND_RESUME +gboolean +mm_context_get_test_no_suspend_resume (void) +{ + return test_no_suspend_resume; +} +#endif + /*****************************************************************************/ static void diff --git a/src/mm-context.h b/src/mm-context.h index 1d02e296..721fee88 100644 --- a/src/mm-context.h +++ b/src/mm-context.h @@ -43,11 +43,14 @@ gboolean mm_context_get_log_timestamps (void); gboolean mm_context_get_log_relative_timestamps (void); /* Testing support */ -gboolean mm_context_get_test_session (void); -gboolean mm_context_get_test_enable (void); -const gchar *mm_context_get_test_plugin_dir (void); +gboolean mm_context_get_test_session (void); +gboolean mm_context_get_test_enable (void); +const gchar *mm_context_get_test_plugin_dir (void); #if defined WITH_UDEV -gboolean mm_context_get_test_no_udev (void); +gboolean mm_context_get_test_no_udev (void); +#endif +#if defined WITH_SYSTEMD_SUSPEND_RESUME +gboolean mm_context_get_test_no_suspend_resume (void); #endif #endif /* MM_CONTEXT_H */ From f3f05f397a7f08272718ee9a2ee75799a44e7bfb Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 23:31:35 +0100 Subject: [PATCH 541/675] device: avoid trying to remove source multiple times ModemManager[115879]: [1613341789.760031] [modem3] completely disposed (ModemManager:115879): GLib-CRITICAL **: 23:29:49.760: Source ID 2379 was not found when attempting to remove it Thread 1 "ModemManager" received signal SIGTRAP, Trace/breakpoint trap. 0x00007ffff774b343 in g_logv () from /usr/lib/libglib-2.0.so.0 (gdb) (gdb) bt #0 0x00007ffff774b343 in g_logv () at /usr/lib/libglib-2.0.so.0 #1 0x00007ffff774b5c0 in g_log () at /usr/lib/libglib-2.0.so.0 #2 0x00007ffff7741c9e in g_source_remove () at /usr/lib/libglib-2.0.so.0 #3 0x00005555555aad02 in dispose (object=0x555555831260) at mm-device.c:802 #4 0x00007ffff7843755 in g_object_unref () at /usr/lib/libgobject-2.0.so.0 #5 0x00005555555a5107 in glib_autoptr_clear_MMDevice (_ptr=0x555555831260) at mm-device.h:63 #6 0x00005555555a5125 in glib_autoptr_cleanup_MMDevice (_ptr=0x7fffffffe090) at mm-device.h:63 #7 0x00005555555a59ab in device_removed (self=0x555555769220, subsystem=0x55555577dc50 "tty", name=0x555555869a40 "ttyUSB3") at mm-base-manager.c:237 #8 0x00005555555a620d in handle_uevent (self=0x555555769220, action=0x5555558987b0 "remove", device=0x555555893840) at mm-base-manager.c:445 #9 0x00007ffff7381acd in () at /usr/lib/libffi.so.7 #10 0x00007ffff738103a in () at /usr/lib/libffi.so.7 #11 0x00007ffff783c8fe in g_cclosure_marshal_generic () at /usr/lib/libgobject-2.0.so.0 #12 0x00007ffff7837072 in g_closure_invoke () at /usr/lib/libgobject-2.0.so.0 #13 0x00007ffff785fa85 in () at /usr/lib/libgobject-2.0.so.0 #14 0x00007ffff78535dd in g_signal_emit_valist () at /usr/lib/libgobject-2.0.so.0 #15 0x00007ffff7853b40 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0 #16 0x00007ffff7e792aa in () at /usr/lib/libgudev-1.0.so.0 #17 0x00007ffff7742b84 in g_main_context_dispatch () at /usr/lib/libglib-2.0.so.0 #18 0x00007ffff7796c21 in () at /usr/lib/libglib-2.0.so.0 #19 0x00007ffff77420d3 in g_main_loop_run () at /usr/lib/libglib-2.0.so.0 #20 0x00005555555a1df4 in main (argc=2, argv=0x7fffffffea88) at main.c:213 --- src/mm-device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mm-device.c b/src/mm-device.c index 488ee5e2..d0e31184 100644 --- a/src/mm-device.c +++ b/src/mm-device.c @@ -383,6 +383,8 @@ reprobe (MMDevice *self) { GError *error = NULL; + self->priv->reprobe_id = 0; + mm_obj_dbg (self, "Reprobing modem..."); if (!mm_device_create_modem (self, &error)) { mm_obj_warn (self, "could not recreate modem: %s", error->message); From c7d0defddeb03a372fb885eab3480cc56f10115b Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Sat, 13 Feb 2021 17:19:12 +0100 Subject: [PATCH 542/675] examples: network-scan: resolve PEP8 issues Use autopep8 utility to resolve issues like spaces before brackets and wrong hanging indentation. Also treat objects like boolean variables to check whether they are None or not. --- .../network-scan-python/network-scan-python | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/network-scan-python/network-scan-python b/examples/network-scan-python/network-scan-python index df295995..db12242a 100755 --- a/examples/network-scan-python/network-scan-python +++ b/examples/network-scan-python/network-scan-python @@ -34,17 +34,19 @@ if __name__ == "__main__": sys.exit(1) # Connection to ModemManager - connection = Gio.bus_get_sync (Gio.BusType.SYSTEM, None) - manager = ModemManager.Manager.new_sync (connection, Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, None) - if manager.get_name_owner() is None: + connection = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) + manager = ModemManager.Manager.new_sync( + connection, Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, None) + if not manager.get_name_owner(): sys.stderr.write('ModemManager not found in bus\n') sys.exit(2) # Iterate modems and scan network with each one by one for obj in manager.get_objects(): modem3gpp = obj.get_modem_3gpp() - if modem3gpp is None: - sys.stderr.write('%s: skipping unusable modem...\n' % obj.get_object_path()) + if not modem3gpp: + sys.stderr.write('%s: skipping unusable modem...\n' % + obj.get_object_path()) continue modem3gpp.set_default_timeout(300000) print('%s: starting network scan...' % modem3gpp.get_object_path()) @@ -52,10 +54,12 @@ if __name__ == "__main__": if networks: for network in networks: print('%s: %s - %s (%s, %s)' % ( - network.get_operator_code(), - network.get_operator_short(), - network.get_operator_short(), - ModemManager.modem_access_technology_build_string_from_mask (network.get_access_technology()), - ModemManager.Modem3gppNetworkAvailability.get_string(network.get_availability()))) + network.get_operator_code(), + network.get_operator_short(), + network.get_operator_short(), + ModemManager.modem_access_technology_build_string_from_mask( + network.get_access_technology()), + ModemManager.Modem3gppNetworkAvailability.get_string( + network.get_availability()))) else: print('no networks found') From 3a32409000ad584ec67b0ddd43b312a37ea5a369 Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Sat, 13 Feb 2021 17:19:13 +0100 Subject: [PATCH 543/675] examples: network-scan: enable modem before the network scan Otherwise we get the following exception: Traceback (most recent call last): File "/root/network-scan-python", line 57, in networks = modem3gpp.scan_sync() gi.repository.GLib.Error: mm_core_error_quark: GDBus.Error:org.freedesktop.ModemManager1.Error.Core.WrongState: Cannot scan networks: not enabled yet (8) --- examples/network-scan-python/network-scan-python | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/network-scan-python/network-scan-python b/examples/network-scan-python/network-scan-python index db12242a..12ee02f7 100755 --- a/examples/network-scan-python/network-scan-python +++ b/examples/network-scan-python/network-scan-python @@ -19,6 +19,7 @@ # import sys +import time import gi gi.require_version('ModemManager', '1.0') @@ -43,6 +44,9 @@ if __name__ == "__main__": # Iterate modems and scan network with each one by one for obj in manager.get_objects(): + modem = obj.get_modem() + modem.enable() + time.sleep(1) modem3gpp = obj.get_modem_3gpp() if not modem3gpp: sys.stderr.write('%s: skipping unusable modem...\n' % From b2f9771b8559c9cb877d1f44189b390b9704bc1e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 15 Feb 2021 00:43:15 +0100 Subject: [PATCH 544/675] broadband-modem-mbim: detect 5G support in custom data class Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/301 --- src/mm-broadband-modem-mbim.c | 11 ++++++++--- src/mm-modem-helpers-mbim.c | 11 +++++++++-- src/mm-modem-helpers-mbim.h | 5 +++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index a3633120..97ce89a9 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -98,6 +98,7 @@ struct _MMBroadbandModemMbimPrivate { /* Queried and cached capabilities */ MbimCellularClass caps_cellular_class; MbimDataClass caps_data_class; + gchar *caps_custom_data_class; MbimSmsCaps caps_sms; guint caps_max_sessions; gchar *caps_device_id; @@ -447,7 +448,7 @@ device_caps_query_ready (MbimDevice *device, &self->priv->caps_sms, NULL, /* ctrl_caps */ &self->priv->caps_max_sessions, - NULL, /* custom_data_class */ + &self->priv->caps_custom_data_class, &self->priv->caps_device_id, &self->priv->caps_firmware_info, &self->priv->caps_hardware_info, @@ -458,7 +459,8 @@ device_caps_query_ready (MbimDevice *device, } ctx->current_mbim = mm_modem_capability_from_mbim_device_caps (self->priv->caps_cellular_class, - self->priv->caps_data_class); + self->priv->caps_data_class, + self->priv->caps_custom_data_class); complete_current_capabilities (task); out: @@ -561,7 +563,9 @@ load_supported_capabilities_mbim (GTask *task) self = g_task_get_source_object (task); /* Current capabilities should have been cached already, just assume them */ - current = mm_modem_capability_from_mbim_device_caps (self->priv->caps_cellular_class, self->priv->caps_data_class); + current = mm_modem_capability_from_mbim_device_caps (self->priv->caps_cellular_class, + self->priv->caps_data_class, + self->priv->caps_custom_data_class); if (current != 0) { supported = g_array_sized_new (FALSE, FALSE, sizeof (MMModemCapability), 1); g_array_append_val (supported, current); @@ -5622,6 +5626,7 @@ finalize (GObject *object) { MMBroadbandModemMbim *self = MM_BROADBAND_MODEM_MBIM (object); + g_free (self->priv->caps_custom_data_class); g_free (self->priv->caps_device_id); g_free (self->priv->caps_firmware_info); g_free (self->priv->caps_hardware_info); diff --git a/src/mm-modem-helpers-mbim.c b/src/mm-modem-helpers-mbim.c index 0d5ff5f9..8dfc2420 100644 --- a/src/mm-modem-helpers-mbim.c +++ b/src/mm-modem-helpers-mbim.c @@ -22,8 +22,9 @@ /*****************************************************************************/ MMModemCapability -mm_modem_capability_from_mbim_device_caps (MbimCellularClass caps_cellular_class, - MbimDataClass caps_data_class) +mm_modem_capability_from_mbim_device_caps (MbimCellularClass caps_cellular_class, + MbimDataClass caps_data_class, + const gchar *caps_custom_data_class) { MMModemCapability mask = 0; @@ -38,6 +39,12 @@ mm_modem_capability_from_mbim_device_caps (MbimCellularClass caps_cellular_class if (caps_data_class & MBIM_DATA_CLASS_LTE) mask |= MM_MODEM_CAPABILITY_LTE; + if ((caps_data_class & MBIM_DATA_CLASS_CUSTOM) && caps_custom_data_class) { + /* e.g. Gosuncn GM800 reports MBIM custom data class "5G/TDS" */ + if (strstr (caps_custom_data_class, "5G")) + mask |= MM_MODEM_CAPABILITY_5GNR; + } + return mask; } diff --git a/src/mm-modem-helpers-mbim.h b/src/mm-modem-helpers-mbim.h index f9d509f8..9cebe95f 100644 --- a/src/mm-modem-helpers-mbim.h +++ b/src/mm-modem-helpers-mbim.h @@ -24,8 +24,9 @@ /*****************************************************************************/ /* MBIM/BasicConnect to MM translations */ -MMModemCapability mm_modem_capability_from_mbim_device_caps (MbimCellularClass caps_cellular_class, - MbimDataClass caps_data_class); +MMModemCapability mm_modem_capability_from_mbim_device_caps (MbimCellularClass caps_cellular_class, + MbimDataClass caps_data_class, + const gchar *caps_custom_data_class); MMModemLock mm_modem_lock_from_mbim_pin_type (MbimPinType pin_type); From 8bf1869f3c5b69e90b1cef21a04c77ff67f717cc Mon Sep 17 00:00:00 2001 From: Yaron Shahrabani Date: Mon, 8 Feb 2021 16:37:47 +0000 Subject: [PATCH 545/675] po: add Hebrew translation --- po/LINGUAS | 1 + po/he.po | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 po/he.po diff --git a/po/LINGUAS b/po/LINGUAS index fdf80dfb..9a35a286 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -4,6 +4,7 @@ de fi fr fur +he hu id it diff --git a/po/he.po b/po/he.po new file mode 100644 index 00000000..485579e5 --- /dev/null +++ b/po/he.po @@ -0,0 +1,105 @@ +# Hebrew translation of Modem Manager +# Copyright (C) 2020 Free Software Foundation, Inc. +# This file is distributed under the same license as the Modem Manager package. +# +# Yaron Shahrabani , 2020. +msgid "" +msgstr "" +"Project-Id-Version: Modem Manager\n" +"Report-Msgid-Bugs-To: https://gitlab.freedesktop.org/mobile-broadband/" +"ModemManager/issues\n" +"POT-Creation-Date: 2020-09-18 10:30+0200\n" +"PO-Revision-Date: 2020-02-08 18:14+0200\n" +"Last-Translator: Yaron Shahrabani \n" +"Language-Team: Hebrew \n" +"Language: he\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: GitLab Editor\n" + +#: data/org.freedesktop.ModemManager1.policy.in.in:13 +msgid "Control the Modem Manager daemon" +msgstr "שליטה בסוכן מנהל המודמים" + +#: data/org.freedesktop.ModemManager1.policy.in.in:14 +msgid "System policy prevents controlling the Modem Manager." +msgstr "מדיניות מערכת מונעת שליטה במנהל המודמים." + +#: data/org.freedesktop.ModemManager1.policy.in.in:22 +msgid "Unlock and control a mobile broadband device" +msgstr "שחרור ושליטה במכשיר לרשת תקשורת סלולרית" + +#: data/org.freedesktop.ModemManager1.policy.in.in:23 +msgid "System policy prevents unlocking or controlling the mobile broadband device." +msgstr "מדיניות המערכת מונעת שחרור או שליטה בהתקן רשת התקשורת האלחוטית." + +#: data/org.freedesktop.ModemManager1.policy.in.in:31 +msgid "Add, modify, and delete mobile broadband contacts" +msgstr "ניתן להוסיף, לערוך ולמחוק אנשי קשר בהתקן רשת תקשורת אלחוטית" + +#: data/org.freedesktop.ModemManager1.policy.in.in:32 +msgid "" +"System policy prevents adding, modifying, or deleting this device's contacts." +msgstr "מדיניות המערכת מונעת הוספה, עריכה או מחיקה של אנשי הקשר במכשיר הזה." + +#: data/org.freedesktop.ModemManager1.policy.in.in:40 +msgid "Send, save, modify, and delete text messages" +msgstr "שליחה, שמירה, עריכה ומחיקה של הודעות טקסט" + +#: data/org.freedesktop.ModemManager1.policy.in.in:41 +msgid "" +"System policy prevents sending or manipulating this device's text messages." +msgstr "" +"מדיניות המערכת מונעת שליחה או עריכה של המסרונים בהתקן הזה." + +#: data/org.freedesktop.ModemManager1.policy.in.in:49 +msgid "Accept incoming voice calls or start outgoing voice calls." +msgstr "לקבל שיחות נכנסות או להוציא שיחות." + +#: data/org.freedesktop.ModemManager1.policy.in.in:50 +msgid "System policy prevents voice calls." +msgstr "מדיניות המערכת מונעת שיחות קוליות." + +#: data/org.freedesktop.ModemManager1.policy.in.in:58 +msgid "Query network time and timezone information" +msgstr "לתשאל את פרטי השעה ואזור הזמן מהרשת" + +#: data/org.freedesktop.ModemManager1.policy.in.in:59 +msgid "System policy prevents querying network time information." +msgstr "מדיניות מערכת מונעת תשאול פרטי זמן מהרשת." + +#: data/org.freedesktop.ModemManager1.policy.in.in:67 +msgid "Enable and view geographic location and positioning information" +msgstr "" +"להפעיל ולהציג פרטי מיקום גאוגרפי" + +#: data/org.freedesktop.ModemManager1.policy.in.in:68 +msgid "" +"System policy prevents enabling or viewing geographic location information." +msgstr "" +"מדיניות מערכת מונעת הפעלה או הצגה של פרטי מיקום גאוגרפי." + +#: data/org.freedesktop.ModemManager1.policy.in.in:76 +msgid "Query and utilize network information and services" +msgstr "תשאול ושימוש בשירותי ומידע על הרשת" + +#: data/org.freedesktop.ModemManager1.policy.in.in:77 +msgid "" +"System policy prevents querying or utilizing network information and " +"services." +msgstr "" +"מדיניות המערכת מונעת תשאול או שימוש במידע על הרשת או שירותים שלה." + +#: data/org.freedesktop.ModemManager1.policy.in.in:85 +msgid "Query and manage firmware on a mobile broadband device" +msgstr "תשאול וניהול קושחה על התקן רשת תקשורת סלולרית" + +#: data/org.freedesktop.ModemManager1.policy.in.in:86 +msgid "System policy prevents querying or managing this device's firmware." +msgstr "מדיניות המערכת מונעת תשאול או ניהול של קושחת ההתקן הזה." + +#: src/mm-sleep-monitor.c:125 +msgid "ModemManager needs to reset devices" +msgstr "על ModemManager לאפס התקנים" From e685ce9ce51f5f1e18ab3f42106715fd659ed2c6 Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Mon, 15 Feb 2021 17:53:38 +0100 Subject: [PATCH 546/675] examples: ModemWatcher: convert comments in the doc strings Move comments under the class and method definitions. Also rework boolean handling. --- examples/modem-watcher-python/ModemWatcher.py | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/examples/modem-watcher-python/ModemWatcher.py b/examples/modem-watcher-python/ModemWatcher.py index 2311a8ad..7ee8939b 100644 --- a/examples/modem-watcher-python/ModemWatcher.py +++ b/examples/modem-watcher-python/ModemWatcher.py @@ -23,22 +23,20 @@ from gi.repository import Gio, GLib, GObject, ModemManager -""" -The ModemWatcher class is responsible for monitoring ModemManager -""" class ModemWatcher: - """ - Constructor + The ModemWatcher class is responsible for monitoring ModemManager. """ + def __init__(self): # Flag for initial logs self.initializing = True # Setup DBus monitoring - self.connection = Gio.bus_get_sync (Gio.BusType.SYSTEM, None) - self.manager = ModemManager.Manager.new_sync (self.connection, - Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, - None) + self.connection = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) + self.manager = ModemManager.Manager.new_sync( + self.connection, + Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, + None) # IDs for added/removed signals self.object_added_id = 0 self.object_removed_id = 0 @@ -49,25 +47,25 @@ def __init__(self): # Finish initialization self.initializing = False - """ - ModemManager is now available - """ def set_available(self): - if self.available == False or self.initializing == True: + """ + ModemManager is now available. + """ + if not self.available or self.initializing: print('[ModemWatcher] ModemManager %s service is available in bus' % self.manager.get_version()) self.object_added_id = self.manager.connect('object-added', self.on_object_added) self.object_removed_id = self.manager.connect('object-removed', self.on_object_removed) self.available = True # Initial scan - if self.initializing == True: + if self.initializing: for obj in self.manager.get_objects(): self.on_object_added(self.manager, obj) - """ - ModemManager is now unavailable - """ def set_unavailable(self): - if self.available == True or self.initializing == True: + """ + ModemManager is now unavailable. + """ + if self.available or self.initializing: print('[ModemWatcher] ModemManager service not available in bus') if self.object_added_id: self.manager.disconnect(self.object_added_id) @@ -77,19 +75,19 @@ def set_unavailable(self): self.object_removed_id = 0 self.available = False - """ - Name owner updates - """ def on_name_owner(self, manager, prop): + """ + Name owner updates. + """ if self.manager.get_name_owner(): self.set_available() else: self.set_unavailable() - """ - Object added - """ def on_object_added(self, manager, obj): + """ + Object added. + """ modem = obj.get_modem() print('[ModemWatcher] %s (%s) modem managed by ModemManager [%s]: %s' % (modem.get_manufacturer(), @@ -100,9 +98,9 @@ def on_object_added(self, manager, obj): print('[ModemWatcher] ignoring failed modem: %s' % obj.get_object_path()) - """ - Object removed - """ def on_object_removed(self, manager, obj): + """ + Object removed. + """ print('[ModemWatcher] modem unmanaged by ModemManager: %s' % obj.get_object_path()) From 69926d93357cc0ed7280586abee1e6871e0894cc Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Mon, 15 Feb 2021 17:53:39 +0100 Subject: [PATCH 547/675] examples: modem-watcher: get rid of global variables Move the code into the main() routine and pass main_loop as a parameter to the signal handler. --- .../modem-watcher-python/modem-watcher-python | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/examples/modem-watcher-python/modem-watcher-python b/examples/modem-watcher-python/modem-watcher-python index 4884beef..f7dd1fc6 100755 --- a/examples/modem-watcher-python/modem-watcher-python +++ b/examples/modem-watcher-python/modem-watcher-python @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- # # This program is free software; you can redistribute it and/or modify it under @@ -24,21 +24,28 @@ from gi.repository import GLib import ModemWatcher -main_loop = None -watcher = None -def signal_handler(data): - main_loop.quit() +def signal_handler(loop): + """SIGHUP and SIGINT handler.""" + loop.quit() -if __name__ == "__main__": + +def main(): + """Main routine.""" # Create modem watcher - watcher = ModemWatcher.ModemWatcher() + ModemWatcher.ModemWatcher() # Main loop main_loop = GLib.MainLoop() - GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGHUP, signal_handler, None) - GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGTERM, signal_handler, None) + GLib.unix_signal_add( + GLib.PRIORITY_HIGH, signal.SIGHUP, signal_handler, main_loop) + GLib.unix_signal_add( + GLib.PRIORITY_HIGH, signal.SIGTERM, signal_handler, main_loop) try: main_loop.run() except KeyboardInterrupt: pass + + +if __name__ == "__main__": + main() From c4f215c9cb2d8497e7ebfea2904563526bb08d90 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 17 Feb 2021 15:21:49 +0100 Subject: [PATCH 548/675] libmm-glib,bearer-properties: consume 'rm-protocol' setting --- libmm-glib/mm-bearer-properties.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c index 904d1248..f3ccddbe 100644 --- a/libmm-glib/mm-bearer-properties.c +++ b/libmm-glib/mm-bearer-properties.c @@ -602,6 +602,10 @@ mm_bearer_properties_consume_variant (MMBearerProperties *properties, mm_bearer_properties_set_allow_roaming ( properties, g_variant_get_boolean (value)); + else if (g_str_equal (key, PROPERTY_RM_PROTOCOL)) + mm_bearer_properties_set_rm_protocol ( + properties, + g_variant_get_uint32 (value)); else if (g_str_equal (key, DEPRECATED_PROPERTY_NUMBER)) { /* NO-OP */ } else { From 6dd5ced86d80c695be9898b9ac4ea3e50ff64f32 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 17 Feb 2021 15:31:08 +0100 Subject: [PATCH 549/675] libmm-glib,simple-connect-properties: add missing APIs to get/set RM protocol Probably not a big deal, since no one has asked for these in the past years, but let's add them for completeness with the DBus API. --- .../libmm-glib/libmm-glib-sections.txt | 2 + libmm-glib/mm-simple-connect-properties.c | 37 +++++++++++++++++++ libmm-glib/mm-simple-connect-properties.h | 21 ++++++----- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 7fc82f91..0a72befa 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -870,6 +870,8 @@ mm_simple_connect_properties_get_ip_type mm_simple_connect_properties_set_ip_type mm_simple_connect_properties_get_allow_roaming mm_simple_connect_properties_set_allow_roaming +mm_simple_connect_properties_get_rm_protocol +mm_simple_connect_properties_set_rm_protocol mm_simple_connect_properties_get_number mm_simple_connect_properties_set_number diff --git a/libmm-glib/mm-simple-connect-properties.c b/libmm-glib/mm-simple-connect-properties.c index 5b9af11a..fd256513 100644 --- a/libmm-glib/mm-simple-connect-properties.c +++ b/libmm-glib/mm-simple-connect-properties.c @@ -364,6 +364,43 @@ mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *self) return mm_bearer_properties_get_allow_roaming (self->priv->bearer_properties); } +/*****************************************************************************/ + +/** + * mm_simple_connect_properties_set_rm_protocol: + * @self: a #MMSimpleConnectProperties. + * @protocol: a #MMModemCdmaRmProtocol. + * + * Sets the RM protocol requested by the user. + * + * Since: 1.16 + */ +void +mm_simple_connect_properties_set_rm_protocol (MMSimpleConnectProperties *self, + MMModemCdmaRmProtocol protocol) +{ + g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self)); + + mm_bearer_properties_set_rm_protocol (self->priv->bearer_properties, protocol); +} + +/** + * mm_simple_connect_properties_get_rm_protocol: + * @self: a #MMSimpleConnectProperties. + * + * Get the RM protocol requested by the user. + * + * Returns: a #MMModemCdmaRmProtocol. + * + * Since: 1.16 + */ +MMModemCdmaRmProtocol +mm_simple_connect_properties_get_rm_protocol (MMSimpleConnectProperties *self) +{ + g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN); + + return mm_bearer_properties_get_rm_protocol (self->priv->bearer_properties); +} /*****************************************************************************/ diff --git a/libmm-glib/mm-simple-connect-properties.h b/libmm-glib/mm-simple-connect-properties.h index c8f24efa..d56f64f2 100644 --- a/libmm-glib/mm-simple-connect-properties.h +++ b/libmm-glib/mm-simple-connect-properties.h @@ -76,15 +76,18 @@ void mm_simple_connect_properties_set_ip_type (MMSimpleConnectProperties * MMBearerIpFamily ip_type); void mm_simple_connect_properties_set_allow_roaming (MMSimpleConnectProperties *self, gboolean allow_roaming); - -const gchar *mm_simple_connect_properties_get_pin (MMSimpleConnectProperties *self); -const gchar *mm_simple_connect_properties_get_operator_id (MMSimpleConnectProperties *self); -const gchar *mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *self); -MMBearerAllowedAuth mm_simple_connect_properties_get_allowed_auth (MMSimpleConnectProperties *self); -const gchar *mm_simple_connect_properties_get_user (MMSimpleConnectProperties *self); -const gchar *mm_simple_connect_properties_get_password (MMSimpleConnectProperties *self); -MMBearerIpFamily mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *self); -gboolean mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *self); +void mm_simple_connect_properties_set_rm_protocol (MMSimpleConnectProperties *self, + MMModemCdmaRmProtocol protocol); + +const gchar *mm_simple_connect_properties_get_pin (MMSimpleConnectProperties *self); +const gchar *mm_simple_connect_properties_get_operator_id (MMSimpleConnectProperties *self); +const gchar *mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *self); +MMBearerAllowedAuth mm_simple_connect_properties_get_allowed_auth (MMSimpleConnectProperties *self); +const gchar *mm_simple_connect_properties_get_user (MMSimpleConnectProperties *self); +const gchar *mm_simple_connect_properties_get_password (MMSimpleConnectProperties *self); +MMBearerIpFamily mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *self); +gboolean mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *self); +MMModemCdmaRmProtocol mm_simple_connect_properties_get_rm_protocol (MMSimpleConnectProperties *self); #ifndef MM_DISABLE_DEPRECATED G_DEPRECATED From 29d9dc7e0cd9b80e0b75f9833b6bb896c78eda33 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 17 Feb 2021 15:38:50 +0100 Subject: [PATCH 550/675] api,introspection: flag as DEPRECATED the 'number' bearer setting This setting is unused since some releases ago, and the corresponding libmm-glib methods were already flagged as deprecated. Let's add an explicit mention to this deprecation on the DBus API itself. --- introspection/org.freedesktop.ModemManager1.Modem.Simple.xml | 3 ++- introspection/org.freedesktop.ModemManager1.Modem.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/introspection/org.freedesktop.ModemManager1.Modem.Simple.xml b/introspection/org.freedesktop.ModemManager1.Modem.Simple.xml index bbc497ed..082e63d8 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.Simple.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.Simple.xml @@ -91,8 +91,9 @@ "number" - For POTS devices the number to dial,, + Number to dial for the data connection, given as a string value (signature "s"). + Deprecated since version 1.10.0. "allow-roaming" diff --git a/introspection/org.freedesktop.ModemManager1.Modem.xml b/introspection/org.freedesktop.ModemManager1.Modem.xml index d9dbd436..529b26bd 100644 --- a/introspection/org.freedesktop.ModemManager1.Modem.xml +++ b/introspection/org.freedesktop.ModemManager1.Modem.xml @@ -80,7 +80,7 @@ "rm-protocol" Protocol of the Rm interface, given as a MMModemCdmaRmProtocol value (signature "u"). Optional in CDMA. "number" - Telephone number to dial, given as a string value (signature "s"). Required in POTS. + Number to dial for the data connection, given as a string value (signature "s"). Deprecated since version 1.10.0. Some properties are only applicable to a bearer of certain access From a546201470ee1067be5494ab5f678016bb2bc2ec Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 22 Feb 2021 15:04:43 +0100 Subject: [PATCH 551/675] bearer-mbim: IP type may be reported as deactivated and still have IP settings If we were requesting for IPv4v6 and we only got IPv4 reported as activated, we would right away ignore the IPv6 bits, even if we received IPv6 settings later on when querying for them. Change that, so that if an IP address of a given type is received, we assume the corresponding context was really activated even if the modem didn't report it in the connect set response. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/320 --- src/mm-bearer-mbim.c | 61 +++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/src/mm-bearer-mbim.c b/src/mm-bearer-mbim.c index e53529ee..b808f547 100644 --- a/src/mm-bearer-mbim.c +++ b/src/mm-bearer-mbim.c @@ -223,7 +223,8 @@ typedef struct { MMBearerProperties *properties; ConnectStep step; MMPort *data; - MbimContextIpType ip_type; + MbimContextIpType requested_ip_type; + MbimContextIpType activated_ip_type; MMBearerConnectResult *connect_result; } ConnectContext; @@ -396,9 +397,11 @@ ip_configuration_query_ready (MbimDevice *device, /* Build connection results */ /* Build IPv4 config */ - if (ctx->ip_type == MBIM_CONTEXT_IP_TYPE_IPV4 || - ctx->ip_type == MBIM_CONTEXT_IP_TYPE_IPV4V6 || - ctx->ip_type == MBIM_CONTEXT_IP_TYPE_IPV4_AND_IPV6) { + if (ctx->requested_ip_type == MBIM_CONTEXT_IP_TYPE_IPV4 || + ctx->requested_ip_type == MBIM_CONTEXT_IP_TYPE_IPV4V6 || + ctx->requested_ip_type == MBIM_CONTEXT_IP_TYPE_IPV4_AND_IPV6) { + gboolean address_set = FALSE; + ipv4_config = mm_bearer_ip_config_new (); /* We assume that if we have an IP we can use static configuration. @@ -416,6 +419,7 @@ ip_configuration_query_ready (MbimDevice *device, mm_bearer_ip_config_set_address (ipv4_config, str); g_free (str); g_object_unref (addr); + address_set = TRUE; /* Netmask */ mm_bearer_ip_config_set_prefix (ipv4_config, ipv4address[0]->on_link_prefix_length); @@ -451,13 +455,23 @@ ip_configuration_query_ready (MbimDevice *device, /* MTU */ if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU) mm_bearer_ip_config_set_mtu (ipv4_config, ipv4mtu); + + /* We requested IPv4, but it wasn't reported as activated. If there is no IP address + * provided by the modem, we assume the IPv4 bearer wasn't truly activated */ + if (!address_set && + ctx->activated_ip_type != MBIM_CONTEXT_IP_TYPE_IPV4 && + ctx->activated_ip_type != MBIM_CONTEXT_IP_TYPE_IPV4V6 && + ctx->activated_ip_type != MBIM_CONTEXT_IP_TYPE_IPV4_AND_IPV6) { + mm_obj_dbg (self, "IPv4 requested but no IPv4 activated and no IPv4 address set: ignoring"); + g_clear_object (&ipv4_config); + } } else ipv4_config = NULL; /* Build IPv6 config */ - if (ctx->ip_type == MBIM_CONTEXT_IP_TYPE_IPV6 || - ctx->ip_type == MBIM_CONTEXT_IP_TYPE_IPV4V6 || - ctx->ip_type == MBIM_CONTEXT_IP_TYPE_IPV4_AND_IPV6) { + if (ctx->requested_ip_type == MBIM_CONTEXT_IP_TYPE_IPV6 || + ctx->requested_ip_type == MBIM_CONTEXT_IP_TYPE_IPV4V6 || + ctx->requested_ip_type == MBIM_CONTEXT_IP_TYPE_IPV4_AND_IPV6) { gboolean address_set = FALSE; gboolean gateway_set = FALSE; gboolean dns_set = FALSE; @@ -528,6 +542,16 @@ ip_configuration_query_ready (MbimDevice *device, mm_bearer_ip_config_set_method (ipv6_config, MM_BEARER_IP_METHOD_STATIC); else mm_bearer_ip_config_set_method (ipv6_config, MM_BEARER_IP_METHOD_DHCP); + + /* We requested IPv6, but it wasn't reported as activated. If there is no IPv6 address + * provided by the modem, we assume the IPv6 bearer wasn't truly activated */ + if (!address_set && + ctx->activated_ip_type != MBIM_CONTEXT_IP_TYPE_IPV6 && + ctx->activated_ip_type != MBIM_CONTEXT_IP_TYPE_IPV4V6 && + ctx->activated_ip_type != MBIM_CONTEXT_IP_TYPE_IPV4_AND_IPV6) { + mm_obj_dbg (self, "IPv6 requested but no IPv6 activated and no IPv6 address set: ignoring"); + g_clear_object (&ipv6_config); + } } else ipv6_config = NULL; @@ -570,7 +594,6 @@ connect_set_ready (MbimDevice *device, GError *error = NULL; MbimMessage *response; guint32 session_id; - MbimContextIpType ip_type; MbimActivationState activation_state; guint32 nw_error; @@ -588,16 +611,16 @@ connect_set_ready (MbimDevice *device, &session_id, &activation_state, NULL, /* voice_call_state */ - &ip_type, + &ctx->activated_ip_type, NULL, /* context_type */ &nw_error, &inner_error)) { /* Report the IP type we asked for and the one returned by the modem */ - mm_obj_dbg (self, "session ID '%u': %s (requested IP type: %s, received IP type: %s, nw error: %s)", + mm_obj_dbg (self, "session ID '%u': %s (requested IP type: %s, activated IP type: %s, nw error: %s)", session_id, mbim_activation_state_get_string (activation_state), - mbim_context_ip_type_get_string (ctx->ip_type), - mbim_context_ip_type_get_string (ip_type), + mbim_context_ip_type_get_string (ctx->requested_ip_type), + mbim_context_ip_type_get_string (ctx->activated_ip_type), nw_error ? mbim_nw_error_get_string (nw_error) : "none"); /* If the response reports an ACTIVATED state, we're good even if * there is a nw_error set (e.g. asking for IPv4v6 may return a @@ -613,11 +636,6 @@ connect_set_ready (MbimDevice *device, "Unknown error: context activation failed"); } } - /* We're now connected, but we may have received an IP type different to the one - * requested (e.g. asking for IPv4v6 but received IPv4 only). Handle that, so that - * the next step getting IP details doesn't get confused. */ - else if (ctx->ip_type != ip_type) - ctx->ip_type = ip_type; } else { /* Prefer the error from the result to the parsing error */ if (!error) @@ -995,14 +1013,15 @@ connect_context_step (GTask *task) g_free (str); } - ctx->ip_type = mm_bearer_ip_family_to_mbim_context_ip_type (ip_family, &error); + ctx->requested_ip_type = mm_bearer_ip_family_to_mbim_context_ip_type (ip_family, &error); if (error) { g_task_return_error (task, error); g_object_unref (task); return; } - mm_obj_dbg (self, "launching %s connection with APN '%s'...", mbim_context_ip_type_get_string (ctx->ip_type), apn); + mm_obj_dbg (self, "launching %s connection with APN '%s'...", + mbim_context_ip_type_get_string (ctx->requested_ip_type), apn); message = (mbim_message_connect_set_new ( self->priv->session_id, MBIM_ACTIVATION_COMMAND_ACTIVATE, @@ -1011,7 +1030,7 @@ connect_context_step (GTask *task) password ? password : "", MBIM_COMPRESSION_NONE, auth, - ctx->ip_type, + ctx->requested_ip_type, mbim_uuid_from_context_type (MBIM_CONTEXT_TYPE_INTERNET), &error)); if (!message) { @@ -1138,6 +1157,8 @@ _connect (MMBaseBearer *self, ctx->device = g_object_ref (device);; ctx->data = g_object_ref (data); ctx->step = CONNECT_STEP_FIRST; + ctx->requested_ip_type = MBIM_CONTEXT_IP_TYPE_DEFAULT; + ctx->activated_ip_type = MBIM_CONTEXT_IP_TYPE_DEFAULT; g_object_get (self, MM_BASE_BEARER_CONFIG, &ctx->properties, From bbd3638d1233efbe05993bf79aa48ada97589724 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 23 Feb 2021 11:22:18 +0100 Subject: [PATCH 552/675] build: require libqmi 1.28.0 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 8c2711f2..08fd93ab 100644 --- a/configure.ac +++ b/configure.ac @@ -401,7 +401,7 @@ dnl----------------------------------------------------------------------------- dnl QMI support (enabled by default) dnl -LIBQMI_VERSION=1.27.3 +LIBQMI_VERSION=1.28.0 AC_ARG_WITH(qmi, AS_HELP_STRING([--without-qmi], [Build without QMI support]), [], [with_qmi=yes]) AM_CONDITIONAL(WITH_QMI, test "x$with_qmi" = "xyes") From 7a5eae2a36e9a544bfdffdfa57af76cf60b97bae Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 23 Feb 2021 11:11:57 +0100 Subject: [PATCH 553/675] NEWS: update for 1.16.0 --- NEWS | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/NEWS b/NEWS index a57854ba..2ded5615 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,149 @@ +ModemManager 1.16.0 +------------------------------------------- +This is a new stable release of ModemManager. + +The following notes are directed to package maintainers: + + * This version now requires: + ** libqmi >= 1.28.0 (for the optional QMI support) + + * The 1.16.x branch will be the last one supporting the 'LEGACY' and 'PARANOID' + filter modes; standard distributions are advised to use the default 'STRICT' + mode if they aren't using it already (i.e. running the daemon without any + explicit '--filter-policy' option). + + * A new 'qcom-soc' plugin is implemented to be able to use ModemManager in + Qualcomm SoCs like the MSM8916 or MSM8974. This plugin uses a combination of + RPMSG based control ports plus BAM-DMUX based network ports. This plugin is + disabled by default, even when `--enable-all-plugins` is used, and if wanted + it must be explicitly enabled with `--enable-plugin-qcom-soc`. Systems + targeting this kind of SoCs, like postmarketos, should enable it. Standard + distributions may or may not include it, up to the targeted hardware in each + distribution. + + * Gentoo's 'libelogind' library may now be used to detect the systemd + suspend/resume support. + +The API is backwards compatible with the previous releases, the only updates +are the following: + + * Modem interface: + ** Updated the 'Ports' property so that it exposes all ports that are + owned by the modem even if they are explicitly ignored and not used. + ** New 'SimSlots' property that exposes the available SIM slots in the modem, + including the SIM object paths in each of them if the cards are present. + ** New 'PrimarySimSlot' property indicating which of the slots in the + 'SimSlots' array is the one currently active. + ** New 'SetPrimarySimSlot' method to select which SIM slot in the 'SimSlots' + array should be considered active. When the switch happens, the modem will + be fully re-probed. + + * Signal interface: + ** New 'Nr5g' dictionary property including signal information for the 5GNR + access technology. + + * SIM interface: + ** New 'Active' boolean property, indicating whether the SIM object is the + currently active one. + ** New 'Eid' string property, indicating the EID of the card, if any. + + * New udev tags: + ** New 'ID_MM_PORT_TYPE_QMI' tag to explicitly flag a port as being QMI, when + there is no other way to guess the type of port; e.g. this tag is not + needed for ports exposed by the qmi_wwan driver. + ** New 'ID_MM_PORT_TYPE_MBIM' tag to explicitly flag a port as being MBIM, + when there is no other way to guess the type of port; e.g. this tag is not + needed for ports exposed by the cdc_mbim driver. + +The most important features and changes in this release are the following: + + * Implemented support for Multi SIM Single Standby support, for systems that + have multiple SIM slots and they can select which of them (only one) is + active at any given time. Currently implemented for QMI modems only. + + * If the modem enabling phase fails in a fatal way, an implicit disabling + sequence is now run, in order to avoid leaving the modem in an inconsistent + state. + + * If the connection attempt includes user/password information but no explicit + authentication type, CHAP will now be used by default instead of PAP. + + * Full USB device removal events reported via udev are no longer used. The + device removal logic relies exclusively on independent port removal events, + as that logic is supported for all subsystems and kernel device backends + (e.g. also working for non-USB devices and for systems without udev like + OpenWRT). + + * Added support to monitor the 'rpmsg' subsystem, but only in plugins that + explicitly require its use (e.g. the 'qcom-soc' plugin). + + * New options in the ModemManager daemon: + ** Added new '--test-no-suspend-resume' option to disable the runtime + suspend/resume support even if the daemon was built with it. + ** Added new '--test-no-udev' option to disable the runtime udev support even + if the daemon was built with it. + + * Serial: + ** Also match OK or ERROR responses that are not at end of line. + + * SIM: + ** Force reprobing the modem if a new SIM is detected in a modem that + initially started in Failed state without SIM. + ** Force reprobing the modem if the lock status cannot be read after sending + SIM-PUK, so that it transitions to the Failed state. + ** Force reprobing the modem if a PUK lock is discovered after sending + SIM-PIN, so that it transitions to the Failed state. + + * QMI: + ** The logic no longer depends on the service version reported by each + client, the support for each feature is explicitly probed instead. + ** Implemented SIM profile (eUICC) change detection. + ** Support for QMI modems on kernels < 3.6 is dropped. Only kernels where the + QMI control ports are exposed in the 'usbmisc' subsystem are supported. + ** Implemented additional step in the connection logic to allow binding the + WDS client to a given SIO port, required in the BAM-DMUX driver setup. + ** Implemented support for the initial EPS bearer settings logic. + ** Disabled explicit signal and access technology polling if indications have + been correctly enabled. + + * MBIM: + ** Enable SIM hot swap detection logic with QMI over MBIM. + ** Allow plugins to specify explicitly that QMI over MBIM is not supported. + + * libmm-glib: + ** Added missing APIs to get/set RM protocol in the Simple connect settings. + + * Plugins: + ** gosuncn: new plugin, for now just with port type hints for the GM800. + ** quectel: implemented GPS support with +QGPS. + ** quectel: implemented custom time support check to prefer +CTZU=3 instead + of +CTZU=1 so that the modem reports localtime instead of UTC in +CCLK. + ** sierra: added support for XMM-specific features (e.g. EM7345). + ** cinterion: implemented support for the initial EPS bearer settings logic. + ** cinterion: added SIM hot swap support to AT-based modems. + ** huawei: updated to avoid applying multiple port type hint methods. + ** huawei: updated the ^GETPORTMODE logic so that we don't assume the hints + in the response apply to specific USB interfaces. + +The following features which were backported to 1.14.x releases are also present +in ModemManager 1.16.0: + + * location: allow CID only updates. + * sms: allow sending/receiving UTF-16 as if it were UCS-2. + * modem: don't consider charset setup failure as fatal. + * QMI: fix reporting signal strength indications. + * QMI: fix parsing of USSD indications with UTF-16 data. + * QMI: run network registration with NAS Set System Selection Preference. + * QMI: when connection aborted, ensure network handles are released. + * MBIM: don't fail IPv4v6 connection attempt if only IPv4 succeeds. + * cinterion: improve user/password handling in AT^SGAUTH calls. + * cinterion: removed limitation to IPv4 only PDP contexts. + * cinterion: configure the PLAS9 to send URCs correctly. + * quectel: add support for MBIM devices. + * telit: add initial delay for AT ports to become responsive. + + ModemManager 1.14.0 ------------------------------------------- This is a new stable release of ModemManager. From 7a5a49b75301b38c2bac6a94de5afb2f9930cf4e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 23 Feb 2021 11:35:50 +0100 Subject: [PATCH 554/675] release: bump version to 1.16.0 --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 08fd93ab..771e1200 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ dnl Package and library versioning support dnl m4_define([mm_major_version], [1]) -m4_define([mm_minor_version], [15]) +m4_define([mm_minor_version], [16]) m4_define([mm_micro_version], [0]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) @@ -18,9 +18,9 @@ dnl If the interface has grown (that is, the new library is compatible dnl with old code), increment a. dnl If the interface has changed in an incompatible way (that is, dnl functions have changed or been removed), then zero a. -m4_define([mm_glib_lt_current], [6]) +m4_define([mm_glib_lt_current], [7]) m4_define([mm_glib_lt_revision], [0]) -m4_define([mm_glib_lt_age], [6]) +m4_define([mm_glib_lt_age], [7]) dnl----------------------------------------------------------------------------- dnl autoconf, automake, libtool initialization From bf8a6c41754046b12b4f65d1c0c3569e3f26c793 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 23 Feb 2021 12:19:52 +0100 Subject: [PATCH 555/675] build: post-release version bump to 1.16.1 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 771e1200..352d6fcb 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ dnl m4_define([mm_major_version], [1]) m4_define([mm_minor_version], [16]) -m4_define([mm_micro_version], [0]) +m4_define([mm_micro_version], [1]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From 4f7ee18d1cf1ce21bba3f2701e408ae83108b3de Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 25 Feb 2021 15:17:45 +0100 Subject: [PATCH 556/675] libmm-glib,bearer-properties: fix 'allow roaming' comparison Fix the 'allow roaming' setting comparison, which was breaking the whole bearer properties comparison logic, and therefore making Simple.Connect() recreate over and over the bearer with the same settings. Fixes 5629f47a59b48f2604fd8e9e4af7209b138aef21 (cherry picked from commit f10e4af919df8b92b5680e646a16a490fa80d9c3) --- libmm-glib/mm-bearer-properties.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c index f3ccddbe..4305cec7 100644 --- a/libmm-glib/mm-bearer-properties.c +++ b/libmm-glib/mm-bearer-properties.c @@ -761,7 +761,7 @@ mm_bearer_properties_cmp (MMBearerProperties *a, if (!(flags & MM_BEARER_PROPERTIES_CMP_FLAGS_NO_ALLOW_ROAMING)) { if (a->priv->allow_roaming != b->priv->allow_roaming) return FALSE; - if (a->priv->allow_roaming_set != b->priv->allow_roaming) + if (a->priv->allow_roaming_set != b->priv->allow_roaming_set) return FALSE; } if (a->priv->rm_protocol != b->priv->rm_protocol) From f1f1a7e25e007116a1eeb6284d7989218c80289c Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 26 Feb 2021 11:16:59 +0100 Subject: [PATCH 557/675] shared-qmi: network registration cancellation logic with asserts disabled g_assert() calls may be disabled, and if so, the network registration task would never get completed. (cherry picked from commit c7d366671f749689c143f7effe2a183eb710def9) --- src/mm-shared-qmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index d3ff0c22..c36dbfe4 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -212,7 +212,7 @@ register_in_network_cancelled (GCancellable *cancellable, g_signal_handler_disconnect (ctx->client, ctx->serving_system_indication_id); ctx->serving_system_indication_id = 0; - g_assert (g_task_return_error_if_cancelled (task)); + g_task_return_error_if_cancelled (task); g_object_unref (task); } From ef6e6c5303efe613479dae655962c6395321aed3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 1 Mar 2021 15:55:22 +0100 Subject: [PATCH 558/675] utils: import ptr array lookup with GEqualFunc from GLib 2.54 This fixes the build when using GLib < 2.54. (cherry picked from commit a9611c62793377d8da08e4cb5e9cb71f5afda22e) --- src/Makefile.am | 2 +- src/kerneldevice/mm-kernel-device-generic.c | 1 + src/mm-plugin-manager.c | 1 + src/mm-utils.c | 47 +++++++++++++++++++++ src/mm-utils.h | 14 ++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/mm-utils.c diff --git a/src/Makefile.am b/src/Makefile.am index e80c10aa..05fc6d48 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -287,7 +287,7 @@ ModemManager_SOURCES = \ main.c \ mm-context.h \ mm-context.c \ - mm-utils.h \ + mm-utils.h mm-utils.c \ mm-private-boxed-types.h \ mm-private-boxed-types.c \ mm-auth-provider.h \ diff --git a/src/kerneldevice/mm-kernel-device-generic.c b/src/kerneldevice/mm-kernel-device-generic.c index b1a3bf97..eeae0bc6 100644 --- a/src/kerneldevice/mm-kernel-device-generic.c +++ b/src/kerneldevice/mm-kernel-device-generic.c @@ -27,6 +27,7 @@ #include "mm-kernel-device-generic.h" #include "mm-kernel-device-generic-rules.h" #include "mm-log-object.h" +#include "mm-utils.h" #if !defined UDEVRULESDIR # error UDEVRULESDIR is not defined diff --git a/src/mm-plugin-manager.c b/src/mm-plugin-manager.c index 6c9bdf1e..4e9f3008 100644 --- a/src/mm-plugin-manager.c +++ b/src/mm-plugin-manager.c @@ -28,6 +28,7 @@ #include "mm-plugin-manager.h" #include "mm-plugin.h" #include "mm-shared.h" +#include "mm-utils.h" #include "mm-log-object.h" #define SHARED_PREFIX "libmm-shared" diff --git a/src/mm-utils.c b/src/mm-utils.c new file mode 100644 index 00000000..95fbb552 --- /dev/null +++ b/src/mm-utils.c @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Singleton support imported from NetworkManager. + * (C) Copyright 2014 Red Hat, Inc. + * + * GPtrArray lookup with GEqualFunc imported from GLib 2.48 + */ + +#include "mm-utils.h" + +#if !GLIB_CHECK_VERSION(2,54,0) + +gboolean +mm_ptr_array_find_with_equal_func (GPtrArray *haystack, + gconstpointer needle, + GEqualFunc equal_func, + guint *index_) +{ + guint i; + + g_return_val_if_fail (haystack != NULL, FALSE); + + if (equal_func == NULL) + equal_func = g_direct_equal; + + for (i = 0; i < haystack->len; i++) { + if (equal_func (g_ptr_array_index (haystack, i), needle)) { + if (index_ != NULL) + *index_ = i; + return TRUE; + } + } + + return FALSE; +} + +#endif diff --git a/src/mm-utils.h b/src/mm-utils.h index cdb123cd..613205a3 100644 --- a/src/mm-utils.h +++ b/src/mm-utils.h @@ -12,6 +12,8 @@ * * Singleton support imported from NetworkManager. * (C) Copyright 2014 Red Hat, Inc. + * + * GPtrArray lookup with GEqualFunc imported from GLib 2.48 */ #ifndef MM_UTILS_H @@ -78,4 +80,16 @@ } \ MM_DEFINE_SINGLETON_DESTRUCTOR(TYPE) + +#if !GLIB_CHECK_VERSION(2,54,0) + +/* Pointer Array lookup with a GEqualFunc, imported from GLib 2.54 */ +#define g_ptr_array_find_with_equal_func mm_ptr_array_find_with_equal_func +gboolean mm_ptr_array_find_with_equal_func (GPtrArray *haystack, + gconstpointer needle, + GEqualFunc equal_func, + guint *index_); + +#endif + #endif /* MM_UTILS_H */ From d8539adbe211ad6b20749df24bb5be403b25a0f7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 1 Mar 2021 15:56:14 +0100 Subject: [PATCH 559/675] modem-helpers-mbim: include string.h explicitly For strstr() (cherry picked from commit da0e610f5f020775e32f43b3343a02d864492224) --- src/mm-modem-helpers-mbim.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mm-modem-helpers-mbim.c b/src/mm-modem-helpers-mbim.c index 8dfc2420..e418969f 100644 --- a/src/mm-modem-helpers-mbim.c +++ b/src/mm-modem-helpers-mbim.c @@ -19,6 +19,8 @@ #include "mm-errors-types.h" #include "mm-log-object.h" +#include + /*****************************************************************************/ MMModemCapability From 64ea5d1e8170ad8de8432024f5137d63d2395663 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 1 Mar 2021 16:02:33 +0100 Subject: [PATCH 560/675] libmm-glib,tests: include string.h explicitly For strlen() (cherry picked from commit 438ff54d0308427dd629e2dbb43b12dc7295873b) --- libmm-glib/tests/test-common-helpers.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libmm-glib/tests/test-common-helpers.c b/libmm-glib/tests/test-common-helpers.c index 78432bed..48995477 100644 --- a/libmm-glib/tests/test-common-helpers.c +++ b/libmm-glib/tests/test-common-helpers.c @@ -13,6 +13,7 @@ * Copyright (C) 2012 Google, Inc. */ +#include #include #include From 35962825c035651df39f698c2bef0e5049deab00 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 2 Mar 2021 14:45:33 +0100 Subject: [PATCH 561/675] NEWS: update for 1.16.2 --- NEWS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS b/NEWS index 2ded5615..942d02df 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,11 @@ +ModemManager 1.16.2 +------------------------------------------- + + * build: fixed with GLib < 2.54. + * qmi: fixed network regitration cancellation when asserts disabled. + * libmm-glib: fix allow-roaming setting comparison in bearer properties. + ModemManager 1.16.0 ------------------------------------------- This is a new stable release of ModemManager. From 52df1aa4b938e0dbbdfd780befa54fce3bfdf875 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 2 Mar 2021 14:45:57 +0100 Subject: [PATCH 562/675] release: bump version to 1.16.2 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 352d6fcb..6dc85198 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ dnl m4_define([mm_major_version], [1]) m4_define([mm_minor_version], [16]) -m4_define([mm_micro_version], [1]) +m4_define([mm_micro_version], [2]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From f776e6ba27f4ffa4d722a48ec1c86ea3e0566dea Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 2 Mar 2021 15:02:37 +0100 Subject: [PATCH 563/675] build: post-release version bump to 1.16.3 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6dc85198..450b3902 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ dnl m4_define([mm_major_version], [1]) m4_define([mm_minor_version], [16]) -m4_define([mm_micro_version], [2]) +m4_define([mm_micro_version], [3]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From 00ee27b075562814f0a9eee386d033245abf981d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 2 Mar 2021 17:18:39 +0100 Subject: [PATCH 564/675] broadband-modem-qmi: use updated system info API if libqmi >= 1.29.2 (cherry picked from commit b509229d5747434be06e17af26c33fd8072a55f9) --- src/mm-broadband-modem-qmi.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 0a63b596..b64c2a6b 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -2978,7 +2978,11 @@ process_gsm_info (MMBroadbandModemQmi *self, NULL, /* true_service_status */ NULL, /* preferred_data_path */ NULL) || +#if QMI_CHECK_VERSION(1,29,2) + !qmi_message_nas_get_system_info_output_get_gsm_system_info_v2 ( +#else !qmi_message_nas_get_system_info_output_get_gsm_system_info ( +#endif response_output, &domain_valid, &domain, NULL, NULL, /* service_capability */ @@ -3002,7 +3006,11 @@ process_gsm_info (MMBroadbandModemQmi *self, NULL, /* true_service_status */ NULL, /* preferred_data_path */ NULL) || +#if QMI_CHECK_VERSION(1,29,2) + !qmi_indication_nas_system_info_output_get_gsm_system_info_v2 ( +#else !qmi_indication_nas_system_info_output_get_gsm_system_info ( +#endif indication_output, &domain_valid, &domain, NULL, NULL, /* service_capability */ @@ -3086,7 +3094,11 @@ process_wcdma_info (MMBroadbandModemQmi *self, NULL, /* true_service_status */ NULL, /* preferred_data_path */ NULL) || +#if QMI_CHECK_VERSION(1,29,2) + !qmi_message_nas_get_system_info_output_get_wcdma_system_info_v2 ( +#else !qmi_message_nas_get_system_info_output_get_wcdma_system_info ( +#endif response_output, &domain_valid, &domain, NULL, NULL, /* service_capability */ @@ -3111,7 +3123,11 @@ process_wcdma_info (MMBroadbandModemQmi *self, NULL, /* true_service_status */ NULL, /* preferred_data_path */ NULL) || +#if QMI_CHECK_VERSION(1,29,2) + !qmi_indication_nas_system_info_output_get_wcdma_system_info_v2 ( +#else !qmi_indication_nas_system_info_output_get_wcdma_system_info ( +#endif indication_output, &domain_valid, &domain, NULL, NULL, /* service_capability */ @@ -3198,7 +3214,11 @@ process_lte_info (MMBroadbandModemQmi *self, NULL, /* true_service_status */ NULL, /* preferred_data_path */ NULL) || +#if QMI_CHECK_VERSION(1,29,2) + !qmi_message_nas_get_system_info_output_get_lte_system_info_v2 ( +#else !qmi_message_nas_get_system_info_output_get_lte_system_info ( +#endif response_output, &domain_valid, &domain, NULL, NULL, /* service_capability */ @@ -3221,7 +3241,12 @@ process_lte_info (MMBroadbandModemQmi *self, NULL, /* true_service_status */ NULL, /* preferred_data_path */ NULL) || +#if QMI_CHECK_VERSION(1,29,2) + !qmi_indication_nas_system_info_output_get_lte_system_info_v2 ( +#else !qmi_indication_nas_system_info_output_get_lte_system_info ( +#endif + indication_output, &domain_valid, &domain, NULL, NULL, /* service_capability */ From fb0670637687d77cd8de584dcf7961d76c17e9b1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 11 Mar 2021 10:33:00 +0100 Subject: [PATCH 565/675] bearer-mbim: plug MbimDevice leak in disconnection context (cherry picked from commit a772b70632008d6c375487a8e711b80bb343a931) --- src/mm-bearer-mbim.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mm-bearer-mbim.c b/src/mm-bearer-mbim.c index b808f547..55064b30 100644 --- a/src/mm-bearer-mbim.c +++ b/src/mm-bearer-mbim.c @@ -1189,6 +1189,7 @@ typedef struct { static void disconnect_context_free (DisconnectContext *ctx) { + g_object_unref (ctx->device); g_object_unref (ctx->data); g_slice_free (DisconnectContext, ctx); } From 2f42f208ba9dc2a29548e8f7010d08fd45b3bee0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 15 Mar 2021 14:58:12 +0100 Subject: [PATCH 566/675] shared-qmi: rename feature check variables We want the "extended_lte_band_preference" with the "nas_ssp" prefix, as we're going to add more checks for SSP features. (cherry picked from commit 67b64eb7eeab5c50381014945cfbd73ebc4cbe11) --- src/mm-shared-qmi.c | 68 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index c36dbfe4..d6a8d8bf 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -71,9 +71,9 @@ typedef struct { /* Capabilities & modes helpers */ MMModemCapability current_capabilities; GArray *supported_radio_interfaces; - Feature feature_nas_technology_preference; - Feature feature_nas_system_selection_preference; - Feature feature_extended_lte_band_preference; + Feature feature_nas_tp; + Feature feature_nas_ssp; + Feature feature_nas_ssp_extended_lte_band_preference; gboolean disable_4g_only_mode; GArray *supported_bands; @@ -141,8 +141,8 @@ get_private (MMSharedQmi *self) if (!priv) { priv = g_slice_new0 (Private); - priv->feature_nas_technology_preference = FEATURE_UNKNOWN; - priv->feature_nas_system_selection_preference = FEATURE_UNKNOWN; + priv->feature_nas_tp = FEATURE_UNKNOWN; + priv->feature_nas_ssp = FEATURE_UNKNOWN; priv->config_active_i = -1; /* Setup parent class' MMIfaceModemLocation */ @@ -476,7 +476,7 @@ mm_shared_qmi_3gpp_register_in_network (MMIfaceModem3gpp *self, } priv = get_private (MM_SHARED_QMI (self)); - if (priv->feature_nas_system_selection_preference == FEATURE_SUPPORTED) + if (priv->feature_nas_ssp == FEATURE_SUPPORTED) register_in_network_sssp (task, client, cancellable, mcc, mnc); else register_in_network_inr (task, client, cancellable, mcc, mnc); @@ -688,8 +688,8 @@ set_current_capabilities_step (GTask *task) switch (ctx->step) { case SET_CURRENT_CAPABILITIES_STEP_FIRST: /* Error out early if both unsupported */ - if ((priv->feature_nas_system_selection_preference != FEATURE_SUPPORTED) && - (priv->feature_nas_technology_preference != FEATURE_SUPPORTED)) { + if ((priv->feature_nas_ssp != FEATURE_SUPPORTED) && + (priv->feature_nas_tp != FEATURE_SUPPORTED)) { g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Setting capabilities is not supported by this device"); g_object_unref (task); @@ -699,7 +699,7 @@ set_current_capabilities_step (GTask *task) /* fall-through */ case SET_CURRENT_CAPABILITIES_STEP_NAS_SYSTEM_SELECTION_PREFERENCE: - if (priv->feature_nas_system_selection_preference == FEATURE_SUPPORTED) { + if (priv->feature_nas_ssp == FEATURE_SUPPORTED) { set_current_capabilities_system_selection_preference (task); return; } @@ -707,7 +707,7 @@ set_current_capabilities_step (GTask *task) /* fall-through */ case SET_CURRENT_CAPABILITIES_STEP_NAS_TECHNOLOGY_PREFERENCE: - if (priv->feature_nas_technology_preference == FEATURE_SUPPORTED) { + if (priv->feature_nas_tp == FEATURE_SUPPORTED) { set_current_capabilities_technology_preference (task); return; } @@ -747,8 +747,8 @@ mm_shared_qmi_set_current_capabilities (MMIfaceModem *self, return; priv = get_private (MM_SHARED_QMI (self)); - g_assert (priv->feature_nas_technology_preference != FEATURE_UNKNOWN); - g_assert (priv->feature_nas_system_selection_preference != FEATURE_UNKNOWN); + g_assert (priv->feature_nas_tp != FEATURE_UNKNOWN); + g_assert (priv->feature_nas_ssp != FEATURE_UNKNOWN); ctx = g_slice_new0 (SetCurrentCapabilitiesContext); ctx->client = g_object_ref (client); @@ -884,18 +884,18 @@ load_current_capabilities_get_technology_preference_ready (QmiClientNas *client, if (!output) { mm_obj_dbg (self, "QMI operation failed: %s", error->message); g_error_free (error); - priv->feature_nas_technology_preference = FEATURE_UNSUPPORTED; + priv->feature_nas_tp = FEATURE_UNSUPPORTED; } else if (!qmi_message_nas_get_technology_preference_output_get_result (output, &error)) { mm_obj_dbg (self, "couldn't get technology preference: %s", error->message); g_error_free (error); - priv->feature_nas_technology_preference = FEATURE_SUPPORTED; + priv->feature_nas_tp = FEATURE_SUPPORTED; } else { qmi_message_nas_get_technology_preference_output_get_active ( output, &ctx->capabilities_context.nas_tp_mask, NULL, /* duration */ NULL); - priv->feature_nas_technology_preference = FEATURE_SUPPORTED; + priv->feature_nas_tp = FEATURE_SUPPORTED; } if (output) @@ -924,17 +924,17 @@ load_current_capabilities_get_system_selection_preference_ready (QmiClientNas *c if (!output) { mm_obj_dbg (self, "QMI operation failed: %s", error->message); g_error_free (error); - priv->feature_nas_system_selection_preference = FEATURE_UNSUPPORTED; + priv->feature_nas_ssp = FEATURE_UNSUPPORTED; } else if (!qmi_message_nas_get_system_selection_preference_output_get_result (output, &error)) { mm_obj_dbg (self, "couldn't get system selection preference: %s", error->message); g_error_free (error); - priv->feature_nas_system_selection_preference = FEATURE_SUPPORTED; + priv->feature_nas_ssp = FEATURE_SUPPORTED; } else { qmi_message_nas_get_system_selection_preference_output_get_mode_preference ( output, &ctx->capabilities_context.nas_ssp_mode_preference_mask, NULL); - priv->feature_nas_system_selection_preference = FEATURE_SUPPORTED; + priv->feature_nas_ssp = FEATURE_SUPPORTED; } if (output) @@ -982,8 +982,8 @@ load_current_capabilities_step (GTask *task) return; case LOAD_CURRENT_CAPABILITIES_STEP_LAST: - g_assert (priv->feature_nas_technology_preference != FEATURE_UNKNOWN); - g_assert (priv->feature_nas_system_selection_preference != FEATURE_UNKNOWN); + g_assert (priv->feature_nas_tp != FEATURE_UNKNOWN); + g_assert (priv->feature_nas_ssp != FEATURE_UNKNOWN); priv->current_capabilities = mm_modem_capability_from_qmi_capabilities_context (&ctx->capabilities_context, self); g_task_return_int (task, priv->current_capabilities); g_object_unref (task); @@ -1033,8 +1033,8 @@ mm_shared_qmi_load_current_capabilities (MMIfaceModem *self, /* Current capabilities is the first thing run, and will only be run once per modem, * so we should here check support for the optional features. */ priv = get_private (MM_SHARED_QMI (self)); - g_assert (priv->feature_nas_technology_preference == FEATURE_UNKNOWN); - g_assert (priv->feature_nas_system_selection_preference == FEATURE_UNKNOWN); + g_assert (priv->feature_nas_tp == FEATURE_UNKNOWN); + g_assert (priv->feature_nas_ssp == FEATURE_UNKNOWN); ctx = g_slice_new0 (LoadCurrentCapabilitiesContext); ctx->nas_client = g_object_ref (nas_client); @@ -1093,7 +1093,7 @@ mm_shared_qmi_load_supported_capabilities (MMIfaceModem *self, * switching only when switching GSM/UMTS+CDMA/EVDO multimode devices, and only if * we have support for the commands doing it. */ - if (priv->feature_nas_technology_preference == FEATURE_SUPPORTED || priv->feature_nas_system_selection_preference == FEATURE_SUPPORTED) { + if (priv->feature_nas_tp == FEATURE_SUPPORTED || priv->feature_nas_ssp == FEATURE_SUPPORTED) { if (mask == (MM_MODEM_CAPABILITY_GSM_UMTS | MM_MODEM_CAPABILITY_CDMA_EVDO)) { /* Multimode GSM/UMTS+CDMA/EVDO device switched to GSM/UMTS only */ single = MM_MODEM_CAPABILITY_GSM_UMTS; @@ -1339,12 +1339,12 @@ mm_shared_qmi_set_current_modes (MMIfaceModem *self, priv = get_private (MM_SHARED_QMI (self)); - if (priv->feature_nas_system_selection_preference == FEATURE_SUPPORTED) { + if (priv->feature_nas_ssp == FEATURE_SUPPORTED) { set_current_modes_system_selection_preference (task); return; } - if (priv->feature_nas_technology_preference == FEATURE_SUPPORTED) { + if (priv->feature_nas_tp == FEATURE_SUPPORTED) { set_current_modes_technology_preference (task); return; } @@ -1582,12 +1582,12 @@ mm_shared_qmi_load_current_modes (MMIfaceModem *self, priv = get_private (MM_SHARED_QMI (self)); - if (priv->feature_nas_system_selection_preference != FEATURE_UNSUPPORTED) { + if (priv->feature_nas_ssp != FEATURE_UNSUPPORTED) { load_current_modes_system_selection_preference (task); return; } - if (priv->feature_nas_technology_preference != FEATURE_UNSUPPORTED) { + if (priv->feature_nas_tp != FEATURE_UNSUPPORTED) { load_current_modes_technology_preference (task); return; } @@ -1638,7 +1638,7 @@ mm_shared_qmi_load_supported_modes (MMIfaceModem *self, g_array_append_val (all, mode); /* If SSP and TP are not supported, ignore supported mode management */ - if (priv->feature_nas_system_selection_preference == FEATURE_UNSUPPORTED && priv->feature_nas_technology_preference == FEATURE_UNSUPPORTED) { + if (priv->feature_nas_ssp == FEATURE_UNSUPPORTED && priv->feature_nas_tp == FEATURE_UNSUPPORTED) { g_task_return_pointer (task, all, (GDestroyNotify) g_array_unref); g_object_unref (task); return; @@ -1655,7 +1655,7 @@ mm_shared_qmi_load_supported_modes (MMIfaceModem *self, if (MODE4 != MM_MODEM_MODE_NONE) \ mode.allowed |= MODE4; \ } \ - if (priv->feature_nas_system_selection_preference != FEATURE_UNSUPPORTED) { \ + if (priv->feature_nas_ssp != FEATURE_UNSUPPORTED) { \ if (MODE3 != MM_MODEM_MODE_NONE) { \ if (MODE4 != MM_MODEM_MODE_NONE) { \ mode.preferred = MODE4; \ @@ -1697,7 +1697,7 @@ mm_shared_qmi_load_supported_modes (MMIfaceModem *self, /* 5G related mode combinations are only supported when NAS SSP is supported, * as there is no 5G support in NAS TP. */ - if (priv->feature_nas_system_selection_preference != FEATURE_UNSUPPORTED) { + if (priv->feature_nas_ssp != FEATURE_UNSUPPORTED) { ADD_MODE_PREFERENCE (MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); ADD_MODE_PREFERENCE (MM_MODEM_MODE_2G, MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); ADD_MODE_PREFERENCE (MM_MODEM_MODE_3G, MM_MODEM_MODE_5G, MM_MODEM_MODE_NONE, MM_MODEM_MODE_NONE); @@ -1866,8 +1866,8 @@ load_bands_get_system_selection_preference_ready (QmiClientNas *client, NULL)) extended_lte_band_preference_size = G_N_ELEMENTS (extended_lte_band_preference); - if (G_UNLIKELY (priv->feature_extended_lte_band_preference == FEATURE_UNKNOWN)) - priv->feature_extended_lte_band_preference = extended_lte_band_preference_size ? FEATURE_SUPPORTED : FEATURE_UNSUPPORTED; + if (G_UNLIKELY (priv->feature_nas_ssp_extended_lte_band_preference == FEATURE_UNKNOWN)) + priv->feature_nas_ssp_extended_lte_band_preference = extended_lte_band_preference_size ? FEATURE_SUPPORTED : FEATURE_UNSUPPORTED; mm_bands = mm_modem_bands_from_qmi_band_preference (band_preference_mask, lte_band_preference_mask, @@ -1987,14 +1987,14 @@ mm_shared_qmi_set_current_bands (MMIfaceModem *self, mm_modem_bands_to_qmi_band_preference (bands_array, &qmi_bands, &qmi_lte_bands, - priv->feature_extended_lte_band_preference == FEATURE_SUPPORTED ? extended_qmi_lte_bands : NULL, + priv->feature_nas_ssp_extended_lte_band_preference == FEATURE_SUPPORTED ? extended_qmi_lte_bands : NULL, G_N_ELEMENTS (extended_qmi_lte_bands), self); input = qmi_message_nas_set_system_selection_preference_input_new (); qmi_message_nas_set_system_selection_preference_input_set_band_preference (input, qmi_bands, NULL); if (mm_iface_modem_is_3gpp_lte (self)) { - if (priv->feature_extended_lte_band_preference == FEATURE_SUPPORTED) + if (priv->feature_nas_ssp_extended_lte_band_preference == FEATURE_SUPPORTED) qmi_message_nas_set_system_selection_preference_input_set_extended_lte_band_preference ( input, extended_qmi_lte_bands[0], From c96524ca7b822341f227bf7b4b8bc9a5c4c2392a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 15 Mar 2021 17:20:30 +0100 Subject: [PATCH 567/675] shared-qmi: add missing feature check flag initialization to UNKNOWN (cherry picked from commit 1a5f90f15bda7b939c75c6b8c7d0022c8f919b42) --- src/mm-shared-qmi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index d6a8d8bf..43e7f4fe 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -143,6 +143,7 @@ get_private (MMSharedQmi *self) priv->feature_nas_tp = FEATURE_UNKNOWN; priv->feature_nas_ssp = FEATURE_UNKNOWN; + priv->feature_nas_ssp_extended_lte_band_preference = FEATURE_UNKNOWN; priv->config_active_i = -1; /* Setup parent class' MMIfaceModemLocation */ From 6f68efc862ca92fcc5d28103224dfdcd31ae10e0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 15 Mar 2021 15:11:41 +0100 Subject: [PATCH 568/675] shared-qmi: if getting TP/SSP fails, assume unsupported Until now we were only considering TP/SSP unsupported if we received a QMI protocol error (e.g. reporting unknown command). We now also consider TP/SSP unsupported if the actual request succeeds, but an error is reported in the response. There is no point in considering TP/SSP supported if the plain get request without input TLVs given fails. (cherry picked from commit 65a7624ffdd39b015d5013743913af8361e83513) --- src/mm-shared-qmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 43e7f4fe..da0a7aa5 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -889,7 +889,7 @@ load_current_capabilities_get_technology_preference_ready (QmiClientNas *client, } else if (!qmi_message_nas_get_technology_preference_output_get_result (output, &error)) { mm_obj_dbg (self, "couldn't get technology preference: %s", error->message); g_error_free (error); - priv->feature_nas_tp = FEATURE_SUPPORTED; + priv->feature_nas_tp = FEATURE_UNSUPPORTED; } else { qmi_message_nas_get_technology_preference_output_get_active ( output, @@ -929,7 +929,7 @@ load_current_capabilities_get_system_selection_preference_ready (QmiClientNas *c } else if (!qmi_message_nas_get_system_selection_preference_output_get_result (output, &error)) { mm_obj_dbg (self, "couldn't get system selection preference: %s", error->message); g_error_free (error); - priv->feature_nas_ssp = FEATURE_SUPPORTED; + priv->feature_nas_ssp = FEATURE_UNSUPPORTED; } else { qmi_message_nas_get_system_selection_preference_output_get_mode_preference ( output, From aae5fe5f5bc49fa0ecb87b2b714611ce16744d66 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 15 Mar 2021 15:19:38 +0100 Subject: [PATCH 569/675] shared-qmi: process all feature checks in SSP response together Loading capabilities is the very first step of the state machines, and so we can rely on the "NAS Get SSP" method performed there to process all feature checks of the SSP response. (cherry picked from commit bb5bc9c8c560a24ef2951bdb9e1da18dedd7c5b0) --- src/mm-shared-qmi.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index da0a7aa5..1aeff089 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -921,21 +921,28 @@ load_current_capabilities_get_system_selection_preference_ready (QmiClientNas *c ctx = g_task_get_task_data (task); priv = get_private (MM_SHARED_QMI (self)); + priv->feature_nas_ssp = FEATURE_UNSUPPORTED; + priv->feature_nas_ssp_extended_lte_band_preference = FEATURE_UNSUPPORTED; + output = qmi_client_nas_get_system_selection_preference_finish (client, res, &error); if (!output) { mm_obj_dbg (self, "QMI operation failed: %s", error->message); g_error_free (error); - priv->feature_nas_ssp = FEATURE_UNSUPPORTED; } else if (!qmi_message_nas_get_system_selection_preference_output_get_result (output, &error)) { mm_obj_dbg (self, "couldn't get system selection preference: %s", error->message); g_error_free (error); - priv->feature_nas_ssp = FEATURE_UNSUPPORTED; } else { + GArray *acquisition_order_preference_array = NULL; + + /* SSP is supported, perform feature checks */ + priv->feature_nas_ssp = FEATURE_SUPPORTED; + if (qmi_message_nas_get_system_selection_preference_output_get_extended_lte_band_preference (output, NULL, NULL, NULL, NULL, NULL)) + priv->feature_nas_ssp_extended_lte_band_preference = FEATURE_SUPPORTED; + qmi_message_nas_get_system_selection_preference_output_get_mode_preference ( output, &ctx->capabilities_context.nas_ssp_mode_preference_mask, NULL); - priv->feature_nas_ssp = FEATURE_SUPPORTED; } if (output) @@ -1460,6 +1467,7 @@ load_current_modes_system_selection_preference_ready (QmiClientNas *client, GTask *task) { MMSharedQmi *self; + Private *priv; LoadCurrentModesResult *result = NULL; QmiMessageNasGetSystemSelectionPreferenceOutput *output = NULL; GError *error = NULL; @@ -1467,6 +1475,7 @@ load_current_modes_system_selection_preference_ready (QmiClientNas *client, MMModemMode allowed; self = g_task_get_source_object (task); + priv = get_private (self); output = qmi_client_nas_get_system_selection_preference_finish (client, res, &error); if (!output || !qmi_message_nas_get_system_selection_preference_output_get_result (output, &error)) { @@ -1858,7 +1867,8 @@ load_bands_get_system_selection_preference_ready (QmiClientNas *client, <e_band_preference_mask, NULL); - if (qmi_message_nas_get_system_selection_preference_output_get_extended_lte_band_preference ( + if ((priv->feature_nas_ssp_extended_lte_band_preference == FEATURE_SUPPORTED) && + qmi_message_nas_get_system_selection_preference_output_get_extended_lte_band_preference ( output, &extended_lte_band_preference[0], &extended_lte_band_preference[1], @@ -1867,9 +1877,6 @@ load_bands_get_system_selection_preference_ready (QmiClientNas *client, NULL)) extended_lte_band_preference_size = G_N_ELEMENTS (extended_lte_band_preference); - if (G_UNLIKELY (priv->feature_nas_ssp_extended_lte_band_preference == FEATURE_UNKNOWN)) - priv->feature_nas_ssp_extended_lte_band_preference = extended_lte_band_preference_size ? FEATURE_SUPPORTED : FEATURE_UNSUPPORTED; - mm_bands = mm_modem_bands_from_qmi_band_preference (band_preference_mask, lte_band_preference_mask, extended_lte_band_preference_size ? extended_lte_band_preference : NULL, From 36974af255ad5a96824de21400d935a6d2ee0ab2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 15 Mar 2021 17:46:49 +0100 Subject: [PATCH 570/675] shared-qmi: acquisition order preference TLV always same items The acquisition order preference TLV must always have the same number of elements, just the order of the elements should be different. Also, always prefer the acquisition order preference TLV to the GSM+WCDMA specific one, which is the same logic the modem applies. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/340 (cherry picked from commit fdfd4b270aa3bb31185feb833691f134c887f869) --- src/mm-modem-helpers-qmi.c | 108 ++++++++++++++++++++----------------- src/mm-modem-helpers-qmi.h | 9 ++-- src/mm-shared-qmi.c | 64 +++++++++++++--------- 3 files changed, 100 insertions(+), 81 deletions(-) diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 8d0e4b88..3e87f0d0 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1106,67 +1106,75 @@ mm_modem_capability_to_qmi_acquisition_order_preference (MMModemCapability caps) return array; } -GArray * -mm_modem_mode_to_qmi_acquisition_order_preference (MMModemMode allowed, - MMModemMode preferred, - gboolean is_cdma, - gboolean is_3gpp) +static gboolean +radio_interface_array_contains (GArray *array, + QmiNasRadioInterface act) { - GArray *array; - QmiNasRadioInterface value; + guint i; - array = g_array_new (FALSE, FALSE, sizeof (QmiNasRadioInterface)); + for (i = 0; i < array->len; i++) { + QmiNasRadioInterface value; - if (allowed & MM_MODEM_MODE_5G) { - value = QMI_NAS_RADIO_INTERFACE_5GNR; - if (preferred == MM_MODEM_MODE_5G) - g_array_prepend_val (array, value); - else - g_array_append_val (array, value); + value = g_array_index (array, QmiNasRadioInterface, i); + if (value == act) + return TRUE; } + return FALSE; +} - if (allowed & MM_MODEM_MODE_4G) { - value = QMI_NAS_RADIO_INTERFACE_LTE; - if (preferred == MM_MODEM_MODE_4G) - g_array_prepend_val (array, value); - else +static void +radio_interface_array_add_missing (GArray *array, + GArray *all) +{ + guint i; + + for (i = 0; i < all->len; i++) { + QmiNasRadioInterface value; + + value = g_array_index (all, QmiNasRadioInterface, i); + if (!radio_interface_array_contains (array, value)) g_array_append_val (array, value); } +} - if (allowed & MM_MODEM_MODE_3G) { - if (is_cdma) { - value = QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO; - if (preferred == MM_MODEM_MODE_3G) - g_array_prepend_val (array, value); - else - g_array_append_val (array, value); - } - if (is_3gpp) { - value = QMI_NAS_RADIO_INTERFACE_UMTS; - if (preferred == MM_MODEM_MODE_3G) - g_array_prepend_val (array, value); - else - g_array_append_val (array, value); - } - } +GArray * +mm_modem_mode_to_qmi_acquisition_order_preference (MMModemMode allowed, + MMModemMode preferred, + GArray *all) +{ + GArray *array; + QmiNasRadioInterface preferred_radio = QMI_NAS_RADIO_INTERFACE_UNKNOWN; + QmiNasRadioInterface value; - if (allowed & MM_MODEM_MODE_2G) { - if (is_cdma) { - value = QMI_NAS_RADIO_INTERFACE_CDMA_1X; - if (preferred == MM_MODEM_MODE_2G) - g_array_prepend_val (array, value); - else - g_array_append_val (array, value); - } - if (is_3gpp) { - value = QMI_NAS_RADIO_INTERFACE_GSM; - if (preferred == MM_MODEM_MODE_2G) - g_array_prepend_val (array, value); - else - g_array_append_val (array, value); - } + array = g_array_sized_new (FALSE, FALSE, sizeof (QmiNasRadioInterface), all->len); + +#define PROCESS_ALLOWED_PREFERRED_MODE(MODE,RADIO) \ + if ((allowed & MODE) && (radio_interface_array_contains (all, RADIO))) { \ + if ((preferred == MODE) && (preferred_radio == QMI_NAS_RADIO_INTERFACE_UNKNOWN)) \ + preferred_radio = RADIO; \ + else { \ + value = RADIO; \ + g_array_append_val (array, value); \ + } \ } + PROCESS_ALLOWED_PREFERRED_MODE (MM_MODEM_MODE_5G, QMI_NAS_RADIO_INTERFACE_5GNR); + PROCESS_ALLOWED_PREFERRED_MODE (MM_MODEM_MODE_4G, QMI_NAS_RADIO_INTERFACE_LTE); + PROCESS_ALLOWED_PREFERRED_MODE (MM_MODEM_MODE_3G, QMI_NAS_RADIO_INTERFACE_UMTS); + PROCESS_ALLOWED_PREFERRED_MODE (MM_MODEM_MODE_3G, QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO); + PROCESS_ALLOWED_PREFERRED_MODE (MM_MODEM_MODE_2G, QMI_NAS_RADIO_INTERFACE_GSM); + PROCESS_ALLOWED_PREFERRED_MODE (MM_MODEM_MODE_2G, QMI_NAS_RADIO_INTERFACE_CDMA_1X); + +#undef PROCESS_ALLOWED_PREFERRED_MODE + + if (preferred_radio != QMI_NAS_RADIO_INTERFACE_UNKNOWN) + g_array_prepend_val (array, preferred_radio); + + /* the acquisition order preference is a TLV that must ALWAYS contain the + * same list of QmiNasRadioInterface values, just with a different order. */ + radio_interface_array_add_missing (array, all); + g_assert_cmpuint (array->len, ==, all->len); + return array; } diff --git a/src/mm-modem-helpers-qmi.h b/src/mm-modem-helpers-qmi.h index 829ac76e..430ac3cf 100644 --- a/src/mm-modem-helpers-qmi.h +++ b/src/mm-modem-helpers-qmi.h @@ -64,11 +64,10 @@ QmiNasRatModePreference mm_modem_mode_to_qmi_rat_mode_preference (MMModemMode mo MMModemCapability mm_modem_capability_from_qmi_rat_mode_preference (QmiNasRatModePreference qmi); QmiNasRatModePreference mm_modem_capability_to_qmi_rat_mode_preference (MMModemCapability caps); -GArray *mm_modem_capability_to_qmi_acquisition_order_preference (MMModemCapability caps); -GArray *mm_modem_mode_to_qmi_acquisition_order_preference (MMModemMode allowed, - MMModemMode preferred, - gboolean is_cdma, - gboolean is_3gpp); +GArray *mm_modem_capability_to_qmi_acquisition_order_preference (MMModemCapability caps); +GArray *mm_modem_mode_to_qmi_acquisition_order_preference (MMModemMode allowed, + MMModemMode preferred, + GArray *all); MMModemCapability mm_modem_capability_from_qmi_radio_technology_preference (QmiNasRadioTechnologyPreference qmi); QmiNasRadioTechnologyPreference mm_modem_capability_to_qmi_radio_technology_preference (MMModemCapability caps); diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 1aeff089..84d93d92 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -74,6 +74,8 @@ typedef struct { Feature feature_nas_tp; Feature feature_nas_ssp; Feature feature_nas_ssp_extended_lte_band_preference; + Feature feature_nas_ssp_acquisition_order_preference; + GArray *feature_nas_ssp_acquisition_order_preference_array; gboolean disable_4g_only_mode; GArray *supported_bands; @@ -125,6 +127,8 @@ private_free (Private *priv) g_object_unref (priv->uim_client); if (priv->uim_refresh_start_timeout_id) g_source_remove (priv->uim_refresh_start_timeout_id); + if (priv->feature_nas_ssp_acquisition_order_preference_array) + g_array_unref (priv->feature_nas_ssp_acquisition_order_preference_array); g_strfreev (priv->loc_assistance_data_servers); g_slice_free (Private, priv); } @@ -144,6 +148,7 @@ get_private (MMSharedQmi *self) priv->feature_nas_tp = FEATURE_UNKNOWN; priv->feature_nas_ssp = FEATURE_UNKNOWN; priv->feature_nas_ssp_extended_lte_band_preference = FEATURE_UNKNOWN; + priv->feature_nas_ssp_acquisition_order_preference = FEATURE_UNKNOWN; priv->config_active_i = -1; /* Setup parent class' MMIfaceModemLocation */ @@ -923,6 +928,7 @@ load_current_capabilities_get_system_selection_preference_ready (QmiClientNas *c priv->feature_nas_ssp = FEATURE_UNSUPPORTED; priv->feature_nas_ssp_extended_lte_band_preference = FEATURE_UNSUPPORTED; + priv->feature_nas_ssp_acquisition_order_preference = FEATURE_UNSUPPORTED; output = qmi_client_nas_get_system_selection_preference_finish (client, res, &error); if (!output) { @@ -938,6 +944,12 @@ load_current_capabilities_get_system_selection_preference_ready (QmiClientNas *c priv->feature_nas_ssp = FEATURE_SUPPORTED; if (qmi_message_nas_get_system_selection_preference_output_get_extended_lte_band_preference (output, NULL, NULL, NULL, NULL, NULL)) priv->feature_nas_ssp_extended_lte_band_preference = FEATURE_SUPPORTED; + if (qmi_message_nas_get_system_selection_preference_output_get_acquisition_order_preference (output, &acquisition_order_preference_array, NULL) && + acquisition_order_preference_array && + acquisition_order_preference_array->len) { + priv->feature_nas_ssp_acquisition_order_preference = FEATURE_SUPPORTED; + priv->feature_nas_ssp_acquisition_order_preference_array = g_array_ref (acquisition_order_preference_array); + } qmi_message_nas_get_system_selection_preference_output_get_mode_preference ( output, @@ -1259,11 +1271,13 @@ static void set_current_modes_system_selection_preference (GTask *task) { MMIfaceModem *self; + Private *priv; SetCurrentModesContext *ctx; QmiMessageNasSetSystemSelectionPreferenceInput *input; QmiNasRatModePreference pref; self = g_task_get_source_object (task); + priv = get_private (MM_SHARED_QMI (self)); ctx = g_task_get_task_data (task); input = qmi_message_nas_set_system_selection_preference_input_new (); @@ -1272,16 +1286,17 @@ set_current_modes_system_selection_preference (GTask *task) /* Preferred modes */ if (ctx->preferred != MM_MODEM_MODE_NONE) { - GArray *array; - - /* Acquisition order array */ - array = mm_modem_mode_to_qmi_acquisition_order_preference (ctx->allowed, - ctx->preferred, - mm_iface_modem_is_cdma (self), - mm_iface_modem_is_3gpp (self)); - g_assert (array); - qmi_message_nas_set_system_selection_preference_input_set_acquisition_order_preference (input, array, NULL); - g_array_unref (array); + if (priv->feature_nas_ssp_acquisition_order_preference == FEATURE_SUPPORTED) { + GArray *array; + + /* Acquisition order array */ + array = mm_modem_mode_to_qmi_acquisition_order_preference (ctx->allowed, + ctx->preferred, + priv->feature_nas_ssp_acquisition_order_preference_array); + g_assert (array); + qmi_message_nas_set_system_selection_preference_input_set_acquisition_order_preference (input, array, NULL); + g_array_unref (array); + } /* Only set GSM/WCDMA acquisition order preference if both 2G and 3G given as allowed */ if (mm_iface_modem_is_3gpp (self) && ((ctx->allowed & (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G)) == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G))) { @@ -1508,24 +1523,11 @@ load_current_modes_system_selection_preference_ready (QmiClientNas *client, result->allowed = allowed; result->preferred = MM_MODEM_MODE_NONE; - /* For 2G+3G only rely on the GSM/WCDMA acquisition order preference TLV */ - if (mode_preference_mask == (QMI_NAS_RAT_MODE_PREFERENCE_GSM | QMI_NAS_RAT_MODE_PREFERENCE_UMTS)) { - QmiNasGsmWcdmaAcquisitionOrderPreference gsm_or_wcdma; - - if (qmi_message_nas_get_system_selection_preference_output_get_gsm_wcdma_acquisition_order_preference ( - output, - &gsm_or_wcdma, - NULL)) - result->preferred = mm_modem_mode_from_qmi_gsm_wcdma_acquisition_order_preference (gsm_or_wcdma, self); - } - /* Otherwise, rely on the acquisition order array TLV */ - else { + /* If acquisition order preference is available, always use that first */ + if (priv->feature_nas_ssp_acquisition_order_preference == FEATURE_SUPPORTED) { GArray *array; - if (qmi_message_nas_get_system_selection_preference_output_get_acquisition_order_preference ( - output, - &array, - NULL) && + if (qmi_message_nas_get_system_selection_preference_output_get_acquisition_order_preference (output, &array, NULL) && array->len > 0) { guint i; @@ -1546,6 +1548,16 @@ load_current_modes_system_selection_preference_ready (QmiClientNas *client, } } } + /* For 2G+3G only rely on the GSM/WCDMA acquisition order preference TLV */ + else if (mode_preference_mask == (QMI_NAS_RAT_MODE_PREFERENCE_GSM | QMI_NAS_RAT_MODE_PREFERENCE_UMTS)) { + QmiNasGsmWcdmaAcquisitionOrderPreference gsm_or_wcdma; + + if (qmi_message_nas_get_system_selection_preference_output_get_gsm_wcdma_acquisition_order_preference ( + output, + &gsm_or_wcdma, + NULL)) + result->preferred = mm_modem_mode_from_qmi_gsm_wcdma_acquisition_order_preference (gsm_or_wcdma, self); + } g_task_return_pointer (task, result, g_free); From 2122de4a1db0f215b75e20c505a8ada5ff07a195 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 22 Nov 2020 15:00:23 +0100 Subject: [PATCH 571/675] charsets: define charset enum explicitly as flags (cherry picked from commit a025e83e5ab10147861334fd94682fdd20fb69d2) --- src/mm-charsets.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mm-charsets.h b/src/mm-charsets.h index c064eef5..14a8b375 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -19,16 +19,16 @@ #include typedef enum { - MM_MODEM_CHARSET_UNKNOWN = 0x00000000, - MM_MODEM_CHARSET_GSM = 0x00000001, - MM_MODEM_CHARSET_IRA = 0x00000002, - MM_MODEM_CHARSET_8859_1 = 0x00000004, - MM_MODEM_CHARSET_UTF8 = 0x00000008, - MM_MODEM_CHARSET_UCS2 = 0x00000010, - MM_MODEM_CHARSET_PCCP437 = 0x00000020, - MM_MODEM_CHARSET_PCDN = 0x00000040, - MM_MODEM_CHARSET_HEX = 0x00000080, - MM_MODEM_CHARSET_UTF16 = 0x00000100, + MM_MODEM_CHARSET_UNKNOWN = 0, + MM_MODEM_CHARSET_GSM = 1 << 0, + MM_MODEM_CHARSET_IRA = 1 << 1, + MM_MODEM_CHARSET_8859_1 = 1 << 2, + MM_MODEM_CHARSET_UTF8 = 1 << 3, + MM_MODEM_CHARSET_UCS2 = 1 << 4, + MM_MODEM_CHARSET_PCCP437 = 1 << 5, + MM_MODEM_CHARSET_PCDN = 1 << 6, + MM_MODEM_CHARSET_HEX = 1 << 7, + MM_MODEM_CHARSET_UTF16 = 1 << 8, } MMModemCharset; const gchar *mm_modem_charset_to_string (MMModemCharset charset); From 021093232dc1b8f8257ef10e667fceb3f1383ab9 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 22 Nov 2020 15:02:07 +0100 Subject: [PATCH 572/675] charsets: remove HEX charset type This is no real charset, it is the fake one we used to represent a UCS2 hex-encoded string. (cherry picked from commit 38a4a9c842bcb0c87bca7b1a5595556fe2c144fc) --- src/mm-charsets.c | 10 ---------- src/mm-charsets.h | 3 +-- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index 19d1874c..acddf0a8 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -42,7 +42,6 @@ static const CharsetEntry charset_map[] = { { "8859-1", NULL, "ISO8859-1", "ISO8859-1//TRANSLIT", MM_MODEM_CHARSET_8859_1 }, { "PCCP437", "CP437", "CP437", "CP437//TRANSLIT", MM_MODEM_CHARSET_PCCP437 }, { "PCDN", "CP850", "CP850", "CP850//TRANSLIT", MM_MODEM_CHARSET_PCDN }, - { "HEX", NULL, NULL, NULL, MM_MODEM_CHARSET_HEX }, { "UTF-16", "UTF16", "UTF-16BE", "UTF-16BE//TRANSLIT", MM_MODEM_CHARSET_UTF16 }, }; @@ -773,11 +772,6 @@ mm_charset_take_and_convert_to_utf8 (gchar *str, utf8 = str; break; - case MM_MODEM_CHARSET_HEX: - /* We'll assume that the HEX string is really valid ASCII at the end */ - utf8 = str; - break; - case MM_MODEM_CHARSET_GSM: utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str)); g_free (str); @@ -903,10 +897,6 @@ mm_utf8_take_and_convert_to_charset (gchar *str, encoded = str; break; - case MM_MODEM_CHARSET_HEX: - encoded = str; - break; - case MM_MODEM_CHARSET_GSM: encoded = (gchar *) mm_charset_utf8_to_unpacked_gsm (str, NULL); g_free (str); diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 14a8b375..233ea4ed 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -27,8 +27,7 @@ typedef enum { MM_MODEM_CHARSET_UCS2 = 1 << 4, MM_MODEM_CHARSET_PCCP437 = 1 << 5, MM_MODEM_CHARSET_PCDN = 1 << 6, - MM_MODEM_CHARSET_HEX = 1 << 7, - MM_MODEM_CHARSET_UTF16 = 1 << 8, + MM_MODEM_CHARSET_UTF16 = 1 << 7, } MMModemCharset; const gchar *mm_modem_charset_to_string (MMModemCharset charset); From 69fcaf3b5c154712bac705f8326210e25b72ca4d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 22 Nov 2020 15:05:56 +0100 Subject: [PATCH 573/675] charsets: don't allow quoting in byte_array_append() There's no point in adding a quoting option to this method; if the caller needs the appended string quoted, it should quote it before passing it to this method. It was nowhere used anyway. (cherry picked from commit 8b590721dfdff5c4382dbc3498d92035b2d4ad64) --- src/mm-broadband-modem-mbim.c | 2 +- src/mm-broadband-modem-qmi.c | 2 +- src/mm-broadband-modem.c | 6 +----- src/mm-charsets.c | 5 ----- src/mm-charsets.h | 1 - src/mm-sms-part-3gpp.c | 2 +- src/mm-sms-part-cdma.c | 12 ++---------- 7 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 97ce89a9..7c592fe4 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4792,7 +4792,7 @@ ussd_encode (const gchar *command, *scheme = MM_MODEM_GSM_USSD_SCHEME_UCS2; array = g_byte_array_sized_new (strlen (command) * 2); - if (!mm_modem_charset_byte_array_append (array, command, FALSE, MM_MODEM_CHARSET_UCS2, &inner_error)) { + if (!mm_modem_charset_byte_array_append (array, command, MM_MODEM_CHARSET_UCS2, &inner_error)) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Failed to encode USSD command in UCS2 charset: %s", inner_error->message); return NULL; diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index b64c2a6b..d4d732f4 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -7282,7 +7282,7 @@ ussd_encode (const gchar *command, } barray = g_byte_array_sized_new (command_len * 2); - if (!mm_modem_charset_byte_array_append (barray, command, FALSE, MM_MODEM_CHARSET_UCS2, &inner_error)) { + if (!mm_modem_charset_byte_array_append (barray, command, MM_MODEM_CHARSET_UCS2, &inner_error)) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Failed to encode USSD command in UCS2 charset: %s", inner_error->message); return NULL; diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 97c60b68..7ba46c91 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -5890,11 +5890,7 @@ modem_3gpp_ussd_encode (MMIfaceModem3gppUssd *self, /* Encode to the current charset (as per AT+CSCS, which is what most modems * (except for Huawei it seems) will ask for. */ - if (mm_modem_charset_byte_array_append (ussd_command, - command, - FALSE, - broadband->priv->modem_current_charset, - NULL)) { + if (mm_modem_charset_byte_array_append (ussd_command, command, broadband->priv->modem_current_charset, NULL)) { /* The scheme value does NOT represent the encoding used to encode the string * we're giving. This scheme reflects the encoding that the modem should use when * sending the data out to the network. We're hardcoding this to GSM-7 because diff --git a/src/mm-charsets.c b/src/mm-charsets.c index acddf0a8..fbbe4855 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -105,7 +105,6 @@ charset_iconv_from (MMModemCharset charset) gboolean mm_modem_charset_byte_array_append (GByteArray *array, const gchar *utf8, - gboolean quoted, MMModemCharset charset, GError **error) { @@ -126,11 +125,7 @@ mm_modem_charset_byte_array_append (GByteArray *array, return FALSE; } - if (quoted) - g_byte_array_append (array, (const guint8 *) "\"", 1); g_byte_array_append (array, (const guint8 *) converted, written); - if (quoted) - g_byte_array_append (array, (const guint8 *) "\"", 1); return TRUE; } diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 233ea4ed..d9542e6a 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -39,7 +39,6 @@ MMModemCharset mm_modem_charset_from_string (const gchar *string); */ gboolean mm_modem_charset_byte_array_append (GByteArray *array, const gchar *utf8, - gboolean quoted, MMModemCharset charset, GError **error); diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index c18aaa75..dd43ac5a 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -1011,7 +1011,7 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, /* Try to guess a good value for the array */ array = g_byte_array_sized_new (strlen (mm_sms_part_get_text (part)) * 2); /* Always assume UTF-16 instead of UCS-2! */ - if (!mm_modem_charset_byte_array_append (array, mm_sms_part_get_text (part), FALSE, MM_MODEM_CHARSET_UTF16, &inner_error)) { + if (!mm_modem_charset_byte_array_append (array, mm_sms_part_get_text (part), MM_MODEM_CHARSET_UTF16, &inner_error)) { g_set_error (error, MM_MESSAGE_ERROR, MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER, diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index e08193cf..fcfd85e9 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -1411,11 +1411,7 @@ decide_best_encoding (const gchar *text, /* Check if we can do Latin encoding */ if (mm_charset_can_convert_to (text, MM_MODEM_CHARSET_8859_1)) { *out = g_byte_array_sized_new (len); - if (!mm_modem_charset_byte_array_append (*out, - text, - FALSE, - MM_MODEM_CHARSET_8859_1, - &error)) + if (!mm_modem_charset_byte_array_append (*out, text, MM_MODEM_CHARSET_8859_1, &error)) mm_obj_warn (log_object, "failed to convert to latin encoding: %s", error->message); *num_fields = (*out)->len; *num_bits_per_field = 8; @@ -1425,11 +1421,7 @@ decide_best_encoding (const gchar *text, /* If no Latin and no ASCII, default to UTF-16 */ *out = g_byte_array_sized_new (len * 2); - if (!mm_modem_charset_byte_array_append (*out, - text, - FALSE, - MM_MODEM_CHARSET_UCS2, - &error)) + if (!mm_modem_charset_byte_array_append (*out, text, MM_MODEM_CHARSET_UCS2, &error)) mm_obj_warn (log_object, "failed to convert to UTF-16 encoding: %s", error->message); *num_fields = (*out)->len / 2; *num_bits_per_field = 16; From 24b276a5cbe70b8b283142be6cda251274c7c5af Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 22 Nov 2020 16:10:06 +0100 Subject: [PATCH 574/675] charsets: remove unused charset_utf8_to_hex() method (cherry picked from commit dbdf67e9f7c55d7f70ed94449160a7ff254359a2) --- src/mm-charsets.c | 28 ---------------------------- src/mm-charsets.h | 6 ------ 2 files changed, 34 deletions(-) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index fbbe4855..2613a660 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -185,34 +185,6 @@ mm_modem_charset_hex_to_utf8 (const gchar *src, return g_steal_pointer (&converted); } -gchar * -mm_modem_charset_utf8_to_hex (const gchar *src, - MMModemCharset charset) -{ - const gchar *iconv_to; - g_autofree gchar *converted = NULL; - g_autoptr(GError) error = NULL; - gsize converted_len = 0; - - g_return_val_if_fail (src != NULL, NULL); - g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); - - iconv_to = charset_iconv_from (charset); - g_return_val_if_fail (iconv_to != NULL, FALSE); - - if (charset == MM_MODEM_CHARSET_UTF8 || charset == MM_MODEM_CHARSET_IRA) - return g_strdup (src); - - converted = g_convert (src, strlen (src), - iconv_to, "UTF-8//TRANSLIT", - NULL, &converted_len, &error); - if (!converted || error) - return NULL; - - /* Get hex representation of the string */ - return mm_utils_bin2hexstr ((guint8 *)converted, converted_len); -} - /* GSM 03.38 encoding conversion stuff */ #define GSM_DEF_ALPHABET_SIZE 128 diff --git a/src/mm-charsets.h b/src/mm-charsets.h index d9542e6a..a84b7ac5 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -53,12 +53,6 @@ gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array, gchar *mm_modem_charset_hex_to_utf8 (const gchar *src, MMModemCharset charset); -/* Take a string in UTF-8 and convert it to the given charset in hex - * representation. - */ -gchar *mm_modem_charset_utf8_to_hex (const gchar *src, - MMModemCharset charset); - guint8 *mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, guint32 *out_len); guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, From d126fa58069e794fe59b9e48d1b86053522ca9c9 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 22 Nov 2020 17:01:19 +0100 Subject: [PATCH 575/675] libmm-glib,common-helpers: make hexstr2bin() return a GError This util method checks whether the input string is a valid hex string, so make sure we return a GError on failure. (cherry picked from commit 657cabcfce6794d2a2f629d63dbd56fc149dab2e) --- libmm-glib/mm-common-helpers.c | 18 +++-- libmm-glib/mm-common-helpers.h | 2 +- plugins/altair/mm-modem-helpers-altair-lte.c | 56 ++++--------- plugins/huawei/mm-broadband-modem-huawei.c | 19 +++-- plugins/huawei/mm-modem-helpers-huawei.c | 2 +- src/mm-base-sim.c | 85 +++++++------------- src/mm-charsets.c | 2 +- src/mm-modem-helpers-qmi.c | 20 ++--- src/mm-modem-helpers.c | 5 +- src/mm-sms-part-3gpp.c | 17 ++-- src/mm-sms-part-cdma.c | 17 ++-- 11 files changed, 90 insertions(+), 153 deletions(-) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index da1cc1cc..b443f1ab 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1687,10 +1687,12 @@ mm_utils_hex2byte (const gchar *hex) } gchar * -mm_utils_hexstr2bin (const gchar *hex, gsize *out_len) +mm_utils_hexstr2bin (const gchar *hex, + gsize *out_len, + GError **error) { const gchar *ipos = hex; - gchar *buf = NULL; + g_autofree gchar *buf = NULL; gsize i; gint a; gchar *opos; @@ -1699,20 +1701,26 @@ mm_utils_hexstr2bin (const gchar *hex, gsize *out_len) len = strlen (hex); /* Length must be a multiple of 2 */ - g_return_val_if_fail ((len % 2) == 0, NULL); + if ((len % 2) != 0) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Hex conversion failed: invalid input length"); + return NULL; + } opos = buf = g_malloc0 ((len / 2) + 1); for (i = 0; i < len; i += 2) { a = mm_utils_hex2byte (ipos); if (a < 0) { - g_free (buf); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Hex byte conversion from '%c%c' failed", + ipos[0], ipos[1]); return NULL; } *opos++ = a; ipos += 2; } *out_len = len / 2; - return buf; + return g_steal_pointer (&buf); } /* End from hostap */ diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h index 65d0e70a..d3cf62d7 100644 --- a/libmm-glib/mm-common-helpers.h +++ b/libmm-glib/mm-common-helpers.h @@ -181,7 +181,7 @@ gchar *mm_get_string_unquoted_from_match_info (GMatchInfo *match_info, const gchar *mm_sms_delivery_state_get_string_extended (guint delivery_state); gint mm_utils_hex2byte (const gchar *hex); -gchar *mm_utils_hexstr2bin (const gchar *hex, gsize *out_len); +gchar *mm_utils_hexstr2bin (const gchar *hex, gsize *out_len, GError **error); gchar *mm_utils_bin2hexstr (const guint8 *bin, gsize len); gboolean mm_utils_ishexstr (const gchar *hex); diff --git a/plugins/altair/mm-modem-helpers-altair-lte.c b/plugins/altair/mm-modem-helpers-altair-lte.c index 278f31e8..6d218800 100644 --- a/plugins/altair/mm-modem-helpers-altair-lte.c +++ b/plugins/altair/mm-modem-helpers-altair-lte.c @@ -155,9 +155,9 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error) G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, NULL); g_assert (regex); - if (!g_regex_match_full (regex, pco_info, strlen (pco_info), 0, 0, &match_info, error)) { + + if (!g_regex_match_full (regex, pco_info, strlen (pco_info), 0, 0, &match_info, error)) return NULL; - } num_matches = g_match_info_get_match_count (match_info); if (num_matches != 5) { @@ -170,22 +170,18 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error) } while (g_match_info_matches (match_info)) { - guint pco_cid; - gchar *pco_id; - gchar *pco_payload; - gsize pco_payload_len; - gchar *pco_payload_bytes = NULL; - gsize pco_payload_bytes_len; - guint8 pco_prefix[6]; + guint pco_cid; + g_autofree gchar *pco_id = NULL; + g_autofree gchar *pco_payload = NULL; + g_autofree gchar *pco_payload_bytes = NULL; + gsize pco_payload_bytes_len; + guint8 pco_prefix[6]; GByteArray *pco_raw; - gsize pco_raw_len; + gsize pco_raw_len; if (!mm_get_uint_from_match_info (match_info, 1, &pco_cid)) { - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't parse CID from PCO info: '%s'", - pco_info); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't parse CID from PCO info: '%s'", pco_info); break; } @@ -197,42 +193,26 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error) pco_id = mm_get_string_unquoted_from_match_info (match_info, 3); if (!pco_id) { - g_set_error (error, - MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Couldn't parse PCO ID from PCO info: '%s'", - pco_info); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't parse PCO ID from PCO info: '%s'", pco_info); break; } if (g_strcmp0 (pco_id, "FF00")) { - g_free (pco_id); g_match_info_next (match_info, error); continue; } - g_free (pco_id); pco_payload = mm_get_string_unquoted_from_match_info (match_info, 4); if (!pco_payload) { - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't parse PCO payload from PCO info: '%s'", - pco_info); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't parse PCO payload from PCO info: '%s'", pco_info); break; } - pco_payload_len = strlen (pco_payload); - if (pco_payload_len % 2 == 0) - pco_payload_bytes = mm_utils_hexstr2bin (pco_payload, &pco_payload_bytes_len); - - g_free (pco_payload); - + pco_payload_bytes = mm_utils_hexstr2bin (pco_payload, &pco_payload_bytes_len, error); if (!pco_payload_bytes) { - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Invalid PCO payload from PCO info: '%s'", - pco_info); + g_prefix_error (error, "Invalid PCO payload from PCO info '%s': ", pco_info); break; } @@ -267,13 +247,11 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error) pco_raw = g_byte_array_sized_new (pco_raw_len); g_byte_array_append (pco_raw, pco_prefix, sizeof (pco_prefix)); g_byte_array_append (pco_raw, (guint8 *)pco_payload_bytes, pco_payload_bytes_len); - g_free (pco_payload_bytes); pco = mm_pco_new (); mm_pco_set_session_id (pco, pco_cid); mm_pco_set_complete (pco, TRUE); mm_pco_set_data (pco, pco_raw->data, pco_raw->len); - g_byte_array_unref (pco_raw); break; } diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index 19249a8c..aec926c1 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2330,21 +2330,20 @@ decode (MMIfaceModem3gppUssd *self, const gchar *reply, GError **error) { - gchar *bin, *utf8; - guint8 *unpacked; - gsize bin_len; - guint32 unpacked_len; + g_autofree gchar *bin = NULL; + g_autofree guint8 *unpacked = NULL; + gsize bin_len = 0; + guint32 unpacked_len; + + bin = mm_utils_hexstr2bin (reply, &bin_len, error); + if (!bin) + return NULL; - bin = mm_utils_hexstr2bin (reply, &bin_len); unpacked = mm_charset_gsm_unpack ((guint8*) bin, (bin_len * 8) / 7, 0, &unpacked_len); /* if the last character in a 7-byte block is padding, then drop it */ if ((bin_len % 7 == 0) && (unpacked[unpacked_len - 1] == 0x0d)) unpacked_len--; - utf8 = (char*) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len); - - g_free (bin); - g_free (unpacked); - return utf8; + return (gchar*) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len); } /*****************************************************************************/ diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c index 2cd94e6a..1f9fe363 100644 --- a/plugins/huawei/mm-modem-helpers-huawei.c +++ b/plugins/huawei/mm-modem-helpers-huawei.c @@ -188,7 +188,7 @@ match_info_to_ip4_addr (GMatchInfo *match_info, else g_assert_not_reached (); - bin = mm_utils_hexstr2bin (buf, &bin_len); + bin = mm_utils_hexstr2bin (buf, &bin_len, NULL); if (!bin || bin_len != 4) goto done; diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 85051191..95273292 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -1291,9 +1291,9 @@ static guint parse_mnc_length (const gchar *response, GError **error) { - guint sw1 = 0; - guint sw2 = 0; - gchar *hex = 0; + guint sw1 = 0; + guint sw2 = 0; + g_autofree gchar *hex = NULL; if (!mm_3gpp_parse_crsm_response (response, &sw1, @@ -1306,47 +1306,34 @@ parse_mnc_length (const gchar *response, (sw1 == 0x91) || (sw1 == 0x92) || (sw1 == 0x9f)) { - gsize buflen = 0; - guint32 mnc_len; - gchar *bin; + gsize buflen = 0; + guint32 mnc_len; + g_autofree gchar *bin = NULL; /* Convert hex string to binary */ - bin = mm_utils_hexstr2bin (hex, &buflen); - if (!bin || buflen < 4) { - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "SIM returned malformed response '%s'", - hex); - g_free (bin); - g_free (hex); + bin = mm_utils_hexstr2bin (hex, &buflen, error); + if (!bin) { + g_prefix_error (error, "SIM returned malformed response '%s': ", hex); + return 0; + } + if (buflen < 4) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "SIM returned malformed response '%s': too short", hex); return 0; } - - g_free (hex); /* MNC length is byte 4 of this SIM file */ mnc_len = bin[3] & 0xFF; - if (mnc_len == 2 || mnc_len == 3) { - g_free (bin); + if (mnc_len == 2 || mnc_len == 3) return mnc_len; - } - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "SIM returned invalid MNC length %d (should be either 2 or 3)", - mnc_len); - g_free (bin); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "SIM returned invalid MNC length %d (should be either 2 or 3)", mnc_len); return 0; } - g_free (hex); - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "SIM failed to handle CRSM request (sw1 %d sw2 %d)", - sw1, sw2); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "SIM failed to handle CRSM request (sw1 %d sw2 %d)", sw1, sw2); return 0; } @@ -1410,9 +1397,9 @@ static gchar * parse_spn (const gchar *response, GError **error) { - guint sw1 = 0; - guint sw2 = 0; - gchar *hex = 0; + guint sw1 = 0; + guint sw2 = 0; + g_autofree gchar *hex = NULL; if (!mm_3gpp_parse_crsm_response (response, &sw1, @@ -1425,40 +1412,26 @@ parse_spn (const gchar *response, (sw1 == 0x91) || (sw1 == 0x92) || (sw1 == 0x9f)) { - gsize buflen = 0; - gchar *bin; - gchar *utf8; + gsize buflen = 0; + g_autofree gchar *bin = NULL; /* Convert hex string to binary */ - bin = mm_utils_hexstr2bin (hex, &buflen); + bin = mm_utils_hexstr2bin (hex, &buflen, error); if (!bin) { - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "SIM returned malformed response '%s'", - hex); - g_free (hex); + g_prefix_error (error, "SIM returned malformed response '%s': ", hex); return NULL; } - g_free (hex); - /* Remove the FF filler at the end */ while (buflen > 1 && bin[buflen - 1] == (char)0xff) buflen--; /* First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */ - utf8 = (gchar *)mm_charset_gsm_unpacked_to_utf8 ((guint8 *)bin + 1, buflen - 1); - g_free (bin); - return utf8; + return (gchar *)mm_charset_gsm_unpacked_to_utf8 ((guint8 *)bin + 1, buflen - 1); } - g_free (hex); - g_set_error (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "SIM failed to handle CRSM request (sw1 %d sw2 %d)", - sw1, sw2); + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "SIM failed to handle CRSM request (sw1 %d sw2 %d)", sw1, sw2); return NULL; } diff --git a/src/mm-charsets.c b/src/mm-charsets.c index 2613a660..f51e92bb 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -169,7 +169,7 @@ mm_modem_charset_hex_to_utf8 (const gchar *src, iconv_from = charset_iconv_from (charset); g_return_val_if_fail (iconv_from != NULL, FALSE); - unconverted = mm_utils_hexstr2bin (src, &unconverted_len); + unconverted = mm_utils_hexstr2bin (src, &unconverted_len, NULL); if (!unconverted) return NULL; diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 3e87f0d0..634d0d35 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1819,25 +1819,19 @@ mm_firmware_unique_id_to_qmi_unique_id (const gchar *unique_id, /* The length will be exactly EXPECTED_QMI_UNIQUE_ID_LENGTH*2 if given in HEX */ if (len == (2 * EXPECTED_QMI_UNIQUE_ID_LENGTH)) { - guint8 *tmp; - gsize tmp_len; - guint i; - - for (i = 0; i < len; i++) { - if (!g_ascii_isxdigit (unique_id[i])) { - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Unexpected character found in unique id (not HEX): %c", unique_id[i]); - return NULL; - } - } + g_autofree guint8 *tmp = NULL; + gsize tmp_len; tmp_len = 0; - tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, &tmp_len); + tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, &tmp_len, error); + if (!tmp) { + g_prefix_error (error, "Unexpected character found in unique id: "); + return NULL; + } g_assert (tmp_len == EXPECTED_QMI_UNIQUE_ID_LENGTH); qmi_unique_id = g_array_sized_new (FALSE, FALSE, sizeof (guint8), tmp_len); g_array_insert_vals (qmi_unique_id, 0, tmp, tmp_len); - g_free (tmp); return qmi_unique_id; } diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 3ee12aaa..a2fb07fa 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -4291,10 +4291,9 @@ mm_3gpp_parse_emergency_numbers (const char *raw, GError **error) return NULL; } - bin = (guint8 *) mm_utils_hexstr2bin (raw, &binlen); + bin = (guint8 *) mm_utils_hexstr2bin (raw, &binlen, error); if (!bin) { - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, - "invalid raw emergency numbers list contents: %s", raw); + g_prefix_error (error, "invalid raw emergency numbers list contents: "); return NULL; } diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index dd43ac5a..bc4310ee 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -339,24 +339,17 @@ mm_sms_part_3gpp_new_from_pdu (guint index, gpointer log_object, GError **error) { - gsize pdu_len; - guint8 *pdu; - MMSmsPart *part; + g_autofree guint8 *pdu = NULL; + gsize pdu_len; /* Convert PDU from hex to binary */ - pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, &pdu_len); + pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, &pdu_len, error); if (!pdu) { - g_set_error_literal (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't convert 3GPP PDU from hex to binary"); + g_prefix_error (error, "Couldn't convert 3GPP PDU from hex to binary: "); return NULL; } - part = mm_sms_part_3gpp_new_from_binary_pdu (index, pdu, pdu_len, log_object, error); - g_free (pdu); - - return part; + return mm_sms_part_3gpp_new_from_binary_pdu (index, pdu, pdu_len, log_object, error); } MMSmsPart * diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index fcfd85e9..39e2cc2f 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -317,24 +317,17 @@ mm_sms_part_cdma_new_from_pdu (guint index, gpointer log_object, GError **error) { - gsize pdu_len; - guint8 *pdu; - MMSmsPart *part; + g_autofree guint8 *pdu = NULL; + gsize pdu_len; /* Convert PDU from hex to binary */ - pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, &pdu_len); + pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, &pdu_len, error); if (!pdu) { - g_set_error_literal (error, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't convert CDMA PDU from hex to binary"); + g_prefix_error (error, "Couldn't convert CDMA PDU from hex to binary: "); return NULL; } - part = mm_sms_part_cdma_new_from_binary_pdu (index, pdu, pdu_len, log_object, error); - g_free (pdu); - - return part; + return mm_sms_part_cdma_new_from_binary_pdu (index, pdu, pdu_len, log_object, error); } struct Parameter { From ce36979813cdc31692e5ffddd57136aa3165e740 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 21 Dec 2020 13:52:54 +0100 Subject: [PATCH 576/675] libmm-glib,common-helpers: make hexstr2bin() accept input string length Optionally given explicitly, and -1 can be used to assume it's NUL-terminated. (cherry picked from commit a211981d4a12b0ef6cab48b7a04ae9e5674cac01) --- libmm-glib/mm-common-helpers.c | 9 +++++---- libmm-glib/mm-common-helpers.h | 2 +- plugins/altair/mm-modem-helpers-altair-lte.c | 2 +- plugins/huawei/mm-broadband-modem-huawei.c | 2 +- plugins/huawei/mm-modem-helpers-huawei.c | 2 +- src/mm-base-sim.c | 4 ++-- src/mm-charsets.c | 2 +- src/mm-modem-helpers-qmi.c | 2 +- src/mm-modem-helpers.c | 2 +- src/mm-sms-part-3gpp.c | 2 +- src/mm-sms-part-cdma.c | 2 +- 11 files changed, 16 insertions(+), 15 deletions(-) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index b443f1ab..3a97e3be 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1688,6 +1688,7 @@ mm_utils_hex2byte (const gchar *hex) gchar * mm_utils_hexstr2bin (const gchar *hex, + gssize len, gsize *out_len, GError **error) { @@ -1695,10 +1696,10 @@ mm_utils_hexstr2bin (const gchar *hex, g_autofree gchar *buf = NULL; gsize i; gint a; - gchar *opos; - gsize len; - - len = strlen (hex); + gchar *opos +; + if (len < 0) + len = strlen (hex); /* Length must be a multiple of 2 */ if ((len % 2) != 0) { diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h index d3cf62d7..50d58134 100644 --- a/libmm-glib/mm-common-helpers.h +++ b/libmm-glib/mm-common-helpers.h @@ -181,7 +181,7 @@ gchar *mm_get_string_unquoted_from_match_info (GMatchInfo *match_info, const gchar *mm_sms_delivery_state_get_string_extended (guint delivery_state); gint mm_utils_hex2byte (const gchar *hex); -gchar *mm_utils_hexstr2bin (const gchar *hex, gsize *out_len, GError **error); +gchar *mm_utils_hexstr2bin (const gchar *hex, gssize len, gsize *out_len, GError **error); gchar *mm_utils_bin2hexstr (const guint8 *bin, gsize len); gboolean mm_utils_ishexstr (const gchar *hex); diff --git a/plugins/altair/mm-modem-helpers-altair-lte.c b/plugins/altair/mm-modem-helpers-altair-lte.c index 6d218800..b71b458a 100644 --- a/plugins/altair/mm-modem-helpers-altair-lte.c +++ b/plugins/altair/mm-modem-helpers-altair-lte.c @@ -210,7 +210,7 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error) break; } - pco_payload_bytes = mm_utils_hexstr2bin (pco_payload, &pco_payload_bytes_len, error); + pco_payload_bytes = mm_utils_hexstr2bin (pco_payload, -1, &pco_payload_bytes_len, error); if (!pco_payload_bytes) { g_prefix_error (error, "Invalid PCO payload from PCO info '%s': ", pco_info); break; diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index aec926c1..feaabd46 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2335,7 +2335,7 @@ decode (MMIfaceModem3gppUssd *self, gsize bin_len = 0; guint32 unpacked_len; - bin = mm_utils_hexstr2bin (reply, &bin_len, error); + bin = mm_utils_hexstr2bin (reply, -1, &bin_len, error); if (!bin) return NULL; diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c index 1f9fe363..49f5a6ea 100644 --- a/plugins/huawei/mm-modem-helpers-huawei.c +++ b/plugins/huawei/mm-modem-helpers-huawei.c @@ -188,7 +188,7 @@ match_info_to_ip4_addr (GMatchInfo *match_info, else g_assert_not_reached (); - bin = mm_utils_hexstr2bin (buf, &bin_len, NULL); + bin = mm_utils_hexstr2bin (buf, -1, &bin_len, NULL); if (!bin || bin_len != 4) goto done; diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 95273292..78ffdc62 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -1311,7 +1311,7 @@ parse_mnc_length (const gchar *response, g_autofree gchar *bin = NULL; /* Convert hex string to binary */ - bin = mm_utils_hexstr2bin (hex, &buflen, error); + bin = mm_utils_hexstr2bin (hex, -1, &buflen, error); if (!bin) { g_prefix_error (error, "SIM returned malformed response '%s': ", hex); return 0; @@ -1416,7 +1416,7 @@ parse_spn (const gchar *response, g_autofree gchar *bin = NULL; /* Convert hex string to binary */ - bin = mm_utils_hexstr2bin (hex, &buflen, error); + bin = mm_utils_hexstr2bin (hex, -1, &buflen, error); if (!bin) { g_prefix_error (error, "SIM returned malformed response '%s': ", hex); return NULL; diff --git a/src/mm-charsets.c b/src/mm-charsets.c index f51e92bb..adc80332 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -169,7 +169,7 @@ mm_modem_charset_hex_to_utf8 (const gchar *src, iconv_from = charset_iconv_from (charset); g_return_val_if_fail (iconv_from != NULL, FALSE); - unconverted = mm_utils_hexstr2bin (src, &unconverted_len, NULL); + unconverted = mm_utils_hexstr2bin (src, -1, &unconverted_len, NULL); if (!unconverted) return NULL; diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 634d0d35..241f150f 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1823,7 +1823,7 @@ mm_firmware_unique_id_to_qmi_unique_id (const gchar *unique_id, gsize tmp_len; tmp_len = 0; - tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, &tmp_len, error); + tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, -1, &tmp_len, error); if (!tmp) { g_prefix_error (error, "Unexpected character found in unique id: "); return NULL; diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index a2fb07fa..5baaef09 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -4291,7 +4291,7 @@ mm_3gpp_parse_emergency_numbers (const char *raw, GError **error) return NULL; } - bin = (guint8 *) mm_utils_hexstr2bin (raw, &binlen, error); + bin = (guint8 *) mm_utils_hexstr2bin (raw, -1, &binlen, error); if (!bin) { g_prefix_error (error, "invalid raw emergency numbers list contents: "); return NULL; diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index bc4310ee..cdf9a1a0 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -343,7 +343,7 @@ mm_sms_part_3gpp_new_from_pdu (guint index, gsize pdu_len; /* Convert PDU from hex to binary */ - pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, &pdu_len, error); + pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error); if (!pdu) { g_prefix_error (error, "Couldn't convert 3GPP PDU from hex to binary: "); return NULL; diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index 39e2cc2f..4275cb8d 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -321,7 +321,7 @@ mm_sms_part_cdma_new_from_pdu (guint index, gsize pdu_len; /* Convert PDU from hex to binary */ - pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, &pdu_len, error); + pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error); if (!pdu) { g_prefix_error (error, "Couldn't convert CDMA PDU from hex to binary: "); return NULL; From c1c0319f3e9110155ab19c4838b3372faaa64c53 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 10:43:35 +0100 Subject: [PATCH 577/675] libmm-glib,common-helpers: hexstr2bin fails on empty input string Also, remove the trailing NUL byte that was appended to the output binary stream, as it's not needed in any case. (cherry picked from commit 8c30a6b6f813114d0cdc6b8a04ae4336c8393d48) --- libmm-glib/mm-common-helpers.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 3a97e3be..30f9f94f 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1701,6 +1701,12 @@ mm_utils_hexstr2bin (const gchar *hex, if (len < 0) len = strlen (hex); + if (len == 0) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Hex conversion failed: empty string"); + return NULL; + } + /* Length must be a multiple of 2 */ if ((len % 2) != 0) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, @@ -1708,7 +1714,7 @@ mm_utils_hexstr2bin (const gchar *hex, return NULL; } - opos = buf = g_malloc0 ((len / 2) + 1); + opos = buf = g_malloc0 (len / 2); for (i = 0; i < len; i += 2) { a = mm_utils_hex2byte (ipos); if (a < 0) { From 7f272cc84e89137b3dcf1a225882a6d5906dc3f6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 10:46:49 +0100 Subject: [PATCH 578/675] libmm-glib,common-helpers: ishexstr() fails on empty input string (cherry picked from commit 6d8610d63ecb8e53e14486533a580ea4f37c644c) --- libmm-glib/mm-common-helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 30f9f94f..0245fd52 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1738,9 +1738,9 @@ mm_utils_ishexstr (const gchar *hex) gsize len; gsize i; - /* Length not multiple of 2? */ + /* Empty string or length not multiple of 2? */ len = strlen (hex); - if (len % 2 != 0) + if (len == 0 || (len % 2) != 0) return FALSE; for (i = 0; i < len; i++) { From da57feee719f234f619567eb7df2a9c69817a7bd Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 11:06:50 +0100 Subject: [PATCH 579/675] libmm-glib,common-helpers: make hexstr2bin() return a guint8 array It makes much more sense than returning a gchar array, as gchar is signed. (cherry picked from commit 34de613deab1c8728118fce389963ecb29ca51e7) --- libmm-glib/mm-common-helpers.c | 10 +++---- libmm-glib/mm-common-helpers.h | 2 +- plugins/altair/mm-modem-helpers-altair-lte.c | 18 ++++++------ plugins/huawei/mm-broadband-modem-huawei.c | 4 +-- plugins/huawei/mm-modem-helpers-huawei.c | 30 +++++++++----------- src/mm-base-sim.c | 16 +++++------ src/mm-charsets.c | 12 ++++---- src/mm-modem-helpers-qmi.c | 2 +- src/mm-modem-helpers.c | 2 +- src/mm-sms-part-3gpp.c | 2 +- src/mm-sms-part-cdma.c | 2 +- 11 files changed, 48 insertions(+), 52 deletions(-) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 0245fd52..43fff922 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1686,18 +1686,18 @@ mm_utils_hex2byte (const gchar *hex) return (a << 4) | b; } -gchar * +guint8 * mm_utils_hexstr2bin (const gchar *hex, gssize len, gsize *out_len, GError **error) { const gchar *ipos = hex; - g_autofree gchar *buf = NULL; + g_autofree guint8 *buf = NULL; gsize i; gint a; - gchar *opos -; + guint8 *opos; + if (len < 0) len = strlen (hex); @@ -1723,7 +1723,7 @@ mm_utils_hexstr2bin (const gchar *hex, ipos[0], ipos[1]); return NULL; } - *opos++ = a; + *opos++ = (guint8)a; ipos += 2; } *out_len = len / 2; diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h index 50d58134..4e6d9784 100644 --- a/libmm-glib/mm-common-helpers.h +++ b/libmm-glib/mm-common-helpers.h @@ -181,7 +181,7 @@ gchar *mm_get_string_unquoted_from_match_info (GMatchInfo *match_info, const gchar *mm_sms_delivery_state_get_string_extended (guint delivery_state); gint mm_utils_hex2byte (const gchar *hex); -gchar *mm_utils_hexstr2bin (const gchar *hex, gssize len, gsize *out_len, GError **error); +guint8 *mm_utils_hexstr2bin (const gchar *hex, gssize len, gsize *out_len, GError **error); gchar *mm_utils_bin2hexstr (const guint8 *bin, gsize len); gboolean mm_utils_ishexstr (const gchar *hex); diff --git a/plugins/altair/mm-modem-helpers-altair-lte.c b/plugins/altair/mm-modem-helpers-altair-lte.c index b71b458a..d2fd9af7 100644 --- a/plugins/altair/mm-modem-helpers-altair-lte.c +++ b/plugins/altair/mm-modem-helpers-altair-lte.c @@ -170,14 +170,14 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error) } while (g_match_info_matches (match_info)) { - guint pco_cid; - g_autofree gchar *pco_id = NULL; - g_autofree gchar *pco_payload = NULL; - g_autofree gchar *pco_payload_bytes = NULL; - gsize pco_payload_bytes_len; - guint8 pco_prefix[6]; - GByteArray *pco_raw; - gsize pco_raw_len; + guint pco_cid; + g_autofree gchar *pco_id = NULL; + g_autofree gchar *pco_payload = NULL; + g_autofree guint8 *pco_payload_bytes = NULL; + gsize pco_payload_bytes_len; + guint8 pco_prefix[6]; + GByteArray *pco_raw; + gsize pco_raw_len; if (!mm_get_uint_from_match_info (match_info, 1, &pco_cid)) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, @@ -246,7 +246,7 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error) pco_raw = g_byte_array_sized_new (pco_raw_len); g_byte_array_append (pco_raw, pco_prefix, sizeof (pco_prefix)); - g_byte_array_append (pco_raw, (guint8 *)pco_payload_bytes, pco_payload_bytes_len); + g_byte_array_append (pco_raw, pco_payload_bytes, pco_payload_bytes_len); pco = mm_pco_new (); mm_pco_set_session_id (pco, pco_cid); diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index feaabd46..e2c90d14 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2330,7 +2330,7 @@ decode (MMIfaceModem3gppUssd *self, const gchar *reply, GError **error) { - g_autofree gchar *bin = NULL; + g_autofree guint8 *bin = NULL; g_autofree guint8 *unpacked = NULL; gsize bin_len = 0; guint32 unpacked_len; @@ -2339,7 +2339,7 @@ decode (MMIfaceModem3gppUssd *self, if (!bin) return NULL; - unpacked = mm_charset_gsm_unpack ((guint8*) bin, (bin_len * 8) / 7, 0, &unpacked_len); + unpacked = mm_charset_gsm_unpack (bin, (bin_len * 8) / 7, 0, &unpacked_len); /* if the last character in a 7-byte block is padding, then drop it */ if ((bin_len % 7 == 0) && (unpacked[unpacked_len - 1] == 0x0d)) unpacked_len--; diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c index 49f5a6ea..1b443052 100644 --- a/plugins/huawei/mm-modem-helpers-huawei.c +++ b/plugins/huawei/mm-modem-helpers-huawei.c @@ -157,14 +157,15 @@ mm_huawei_parse_ndisstatqry_response (const gchar *response, static gboolean match_info_to_ip4_addr (GMatchInfo *match_info, - guint match_index, - guint *out_addr) + guint match_index, + guint *out_addr) { - gchar *s, *bin = NULL; - gchar buf[9]; - gsize len, bin_len; - gboolean success = FALSE; - guint32 aux; + g_autofree gchar *s = NULL; + g_autofree guint8 *bin = NULL; + gchar buf[9]; + gsize len; + gsize bin_len; + guint32 aux; s = g_match_info_fetch (match_info, match_index); g_return_val_if_fail (s != NULL, FALSE); @@ -172,11 +173,11 @@ match_info_to_ip4_addr (GMatchInfo *match_info, len = strlen (s); if (len == 1 && s[0] == '0') { *out_addr = 0; - success = TRUE; - goto done; + return TRUE; } + if (len < 7 || len > 8) - goto done; + return FALSE; /* Handle possibly missing leading zero */ memset (buf, 0, sizeof (buf)); @@ -190,16 +191,11 @@ match_info_to_ip4_addr (GMatchInfo *match_info, bin = mm_utils_hexstr2bin (buf, -1, &bin_len, NULL); if (!bin || bin_len != 4) - goto done; + return FALSE; memcpy (&aux, bin, 4); *out_addr = GUINT32_SWAP_LE_BE (aux); - success = TRUE; - -done: - g_free (s); - g_free (bin); - return success; + return TRUE; } gboolean diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 78ffdc62..0e00342c 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -1306,9 +1306,9 @@ parse_mnc_length (const gchar *response, (sw1 == 0x91) || (sw1 == 0x92) || (sw1 == 0x9f)) { - gsize buflen = 0; - guint32 mnc_len; - g_autofree gchar *bin = NULL; + gsize buflen = 0; + guint32 mnc_len; + g_autofree guint8 *bin = NULL; /* Convert hex string to binary */ bin = mm_utils_hexstr2bin (hex, -1, &buflen, error); @@ -1323,7 +1323,7 @@ parse_mnc_length (const gchar *response, } /* MNC length is byte 4 of this SIM file */ - mnc_len = bin[3] & 0xFF; + mnc_len = bin[3]; if (mnc_len == 2 || mnc_len == 3) return mnc_len; @@ -1412,8 +1412,8 @@ parse_spn (const gchar *response, (sw1 == 0x91) || (sw1 == 0x92) || (sw1 == 0x9f)) { - gsize buflen = 0; - g_autofree gchar *bin = NULL; + gsize buflen = 0; + g_autofree guint8 *bin = NULL; /* Convert hex string to binary */ bin = mm_utils_hexstr2bin (hex, -1, &buflen, error); @@ -1423,11 +1423,11 @@ parse_spn (const gchar *response, } /* Remove the FF filler at the end */ - while (buflen > 1 && bin[buflen - 1] == (char)0xff) + while (buflen > 1 && bin[buflen - 1] == 0xff) buflen--; /* First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */ - return (gchar *)mm_charset_gsm_unpacked_to_utf8 ((guint8 *)bin + 1, buflen - 1); + return (gchar *)mm_charset_gsm_unpacked_to_utf8 (bin + 1, buflen - 1); } g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, diff --git a/src/mm-charsets.c b/src/mm-charsets.c index adc80332..bc33b2ae 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -157,11 +157,11 @@ gchar * mm_modem_charset_hex_to_utf8 (const gchar *src, MMModemCharset charset) { - const gchar *iconv_from; - g_autofree gchar *unconverted = NULL; - g_autofree gchar *converted = NULL; - g_autoptr(GError) error = NULL; - gsize unconverted_len = 0; + const gchar *iconv_from; + g_autofree guint8 *unconverted = NULL; + g_autofree gchar *converted = NULL; + g_autoptr(GError) error = NULL; + gsize unconverted_len = 0; g_return_val_if_fail (src != NULL, NULL); g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); @@ -176,7 +176,7 @@ mm_modem_charset_hex_to_utf8 (const gchar *src, if (charset == MM_MODEM_CHARSET_UTF8 || charset == MM_MODEM_CHARSET_IRA) return g_steal_pointer (&unconverted); - converted = g_convert (unconverted, unconverted_len, + converted = g_convert ((const gchar *)unconverted, unconverted_len, "UTF-8//TRANSLIT", iconv_from, NULL, NULL, &error); if (!converted || error) diff --git a/src/mm-modem-helpers-qmi.c b/src/mm-modem-helpers-qmi.c index 241f150f..27dbeab6 100644 --- a/src/mm-modem-helpers-qmi.c +++ b/src/mm-modem-helpers-qmi.c @@ -1823,7 +1823,7 @@ mm_firmware_unique_id_to_qmi_unique_id (const gchar *unique_id, gsize tmp_len; tmp_len = 0; - tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, -1, &tmp_len, error); + tmp = mm_utils_hexstr2bin (unique_id, -1, &tmp_len, error); if (!tmp) { g_prefix_error (error, "Unexpected character found in unique id: "); return NULL; diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 5baaef09..b4b5515a 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -4291,7 +4291,7 @@ mm_3gpp_parse_emergency_numbers (const char *raw, GError **error) return NULL; } - bin = (guint8 *) mm_utils_hexstr2bin (raw, -1, &binlen, error); + bin = mm_utils_hexstr2bin (raw, -1, &binlen, error); if (!bin) { g_prefix_error (error, "invalid raw emergency numbers list contents: "); return NULL; diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index cdf9a1a0..83181d3b 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -343,7 +343,7 @@ mm_sms_part_3gpp_new_from_pdu (guint index, gsize pdu_len; /* Convert PDU from hex to binary */ - pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error); + pdu = mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error); if (!pdu) { g_prefix_error (error, "Couldn't convert 3GPP PDU from hex to binary: "); return NULL; diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index 4275cb8d..befc557c 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -321,7 +321,7 @@ mm_sms_part_cdma_new_from_pdu (guint index, gsize pdu_len; /* Convert PDU from hex to binary */ - pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error); + pdu = mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error); if (!pdu) { g_prefix_error (error, "Couldn't convert CDMA PDU from hex to binary: "); return NULL; From 64296ce39744c959aca690d0ab9b2b69820240b4 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 10:20:44 +0100 Subject: [PATCH 580/675] libmm-glib,tests: add ishexstr/hexstr2bin/bin2hexstr unit tests (cherry picked from commit 5480cb67b283c078770b02766c37768cb0930d7b) --- libmm-glib/tests/test-common-helpers.c | 104 +++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/libmm-glib/tests/test-common-helpers.c b/libmm-glib/tests/test-common-helpers.c index 48995477..19e1122a 100644 --- a/libmm-glib/tests/test-common-helpers.c +++ b/libmm-glib/tests/test-common-helpers.c @@ -502,6 +502,102 @@ field_parser_double (void) g_free (str); } +/**************************************************************/ +/* hexstr2bin & bin2hexstr */ + +static void +common_hexstr2bin_test_failure (const gchar *input_hex) +{ + g_autoptr(GError) error = NULL; + g_autofree guint8 *bin = NULL; + gsize bin_len = 0; + + g_assert (mm_utils_ishexstr (input_hex) == FALSE); + + bin = mm_utils_hexstr2bin (input_hex, -1, &bin_len, &error); + g_assert_null (bin); + g_assert_nonnull (error); +} + +static void +common_hexstr2bin_test_success_len (const gchar *input_hex, + gssize input_hex_len) +{ + g_autoptr(GError) error = NULL; + g_autofree guint8 *bin = NULL; + gsize bin_len = 0; + g_autofree gchar *hex = NULL; + + bin = mm_utils_hexstr2bin (input_hex, input_hex_len, &bin_len, &error); + g_assert_nonnull (bin); + g_assert_no_error (error); + + hex = mm_utils_bin2hexstr (bin, bin_len); + g_assert_nonnull (hex); + + if (input_hex_len == -1) + g_assert (g_ascii_strcasecmp (input_hex, hex) == 0); + else + g_assert (g_ascii_strncasecmp (input_hex, hex, (gsize)input_hex_len) == 0); +} + +static void +common_hexstr2bin_test_success (const gchar *input_hex) +{ + gsize input_hex_len; + gssize i; + + g_assert (mm_utils_ishexstr (input_hex) == TRUE); + + common_hexstr2bin_test_success_len (input_hex, -1); + + input_hex_len = strlen (input_hex); + for (i = input_hex_len; i >= 2; i-=2) + common_hexstr2bin_test_success_len (input_hex, i); +} + +static void +hexstr_lower_case (void) +{ + common_hexstr2bin_test_success ("000123456789abcdefff"); +} + +static void +hexstr_upper_case (void) +{ + common_hexstr2bin_test_success ("000123456789ABCDEFFF"); +} + +static void +hexstr_mixed_case (void) +{ + common_hexstr2bin_test_success ("000123456789AbcDefFf"); +} + +static void +hexstr_empty (void) +{ + common_hexstr2bin_test_failure (""); +} + +static void +hexstr_missing_digits (void) +{ + common_hexstr2bin_test_failure ("012"); +} + +static void +hexstr_wrong_digits_all (void) +{ + common_hexstr2bin_test_failure ("helloworld"); +} + +static void +hexstr_wrong_digits_some (void) +{ + common_hexstr2bin_test_failure ("012345k7"); +} + /**************************************************************/ int main (int argc, char **argv) @@ -540,5 +636,13 @@ int main (int argc, char **argv) g_test_add_func ("/MM/Common/FieldParsers/Uint", field_parser_uint); g_test_add_func ("/MM/Common/FieldParsers/Double", field_parser_double); + g_test_add_func ("/MM/Common/HexStr/lower-case", hexstr_lower_case); + g_test_add_func ("/MM/Common/HexStr/upper-case", hexstr_upper_case); + g_test_add_func ("/MM/Common/HexStr/mixed-case", hexstr_mixed_case); + g_test_add_func ("/MM/Common/HexStr/missing-empty", hexstr_empty); + g_test_add_func ("/MM/Common/HexStr/missing-digits", hexstr_missing_digits); + g_test_add_func ("/MM/Common/HexStr/wrong-digits-all", hexstr_wrong_digits_all); + g_test_add_func ("/MM/Common/HexStr/wrong-digits-some", hexstr_wrong_digits_some); + return g_test_run (); } From 5aa572d7f8604e68d08dc678dcc7f9ccc5240530 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 26 Nov 2020 23:07:11 +0100 Subject: [PATCH 581/675] charsets: make translit optional in gsm_unpacked_to_utf8() Until now, this method would automatically apply transliteration; i.e. replacing characters with '?' when no direct translation was available. We can attempt to do that transliteration on strings that are not critical, e.g. the operator name reported by the network. But we should not do that on other types of strings, e.g. on SMS contents that may really have additional purposes than just being human-readable. This commit makes the transliteration option to be explicitly requested by the caller. (cherry picked from commit 5ce97abd73da12b64393be798f2c294d29be2705) --- plugins/huawei/mm-broadband-modem-huawei.c | 2 +- src/mm-base-sim.c | 2 +- src/mm-broadband-modem-mbim.c | 6 +- src/mm-charsets.c | 21 ++-- src/mm-charsets.h | 10 +- src/mm-sms-part-3gpp.c | 116 ++++++++++++--------- src/tests/test-charsets.c | 4 +- 7 files changed, 96 insertions(+), 65 deletions(-) diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index e2c90d14..a20c0eda 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2343,7 +2343,7 @@ decode (MMIfaceModem3gppUssd *self, /* if the last character in a 7-byte block is padding, then drop it */ if ((bin_len % 7 == 0) && (unpacked[unpacked_len - 1] == 0x0d)) unpacked_len--; - return (gchar*) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len); + return (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error); } /*****************************************************************************/ diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 0e00342c..f50af820 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -1427,7 +1427,7 @@ parse_spn (const gchar *response, buflen--; /* First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */ - return (gchar *)mm_charset_gsm_unpacked_to_utf8 (bin + 1, buflen - 1); + return (gchar *)mm_charset_gsm_unpacked_to_utf8 (bin + 1, buflen - 1, FALSE, error); } g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 7c592fe4..c073bb29 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4820,11 +4820,9 @@ ussd_decode (guint32 scheme, guint32 unpacked_len; unpacked = mm_charset_gsm_unpack ((const guint8 *)data->data, (data->len * 8) / 7, 0, &unpacked_len); - decoded = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len); + decoded = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error); if (!decoded) - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, - "Error decoding USSD command in 0x%04x scheme (GSM7 charset)", - scheme); + g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (GSM7 charset): ", scheme); } else if (scheme == MM_MODEM_GSM_USSD_SCHEME_UCS2) { decoded = mm_modem_charset_byte_array_to_utf8 (data, MM_MODEM_CHARSET_UCS2); if (!decoded) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index bc33b2ae..3a8ea719 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -360,11 +360,13 @@ utf8_to_gsm_ext_char (const gchar *utf8, } guint8 * -mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, - guint32 len) +mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, + guint32 len, + gboolean translit, + GError **error) { - guint i; - GByteArray *utf8; + g_autoptr(GByteArray) utf8 = NULL; + guint i; g_return_val_if_fail (gsm != NULL, NULL); g_return_val_if_fail (len < 4096, NULL); @@ -410,13 +412,18 @@ mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, if (ulen) g_byte_array_append (utf8, &uchars[0], ulen); - else + else if (translit) g_byte_array_append (utf8, (guint8 *) "?", 1); + else { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Invalid conversion from GSM7"); + return NULL; + } } /* Always make sure returned string is NUL terminated */ g_byte_array_append (utf8, (guint8 *) "\0", 1); - return g_byte_array_free (utf8, FALSE); + return g_byte_array_free (g_steal_pointer (&utf8), FALSE); } guint8 * @@ -740,7 +747,7 @@ mm_charset_take_and_convert_to_utf8 (gchar *str, break; case MM_MODEM_CHARSET_GSM: - utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str)); + utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str), FALSE, NULL); g_free (str); break; diff --git a/src/mm-charsets.h b/src/mm-charsets.h index a84b7ac5..dc8613a5 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -53,10 +53,12 @@ gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array, gchar *mm_modem_charset_hex_to_utf8 (const gchar *src, MMModemCharset charset); -guint8 *mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, - guint32 *out_len); -guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, - guint32 len); +guint8 *mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, + guint32 *out_len); +guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, + guint32 len, + gboolean translit, + GError **error); /* Checks whether conversion to the given charset may be done without errors */ gboolean mm_charset_can_convert_to (const gchar *utf8, diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index 83181d3b..e7735e1d 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -120,23 +120,24 @@ sms_string_to_bcd_semi_octets (guint8 *buf, gsize buflen, const char *string) } /* len is in semi-octets */ -static char * -sms_decode_address (const guint8 *address, int len) +static gchar * +sms_decode_address (const guint8 *address, + gint len, + GError **error) { guint8 addrtype, addrplan; - char *utf8; + gchar *utf8; addrtype = address[0] & SMS_NUMBER_TYPE_MASK; addrplan = address[0] & SMS_NUMBER_PLAN_MASK; address++; if (addrtype == SMS_NUMBER_TYPE_ALPHA) { - guint8 *unpacked; - guint32 unpacked_len; + g_autofree guint8 *unpacked = NULL; + guint32 unpacked_len; + unpacked = mm_charset_gsm_unpack (address, (len * 4) / 7, 0, &unpacked_len); - utf8 = (char *)mm_charset_gsm_unpacked_to_utf8 (unpacked, - unpacked_len); - g_free (unpacked); + utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error); } else if (addrtype == SMS_NUMBER_TYPE_INTL && addrplan == SMS_NUMBER_PLAN_TELEPHONE) { /* International telphone number, format as "+1234567890" */ @@ -239,41 +240,45 @@ sms_encoding_type (int dcs) return scheme; } -static char * -sms_decode_text (const guint8 *text, - int len, - MMSmsEncoding encoding, - int bit_offset, - gpointer log_object) +static gchar * +sms_decode_text (const guint8 *text, + int len, + MMSmsEncoding encoding, + int bit_offset, + gpointer log_object, + GError **error) { - gchar *utf8; - if (encoding == MM_SMS_ENCODING_GSM7) { g_autofree guint8 *unpacked = NULL; guint32 unpacked_len; + gchar *utf8; - mm_obj_dbg (log_object, "converting SMS part text from GSM-7 to UTF-8..."); unpacked = mm_charset_gsm_unpack ((const guint8 *) text, len, bit_offset, &unpacked_len); - utf8 = (char *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len); - mm_obj_dbg (log_object, " got UTF-8 text: '%s'", utf8); - } else if (encoding == MM_SMS_ENCODING_UCS2) { - g_autoptr(GByteArray) bytearray = NULL; + utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error); + if (utf8) + mm_obj_dbg (log_object, "converted SMS part text from GSM-7 to UTF-8: %s", utf8); + return utf8; + } + + if (encoding == MM_SMS_ENCODING_UCS2) { + g_autoptr(GByteArray) bytearray = NULL; + gchar *utf8; - mm_obj_dbg (log_object, "converting SMS part text from UTF-16BE to UTF-8..."); bytearray = g_byte_array_append (g_byte_array_sized_new (len), (const guint8 *)text, len); /* Always assume UTF-16 instead of UCS-2! */ utf8 = mm_modem_charset_byte_array_to_utf8 (bytearray, MM_MODEM_CHARSET_UTF16); - if (!utf8) { - mm_obj_warn (log_object, "couldn't convert SMS part contents from UTF-16BE to UTF-8: not decoding any text"); - utf8 = g_strdup (""); - } else - mm_obj_dbg (log_object, " got UTF-8 text: '%s'", utf8); - } else { - mm_obj_warn (log_object, "unexpected encoding: %s; not decoding any text", mm_sms_encoding_get_string (encoding)); - utf8 = g_strdup (""); + if (!utf8) + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't convert SMS part contents from UTF-16BE to UTF-8: not decoding any text"); + else + mm_obj_dbg (log_object, "converted SMS part text from UTF-16BE to UTF-8: %s", utf8); + return utf8; } - return utf8; + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't convert SMS part contents from %s to UTF-8", + mm_sms_encoding_get_string (encoding)); + return NULL; } static guint @@ -373,6 +378,7 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, guint tp_dcs_offset = 0; guint tp_user_data_len_offset = 0; MMSmsEncoding user_data_encoding = MM_SMS_ENCODING_UNKNOWN; + gchar *address; /* Create the new MMSmsPart */ sms_part = mm_sms_part_new (index, MM_SMS_PDU_TYPE_UNKNOWN); @@ -405,8 +411,13 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, if (smsc_addr_size_bytes > 0) { PDU_SIZE_CHECK (offset + smsc_addr_size_bytes, "cannot read SMSC address"); /* SMSC may not be given in DELIVER PDUs */ - mm_sms_part_take_smsc (sms_part, - sms_decode_address (&pdu[1], 2 * (smsc_addr_size_bytes - 1))); + address = sms_decode_address (&pdu[1], 2 * (smsc_addr_size_bytes - 1), error); + if (!address) { + g_prefix_error (error, "Couldn't read SMSC address: "); + mm_sms_part_free (sms_part); + return NULL; + } + mm_sms_part_take_smsc (sms_part, g_steal_pointer (&address)); mm_obj_dbg (log_object, " SMSC address parsed: '%s'", mm_sms_part_get_smsc (sms_part)); offset += smsc_addr_size_bytes; } else @@ -478,9 +489,13 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, tp_addr_size_bytes = (tp_addr_size_digits + 1) >> 1; PDU_SIZE_CHECK (offset + tp_addr_size_bytes, "cannot read number"); - mm_sms_part_take_number (sms_part, - sms_decode_address (&pdu[offset], - tp_addr_size_digits)); + address = sms_decode_address (&pdu[offset], tp_addr_size_digits, error); + if (!address) { + g_prefix_error (error, "Couldn't read address: "); + mm_sms_part_free (sms_part); + return NULL; + } + mm_sms_part_take_number (sms_part, g_steal_pointer (&address)); mm_obj_dbg (log_object, " number parsed: %s", mm_sms_part_get_number (sms_part)); offset += (1 + tp_addr_size_bytes); /* +1 due to the Type of Address byte */ @@ -709,17 +724,24 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, switch (user_data_encoding) { case MM_SMS_ENCODING_GSM7: case MM_SMS_ENCODING_UCS2: - /* Otherwise if it's 7-bit or UCS2 we can decode it */ - mm_obj_dbg (log_object, "decoding SMS text with %u elements", tp_user_data_size_elements); - mm_sms_part_take_text (sms_part, - sms_decode_text (&pdu[tp_user_data_offset], - tp_user_data_size_elements, - user_data_encoding, - bit_offset, - log_object)); - g_warn_if_fail (mm_sms_part_get_text (sms_part) != NULL); - break; - + { + gchar *text; + + /* Otherwise if it's 7-bit or UCS2 we can decode it */ + mm_obj_dbg (log_object, "decoding SMS text with %u elements", tp_user_data_size_elements); + text = sms_decode_text (&pdu[tp_user_data_offset], + tp_user_data_size_elements, + user_data_encoding, + bit_offset, + log_object, + error); + if (!text) { + mm_sms_part_free (sms_part); + return NULL; + } + mm_sms_part_take_text (sms_part, text); + break; + } case MM_SMS_ENCODING_8BIT: case MM_SMS_ENCODING_UNKNOWN: default: diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c index a15e0332..b18c11b1 100644 --- a/src/tests/test-charsets.c +++ b/src/tests/test-charsets.c @@ -30,6 +30,7 @@ common_test_gsm7 (const gchar *in_utf8) g_autofree guint8 *packed_gsm = NULL; g_autofree guint8 *unpacked_gsm_2 = NULL; g_autofree gchar *built_utf8 = NULL; + g_autoptr(GError) error = NULL; /* Convert to GSM */ unpacked_gsm = mm_charset_utf8_to_unpacked_gsm (in_utf8, &unpacked_gsm_len); @@ -58,8 +59,9 @@ common_test_gsm7 (const gchar *in_utf8) g_assert_nonnull (unpacked_gsm_2); /* And back to UTF-8 */ - built_utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked_gsm_2, unpacked_gsm_len_2); + built_utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked_gsm_2, unpacked_gsm_len_2, FALSE, &error); g_assert_nonnull (built_utf8); + g_assert_no_error (error); g_assert_cmpstr (built_utf8, ==, in_utf8); } From c23b4cd78a38e860130b6673a926272e8f3930a1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 26 Nov 2020 23:22:57 +0100 Subject: [PATCH 582/675] charsets: make translit optional in utf8_to_unpacked_gsm() If the conversion is not fully compatible, the user of the method needs to request transliteration enabled explicitly in order to avoid returning errors in this method. (cherry picked from commit bc449cbe87ccebccbe35f926e88a2dd110832ddf) --- plugins/huawei/mm-broadband-modem-huawei.c | 5 ++- src/mm-broadband-modem-mbim.c | 5 ++- src/mm-charsets.c | 39 ++++++++++++++-------- src/mm-charsets.h | 4 ++- src/mm-sms-part-3gpp.c | 7 ++-- src/tests/test-charsets.c | 3 +- 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index a20c0eda..dc8f758d 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2305,8 +2305,11 @@ encode (MMIfaceModem3gppUssd *self, guint8 *gsm, *packed; guint32 len = 0, packed_len = 0; + gsm = mm_charset_utf8_to_unpacked_gsm (command, FALSE, &len, error); + if (!gsm) + return NULL; + *scheme = MM_MODEM_GSM_USSD_SCHEME_7BIT; - gsm = mm_charset_utf8_to_unpacked_gsm (command, &len); /* If command is a multiple of 7 characters long, Huawei firmwares * apparently want that padded. Maybe all modems? diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index c073bb29..ba37cdb7 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4777,10 +4777,9 @@ ussd_encode (const gchar *command, guint32 packed_len = 0; *scheme = MM_MODEM_GSM_USSD_SCHEME_7BIT; - gsm = mm_charset_utf8_to_unpacked_gsm (command, &len); + gsm = mm_charset_utf8_to_unpacked_gsm (command, FALSE, &len, error); if (!gsm) { - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, - "Failed to encode USSD command in GSM7 charset"); + g_prefix_error (error, "Failed to encode USSD command in GSM7 charset: "); return NULL; } packed = mm_charset_gsm_pack (gsm, len, 0, &packed_len); diff --git a/src/mm-charsets.c b/src/mm-charsets.c index 3a8ea719..4b571c49 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -427,16 +427,21 @@ mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, } guint8 * -mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, - guint32 *out_len) +mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, + gboolean translit, + guint32 *out_len, + GError **error) { - GByteArray *gsm; - const gchar *c; - const gchar *next; - static const guint8 gesc = GSM_ESCAPE_CHAR; - - g_return_val_if_fail (utf8 != NULL, NULL); - g_return_val_if_fail (g_utf8_validate (utf8, -1, NULL), NULL); + g_autoptr(GByteArray) gsm = NULL; + const gchar *c; + const gchar *next; + static const guint8 gesc = GSM_ESCAPE_CHAR; + + if (!utf8 || !g_utf8_validate (utf8, -1, NULL)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Couldn't convert UTF-8 to GSM: input UTF-8 validation failed"); + return NULL; + } /* worst case initial length */ gsm = g_byte_array_sized_new (g_utf8_strlen (utf8, -1) * 2 + 1); @@ -446,7 +451,7 @@ mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, g_byte_array_append (gsm, (guint8 *) "\0", 1); if (out_len) *out_len = 0; - return g_byte_array_free (gsm, FALSE); + return g_byte_array_free (g_steal_pointer (&gsm), FALSE); } next = utf8; @@ -461,8 +466,16 @@ mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, /* Add the escape char */ g_byte_array_append (gsm, &gesc, 1); g_byte_array_append (gsm, &gch, 1); - } else if (utf8_to_gsm_def_char (c, next - c, &gch)) + } else if (utf8_to_gsm_def_char (c, next - c, &gch)) { + g_byte_array_append (gsm, &gch, 1); + } else if (translit) { + /* add ? */ g_byte_array_append (gsm, &gch, 1); + } else { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Couldn't convert UTF-8 char to GSM"); + return NULL; + } c = next; } @@ -473,7 +486,7 @@ mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, /* Always make sure returned string is NUL terminated */ g_byte_array_append (gsm, (guint8 *) "\0", 1); - return g_byte_array_free (gsm, FALSE); + return g_byte_array_free (g_steal_pointer (&gsm), FALSE); } static gboolean @@ -872,7 +885,7 @@ mm_utf8_take_and_convert_to_charset (gchar *str, break; case MM_MODEM_CHARSET_GSM: - encoded = (gchar *) mm_charset_utf8_to_unpacked_gsm (str, NULL); + encoded = (gchar *) mm_charset_utf8_to_unpacked_gsm (str, FALSE, NULL, NULL); g_free (str); break; diff --git a/src/mm-charsets.h b/src/mm-charsets.h index dc8613a5..b59eeeaa 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -54,7 +54,9 @@ gchar *mm_modem_charset_hex_to_utf8 (const gchar *src, MMModemCharset charset); guint8 *mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, - guint32 *out_len); + gboolean translit, + guint32 *out_len, + GError **error); guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, guint32 len, gboolean translit, diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index e7735e1d..7547d029 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -987,8 +987,11 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, guint8 *unpacked, *packed; guint32 unlen = 0, packlen = 0; - unpacked = mm_charset_utf8_to_unpacked_gsm (mm_sms_part_get_text (part), &unlen); - if (!unpacked || unlen == 0) { + unpacked = mm_charset_utf8_to_unpacked_gsm (mm_sms_part_get_text (part), FALSE, &unlen, error); + if (!unpacked) + goto error; + + if (unlen == 0) { g_free (unpacked); g_set_error_literal (error, MM_MESSAGE_ERROR, diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c index b18c11b1..c2e08591 100644 --- a/src/tests/test-charsets.c +++ b/src/tests/test-charsets.c @@ -33,8 +33,9 @@ common_test_gsm7 (const gchar *in_utf8) g_autoptr(GError) error = NULL; /* Convert to GSM */ - unpacked_gsm = mm_charset_utf8_to_unpacked_gsm (in_utf8, &unpacked_gsm_len); + unpacked_gsm = mm_charset_utf8_to_unpacked_gsm (in_utf8, FALSE, &unpacked_gsm_len, &error); g_assert_nonnull (unpacked_gsm); + g_assert_no_error (error); g_assert_cmpuint (unpacked_gsm_len, >, 0); /* Pack */ From 6e0a686228ac5a2da1b5a97d57c8d60082f24ffa Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 13:47:21 +0100 Subject: [PATCH 583/675] charsets: avoid //TRANSLIT when converting to/from charsets The //TRANSLIT extension is not always supported by the different iconv() implementations that we may find out there, so let's completely avoid using it. For some of the charsets it actually didn't make much sense anyway, e.g. as converting to UTF-16 or UTF-8 would always be possible without requiring //TRANSLIT to take effect. The //TRANSLIT extension was also being used sometimes in the source charset identification, which was also not fully correct, as we would only expect it in the target charset identification. (cherry picked from commit 6f32c8d38f2c7ad269c4ccf84190ad6e917293a9) --- src/mm-charsets.c | 81 +++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index 4b571c49..1b7d3d7c 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -26,23 +26,25 @@ #include "mm-charsets.h" #include "mm-log.h" +/******************************************************************************/ +/* Expected charset settings */ + typedef struct { + MMModemCharset charset; const gchar *gsm_name; const gchar *other_name; - const gchar *iconv_from_name; - const gchar *iconv_to_name; - MMModemCharset charset; -} CharsetEntry; - -static const CharsetEntry charset_map[] = { - { "UTF-8", "UTF8", "UTF-8", "UTF-8//TRANSLIT", MM_MODEM_CHARSET_UTF8 }, - { "UCS2", NULL, "UCS-2BE", "UCS-2BE//TRANSLIT", MM_MODEM_CHARSET_UCS2 }, - { "IRA", "ASCII", "ASCII", "ASCII//TRANSLIT", MM_MODEM_CHARSET_IRA }, - { "GSM", NULL, NULL, NULL, MM_MODEM_CHARSET_GSM }, - { "8859-1", NULL, "ISO8859-1", "ISO8859-1//TRANSLIT", MM_MODEM_CHARSET_8859_1 }, - { "PCCP437", "CP437", "CP437", "CP437//TRANSLIT", MM_MODEM_CHARSET_PCCP437 }, - { "PCDN", "CP850", "CP850", "CP850//TRANSLIT", MM_MODEM_CHARSET_PCDN }, - { "UTF-16", "UTF16", "UTF-16BE", "UTF-16BE//TRANSLIT", MM_MODEM_CHARSET_UTF16 }, + const gchar *iconv_name; +} CharsetSettings; + +static const CharsetSettings charset_settings[] = { + { MM_MODEM_CHARSET_UTF8, "UTF-8", "UTF8", "UTF-8" }, + { MM_MODEM_CHARSET_UCS2, "UCS2", NULL, "UCS-2BE" }, + { MM_MODEM_CHARSET_IRA, "IRA", "ASCII", "ASCII" }, + { MM_MODEM_CHARSET_GSM, "GSM", NULL, NULL }, + { MM_MODEM_CHARSET_8859_1, "8859-1", NULL, "ISO8859-1" }, + { MM_MODEM_CHARSET_PCCP437, "PCCP437", "CP437", "CP437" }, + { MM_MODEM_CHARSET_PCDN, "PCDN", "CP850", "CP850" }, + { MM_MODEM_CHARSET_UTF16, "UTF-16", "UTF16", "UTF-16BE" }, }; MMModemCharset @@ -52,24 +54,24 @@ mm_modem_charset_from_string (const gchar *string) g_return_val_if_fail (string != NULL, MM_MODEM_CHARSET_UNKNOWN); - for (i = 0; i < G_N_ELEMENTS (charset_map); i++) { - if (strcasestr (string, charset_map[i].gsm_name)) - return charset_map[i].charset; - if (charset_map[i].other_name && strcasestr (string, charset_map[i].other_name)) - return charset_map[i].charset; + for (i = 0; i < G_N_ELEMENTS (charset_settings); i++) { + if (strcasestr (string, charset_settings[i].gsm_name)) + return charset_settings[i].charset; + if (charset_settings[i].other_name && strcasestr (string, charset_settings[i].other_name)) + return charset_settings[i].charset; } return MM_MODEM_CHARSET_UNKNOWN; } -static const CharsetEntry * -lookup_charset_by_id (MMModemCharset charset) +static const CharsetSettings * +lookup_charset_settings (MMModemCharset charset) { guint i; g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); - for (i = 0; i < G_N_ELEMENTS (charset_map); i++) { - if (charset_map[i].charset == charset) - return &charset_map[i]; + for (i = 0; i < G_N_ELEMENTS (charset_settings); i++) { + if (charset_settings[i].charset == charset) + return &charset_settings[i]; } g_warn_if_reached (); return NULL; @@ -78,28 +80,25 @@ lookup_charset_by_id (MMModemCharset charset) const gchar * mm_modem_charset_to_string (MMModemCharset charset) { - const CharsetEntry *entry; + const CharsetSettings *settings; - entry = lookup_charset_by_id (charset); - return entry ? entry->gsm_name : NULL; + settings = lookup_charset_settings (charset); + return settings ? settings->gsm_name : NULL; } static const gchar * -charset_iconv_to (MMModemCharset charset) +charset_iconv_from (MMModemCharset charset) { - const CharsetEntry *entry; + const CharsetSettings *settings; - entry = lookup_charset_by_id (charset); - return entry ? entry->iconv_to_name : NULL; + settings = lookup_charset_settings (charset); + return settings ? settings->iconv_name : NULL; } static const gchar * -charset_iconv_from (MMModemCharset charset) +charset_iconv_to (MMModemCharset charset) { - const CharsetEntry *entry; - - entry = lookup_charset_by_id (charset); - return entry ? entry->iconv_from_name : NULL; + return charset_iconv_from (charset); } gboolean @@ -145,7 +144,7 @@ mm_modem_charset_byte_array_to_utf8 (GByteArray *array, g_return_val_if_fail (iconv_from != NULL, FALSE); converted = g_convert ((const gchar *)array->data, array->len, - "UTF-8//TRANSLIT", iconv_from, + "UTF-8", iconv_from, NULL, NULL, &error); if (!converted || error) return NULL; @@ -177,7 +176,7 @@ mm_modem_charset_hex_to_utf8 (const gchar *src, return g_steal_pointer (&unconverted); converted = g_convert ((const gchar *)unconverted, unconverted_len, - "UTF-8//TRANSLIT", iconv_from, + "UTF-8", iconv_from, NULL, NULL, &error); if (!converted || error) return NULL; @@ -772,7 +771,7 @@ mm_charset_take_and_convert_to_utf8 (gchar *str, iconv_from = charset_iconv_from (charset); utf8 = g_convert (str, strlen (str), - "UTF-8//TRANSLIT", iconv_from, + "UTF-8", iconv_from, NULL, NULL, &error); if (!utf8 || error) { g_clear_error (&error); @@ -816,7 +815,7 @@ mm_charset_take_and_convert_to_utf8 (gchar *str, * that is UTF-8, if any. */ utf8 = g_convert (str, strlen (str), - "UTF-8//TRANSLIT", "UTF-8//TRANSLIT", + "UTF-8", "UTF-8", &bread, &bwritten, NULL); /* Valid conversion, or we didn't get enough valid UTF-8 */ @@ -830,7 +829,7 @@ mm_charset_take_and_convert_to_utf8 (gchar *str, */ str[bread] = '\0'; utf8 = g_convert (str, strlen (str), - "UTF-8//TRANSLIT", "UTF-8//TRANSLIT", + "UTF-8", "UTF-8", NULL, NULL, NULL); g_free (str); break; From 061da8e4921862b5de514f4ca82d142debe28be1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 27 Nov 2020 00:41:40 +0100 Subject: [PATCH 584/675] charsets: new common APIs to convert from/to charsets and UTF-8 (cherry picked from commit 9c613d33e1f60501cc8406f6429097d8bda87c59) --- src/mm-charsets.c | 298 ++++++++++++++++++++++++++++++++++++++++++++-- src/mm-charsets.h | 61 ++++++++++ 2 files changed, 352 insertions(+), 7 deletions(-) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index 1b7d3d7c..caf2abb5 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -11,6 +11,7 @@ * GNU General Public License for more details: * * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2020 Aleksander Morgado */ #include @@ -184,6 +185,7 @@ mm_modem_charset_hex_to_utf8 (const gchar *src, return g_steal_pointer (&converted); } +/******************************************************************************/ /* GSM 03.38 encoding conversion stuff */ #define GSM_DEF_ALPHABET_SIZE 128 @@ -302,6 +304,23 @@ utf8_to_gsm_def_char (const gchar *utf8, return FALSE; } +static gboolean +translit_gsm_nul_byte (GByteArray *gsm) +{ + static const gchar *replacement = "?"; + guint i; + guint n_replaces = 0; + + for (i = 0; i < gsm->len; i++) { + if (gsm->data[i] == 0x00) { + utf8_to_gsm_def_char (replacement, 1, &gsm->data[i]); + n_replaces++; + } + } + + return (n_replaces > 0); +} + #define EONE(a, g) { {a, 0x00, 0x00}, 1, g } #define ETHR(a, b, c, g) { {a, b, c}, 3, g } @@ -488,6 +507,10 @@ mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, return g_byte_array_free (g_steal_pointer (&gsm), FALSE); } +/******************************************************************************/ +/* Checks to see whether conversion to a target charset may be done without + * any loss. */ + static gboolean gsm_is_subset (gunichar c, const gchar *utf8, @@ -617,13 +640,6 @@ const SubsetEntry subset_table[] = { { MM_MODEM_CHARSET_PCDN, pcdn_is_subset }, }; -/** - * mm_charset_can_covert_to: - * @utf8: UTF-8 valid string. - * @charset: the #MMModemCharset to validate the conversion from @utf8. - * - * Returns: %TRUE if the conversion is possible without errors, %FALSE otherwise. - */ gboolean mm_charset_can_convert_to (const gchar *utf8, MMModemCharset charset) @@ -667,6 +683,9 @@ mm_charset_can_convert_to (const gchar *utf8, return TRUE; } +/******************************************************************************/ +/* GSM-7 pack/unpack operations */ + guint8 * mm_charset_gsm_unpack (const guint8 *gsm, guint32 num_septets, @@ -944,3 +963,268 @@ mm_utf8_take_and_convert_to_charset (gchar *str, return encoded; } + +/*****************************************************************************/ +/* Main conversion functions */ + +static guint8 * +charset_iconv_from_utf8 (const gchar *utf8, + MMModemCharset charset, + gboolean translit, + guint *out_size, + GError **error) +{ + g_autoptr(GError) inner_error = NULL; + const CharsetSettings *settings; + gsize bytes_written = 0; + g_autofree guint8 *encoded = NULL; + + settings = lookup_charset_settings (charset); + + encoded = (guint8 *) g_convert (utf8, -1, + settings->iconv_name, "UTF-8", + NULL, &bytes_written, &inner_error); + if (encoded) { + if (out_size) + *out_size = (guint) bytes_written; + return g_steal_pointer (&encoded); + } + + if (!translit) { + g_propagate_error (error, g_steal_pointer (&inner_error)); + g_prefix_error (error, "Couldn't convert from UTF-8 to %s: ", settings->gsm_name); + return NULL; + } + + encoded = (guint8 *) g_convert_with_fallback (utf8, -1, + settings->iconv_name, "UTF-8", "?", + NULL, &bytes_written, error); + if (encoded) { + if (out_size) + *out_size = (guint) bytes_written; + return g_steal_pointer (&encoded); + } + + g_prefix_error (error, "Couldn't convert from UTF-8 to %s with translit: ", settings->gsm_name); + return NULL; +} + +GByteArray * +mm_modem_charset_bytearray_from_utf8 (const gchar *utf8, + MMModemCharset charset, + gboolean translit, + GError **error) +{ + guint8 *encoded = NULL; + guint encoded_size = 0; + + if (charset == MM_MODEM_CHARSET_UNKNOWN) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Cannot convert from UTF-8: unknown target charset"); + return NULL; + } + + switch (charset) { + case MM_MODEM_CHARSET_GSM: + encoded = mm_charset_utf8_to_unpacked_gsm (utf8, translit, &encoded_size, error); + break; + case MM_MODEM_CHARSET_IRA: + case MM_MODEM_CHARSET_8859_1: + case MM_MODEM_CHARSET_UTF8: + case MM_MODEM_CHARSET_UCS2: + case MM_MODEM_CHARSET_PCCP437: + case MM_MODEM_CHARSET_PCDN: + case MM_MODEM_CHARSET_UTF16: + encoded = charset_iconv_from_utf8 (utf8, charset, translit, &encoded_size, error); + break; + case MM_MODEM_CHARSET_UNKNOWN: + default: + g_assert_not_reached (); + } + + return g_byte_array_new_take (encoded, encoded_size); +} + +gchar * +mm_modem_charset_str_from_utf8 (const gchar *utf8, + MMModemCharset charset, + gboolean translit, + GError **error) +{ + g_autoptr(GByteArray) bytearray = NULL; + + if (charset == MM_MODEM_CHARSET_UNKNOWN) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Cannot convert from UTF-8: unknown target charset"); + return NULL; + } + + bytearray = mm_modem_charset_bytearray_from_utf8 (utf8, charset, translit, error); + if (!bytearray) + return NULL; + + switch (charset) { + case MM_MODEM_CHARSET_GSM: + /* Note: strings encoded in unpacked GSM-7 can be used as plain + * strings as long as the string doesn't contain character '@', which + * is the one encoded as 0x00. At this point, we perform transliteration + * of the NUL bytes in the GSM-7 bytearray, and we fail the operation + * if one or more replacements were done and transliteration wasn't + * requested */ + if (translit_gsm_nul_byte (bytearray) && !translit) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Cannot convert to GSM-7 string: transliteration required for embedded '@'"); + return NULL; + } + /* fall through */ + case MM_MODEM_CHARSET_IRA: + case MM_MODEM_CHARSET_8859_1: + case MM_MODEM_CHARSET_UTF8: + case MM_MODEM_CHARSET_PCCP437: + case MM_MODEM_CHARSET_PCDN: + return (gchar *) g_byte_array_free (g_steal_pointer (&bytearray), FALSE); + case MM_MODEM_CHARSET_UCS2: + case MM_MODEM_CHARSET_UTF16: + return mm_utils_bin2hexstr (bytearray->data, bytearray->len); + default: + case MM_MODEM_CHARSET_UNKNOWN: + g_assert_not_reached (); + } +} + +static gchar * +charset_iconv_to_utf8 (const guint8 *data, + guint32 len, + MMModemCharset charset, + gboolean translit, + GError **error) +{ + g_autoptr(GError) inner_error = NULL; + g_autofree gchar *utf8 = NULL; + const CharsetSettings *settings; + + settings = lookup_charset_settings (charset); + + utf8 = g_convert ((const gchar *) data, len, + "UTF-8", + settings->iconv_name, + NULL, NULL, &inner_error); + if (utf8) + return g_steal_pointer (&utf8); + + if (!translit) { + g_propagate_error (error, g_steal_pointer (&inner_error)); + g_prefix_error (error, "Couldn't convert from %s to UTF-8: ", settings->gsm_name); + return NULL; + } + + utf8 = g_convert_with_fallback ((const gchar *) data, len, + "UTF-8", settings->iconv_name, "?", + NULL, NULL, error); + if (utf8) + return g_steal_pointer (&utf8); + + g_prefix_error (error, "Couldn't convert from %s to UTF-8 with translit: ", settings->gsm_name); + return NULL; +} + +gchar * +mm_modem_charset_bytearray_to_utf8 (GByteArray *bytearray, + MMModemCharset charset, + gboolean translit, + GError **error) +{ + const CharsetSettings *settings; + g_autofree gchar *utf8 = NULL; + + if (charset == MM_MODEM_CHARSET_UNKNOWN) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Cannot convert from UTF-8: unknown target charset"); + return NULL; + } + + settings = lookup_charset_settings (charset); + switch (charset) { + case MM_MODEM_CHARSET_GSM: + utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (bytearray->data, + bytearray->len, + translit, + error); + break; + case MM_MODEM_CHARSET_IRA: + case MM_MODEM_CHARSET_UTF8: + case MM_MODEM_CHARSET_8859_1: + case MM_MODEM_CHARSET_PCCP437: + case MM_MODEM_CHARSET_PCDN: + case MM_MODEM_CHARSET_UCS2: + case MM_MODEM_CHARSET_UTF16: + utf8 = charset_iconv_to_utf8 (bytearray->data, + bytearray->len, + charset, + translit, + error); + break; + case MM_MODEM_CHARSET_UNKNOWN: + default: + g_assert_not_reached (); + } + + if (utf8 && g_utf8_validate (utf8, -1, NULL)) + return g_steal_pointer (&utf8); + + g_prefix_error (error, "Invalid conversion from %s to UTF-8: ", settings->gsm_name); + return NULL; +} + +gchar * +mm_modem_charset_str_to_utf8 (const gchar *str, + gssize len, + MMModemCharset charset, + gboolean translit, + GError **error) +{ + g_autoptr(GByteArray) bytearray = NULL; + + if (charset == MM_MODEM_CHARSET_UNKNOWN) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Cannot convert from UTF-8: unknown target charset"); + return NULL; + } + + /* Note: if the input string is GSM-7 encoded and it contains the '@' + * character, using -1 to indicate string length won't work properly, + * as '@' is encoded as 0x00. Whenever possible, if using GSM-7, + * give a proper len value or otherwise use the bytearray_to_utf8() + * method instead. */ + if (len < 0) + len = strlen (str); + + switch (charset) { + case MM_MODEM_CHARSET_GSM: + case MM_MODEM_CHARSET_IRA: + case MM_MODEM_CHARSET_8859_1: + case MM_MODEM_CHARSET_UTF8: + case MM_MODEM_CHARSET_PCCP437: + case MM_MODEM_CHARSET_PCDN: + bytearray = g_byte_array_sized_new (len); + g_byte_array_append (bytearray, (const guint8 *)str, len); + break; + case MM_MODEM_CHARSET_UCS2: + case MM_MODEM_CHARSET_UTF16: { + guint8 *bin = NULL; + gsize bin_len; + + bin = (guint8 *) mm_utils_hexstr2bin (str, len, &bin_len, error); + if (!bin) + return NULL; + + bytearray = g_byte_array_new_take (bin, bin_len); + break; + } + case MM_MODEM_CHARSET_UNKNOWN: + default: + g_assert_not_reached (); + } + + return mm_modem_charset_bytearray_to_utf8 (bytearray, charset, translit, error); +} diff --git a/src/mm-charsets.h b/src/mm-charsets.h index b59eeeaa..4d032f38 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -18,6 +18,8 @@ #include +/*****************************************************************************************/ + typedef enum { MM_MODEM_CHARSET_UNKNOWN = 0, MM_MODEM_CHARSET_GSM = 1 << 0, @@ -33,6 +35,8 @@ typedef enum { const gchar *mm_modem_charset_to_string (MMModemCharset charset); MMModemCharset mm_modem_charset_from_string (const gchar *string); +/*****************************************************************************************/ + /* Append the given string to the given byte array but re-encode it * into the given charset first. The original string is assumed to be * UTF-8 encoded. @@ -81,4 +85,61 @@ gchar *mm_charset_take_and_convert_to_utf8 (gchar *str, gchar *mm_utf8_take_and_convert_to_charset (gchar *str, MMModemCharset charset); +/*****************************************************************************************/ + +/* + * Convert the given UTF-8 encoded string into the given charset. + * + * The output is given as a bytearray, because the target charset may allow + * embedded NUL bytes (e.g. UTF-16). + * + * The output encoded string is not guaranteed to be NUL-terminated, instead + * the bytearray length itself gives the correct string length. + */ +GByteArray *mm_modem_charset_bytearray_from_utf8 (const gchar *utf8, + MMModemCharset charset, + gboolean translit, + GError **error); + +/* + * Convert the given UTF-8 encoded string into the given charset. + * + * The output is given as a C string, and those charsets that allow + * embedded NUL bytes (e.g. UTF-16) will be hex-encoded. + * + * The output encoded string is guaranteed to be NUL-terminated, and so no + * explicit output length is returned. + */ +gchar *mm_modem_charset_str_from_utf8 (const gchar *utf8, + MMModemCharset charset, + gboolean translit, + GError **error); + +/* + * Convert into an UTF-8 encoded string the input byte array, which is + * encoded in the given charset. + * + * The output string is guaranteed to be valid UTF-8 and NUL-terminated. + */ +gchar *mm_modem_charset_bytearray_to_utf8 (GByteArray *bytearray, + MMModemCharset charset, + gboolean translit, + GError **error); + +/* + * Convert into an UTF-8 encoded string the input string, which is + * encoded in the given charset. Those charsets that allow embedded NUL + * bytes (e.g. UTF-16) need to be hex-encoded. + * + * If the input string is NUL-terminated, len may be given as -1; otherwise + * len needs to specify the number of valid bytes in the input string. + * + * The output string is guaranteed to be valid UTF-8 and NUL-terminated. + */ +gchar *mm_modem_charset_str_to_utf8 (const gchar *str, + gssize len, + MMModemCharset charset, + gboolean translit, + GError **error); + #endif /* MM_CHARSETS_H */ From cafdcb1311bbe4afbce56f97148b1794cf59621f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 15:23:43 +0100 Subject: [PATCH 585/675] charsets: make charset_utf8_to_unpacked_gsm() private Use the generic mm_modem_charset_bytearray_from_utf8() instead. (cherry picked from commit 75b37e16b12ca3807852804fed668ba2fd7ca317) --- plugins/huawei/mm-broadband-modem-huawei.c | 24 +++++------ src/mm-broadband-modem-mbim.c | 13 +++--- src/mm-charsets.c | 49 +++++++++++----------- src/mm-charsets.h | 4 -- src/mm-sms-part-3gpp.c | 17 ++++---- src/tests/test-charsets.c | 15 ++++--- 6 files changed, 55 insertions(+), 67 deletions(-) diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index dc8f758d..8e17d531 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2301,11 +2301,11 @@ encode (MMIfaceModem3gppUssd *self, guint *scheme, GError **error) { - gchar *hex; - guint8 *gsm, *packed; - guint32 len = 0, packed_len = 0; + g_autoptr(GByteArray) gsm = NULL; + g_autofree guint8 *packed = NULL; + guint32 packed_len = 0; - gsm = mm_charset_utf8_to_unpacked_gsm (command, FALSE, &len, error); + gsm = mm_modem_charset_bytearray_from_utf8 (command, MM_MODEM_CHARSET_GSM, FALSE, error); if (!gsm) return NULL; @@ -2314,18 +2314,14 @@ encode (MMIfaceModem3gppUssd *self, /* If command is a multiple of 7 characters long, Huawei firmwares * apparently want that padded. Maybe all modems? */ - if (len % 7 == 0) { - gsm = g_realloc (gsm, len + 1); - gsm[len] = 0x0d; - len++; - } + if (gsm->len % 7 == 0) { + static const guint8 padding = 0x0d; - packed = mm_charset_gsm_pack (gsm, len, 0, &packed_len); - hex = mm_utils_bin2hexstr (packed, packed_len); - g_free (packed); - g_free (gsm); + g_byte_array_append (gsm, &padding, 1); + } - return hex; + packed = mm_charset_gsm_pack (gsm->data, gsm->len, 0, &packed_len); + return mm_utils_bin2hexstr (packed, packed_len); } static gchar * diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index ba37cdb7..513017a8 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4771,20 +4771,17 @@ ussd_encode (const gchar *command, g_autoptr(GByteArray) array = NULL; if (mm_charset_can_convert_to (command, MM_MODEM_CHARSET_GSM)) { - guint8 *gsm; - guint8 *packed; - guint32 len = 0; - guint32 packed_len = 0; + g_autoptr(GByteArray) gsm = NULL; + guint8 *packed; + guint32 packed_len = 0; *scheme = MM_MODEM_GSM_USSD_SCHEME_7BIT; - gsm = mm_charset_utf8_to_unpacked_gsm (command, FALSE, &len, error); + gsm = mm_modem_charset_bytearray_from_utf8 (command, MM_MODEM_CHARSET_GSM, FALSE, error); if (!gsm) { g_prefix_error (error, "Failed to encode USSD command in GSM7 charset: "); return NULL; } - packed = mm_charset_gsm_pack (gsm, len, 0, &packed_len); - g_free (gsm); - + packed = mm_charset_gsm_pack (gsm->data, gsm->len, 0, &packed_len); array = g_byte_array_new_take (packed, packed_len); } else { g_autoptr(GError) inner_error = NULL; diff --git a/src/mm-charsets.c b/src/mm-charsets.c index caf2abb5..ec5bb404 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -444,11 +444,11 @@ mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, return g_byte_array_free (g_steal_pointer (&utf8), FALSE); } -guint8 * -mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, - gboolean translit, - guint32 *out_len, - GError **error) +static guint8 * +charset_utf8_to_unpacked_gsm (const gchar *utf8, + gboolean translit, + guint32 *out_len, + GError **error) { g_autoptr(GByteArray) gsm = NULL; const gchar *c; @@ -903,7 +903,8 @@ mm_utf8_take_and_convert_to_charset (gchar *str, break; case MM_MODEM_CHARSET_GSM: - encoded = (gchar *) mm_charset_utf8_to_unpacked_gsm (str, FALSE, NULL, NULL); + /* This is WRONG! GSM may have embedded NULs (character @)! */ + encoded = mm_modem_charset_str_from_utf8 (str, MM_MODEM_CHARSET_GSM, FALSE, NULL); g_free (str); break; @@ -968,19 +969,16 @@ mm_utf8_take_and_convert_to_charset (gchar *str, /* Main conversion functions */ static guint8 * -charset_iconv_from_utf8 (const gchar *utf8, - MMModemCharset charset, - gboolean translit, - guint *out_size, - GError **error) +charset_iconv_from_utf8 (const gchar *utf8, + const CharsetSettings *settings, + gboolean translit, + guint *out_size, + GError **error) { g_autoptr(GError) inner_error = NULL; - const CharsetSettings *settings; gsize bytes_written = 0; g_autofree guint8 *encoded = NULL; - settings = lookup_charset_settings (charset); - encoded = (guint8 *) g_convert (utf8, -1, settings->iconv_name, "UTF-8", NULL, &bytes_written, &inner_error); @@ -1015,8 +1013,11 @@ mm_modem_charset_bytearray_from_utf8 (const gchar *utf8, gboolean translit, GError **error) { - guint8 *encoded = NULL; - guint encoded_size = 0; + const CharsetSettings *settings; + guint8 *encoded = NULL; + guint encoded_size = 0; + + settings = lookup_charset_settings (charset); if (charset == MM_MODEM_CHARSET_UNKNOWN) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, @@ -1026,7 +1027,7 @@ mm_modem_charset_bytearray_from_utf8 (const gchar *utf8, switch (charset) { case MM_MODEM_CHARSET_GSM: - encoded = mm_charset_utf8_to_unpacked_gsm (utf8, translit, &encoded_size, error); + encoded = charset_utf8_to_unpacked_gsm (utf8, translit, &encoded_size, error); break; case MM_MODEM_CHARSET_IRA: case MM_MODEM_CHARSET_8859_1: @@ -1035,7 +1036,7 @@ mm_modem_charset_bytearray_from_utf8 (const gchar *utf8, case MM_MODEM_CHARSET_PCCP437: case MM_MODEM_CHARSET_PCDN: case MM_MODEM_CHARSET_UTF16: - encoded = charset_iconv_from_utf8 (utf8, charset, translit, &encoded_size, error); + encoded = charset_iconv_from_utf8 (utf8, settings, translit, &encoded_size, error); break; case MM_MODEM_CHARSET_UNKNOWN: default: @@ -1095,15 +1096,12 @@ mm_modem_charset_str_from_utf8 (const gchar *utf8, static gchar * charset_iconv_to_utf8 (const guint8 *data, guint32 len, - MMModemCharset charset, + const CharsetSettings *settings, gboolean translit, GError **error) { - g_autoptr(GError) inner_error = NULL; - g_autofree gchar *utf8 = NULL; - const CharsetSettings *settings; - - settings = lookup_charset_settings (charset); + g_autoptr(GError) inner_error = NULL; + g_autofree gchar *utf8 = NULL; utf8 = g_convert ((const gchar *) data, len, "UTF-8", @@ -1144,6 +1142,7 @@ mm_modem_charset_bytearray_to_utf8 (GByteArray *bytearray, } settings = lookup_charset_settings (charset); + switch (charset) { case MM_MODEM_CHARSET_GSM: utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (bytearray->data, @@ -1160,7 +1159,7 @@ mm_modem_charset_bytearray_to_utf8 (GByteArray *bytearray, case MM_MODEM_CHARSET_UTF16: utf8 = charset_iconv_to_utf8 (bytearray->data, bytearray->len, - charset, + settings, translit, error); break; diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 4d032f38..1f635aa1 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -57,10 +57,6 @@ gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array, gchar *mm_modem_charset_hex_to_utf8 (const gchar *src, MMModemCharset charset); -guint8 *mm_charset_utf8_to_unpacked_gsm (const gchar *utf8, - gboolean translit, - guint32 *out_len, - GError **error); guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, guint32 len, gboolean translit, diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index 7547d029..4bd22626 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -984,15 +984,15 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, } if (encoding == MM_SMS_ENCODING_GSM7) { - guint8 *unpacked, *packed; - guint32 unlen = 0, packlen = 0; + g_autoptr(GByteArray) unpacked = NULL; + g_autofree guint8 *packed = NULL; + guint32 packlen = 0; - unpacked = mm_charset_utf8_to_unpacked_gsm (mm_sms_part_get_text (part), FALSE, &unlen, error); + unpacked = mm_modem_charset_bytearray_from_utf8 (mm_sms_part_get_text (part), MM_MODEM_CHARSET_GSM, FALSE, error); if (!unpacked) goto error; - if (unlen == 0) { - g_free (unpacked); + if (unpacked->len == 0) { g_set_error_literal (error, MM_MESSAGE_ERROR, MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER, @@ -1003,15 +1003,13 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, /* Set real data length, in septets * If we had UDH, add 7 septets */ - *udl_ptr = mm_sms_part_get_concat_sequence (part) ? (7 + unlen) : unlen; + *udl_ptr = mm_sms_part_get_concat_sequence (part) ? (7 + unpacked->len) : unpacked->len; mm_obj_dbg (log_object, " user data length is %u septets (%s UDH)", *udl_ptr, mm_sms_part_get_concat_sequence (part) ? "with" : "without"); - packed = mm_charset_gsm_pack (unpacked, unlen, shift, &packlen); - g_free (unpacked); + packed = mm_charset_gsm_pack (unpacked->data, unpacked->len, shift, &packlen); if (!packed || packlen == 0) { - g_free (packed); g_set_error_literal (error, MM_MESSAGE_ERROR, MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER, @@ -1020,7 +1018,6 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, } memcpy (&pdu[offset], packed, packlen); - g_free (packed); offset += packlen; } else if (encoding == MM_SMS_ENCODING_UCS2) { g_autoptr(GByteArray) array = NULL; diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c index c2e08591..4df104ed 100644 --- a/src/tests/test-charsets.c +++ b/src/tests/test-charsets.c @@ -23,25 +23,23 @@ static void common_test_gsm7 (const gchar *in_utf8) { - guint32 unpacked_gsm_len = 0; guint32 packed_gsm_len = 0; guint32 unpacked_gsm_len_2 = 0; - g_autofree guint8 *unpacked_gsm = NULL; + g_autoptr(GByteArray) unpacked_gsm = NULL; g_autofree guint8 *packed_gsm = NULL; g_autofree guint8 *unpacked_gsm_2 = NULL; g_autofree gchar *built_utf8 = NULL; g_autoptr(GError) error = NULL; /* Convert to GSM */ - unpacked_gsm = mm_charset_utf8_to_unpacked_gsm (in_utf8, FALSE, &unpacked_gsm_len, &error); + unpacked_gsm = mm_modem_charset_bytearray_from_utf8 (in_utf8, MM_MODEM_CHARSET_GSM, FALSE, &error); g_assert_nonnull (unpacked_gsm); g_assert_no_error (error); - g_assert_cmpuint (unpacked_gsm_len, >, 0); /* Pack */ - packed_gsm = mm_charset_gsm_pack (unpacked_gsm, unpacked_gsm_len, 0, &packed_gsm_len); + packed_gsm = mm_charset_gsm_pack (unpacked_gsm->data, unpacked_gsm->len, 0, &packed_gsm_len); g_assert_nonnull (packed_gsm); - g_assert_cmpuint (packed_gsm_len, <=, unpacked_gsm_len); + g_assert_cmpuint (packed_gsm_len, <=, unpacked_gsm->len); #if 0 { @@ -356,6 +354,10 @@ test_take_convert_ucs2_bad_ascii2 (void) static void test_take_convert_gsm_utf8 (void) { + /* NOTE: this is wrong, charset GSM may contain embedded NULs so we cannot convert + * from a plain UTF-8 string to a NUL-terminated string in GSM, as there is no + * such, thing. */ +#if 0 gchar *src, *converted, *utf8; src = g_strdup ("T-Mobile"); @@ -364,6 +366,7 @@ test_take_convert_gsm_utf8 (void) utf8 = mm_utf8_take_and_convert_to_charset (converted, MM_MODEM_CHARSET_GSM); g_assert_cmpstr (utf8, ==, "T-Mobile"); g_free (utf8); +#endif } struct charset_can_convert_to_test_s { From 2b05740820c63d4b977b148eda3e1ca2198669b7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 21 Dec 2020 13:37:13 +0100 Subject: [PATCH 586/675] charsets: use new bytearray_from_utf8() instead of byte_array_append() (cherry picked from commit 8bfdfb187b9c911366376f1574dc7e45fe4f0767) --- src/mm-broadband-modem-mbim.c | 9 ++--- src/mm-broadband-modem-qmi.c | 4 +- src/mm-broadband-modem.c | 34 ++++++++-------- src/mm-charsets.c | 34 ---------------- src/mm-charsets.h | 9 ----- src/mm-sms-part-3gpp.c | 5 +-- src/mm-sms-part-cdma.c | 76 ++++++++++++++++------------------- 7 files changed, 59 insertions(+), 112 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 513017a8..5168b0e1 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4784,13 +4784,10 @@ ussd_encode (const gchar *command, packed = mm_charset_gsm_pack (gsm->data, gsm->len, 0, &packed_len); array = g_byte_array_new_take (packed, packed_len); } else { - g_autoptr(GError) inner_error = NULL; - *scheme = MM_MODEM_GSM_USSD_SCHEME_UCS2; - array = g_byte_array_sized_new (strlen (command) * 2); - if (!mm_modem_charset_byte_array_append (array, command, MM_MODEM_CHARSET_UCS2, &inner_error)) { - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, - "Failed to encode USSD command in UCS2 charset: %s", inner_error->message); + array = mm_modem_charset_bytearray_from_utf8 (command, MM_MODEM_CHARSET_UCS2, FALSE, error); + if (!array) { + g_prefix_error (error, "Failed to encode USSD command in UCS2 charset: "); return NULL; } } diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index d4d732f4..3d54d5ac 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -7281,8 +7281,8 @@ ussd_encode (const gchar *command, return (GArray *) g_steal_pointer (&barray); } - barray = g_byte_array_sized_new (command_len * 2); - if (!mm_modem_charset_byte_array_append (barray, command, MM_MODEM_CHARSET_UCS2, &inner_error)) { + barray = mm_modem_charset_bytearray_from_utf8 (command, MM_MODEM_CHARSET_UCS2, FALSE, &inner_error); + if (!barray) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Failed to encode USSD command in UCS2 charset: %s", inner_error->message); return NULL; diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 7ba46c91..43a9e229 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -5877,31 +5877,31 @@ modem_3gpp_ussd_send (MMIfaceModem3gppUssd *_self, /* USSD Encode/Decode (3GPP/USSD interface) */ static gchar * -modem_3gpp_ussd_encode (MMIfaceModem3gppUssd *self, +modem_3gpp_ussd_encode (MMIfaceModem3gppUssd *_self, const gchar *command, guint *scheme, GError **error) { - MMBroadbandModem *broadband = MM_BROADBAND_MODEM (self); - gchar *hex = NULL; + MMBroadbandModem *self = MM_BROADBAND_MODEM (_self); g_autoptr(GByteArray) ussd_command = NULL; - ussd_command = g_byte_array_new (); - /* Encode to the current charset (as per AT+CSCS, which is what most modems * (except for Huawei it seems) will ask for. */ - if (mm_modem_charset_byte_array_append (ussd_command, command, broadband->priv->modem_current_charset, NULL)) { - /* The scheme value does NOT represent the encoding used to encode the string - * we're giving. This scheme reflects the encoding that the modem should use when - * sending the data out to the network. We're hardcoding this to GSM-7 because - * USSD commands fit well in GSM-7, unlike USSD responses that may contain code - * points that may only be encoded in UCS-2. */ - *scheme = MM_MODEM_GSM_USSD_SCHEME_7BIT; - /* convert to hex representation */ - hex = mm_utils_bin2hexstr (ussd_command->data, ussd_command->len); - } - - return hex; + ussd_command = mm_modem_charset_bytearray_from_utf8 (command, self->priv->modem_current_charset, FALSE, error); + if (!ussd_command) { + g_prefix_error (error, "Failed to encode USSD command: "); + return NULL; + } + + /* The scheme value does NOT represent the encoding used to encode the string + * we're giving. This scheme reflects the encoding that the modem should use when + * sending the data out to the network. We're hardcoding this to GSM-7 because + * USSD commands fit well in GSM-7, unlike USSD responses that may contain code + * points that may only be encoded in UCS-2. */ + *scheme = MM_MODEM_GSM_USSD_SCHEME_7BIT; + + /* convert to hex representation */ + return (gchar *) mm_utils_bin2hexstr (ussd_command->data, ussd_command->len); } static gchar * diff --git a/src/mm-charsets.c b/src/mm-charsets.c index ec5bb404..b0f4ea60 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -96,40 +96,6 @@ charset_iconv_from (MMModemCharset charset) return settings ? settings->iconv_name : NULL; } -static const gchar * -charset_iconv_to (MMModemCharset charset) -{ - return charset_iconv_from (charset); -} - -gboolean -mm_modem_charset_byte_array_append (GByteArray *array, - const gchar *utf8, - MMModemCharset charset, - GError **error) -{ - g_autofree gchar *converted = NULL; - const gchar *iconv_to; - gsize written = 0; - - g_return_val_if_fail (array != NULL, FALSE); - g_return_val_if_fail (utf8 != NULL, FALSE); - - iconv_to = charset_iconv_to (charset); - g_assert (iconv_to); - - converted = g_convert (utf8, -1, iconv_to, "UTF-8", NULL, &written, error); - if (!converted) { - g_prefix_error (error, "Failed to convert '%s' to %s character set", - utf8, iconv_to); - return FALSE; - } - - g_byte_array_append (array, (const guint8 *) converted, written); - - return TRUE; -} - gchar * mm_modem_charset_byte_array_to_utf8 (GByteArray *array, MMModemCharset charset) diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 1f635aa1..8300ad6c 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -37,15 +37,6 @@ MMModemCharset mm_modem_charset_from_string (const gchar *string); /*****************************************************************************************/ -/* Append the given string to the given byte array but re-encode it - * into the given charset first. The original string is assumed to be - * UTF-8 encoded. - */ -gboolean mm_modem_charset_byte_array_append (GByteArray *array, - const gchar *utf8, - MMModemCharset charset, - GError **error); - /* Take a string encoded in the given charset in binary form, and * convert it to UTF-8. */ gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array, diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index 4bd22626..f467c97b 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -1023,10 +1023,9 @@ mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, g_autoptr(GByteArray) array = NULL; g_autoptr(GError) inner_error = NULL; - /* Try to guess a good value for the array */ - array = g_byte_array_sized_new (strlen (mm_sms_part_get_text (part)) * 2); /* Always assume UTF-16 instead of UCS-2! */ - if (!mm_modem_charset_byte_array_append (array, mm_sms_part_get_text (part), MM_MODEM_CHARSET_UTF16, &inner_error)) { + array = mm_modem_charset_bytearray_from_utf8 (mm_sms_part_get_text (part), MM_MODEM_CHARSET_UTF16, FALSE, &inner_error); + if (!array) { g_set_error (error, MM_MESSAGE_ERROR, MM_MESSAGE_ERROR_INVALID_PDU_PARAMETER, diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index befc557c..d79a0f91 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -1368,57 +1368,49 @@ write_bearer_data_message_identifier (MMSmsPart *part, return TRUE; } -static void +static GByteArray * decide_best_encoding (const gchar *text, gpointer log_object, - GByteArray **out, guint *num_fields, guint *num_bits_per_field, - Encoding *encoding) + Encoding *encoding, + GError **error) { - guint ascii_unsupported = 0; - guint i; - guint len; - g_autoptr(GError) error = NULL; + g_autoptr(GByteArray) barray = NULL; + MMModemCharset target_charset = MM_MODEM_CHARSET_UNKNOWN; + guint len; len = strlen (text); - /* Check if we can do ASCII-7 */ - for (i = 0; i < len; i++) { - if (text[i] & 0x80) { - ascii_unsupported++; - break; - } + if (mm_charset_can_convert_to (text, MM_MODEM_CHARSET_IRA)) + target_charset = MM_MODEM_CHARSET_IRA; + else if (mm_charset_can_convert_to (text, MM_MODEM_CHARSET_8859_1)) + target_charset = MM_MODEM_CHARSET_8859_1; + else + target_charset = MM_MODEM_CHARSET_UCS2; + + barray = mm_modem_charset_bytearray_from_utf8 (text, target_charset, FALSE, error); + if (!barray) { + g_prefix_error (error, "Couldn't decide best encoding: "); + return NULL; } - /* If ASCII-7 already supported, done we are */ - if (!ascii_unsupported) { - *out = g_byte_array_sized_new (len); - g_byte_array_append (*out, (const guint8 *)text, len); + if (target_charset == MM_MODEM_CHARSET_IRA) { *num_fields = len; *num_bits_per_field = 7; *encoding = ENCODING_ASCII_7BIT; - return; - } - - /* Check if we can do Latin encoding */ - if (mm_charset_can_convert_to (text, MM_MODEM_CHARSET_8859_1)) { - *out = g_byte_array_sized_new (len); - if (!mm_modem_charset_byte_array_append (*out, text, MM_MODEM_CHARSET_8859_1, &error)) - mm_obj_warn (log_object, "failed to convert to latin encoding: %s", error->message); - *num_fields = (*out)->len; + } else if (target_charset == MM_MODEM_CHARSET_8859_1) { + *num_fields = barray->len; *num_bits_per_field = 8; *encoding = ENCODING_LATIN; - return; - } + } else if (target_charset == MM_MODEM_CHARSET_UCS2) { + *num_fields = barray->len / 2; + *num_bits_per_field = 16; + *encoding = ENCODING_UNICODE; + } else + g_assert_not_reached (); - /* If no Latin and no ASCII, default to UTF-16 */ - *out = g_byte_array_sized_new (len * 2); - if (!mm_modem_charset_byte_array_append (*out, text, MM_MODEM_CHARSET_UCS2, &error)) - mm_obj_warn (log_object, "failed to convert to UTF-16 encoding: %s", error->message); - *num_fields = (*out)->len / 2; - *num_bits_per_field = 16; - *encoding = ENCODING_UNICODE; + return g_steal_pointer (&barray); } static gboolean @@ -1462,12 +1454,14 @@ write_bearer_data_user_data (MMSmsPart *part, /* Text or Data */ if (text) { - decide_best_encoding (text, - log_object, - &converted, - &num_fields, - &num_bits_per_field, - &encoding); + converted = decide_best_encoding (text, + log_object, + &num_fields, + &num_bits_per_field, + &encoding, + error); + if (!converted) + return FALSE; aux = (const GByteArray *)converted; } else { aux = data; From aa67dd24c3853362d385686b6f1acbbc7f94cccf Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 21 Dec 2020 14:20:13 +0100 Subject: [PATCH 587/675] charsets: make charset_gsm_unpacked_to_utf8() private Use the generic mm_modem_charset_bytearray_to_utf8() instead. (cherry picked from commit 033e174e445ff7606ea43191a4a5c141413e10e2) --- plugins/huawei/mm-broadband-modem-huawei.c | 15 +++++++++----- src/mm-base-sim.c | 23 +++++++++++++++------- src/mm-broadband-modem-mbim.c | 9 ++++++--- src/mm-charsets.c | 21 ++++++++++---------- src/mm-charsets.h | 5 ----- src/mm-sms-part-3gpp.c | 18 ++++++++++------- src/tests/test-charsets.c | 6 ++++-- 7 files changed, 58 insertions(+), 39 deletions(-) diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c index 8e17d531..250784be 100644 --- a/plugins/huawei/mm-broadband-modem-huawei.c +++ b/plugins/huawei/mm-broadband-modem-huawei.c @@ -2329,10 +2329,11 @@ decode (MMIfaceModem3gppUssd *self, const gchar *reply, GError **error) { - g_autofree guint8 *bin = NULL; - g_autofree guint8 *unpacked = NULL; - gsize bin_len = 0; - guint32 unpacked_len; + g_autofree guint8 *bin = NULL; + gsize bin_len = 0; + g_autofree guint8 *unpacked = NULL; + guint32 unpacked_len; + g_autoptr(GByteArray) unpacked_array = NULL; bin = mm_utils_hexstr2bin (reply, -1, &bin_len, error); if (!bin) @@ -2342,7 +2343,11 @@ decode (MMIfaceModem3gppUssd *self, /* if the last character in a 7-byte block is padding, then drop it */ if ((bin_len % 7 == 0) && (unpacked[unpacked_len - 1] == 0x0d)) unpacked_len--; - return (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error); + + unpacked_array = g_byte_array_sized_new (unpacked_len); + g_byte_array_append (unpacked_array, unpacked, unpacked_len); + + return mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error); } /*****************************************************************************/ diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index f50af820..c8bd32d4 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -1412,22 +1412,31 @@ parse_spn (const gchar *response, (sw1 == 0x91) || (sw1 == 0x92) || (sw1 == 0x9f)) { - gsize buflen = 0; - g_autofree guint8 *bin = NULL; + g_autoptr(GByteArray) bin_array = NULL; + g_autofree guint8 *bin = NULL; + gsize binlen = 0; /* Convert hex string to binary */ - bin = mm_utils_hexstr2bin (hex, -1, &buflen, error); + bin = mm_utils_hexstr2bin (hex, -1, &binlen, error); if (!bin) { g_prefix_error (error, "SIM returned malformed response '%s': ", hex); return NULL; } /* Remove the FF filler at the end */ - while (buflen > 1 && bin[buflen - 1] == 0xff) - buflen--; + while (binlen > 1 && bin[binlen - 1] == 0xff) + binlen--; + if (binlen <= 1) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "SIM returned empty response '%s'", hex); + return NULL; + } + /* Setup as bytearray. + * First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */ + bin_array = g_byte_array_sized_new (binlen - 1); + g_byte_array_append (bin_array, bin + 1, binlen - 1); - /* First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */ - return (gchar *)mm_charset_gsm_unpacked_to_utf8 (bin + 1, buflen - 1, FALSE, error); + return mm_modem_charset_bytearray_to_utf8 (bin_array, MM_MODEM_CHARSET_GSM, FALSE, error); } g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 5168b0e1..dc199d5d 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4809,11 +4809,14 @@ ussd_decode (guint32 scheme, gchar *decoded = NULL; if (scheme == MM_MODEM_GSM_USSD_SCHEME_7BIT) { - g_autofree guint8 *unpacked = NULL; - guint32 unpacked_len; + g_autoptr(GByteArray) unpacked_array = NULL; + guint8 *unpacked = NULL; + guint32 unpacked_len; unpacked = mm_charset_gsm_unpack ((const guint8 *)data->data, (data->len * 8) / 7, 0, &unpacked_len); - decoded = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error); + unpacked_array = g_byte_array_new_take (unpacked, unpacked_len); + + decoded = mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error); if (!decoded) g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (GSM7 charset): ", scheme); } else if (scheme == MM_MODEM_GSM_USSD_SCHEME_UCS2) { diff --git a/src/mm-charsets.c b/src/mm-charsets.c index b0f4ea60..93e60e10 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -343,11 +343,11 @@ utf8_to_gsm_ext_char (const gchar *utf8, return FALSE; } -guint8 * -mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, - guint32 len, - gboolean translit, - GError **error) +static guint8 * +charset_gsm_unpacked_to_utf8 (const guint8 *gsm, + guint32 len, + gboolean translit, + GError **error) { g_autoptr(GByteArray) utf8 = NULL; guint i; @@ -744,7 +744,8 @@ mm_charset_take_and_convert_to_utf8 (gchar *str, break; case MM_MODEM_CHARSET_GSM: - utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str), FALSE, NULL); + /* This is WRONG! GSM may have embedded NULs (character @)! */ + utf8 = (gchar *) charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str), FALSE, NULL); g_free (str); break; @@ -1111,10 +1112,10 @@ mm_modem_charset_bytearray_to_utf8 (GByteArray *bytearray, switch (charset) { case MM_MODEM_CHARSET_GSM: - utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (bytearray->data, - bytearray->len, - translit, - error); + utf8 = (gchar *) charset_gsm_unpacked_to_utf8 (bytearray->data, + bytearray->len, + translit, + error); break; case MM_MODEM_CHARSET_IRA: case MM_MODEM_CHARSET_UTF8: diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 8300ad6c..9f2ac7e8 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -48,11 +48,6 @@ gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array, gchar *mm_modem_charset_hex_to_utf8 (const gchar *src, MMModemCharset charset); -guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, - guint32 len, - gboolean translit, - GError **error); - /* Checks whether conversion to the given charset may be done without errors */ gboolean mm_charset_can_convert_to (const gchar *utf8, MMModemCharset charset); diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index f467c97b..29b49a68 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -133,11 +133,13 @@ sms_decode_address (const guint8 *address, address++; if (addrtype == SMS_NUMBER_TYPE_ALPHA) { - g_autofree guint8 *unpacked = NULL; - guint32 unpacked_len; + g_autoptr(GByteArray) unpacked_array = NULL; + guint8 *unpacked = NULL; + guint32 unpacked_len; unpacked = mm_charset_gsm_unpack (address, (len * 4) / 7, 0, &unpacked_len); - utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error); + unpacked_array = g_byte_array_new_take (unpacked, unpacked_len); + utf8 = mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error); } else if (addrtype == SMS_NUMBER_TYPE_INTL && addrplan == SMS_NUMBER_PLAN_TELEPHONE) { /* International telphone number, format as "+1234567890" */ @@ -249,12 +251,14 @@ sms_decode_text (const guint8 *text, GError **error) { if (encoding == MM_SMS_ENCODING_GSM7) { - g_autofree guint8 *unpacked = NULL; - guint32 unpacked_len; - gchar *utf8; + g_autoptr(GByteArray) unpacked_array = NULL; + guint8 *unpacked = NULL; + guint32 unpacked_len; + gchar *utf8; unpacked = mm_charset_gsm_unpack ((const guint8 *) text, len, bit_offset, &unpacked_len); - utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error); + unpacked_array = g_byte_array_new_take (unpacked, unpacked_len); + utf8 = mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error); if (utf8) mm_obj_dbg (log_object, "converted SMS part text from GSM-7 to UTF-8: %s", utf8); return utf8; diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c index 4df104ed..d2c07297 100644 --- a/src/tests/test-charsets.c +++ b/src/tests/test-charsets.c @@ -27,7 +27,8 @@ common_test_gsm7 (const gchar *in_utf8) guint32 unpacked_gsm_len_2 = 0; g_autoptr(GByteArray) unpacked_gsm = NULL; g_autofree guint8 *packed_gsm = NULL; - g_autofree guint8 *unpacked_gsm_2 = NULL; + guint8 *unpacked_gsm_2 = NULL; + g_autoptr(GByteArray) unpacked_gsm_2_array = NULL; g_autofree gchar *built_utf8 = NULL; g_autoptr(GError) error = NULL; @@ -56,9 +57,10 @@ common_test_gsm7 (const gchar *in_utf8) /* Unpack */ unpacked_gsm_2 = mm_charset_gsm_unpack (packed_gsm, packed_gsm_len * 8 / 7, 0, &unpacked_gsm_len_2); g_assert_nonnull (unpacked_gsm_2); + unpacked_gsm_2_array = g_byte_array_new_take (unpacked_gsm_2, unpacked_gsm_len_2); /* And back to UTF-8 */ - built_utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked_gsm_2, unpacked_gsm_len_2, FALSE, &error); + built_utf8 = mm_modem_charset_bytearray_to_utf8 (unpacked_gsm_2_array, MM_MODEM_CHARSET_GSM, FALSE, &error); g_assert_nonnull (built_utf8); g_assert_no_error (error); g_assert_cmpstr (built_utf8, ==, in_utf8); From c87f85d4709284e2059da9214df1cb9e36cfdb62 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 21 Dec 2020 14:28:08 +0100 Subject: [PATCH 588/675] charsets: use new bytearray_to_utf8() instead of byte_array_to_utf8() (cherry picked from commit 5ea4a591a40748c5be5f9f4b14ac4f7a09fe2857) --- src/mm-broadband-modem-mbim.c | 6 ++---- src/mm-broadband-modem-qmi.c | 6 ++---- src/mm-charsets.c | 23 ----------------------- src/mm-charsets.h | 5 ----- src/mm-sms-part-3gpp.c | 9 +++------ 5 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index dc199d5d..df9fc15a 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -4820,11 +4820,9 @@ ussd_decode (guint32 scheme, if (!decoded) g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (GSM7 charset): ", scheme); } else if (scheme == MM_MODEM_GSM_USSD_SCHEME_UCS2) { - decoded = mm_modem_charset_byte_array_to_utf8 (data, MM_MODEM_CHARSET_UCS2); + decoded = mm_modem_charset_bytearray_to_utf8 (data, MM_MODEM_CHARSET_UCS2, FALSE, error); if (!decoded) - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, - "Error decoding USSD command in 0x%04x scheme (UCS2 charset)", - scheme); + g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (UCS2 charset): ", scheme); } else g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Failed to decode USSD command in unsupported 0x%04x scheme", scheme); diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 3d54d5ac..b910a585 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -7306,11 +7306,9 @@ ussd_decode (QmiVoiceUssDataCodingScheme scheme, "Error decoding USSD command in 0x%04x scheme (ASCII charset)", scheme); } else if (scheme == QMI_VOICE_USS_DATA_CODING_SCHEME_UCS2) { - decoded = mm_modem_charset_byte_array_to_utf8 ((GByteArray *) data, MM_MODEM_CHARSET_UCS2); + decoded = mm_modem_charset_bytearray_to_utf8 ((GByteArray *) data, MM_MODEM_CHARSET_UCS2, FALSE, error); if (!decoded) - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, - "Error decoding USSD command in 0x%04x scheme (UCS2 charset)", - scheme); + g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (UCS2 charset): ", scheme); } else g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "Failed to decode USSD command in unsupported 0x%04x scheme", scheme); diff --git a/src/mm-charsets.c b/src/mm-charsets.c index 93e60e10..5c0eb6ad 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -96,29 +96,6 @@ charset_iconv_from (MMModemCharset charset) return settings ? settings->iconv_name : NULL; } -gchar * -mm_modem_charset_byte_array_to_utf8 (GByteArray *array, - MMModemCharset charset) -{ - const gchar *iconv_from; - g_autofree gchar *converted = NULL; - g_autoptr(GError) error = NULL; - - g_return_val_if_fail (array != NULL, NULL); - g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); - - iconv_from = charset_iconv_from (charset); - g_return_val_if_fail (iconv_from != NULL, FALSE); - - converted = g_convert ((const gchar *)array->data, array->len, - "UTF-8", iconv_from, - NULL, NULL, &error); - if (!converted || error) - return NULL; - - return g_steal_pointer (&converted); -} - gchar * mm_modem_charset_hex_to_utf8 (const gchar *src, MMModemCharset charset) diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 9f2ac7e8..37b39d7e 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -37,11 +37,6 @@ MMModemCharset mm_modem_charset_from_string (const gchar *string); /*****************************************************************************************/ -/* Take a string encoded in the given charset in binary form, and - * convert it to UTF-8. */ -gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array, - MMModemCharset charset); - /* Take a string in hex representation ("00430052" or "A4BE11" for example) * and convert it from the given character set to UTF-8. */ diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index 29b49a68..fbf8e114 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -264,17 +264,14 @@ sms_decode_text (const guint8 *text, return utf8; } + /* Always assume UTF-16 instead of UCS-2! */ if (encoding == MM_SMS_ENCODING_UCS2) { g_autoptr(GByteArray) bytearray = NULL; gchar *utf8; bytearray = g_byte_array_append (g_byte_array_sized_new (len), (const guint8 *)text, len); - /* Always assume UTF-16 instead of UCS-2! */ - utf8 = mm_modem_charset_byte_array_to_utf8 (bytearray, MM_MODEM_CHARSET_UTF16); - if (!utf8) - g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Couldn't convert SMS part contents from UTF-16BE to UTF-8: not decoding any text"); - else + utf8 = mm_modem_charset_bytearray_to_utf8 (bytearray, MM_MODEM_CHARSET_UTF16, FALSE, error); + if (utf8) mm_obj_dbg (log_object, "converted SMS part text from UTF-16BE to UTF-8: %s", utf8); return utf8; } From ee08721984b93303fac2e00ba456b79826a83f4a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 22 Dec 2020 15:10:55 +0100 Subject: [PATCH 589/675] charsets: use new bytearray_to_utf8() instead of hex_to_utf8() (cherry picked from commit 395ab06c03086bf127970d14a97102e21222126f) --- src/mm-broadband-modem.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 43a9e229..873a1059 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -5905,15 +5905,25 @@ modem_3gpp_ussd_encode (MMIfaceModem3gppUssd *_self, } static gchar * -modem_3gpp_ussd_decode (MMIfaceModem3gppUssd *self, - const gchar *reply, - GError **error) +modem_3gpp_ussd_decode (MMIfaceModem3gppUssd *self, + const gchar *reply, + GError **error) { - MMBroadbandModem *broadband = MM_BROADBAND_MODEM (self); + MMBroadbandModem *broadband = MM_BROADBAND_MODEM (self); + guint8 *bin = NULL; + gsize bin_len = 0; + g_autoptr(GByteArray) barray = NULL; + + bin = (guint8 *) mm_utils_hexstr2bin (reply, -1, &bin_len, error); + if (!bin) { + g_prefix_error (error, "Couldn't convert HEX string to binary: "); + return NULL; + } + barray = g_byte_array_new_take (bin, bin_len); /* Decode from current charset (as per AT+CSCS, which is what most modems * (except for Huawei it seems) will ask for. */ - return mm_modem_charset_hex_to_utf8 (reply, broadband->priv->modem_current_charset); + return mm_modem_charset_bytearray_to_utf8 (barray, broadband->priv->modem_current_charset, FALSE, error); } /*****************************************************************************/ From e7a949de935dc09e7012d9bedbf6bd6f0b80f3d4 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 13 Feb 2021 14:44:27 +0100 Subject: [PATCH 590/675] charsets: use new str_from_utf8() instead of take_and_convert_to_current_charset() (cherry picked from commit e5363b546b72403451f14f24502f6c9a90728616) --- .../cinterion/mm-broadband-modem-cinterion.c | 77 ++++++++--- plugins/mbm/mm-broadband-bearer-mbm.c | 40 ++++-- src/mm-broadband-modem.c | 126 ++++++++---------- src/mm-broadband-modem.h | 12 -- 4 files changed, 142 insertions(+), 113 deletions(-) diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 4986eea5..9b085433 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -2154,22 +2154,59 @@ set_bands_3g (GTask *task, FALSE, (GAsyncReadyCallback)scfg_set_ready, task); - } else { /* self->priv->rb_format == MM_CINTERION_RADIO_BAND_FORMAT_MULTIPLE */ + return; + } + + if (self->priv->rb_format == MM_CINTERION_RADIO_BAND_FORMAT_MULTIPLE) { if (self->priv->modem_family == MM_CINTERION_MODEM_FAMILY_IMT) { g_autofree gchar *bandstr2G = NULL; g_autofree gchar *bandstr3G = NULL; g_autofree gchar *bandstr4G = NULL; + g_autofree gchar *bandstr2G_enc = NULL; + g_autofree gchar *bandstr3G_enc = NULL; + g_autofree gchar *bandstr4G_enc = NULL; bandstr2G = g_strdup_printf ("0x%08X", band[MM_CINTERION_RB_BLOCK_GSM]); bandstr3G = g_strdup_printf ("0x%08X", band[MM_CINTERION_RB_BLOCK_UMTS]); bandstr4G = g_strdup_printf ("0x%08X", band[MM_CINTERION_RB_BLOCK_LTE_LOW]); - bandstr2G = mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM (self), bandstr2G); - bandstr3G = mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM (self), bandstr3G); - bandstr4G = mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM (self), bandstr4G); + + bandstr2G_enc = mm_modem_charset_str_from_utf8 (bandstr2G, + mm_broadband_modem_get_current_charset (MM_BROADBAND_MODEM (self)), + FALSE, + &error); + if (!bandstr2G_enc) { + g_prefix_error (&error, "Couldn't convert 2G band string to current charset: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + bandstr3G_enc = mm_modem_charset_str_from_utf8 (bandstr3G, + mm_broadband_modem_get_current_charset (MM_BROADBAND_MODEM (self)), + FALSE, + &error); + if (!bandstr3G_enc) { + g_prefix_error (&error, "Couldn't convert 3G band string to current charset: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + bandstr4G_enc = mm_modem_charset_str_from_utf8 (bandstr4G, + mm_broadband_modem_get_current_charset (MM_BROADBAND_MODEM (self)), + FALSE, + &error); + if (!bandstr4G_enc) { + g_prefix_error (&error, "Couldn't convert 4G band string to current charset: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + self->priv->cmds = g_new0 (MMBaseModemAtCommandAlloc, 3 + 1); - self->priv->cmds[0].command = g_strdup_printf ("^SCFG=\"Radio/Band/2G\",\"%s\"", bandstr2G); - self->priv->cmds[1].command = g_strdup_printf ("^SCFG=\"Radio/Band/3G\",\"%s\"", bandstr3G); - self->priv->cmds[2].command = g_strdup_printf ("^SCFG=\"Radio/Band/4G\",\"%s\"", bandstr4G); + self->priv->cmds[0].command = g_strdup_printf ("^SCFG=\"Radio/Band/2G\",\"%s\"", bandstr2G_enc); + self->priv->cmds[1].command = g_strdup_printf ("^SCFG=\"Radio/Band/3G\",\"%s\"", bandstr3G_enc); + self->priv->cmds[2].command = g_strdup_printf ("^SCFG=\"Radio/Band/4G\",\"%s\"", bandstr4G_enc); self->priv->cmds[0].timeout = self->priv->cmds[1].timeout = self->priv->cmds[2].timeout = 60; } else { self->priv->cmds = g_new0 (MMBaseModemAtCommandAlloc, 3 + 1); @@ -2185,8 +2222,10 @@ set_bands_3g (GTask *task, NULL, (GAsyncReadyCallback)scfg_set_ready_sequence, task); + return; } + g_assert_not_reached (); } static void @@ -2196,8 +2235,9 @@ set_bands_2g (GTask *task, MMBroadbandModemCinterion *self; GError *error = NULL; guint band[MM_CINTERION_RB_BLOCK_N] = { 0 }; - gchar *cmd; - gchar *bandstr; + g_autofree gchar *cmd = NULL; + g_autofree gchar *bandstr = NULL; + g_autofree gchar *bandstr_enc = NULL; self = g_task_get_source_object (task); @@ -2215,12 +2255,13 @@ set_bands_2g (GTask *task, /* Build string with the value, in the proper charset */ bandstr = g_strdup_printf ("%u", band[MM_CINTERION_RB_BLOCK_LEGACY]); - bandstr = mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM (self), bandstr); - if (!bandstr) { - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_UNSUPPORTED, - "Couldn't convert band set to current charset"); + bandstr_enc = mm_modem_charset_str_from_utf8 (bandstr, + mm_broadband_modem_get_current_charset (MM_BROADBAND_MODEM (self)), + FALSE, + &error); + if (!bandstr_enc) { + g_prefix_error (&error, "Couldn't convert band string to current charset: "); + g_task_return_error (task, error); g_object_unref (task); return; } @@ -2231,17 +2272,13 @@ set_bands_2g (GTask *task, * the modem to connect at that specific frequency only. Note that we will be * passing double-quote enclosed strings here! */ - cmd = g_strdup_printf ("^SCFG=\"Radio/Band\",\"%s\",\"%s\"", bandstr, bandstr); - + cmd = g_strdup_printf ("^SCFG=\"Radio/Band\",\"%s\",\"%s\"", bandstr_enc, bandstr_enc); mm_base_modem_at_command (MM_BASE_MODEM (self), cmd, 15, FALSE, (GAsyncReadyCallback)scfg_set_ready, task); - - g_free (cmd); - g_free (bandstr); } static void diff --git a/plugins/mbm/mm-broadband-bearer-mbm.c b/plugins/mbm/mm-broadband-bearer-mbm.c index b4bba2d9..8de7a09f 100644 --- a/plugins/mbm/mm-broadband-bearer-mbm.c +++ b/plugins/mbm/mm-broadband-bearer-mbm.c @@ -359,22 +359,35 @@ authenticate (GTask *task) /* Both user and password are required; otherwise firmware returns an error */ if (user || password) { - gchar *command; - gchar *encoded_user; - gchar *encoded_password; + g_autofree gchar *command = NULL; + g_autofree gchar *user_enc = NULL; + g_autofree gchar *password_enc = NULL; + GError *error = NULL; + + user_enc = mm_modem_charset_str_from_utf8 (user, + mm_broadband_modem_get_current_charset (MM_BROADBAND_MODEM (ctx->modem)), + FALSE, + &error); + if (!user_enc) { + g_prefix_error (&error, "Couldn't convert user to current charset: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } - encoded_user = mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM (ctx->modem), - g_strdup (user)); - encoded_password = mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM (ctx->modem), - g_strdup (password)); + password_enc = mm_modem_charset_str_from_utf8 (password, + mm_broadband_modem_get_current_charset (MM_BROADBAND_MODEM (ctx->modem)), + FALSE, + &error); + if (!password_enc) { + g_prefix_error (&error, "Couldn't convert password to current charset: "); + g_task_return_error (task, error); + g_object_unref (task); + return; + } command = g_strdup_printf ("AT*EIAAUW=%d,1,\"%s\",\"%s\"", - ctx->cid, - encoded_user ? encoded_user : "", - encoded_password ? encoded_password : ""); - g_free (encoded_user); - g_free (encoded_password); - + ctx->cid, user_enc, password_enc); mm_base_modem_at_command_full (ctx->modem, ctx->primary, command, @@ -384,7 +397,6 @@ authenticate (GTask *task) g_task_get_cancellable (task), (GAsyncReadyCallback) authenticate_ready, task); - g_free (command); return; } diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 873a1059..fc67104f 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -4800,27 +4800,37 @@ cops_set_ready (MMBaseModem *self, } static void -cops_ascii_set_ready (MMBaseModem *self, +cops_ascii_set_ready (MMBaseModem *_self, GAsyncResult *res, GTask *task) { - GError *error = NULL; + MMBroadbandModem *self = MM_BROADBAND_MODEM (_self); + g_autoptr(GError) error = NULL; - if (!mm_base_modem_at_command_full_finish (MM_BASE_MODEM (self), res, &error)) { + if (!mm_base_modem_at_command_full_finish (_self, res, &error)) { /* If it failed with an unsupported error, retry with current modem charset */ if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_NOT_SUPPORTED)) { - gchar *operator_id; - gchar *operator_id_current_charset; + g_autoptr(GError) enc_error = NULL; + g_autofree gchar *operator_id_enc = NULL; + gchar *operator_id; + /* try to encode to current charset */ operator_id = g_task_get_task_data (task); - operator_id_current_charset = mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM (self), g_strdup (operator_id)); + operator_id_enc = mm_modem_charset_str_from_utf8 (operator_id, self->priv->modem_current_charset, FALSE, &enc_error); + if (!operator_id_enc) { + mm_obj_dbg (self, "couldn't convert operator id to current charset: %s", enc_error->message); + g_task_return_error (task, g_steal_pointer (&error)); + g_object_unref (task); + return; + } - if (g_strcmp0 (operator_id, operator_id_current_charset) != 0) { - gchar *command; + /* retry only if encoded string is different to the non-encoded one */ + if (g_strcmp0 (operator_id, operator_id_enc) != 0) { + g_autofree gchar *command = NULL; - command = g_strdup_printf ("+COPS=1,2,\"%s\"", operator_id_current_charset); - mm_base_modem_at_command_full (MM_BASE_MODEM (self), - mm_base_modem_peek_best_at_port (MM_BASE_MODEM (self), NULL), + command = g_strdup_printf ("+COPS=1,2,\"%s\"", operator_id_enc); + mm_base_modem_at_command_full (_self, + mm_base_modem_peek_best_at_port (_self, NULL), command, 120, FALSE, @@ -4828,16 +4838,10 @@ cops_ascii_set_ready (MMBaseModem *self, g_task_get_cancellable (task), (GAsyncReadyCallback)cops_set_ready, task); - g_error_free (error); - g_free (operator_id_current_charset); - g_free (command); return; } - /* operator id string would be the same on the current charset, - * so fallback and return the not supported error */ - g_free (operator_id_current_charset); } - g_task_return_error (task, error); + g_task_return_error (task, g_steal_pointer (&error)); } else g_task_return_boolean (task, TRUE); g_object_unref (task); @@ -7311,11 +7315,17 @@ sms_text_part_list_ready (MMBroadbandModem *self, ctx = g_task_get_task_data (task); while (g_match_info_matches (match_info)) { - MMSmsPart *part; - guint matches, idx; - gchar *number, *timestamp, *text, *ucs2_text, *stat; - gsize ucs2_len = 0; - GByteArray *raw; + MMSmsPart *part; + guint matches; + guint idx; + g_autofree gchar *number_enc = NULL; + g_autofree gchar *number = NULL; + g_autofree gchar *timestamp = NULL; + g_autofree gchar *text_enc = NULL; + g_autofree gchar *text = NULL; + g_autofree gchar *stat = NULL; + g_autoptr(GByteArray) raw = NULL; + g_autoptr(GError) inner_error = NULL; matches = g_match_info_get_match_count (match_info); if (matches != 7) { @@ -7336,39 +7346,44 @@ sms_text_part_list_ready (MMBroadbandModem *self, } /* Get and parse number */ - number = mm_get_string_unquoted_from_match_info (match_info, 3); - if (!number) { + number_enc = mm_get_string_unquoted_from_match_info (match_info, 3); + if (!number_enc) { mm_obj_dbg (self, "failed to get message sender number"); - g_free (stat); goto next; } - - number = mm_broadband_modem_take_and_convert_to_utf8 (MM_BROADBAND_MODEM (self), - number); + number = mm_modem_charset_str_to_utf8 (number_enc, -1, self->priv->modem_current_charset, FALSE, &inner_error); + if (!number) { + mm_obj_dbg (self, "failed to convert message sender number to UTF-8: %s", inner_error->message); + goto next; + } /* Get and parse timestamp (always expected in ASCII) */ timestamp = mm_get_string_unquoted_from_match_info (match_info, 5); + if (timestamp && !g_str_is_ascii (timestamp)) { + mm_obj_dbg (self, "failed to parse input timestamp as ASCII"); + goto next; + } /* Get and parse text */ - text = mm_broadband_modem_take_and_convert_to_utf8 (MM_BROADBAND_MODEM (self), - g_match_info_fetch (match_info, 6)); + text_enc = g_match_info_fetch (match_info, 6); + text = mm_modem_charset_str_to_utf8 (text_enc, -1, self->priv->modem_current_charset, FALSE, &inner_error); + if (!text) { + mm_obj_dbg (self, "failed to convert message text to UTF-8: %s", inner_error->message); + goto next; + } /* The raw SMS data can only be GSM, UCS2, or unknown (8-bit), so we * need to convert to UCS2 here. */ - ucs2_text = g_convert (text, -1, "UCS-2BE//TRANSLIT", "UTF-8", NULL, &ucs2_len, NULL); - g_assert (ucs2_text); - raw = g_byte_array_sized_new (ucs2_len); - g_byte_array_append (raw, (const guint8 *) ucs2_text, ucs2_len); - g_free (ucs2_text); + raw = mm_modem_charset_bytearray_from_utf8 (text, MM_MODEM_CHARSET_UCS2, FALSE, NULL); + g_assert (raw); /* all take() methods pass ownership of the value as well */ - part = mm_sms_part_new (idx, - sms_pdu_type_from_str (stat)); - mm_sms_part_take_number (part, number); - mm_sms_part_take_timestamp (part, timestamp); - mm_sms_part_take_text (part, text); - mm_sms_part_take_data (part, raw); + part = mm_sms_part_new (idx, sms_pdu_type_from_str (stat)); + mm_sms_part_take_number (part, g_steal_pointer (&number)); + mm_sms_part_take_timestamp (part, g_steal_pointer (×tamp)); + mm_sms_part_take_text (part, g_steal_pointer (&text)); + mm_sms_part_take_data (part, g_steal_pointer (&raw)); mm_sms_part_set_class (part, -1); mm_obj_dbg (self, "correctly parsed SMS list entry (%d)", idx); @@ -7376,7 +7391,6 @@ sms_text_part_list_ready (MMBroadbandModem *self, part, sms_state_from_str (stat), ctx->list_storage); - g_free (stat); next: g_match_info_next (match_info, NULL); } @@ -11890,35 +11904,14 @@ initialize (MMBaseModem *self, /*****************************************************************************/ -gchar * -mm_broadband_modem_take_and_convert_to_utf8 (MMBroadbandModem *self, - gchar *str) -{ - /* should only be used AFTER current charset is set */ - if (self->priv->modem_current_charset == MM_MODEM_CHARSET_UNKNOWN) - return str; - - return mm_charset_take_and_convert_to_utf8 (str, - self->priv->modem_current_charset); -} - -gchar * -mm_broadband_modem_take_and_convert_to_current_charset (MMBroadbandModem *self, - gchar *str) -{ - /* should only be used AFTER current charset is set */ - if (self->priv->modem_current_charset == MM_MODEM_CHARSET_UNKNOWN) - return str; - - return mm_utf8_take_and_convert_to_charset (str, self->priv->modem_current_charset); -} - MMModemCharset mm_broadband_modem_get_current_charset (MMBroadbandModem *self) { return self->priv->modem_current_charset; } +/*****************************************************************************/ + gchar * mm_broadband_modem_create_device_identifier (MMBroadbandModem *self, const gchar *ati, @@ -11940,7 +11933,6 @@ mm_broadband_modem_create_device_identifier (MMBroadbandModem *self, MM_GDBUS_MODEM (self->priv->modem_dbus_skeleton)))); } - /*****************************************************************************/ void diff --git a/src/mm-broadband-modem.h b/src/mm-broadband-modem.h index eafca857..1f5acac3 100644 --- a/src/mm-broadband-modem.h +++ b/src/mm-broadband-modem.h @@ -100,18 +100,6 @@ MMBroadbandModem *mm_broadband_modem_new (const gchar *device, guint16 vendor_id, guint16 product_id); -/* Convert the given string, which comes in the charset currently set in the - * modem, to UTF-8. Given in the API so that subclasses can also use it directly. - */ -gchar *mm_broadband_modem_take_and_convert_to_utf8 (MMBroadbandModem *self, - gchar *str); - -/* Convert the given string, which comes in UTF-8, to the charset currently set - * in the modem. Given in the API so that subclasses can also use it directly. - */ -gchar *mm_broadband_modem_take_and_convert_to_current_charset (MMBroadbandModem *self, - gchar *str); - MMModemCharset mm_broadband_modem_get_current_charset (MMBroadbandModem *self); /* Create a unique device identifier string using the ATI and ATI1 replies and some From ada8ec6786cc9aff9b1c93caa62c16292681bdf6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 13 Feb 2021 14:54:54 +0100 Subject: [PATCH 591/675] cinterion: move sequence to set bands to private ctx The sequence of commands is exclusively used during the set current bands operation, so there is no point in storing it in the private object data. (cherry picked from commit 3ac248a7a6a4ad03d10dc691905e43be8722ab31) --- .../cinterion/mm-broadband-modem-cinterion.c | 65 +++++++++++-------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 9b085433..7eeb8ade 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -107,9 +107,6 @@ struct _MMBroadbandModemCinterionPrivate { /* Initial EPS bearer context number */ gint initial_eps_bearer_cid; - - /* Command sequence */ - MMBaseModemAtCommandAlloc *cmds; }; /*****************************************************************************/ @@ -2070,6 +2067,23 @@ load_current_bands (MMIfaceModem *self, /*****************************************************************************/ /* Set current bands (Modem interface) */ +typedef struct { + MMBaseModemAtCommandAlloc *cmds; +} SetCurrentBandsContext; + +static void +set_current_bands_context_free (SetCurrentBandsContext *ctx) +{ + if (ctx->cmds) { + guint i; + + for (i = 0; ctx->cmds[i].command; i++) + mm_base_modem_at_command_alloc_clear (&ctx->cmds[i]); + g_free (ctx->cmds); + } + g_slice_free (SetCurrentBandsContext, ctx); +} + static gboolean set_current_bands_finish (MMIfaceModem *self, GAsyncResult *res, @@ -2093,23 +2107,17 @@ scfg_set_ready (MMBaseModem *self, } static void -scfg_set_ready_sequence (MMBaseModem *_self, +scfg_set_ready_sequence (MMBaseModem *self, GAsyncResult *res, GTask *task) { GError *error = NULL; - gpointer ctx = NULL; - guint i; - MMBroadbandModemCinterion *self; - - self = g_task_get_source_object (task); - for (i = 0; self->priv->cmds[i].command; i++) - mm_base_modem_at_command_alloc_clear (&self->priv->cmds[i]); - g_free (self->priv->cmds); - self->priv->cmds = NULL; - mm_base_modem_at_sequence_finish (_self, res, &ctx, &error); - g_task_return_boolean (task, TRUE); + mm_base_modem_at_sequence_finish (self, res, NULL, &error); + if (error) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); g_object_unref (task); } @@ -2158,6 +2166,11 @@ set_bands_3g (GTask *task, } if (self->priv->rb_format == MM_CINTERION_RADIO_BAND_FORMAT_MULTIPLE) { + SetCurrentBandsContext *ctx; + + ctx = g_slice_new0 (SetCurrentBandsContext); + g_task_set_task_data (task, ctx, (GDestroyNotify)set_current_bands_context_free); + if (self->priv->modem_family == MM_CINTERION_MODEM_FAMILY_IMT) { g_autofree gchar *bandstr2G = NULL; g_autofree gchar *bandstr3G = NULL; @@ -2203,21 +2216,21 @@ set_bands_3g (GTask *task, return; } - self->priv->cmds = g_new0 (MMBaseModemAtCommandAlloc, 3 + 1); - self->priv->cmds[0].command = g_strdup_printf ("^SCFG=\"Radio/Band/2G\",\"%s\"", bandstr2G_enc); - self->priv->cmds[1].command = g_strdup_printf ("^SCFG=\"Radio/Band/3G\",\"%s\"", bandstr3G_enc); - self->priv->cmds[2].command = g_strdup_printf ("^SCFG=\"Radio/Band/4G\",\"%s\"", bandstr4G_enc); - self->priv->cmds[0].timeout = self->priv->cmds[1].timeout = self->priv->cmds[2].timeout = 60; + ctx->cmds = g_new0 (MMBaseModemAtCommandAlloc, 3 + 1); + ctx->cmds[0].command = g_strdup_printf ("^SCFG=\"Radio/Band/2G\",\"%s\"", bandstr2G_enc); + ctx->cmds[1].command = g_strdup_printf ("^SCFG=\"Radio/Band/3G\",\"%s\"", bandstr3G_enc); + ctx->cmds[2].command = g_strdup_printf ("^SCFG=\"Radio/Band/4G\",\"%s\"", bandstr4G_enc); + ctx->cmds[0].timeout = ctx->cmds[1].timeout = ctx->cmds[2].timeout = 60; } else { - self->priv->cmds = g_new0 (MMBaseModemAtCommandAlloc, 3 + 1); - self->priv->cmds[0].command = g_strdup_printf ("^SCFG=\"Radio/Band/2G\",\"%08x\",,1", band[MM_CINTERION_RB_BLOCK_GSM]); - self->priv->cmds[1].command = g_strdup_printf ("^SCFG=\"Radio/Band/3G\",\"%08x\",,1", band[MM_CINTERION_RB_BLOCK_UMTS]); - self->priv->cmds[2].command = g_strdup_printf ("^SCFG=\"Radio/Band/4G\",\"%08x\",\"%08x\",1", band[MM_CINTERION_RB_BLOCK_LTE_LOW], band[MM_CINTERION_RB_BLOCK_LTE_HIGH]); - self->priv->cmds[0].timeout = self->priv->cmds[1].timeout = self->priv->cmds[2].timeout = 15; + ctx->cmds = g_new0 (MMBaseModemAtCommandAlloc, 3 + 1); + ctx->cmds[0].command = g_strdup_printf ("^SCFG=\"Radio/Band/2G\",\"%08x\",,1", band[MM_CINTERION_RB_BLOCK_GSM]); + ctx->cmds[1].command = g_strdup_printf ("^SCFG=\"Radio/Band/3G\",\"%08x\",,1", band[MM_CINTERION_RB_BLOCK_UMTS]); + ctx->cmds[2].command = g_strdup_printf ("^SCFG=\"Radio/Band/4G\",\"%08x\",\"%08x\",1", band[MM_CINTERION_RB_BLOCK_LTE_LOW], band[MM_CINTERION_RB_BLOCK_LTE_HIGH]); + ctx->cmds[0].timeout = ctx->cmds[1].timeout = ctx->cmds[2].timeout = 15; } mm_base_modem_at_sequence (MM_BASE_MODEM (self), - (const MMBaseModemAtCommand *)self->priv->cmds, + (const MMBaseModemAtCommand *)ctx->cmds, NULL, NULL, (GAsyncReadyCallback)scfg_set_ready_sequence, From bba502c4be260e46c97f266957b3cb1bc67af7eb Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 13 Feb 2021 15:45:52 +0100 Subject: [PATCH 592/675] charsets,tests: update take_and_convert tests to str_from/to (cherry picked from commit 63fa9eee462de9270e3ab44eab43050877982cf1) --- src/tests/test-charsets.c | 98 ++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c index d2c07297..8735fd22 100644 --- a/src/tests/test-charsets.c +++ b/src/tests/test-charsets.c @@ -317,58 +317,71 @@ test_gsm7_pack_7_chars_offset (void) } static void -test_take_convert_ucs2_hex_utf8 (void) +test_str_ucs2_to_from_utf8 (void) { - gchar *src, *converted, *utf8; - - /* Ensure hex-encoded UCS-2 works */ - src = g_strdup ("0054002d004d006f00620069006c0065"); - converted = mm_charset_take_and_convert_to_utf8 (src, MM_MODEM_CHARSET_UCS2); - g_assert_cmpstr (converted, ==, "T-Mobile"); - utf8 = mm_utf8_take_and_convert_to_charset (converted, MM_MODEM_CHARSET_UCS2); - g_assert_cmpstr (utf8, ==, "0054002D004D006F00620069006C0065"); - g_free (utf8); -} + const gchar *src = "0054002D004D006F00620069006C0065"; + g_autofree gchar *utf8 = NULL; + g_autofree gchar *dst = NULL; + g_autoptr(GError) error = NULL; -static void -test_take_convert_ucs2_bad_ascii (void) -{ - gchar *src, *converted; + utf8 = mm_modem_charset_str_to_utf8 (src, -1, MM_MODEM_CHARSET_UCS2, FALSE, &error); + g_assert_no_error (error); + g_assert_cmpstr (utf8, ==, "T-Mobile"); - /* Test that something mostly ASCII returns most of the original string */ - src = g_strdup ("Orange\241"); - converted = mm_charset_take_and_convert_to_utf8 (src, MM_MODEM_CHARSET_UCS2); - g_assert_cmpstr (converted, ==, "Orange"); - g_free (converted); + dst = mm_modem_charset_str_from_utf8 (utf8, MM_MODEM_CHARSET_UCS2, FALSE, &error); + g_assert_no_error (error); + g_assert_cmpstr (dst, ==, src); } static void -test_take_convert_ucs2_bad_ascii2 (void) +test_str_gsm_to_from_utf8 (void) { - gchar *src, *converted; + const gchar *src = "T-Mobile"; + g_autofree gchar *utf8 = NULL; + g_autofree gchar *dst = NULL; + g_autoptr(GError) error = NULL; + + /* Note: as long as the GSM string doesn't contain the '@' character, str_to_utf8() + * and str_from_utf8() can safely be used */ + + utf8 = mm_modem_charset_str_to_utf8 (src, -1, MM_MODEM_CHARSET_GSM, FALSE, &error); + g_assert_no_error (error); + g_assert_cmpstr (utf8, ==, src); - /* Ensure something completely screwed up doesn't crash */ - src = g_strdup ("\241\255\254\250\244\234"); - converted = mm_charset_take_and_convert_to_utf8 (src, MM_MODEM_CHARSET_UCS2); - g_assert (converted == NULL); + dst = mm_modem_charset_str_from_utf8 (utf8, MM_MODEM_CHARSET_GSM, FALSE, &error); + g_assert_no_error (error); + g_assert_cmpstr (dst, ==, src); } static void -test_take_convert_gsm_utf8 (void) +test_str_gsm_to_from_utf8_with_at (void) { - /* NOTE: this is wrong, charset GSM may contain embedded NULs so we cannot convert - * from a plain UTF-8 string to a NUL-terminated string in GSM, as there is no - * such, thing. */ -#if 0 - gchar *src, *converted, *utf8; + /* The NULs are '@' chars, except for the trailing one which is always taken as end-of-string */ + const gchar src[] = { 'T', '-', 'M', 0x00, 'o', 'b', 'i', 0x00, 'l', 'e', 0x00 }; + const gchar *utf8_expected = "T-M@obi@le"; + const gchar *src_translit = "T-M?obi?le"; + g_autofree gchar *utf8 = NULL; + g_autofree gchar *dst = NULL; + g_autoptr(GError) error = NULL; + + /* Note: as long as the GSM string doesn't contain the '@' character, str_to_utf8() + * and str_from_utf8() can safely be used */ + + utf8 = mm_modem_charset_str_to_utf8 (src, G_N_ELEMENTS (src), MM_MODEM_CHARSET_GSM, FALSE, &error); + g_assert_no_error (error); + g_assert_cmpstr (utf8, ==, utf8_expected); - src = g_strdup ("T-Mobile"); - converted = mm_charset_take_and_convert_to_utf8 (src, MM_MODEM_CHARSET_GSM); - g_assert_cmpstr (converted, ==, "T-Mobile"); - utf8 = mm_utf8_take_and_convert_to_charset (converted, MM_MODEM_CHARSET_GSM); - g_assert_cmpstr (utf8, ==, "T-Mobile"); - g_free (utf8); -#endif + /* if charset conversion from UTF-8 contains '@' chars, running without transliteration + * will return an error */ + dst = mm_modem_charset_str_from_utf8 (utf8, MM_MODEM_CHARSET_GSM, FALSE, &error); + g_assert_nonnull (error); + g_assert_null (dst); + g_clear_error (&error); + + /* with transliteration, '@'->'?' */ + dst = mm_modem_charset_str_from_utf8 (utf8, MM_MODEM_CHARSET_GSM, TRUE, &error); + g_assert_no_error (error); + g_assert_cmpstr (dst, ==, src_translit); } struct charset_can_convert_to_test_s { @@ -452,10 +465,9 @@ int main (int argc, char **argv) g_test_add_func ("/MM/charsets/gsm7/pack/last-septet-alone", test_gsm7_pack_last_septet_alone); g_test_add_func ("/MM/charsets/gsm7/pack/7-chars-offset", test_gsm7_pack_7_chars_offset); - g_test_add_func ("/MM/charsets/take-convert/ucs2/hex", test_take_convert_ucs2_hex_utf8); - g_test_add_func ("/MM/charsets/take-convert/ucs2/bad-ascii", test_take_convert_ucs2_bad_ascii); - g_test_add_func ("/MM/charsets/take-convert/ucs2/bad-ascii-2", test_take_convert_ucs2_bad_ascii2); - g_test_add_func ("/MM/charsets/take-convert/gsm", test_take_convert_gsm_utf8); + g_test_add_func ("/MM/charsets/str-from-to/ucs2", test_str_ucs2_to_from_utf8); + g_test_add_func ("/MM/charsets/str-from-to/gsm", test_str_gsm_to_from_utf8); + g_test_add_func ("/MM/charsets/str-from-to/gsm-with-at", test_str_gsm_to_from_utf8_with_at); g_test_add_func ("/MM/charsets/can-convert-to", test_charset_can_covert_to); From 251d2096f6a8748b031e8434ccea9a17ea7bcd59 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 13 Feb 2021 16:04:56 +0100 Subject: [PATCH 593/675] helpers: rework normalize_operator() to use str_to_utf8() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of blindly assuming that we can take whatever string given as valid UTF-8, we'll always attempt to convert from the current modem charset into UTF-8. Before we were doing this for hex-encoded UCS2, but not for example for GSM-7. And due to the now applied GSM-7 conversion, the mf627a/mf627b +COPS parsing unit tests are updated accordingly, because when converting from an input string that contains byte 0x40 ('@' in UTF-8) as if it were GSM-7, the 0x40 is taken as character '¡', encoded as 0xc2,0xa1 in UTF-8). (cherry picked from commit 16df1e17e6e96f8dd0ba67003c6abb7083b9d7ec) --- .../altair/mm-broadband-modem-altair-lte.c | 2 +- src/mm-broadband-modem.c | 4 +- src/mm-modem-helpers.c | 42 ++++++++++++------- src/mm-modem-helpers.h | 3 +- src/tests/test-modem-helpers.c | 8 ++-- 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/plugins/altair/mm-broadband-modem-altair-lte.c b/plugins/altair/mm-broadband-modem-altair-lte.c index d26335f7..6aebbd93 100644 --- a/plugins/altair/mm-broadband-modem-altair-lte.c +++ b/plugins/altair/mm-broadband-modem-altair-lte.c @@ -1067,7 +1067,7 @@ modem_3gpp_load_operator_name_finish (MMIfaceModem3gpp *self, error)) return NULL; - mm_3gpp_normalize_operator (&operator_name, MM_MODEM_CHARSET_UNKNOWN); + mm_3gpp_normalize_operator (&operator_name, MM_MODEM_CHARSET_UNKNOWN, self); return operator_name; } diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index fc67104f..a25883ac 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -4465,7 +4465,7 @@ modem_3gpp_load_operator_code_finish (MMIfaceModem3gpp *self, error)) return NULL; - mm_3gpp_normalize_operator (&operator_code, MM_BROADBAND_MODEM (self)->priv->modem_current_charset); + mm_3gpp_normalize_operator (&operator_code, MM_BROADBAND_MODEM (self)->priv->modem_current_charset, self); if (operator_code) mm_obj_dbg (self, "loaded Operator Code: %s", operator_code); return operator_code; @@ -4504,7 +4504,7 @@ modem_3gpp_load_operator_name_finish (MMIfaceModem3gpp *self, error)) return NULL; - mm_3gpp_normalize_operator (&operator_name, MM_BROADBAND_MODEM (self)->priv->modem_current_charset); + mm_3gpp_normalize_operator (&operator_name, MM_BROADBAND_MODEM (self)->priv->modem_current_charset, self); if (operator_name) mm_obj_dbg (self, "loaded Operator Name: %s", operator_name); return operator_name; diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index b4b5515a..26b55f71 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1289,9 +1289,9 @@ mm_3gpp_parse_cops_test_response (const gchar *reply, info->operator_code = mm_get_string_unquoted_from_match_info (match_info, 4); /* The returned strings may be given in e.g. UCS2 */ - mm_3gpp_normalize_operator (&info->operator_long, cur_charset); - mm_3gpp_normalize_operator (&info->operator_short, cur_charset); - mm_3gpp_normalize_operator (&info->operator_code, cur_charset); + mm_3gpp_normalize_operator (&info->operator_long, cur_charset, log_object); + mm_3gpp_normalize_operator (&info->operator_short, cur_charset, log_object); + mm_3gpp_normalize_operator (&info->operator_code, cur_charset, log_object); /* Only try for access technology with UMTS-format matches. * If none give, assume GSM */ @@ -4018,8 +4018,11 @@ mm_string_to_access_tech (const gchar *string) void mm_3gpp_normalize_operator (gchar **operator, - MMModemCharset cur_charset) + MMModemCharset cur_charset, + gpointer log_object) { + g_autofree gchar *normalized = NULL; + g_assert (operator); if (*operator == NULL) @@ -4027,31 +4030,38 @@ mm_3gpp_normalize_operator (gchar **operator, /* Despite +CSCS? may claim supporting UCS2, Some modems (e.g. Huawei) * always report the operator name in ASCII in a +COPS response. */ - if (cur_charset == MM_MODEM_CHARSET_UCS2) { - gchar *tmp; + if (cur_charset != MM_MODEM_CHARSET_UNKNOWN) { + g_autoptr(GError) error = NULL; - tmp = g_strdup (*operator); - /* In this case we're already checking UTF-8 validity */ - tmp = mm_charset_take_and_convert_to_utf8 (tmp, cur_charset); - if (tmp) { - g_clear_pointer (operator, g_free); - *operator = tmp; + normalized = mm_modem_charset_str_to_utf8 (*operator, -1, cur_charset, TRUE, &error); + if (normalized) goto out; - } + + mm_obj_dbg (log_object, "couldn't convert operator string '%s' from charset '%s': %s", + *operator, + mm_modem_charset_to_string (cur_charset), + error->message); } /* Charset is unknown or there was an error in conversion; try to see * if the contents we got are valid UTF-8 already. */ - if (!g_utf8_validate (*operator, -1, NULL)) - g_clear_pointer (operator, g_free); + if (g_utf8_validate (*operator, -1, NULL)) + normalized = g_strdup (*operator); out: /* Some modems (Novatel LTE) return the operator name as "Unknown" when * it fails to obtain the operator name. Return NULL in such case. */ - if (*operator && g_ascii_strcasecmp (*operator, "unknown") == 0) + if (!normalized || g_ascii_strcasecmp (normalized, "unknown") == 0) { + /* If normalization failed, just cleanup the string */ g_clear_pointer (operator, g_free); + return; + } + + mm_obj_dbg (log_object, "operator normalized '%s'->'%s'", *operator, normalized); + g_clear_pointer (operator, g_free); + *operator = g_steal_pointer (&normalized); } /*************************************************************************/ diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index fb556543..0f314959 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -429,7 +429,8 @@ const gchar *mm_3gpp_facility_to_acronym (MMModem3gppFacility facility) MMModemAccessTechnology mm_string_to_access_tech (const gchar *string); void mm_3gpp_normalize_operator (gchar **operator, - MMModemCharset cur_charset); + MMModemCharset cur_charset, + gpointer log_object); gboolean mm_3gpp_parse_operator_id (const gchar *operator_id, guint16 *mcc, diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index a6bc72d2..9624c520 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -626,9 +626,10 @@ test_cops_response_motoc (void *f, gpointer d) static void test_cops_response_mf627a (void *f, gpointer d) { + /* The '@' in this string is ASCII 0x40, and 0x40 is a valid GSM-7 char: '¡' (which is 0xc2,0xa1 in UTF-8) */ const char *reply = "+COPS: (2,\"AT&T@\",\"AT&TD\",\"310410\",0),(3,\"Vstream Wireless\",\"VSTREAM\",\"31026\",0),"; static MM3gppNetworkInfo expected[] = { - { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, (gchar *) "AT&T@", (gchar *) "AT&TD", (gchar *) "310410", MM_MODEM_ACCESS_TECHNOLOGY_GSM }, + { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, (gchar *) "AT&T¡", (gchar *) "AT&TD", (gchar *) "310410", MM_MODEM_ACCESS_TECHNOLOGY_GSM }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN, (gchar *) "Vstream Wireless", (gchar *) "VSTREAM", (gchar *) "31026", MM_MODEM_ACCESS_TECHNOLOGY_GSM }, }; @@ -638,9 +639,10 @@ test_cops_response_mf627a (void *f, gpointer d) static void test_cops_response_mf627b (void *f, gpointer d) { + /* The '@' in this string is ASCII 0x40, and 0x40 is a valid GSM-7 char: '¡' (which is 0xc2,0xa1 in UTF-8) */ const char *reply = "+COPS: (2,\"AT&Tp\",\"AT&T@\",\"310410\",0),(3,\"\",\"\",\"31026\",0),"; static MM3gppNetworkInfo expected[] = { - { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, (gchar *) "AT&Tp", (gchar *) "AT&T@", (gchar *) "310410", MM_MODEM_ACCESS_TECHNOLOGY_GSM }, + { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, (gchar *) "AT&Tp", (gchar *) "AT&T¡", (gchar *) "310410", MM_MODEM_ACCESS_TECHNOLOGY_GSM }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN, NULL, NULL, (gchar *) "31026", MM_MODEM_ACCESS_TECHNOLOGY_GSM }, }; @@ -1041,7 +1043,7 @@ common_test_normalize_operator (const NormalizeOperatorTest *t) gchar *str; str = g_strdup (t->input); - mm_3gpp_normalize_operator (&str, t->charset); + mm_3gpp_normalize_operator (&str, t->charset, NULL); if (!t->normalized) g_assert (!str); else From b42a60e4803916352143a0fc14032fd7bd50a379 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 09:01:49 +0100 Subject: [PATCH 594/675] cinterion: rework band encoding to use str_to_utf8() Also providing support to report errors when attempting to decode the strings. (cherry picked from commit 6bc07b4b1487cfc6e171ec1f2c34958f17202a8b) --- .../cinterion/mm-modem-helpers-cinterion.c | 88 ++++++++++++++----- 1 file changed, 67 insertions(+), 21 deletions(-) diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index 05228815..543303a5 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -217,20 +217,34 @@ parse_bands (guint bandlist, } static guint -take_and_convert_from_matched_string (gchar *str, - MMModemCharset charset, - MMCinterionModemFamily modem_family) +take_and_convert_from_matched_string (gchar *str, + MMModemCharset charset, + MMCinterionModemFamily modem_family, + GError **error) { - guint val = 0; + guint val = 0; + g_autofree gchar *utf8 = NULL; + g_autofree gchar *taken_str = str; - if (!str) + if (!taken_str) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Couldn't convert to integer number: no input string"); return 0; + } - if (modem_family == MM_CINTERION_MODEM_FAMILY_IMT) - str = mm_charset_take_and_convert_to_utf8 (str, charset); + if (modem_family == MM_CINTERION_MODEM_FAMILY_IMT) { + utf8 = mm_modem_charset_str_to_utf8 (taken_str, -1, charset, FALSE, error); + if (!utf8) { + g_prefix_error (error, "Couldn't convert to integer number: "); + return 0; + } + } - mm_get_uint_from_hex_str (str, &val); - g_free (str); + if (!mm_get_uint_from_hex_str (utf8 ? utf8 : taken_str, &val)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't convert to integer number: wrong hex encoding: %s", utf8 ? utf8 : taken_str); + return 0; + } return val; } @@ -292,12 +306,16 @@ mm_cinterion_parse_scfg_test (const gchar *response, goto finish; } - r2 = g_regex_new ("\\^SCFG:\\s*\"Radio/Band/([234]G)\",\\(\"?([0-9A-Fa-fx]*)\"?-\"?([0-9A-Fa-fx]*)\"?\\)(,*\\(\"?([0-9A-Fa-fx]*)\"?-\"?([0-9A-Fa-fx]*)\"?\\))?", + r2 = g_regex_new ("\\^SCFG:\\s*\"Radio/Band/([234]G)\"," + "\\(\"?([0-9A-Fa-fx]*)\"?-\"?([0-9A-Fa-fx]*)\"?\\)" + "(,*\\(\"?([0-9A-Fa-fx]*)\"?-\"?([0-9A-Fa-fx]*)\"?\\))?", 0, 0, NULL); g_assert (r2 != NULL); + g_regex_match_full (r2, response, strlen (response), 0, 0, &match_info2, &inner_error); if (inner_error) goto finish; + while (g_match_info_matches (match_info2)) { g_autofree gchar *techstr = NULL; guint maxband; @@ -306,16 +324,28 @@ mm_cinterion_parse_scfg_test (const gchar *response, techstr = mm_get_string_unquoted_from_match_info (match_info2, 1); if (g_strcmp0 (techstr, "2G") == 0) { - maxband = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info2, 3), charset, modem_family); + maxband = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info2, 3), + charset, modem_family, &inner_error); + if (inner_error) + break; parse_bands (maxband, &bands, MM_CINTERION_RB_BLOCK_GSM, modem_family); } else if (g_strcmp0 (techstr, "3G") == 0) { - maxband = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info2, 3), charset, modem_family); + maxband = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info2, 3), + charset, modem_family, &inner_error); + if (inner_error) + break; parse_bands (maxband, &bands, MM_CINTERION_RB_BLOCK_UMTS, modem_family); } else if (g_strcmp0 (techstr, "4G") == 0) { - maxband = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info2, 3), charset, modem_family); + maxband = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info2, 3), + charset, modem_family, &inner_error); + if (inner_error) + break; parse_bands (maxband, &bands, MM_CINTERION_RB_BLOCK_LTE_LOW, modem_family); if (modem_family == MM_CINTERION_MODEM_FAMILY_DEFAULT) { - maxband = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info2, 6), charset, modem_family); + maxband = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info2, 6), + charset, modem_family, &inner_error); + if (inner_error) + break; parse_bands (maxband, &bands, MM_CINTERION_RB_BLOCK_LTE_HIGH, modem_family); } } else { @@ -407,9 +437,11 @@ mm_cinterion_parse_scfg_response (const gchar *response, if (format == MM_CINTERION_RADIO_BAND_FORMAT_SINGLE) { r = g_regex_new ("\\^SCFG:\\s*\"Radio/Band\",\\s*\"?([0-9a-fA-F]*)\"?", 0, 0, NULL); g_assert (r != NULL); + g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); if (inner_error) goto finish; + if (g_match_info_matches (match_info)) { g_autofree gchar *currentstr = NULL; guint current = 0; @@ -438,26 +470,40 @@ mm_cinterion_parse_scfg_response (const gchar *response, r = g_regex_new ("\\^SCFG:\\s*\"Radio/Band/([234]G)\",\"?([0-9A-Fa-fx]*)\"?,?\"?([0-9A-Fa-fx]*)?\"?", 0, 0, NULL); g_assert (r != NULL); + g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); if (inner_error) goto finish; + while (g_match_info_matches (match_info)) { g_autofree gchar *techstr = NULL; guint current; techstr = mm_get_string_unquoted_from_match_info (match_info, 1); - if (g_strcmp0(techstr, "2G") == 0) { - current = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info, 2), charset, modem_family); + if (g_strcmp0 (techstr, "2G") == 0) { + current = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info, 2), + charset, modem_family, &inner_error); + if (inner_error) + break; parse_bands (current, &bands, MM_CINTERION_RB_BLOCK_GSM, modem_family); - } else if (g_strcmp0(techstr, "3G") == 0) { - current = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info, 2), charset, modem_family); + } else if (g_strcmp0 (techstr, "3G") == 0) { + current = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info, 2), + charset, modem_family, &inner_error); + if (inner_error) + break; parse_bands (current, &bands, MM_CINTERION_RB_BLOCK_UMTS, modem_family); - } else if (g_strcmp0(techstr, "4G") == 0) { - current = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info, 2), charset, modem_family); + } else if (g_strcmp0 (techstr, "4G") == 0) { + current = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info, 2), + charset, modem_family, &inner_error); + if (inner_error) + break; parse_bands (current, &bands, MM_CINTERION_RB_BLOCK_LTE_LOW, modem_family); if (modem_family == MM_CINTERION_MODEM_FAMILY_DEFAULT) { - current = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info, 3), charset, modem_family); + current = take_and_convert_from_matched_string (mm_get_string_unquoted_from_match_info (match_info, 3), + charset, modem_family, &inner_error); + if (inner_error) + break; parse_bands (current, &bands, MM_CINTERION_RB_BLOCK_LTE_HIGH, modem_family); } } else { From a030ea61498e736b3ba8405ce8d6e5ea37045fa7 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 09:07:21 +0100 Subject: [PATCH 595/675] cinterion: rework mno decoding to use str_to_utf8() (cherry picked from commit ab4c31ec0b2c79285e24b9a117ff5e5c21f8fd71) --- plugins/cinterion/mm-modem-helpers-cinterion.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index 543303a5..cf18ea69 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -1523,9 +1523,15 @@ mm_cinterion_provcfg_response_to_cid (const gchar *response, mno = mm_get_string_unquoted_from_match_info (match_info, 1); if (mno && modem_family == MM_CINTERION_MODEM_FAMILY_IMT) { - mno = mm_charset_take_and_convert_to_utf8 (mno, charset); - mm_obj_dbg (log_object, "current mno: %s", mno); + gchar *mno_utf8; + + mno_utf8 = mm_modem_charset_str_to_utf8 (mno, -1, charset, FALSE, error); + if (!mno_utf8) + return FALSE; + g_free (mno); + mno = mno_utf8; } + mm_obj_dbg (log_object, "current mno: %s", mno ? mno : "none"); /* for Cinterion LTE modules, some CID numbers have special meaning. * This is dictated by the chipset and by the MNO: From abd41673a2f3ed9178c08975d223ba744970ac40 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 09:09:45 +0100 Subject: [PATCH 596/675] charsets: remove take_and_convert methods These methods worked in a very strict way for some encodings, and in a very very loose way for others. E.g. when converting from hex-encoded UCS-2, we would attempt to convert as much text as we could even if the input string was truly not even close to UCS-2. This kind of "do our best" could make sense when processing e.g. the operator name reported by the modem, as that is some string to show to the user and there may be no strict requirement to have it perfectly fine. But the kind of loose comparison done for UCS-2 doesn't make sense e.g. when converting USSD responses or SMS messages. (cherry picked from commit 0ff3eb7ee0106423519152a68de1621cedf567c8) --- src/mm-charsets.c | 208 ---------------------------------------------- src/mm-charsets.h | 5 -- 2 files changed, 213 deletions(-) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index 5c0eb6ad..c131ad41 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -701,214 +701,6 @@ mm_charset_gsm_pack (const guint8 *src, return packed; } -/* We do all our best to get the given string, which is possibly given in the - * specified charset, to UTF8. It may happen that the given string is really - * the hex representation of the charset-encoded string, so we need to cope with - * that case. */ -gchar * -mm_charset_take_and_convert_to_utf8 (gchar *str, - MMModemCharset charset) -{ - gchar *utf8 = NULL; - - if (!str) - return NULL; - - switch (charset) { - case MM_MODEM_CHARSET_UNKNOWN: - g_warn_if_reached (); - utf8 = str; - break; - - case MM_MODEM_CHARSET_GSM: - /* This is WRONG! GSM may have embedded NULs (character @)! */ - utf8 = (gchar *) charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str), FALSE, NULL); - g_free (str); - break; - - case MM_MODEM_CHARSET_8859_1: - case MM_MODEM_CHARSET_PCCP437: - case MM_MODEM_CHARSET_PCDN: { - const gchar *iconv_from; - GError *error = NULL; - - iconv_from = charset_iconv_from (charset); - utf8 = g_convert (str, strlen (str), - "UTF-8", iconv_from, - NULL, NULL, &error); - if (!utf8 || error) { - g_clear_error (&error); - utf8 = NULL; - } - - g_free (str); - break; - } - - case MM_MODEM_CHARSET_UCS2: - case MM_MODEM_CHARSET_UTF16: { - gsize len; - gboolean possibly_hex = TRUE; - gsize bread = 0, bwritten = 0; - - /* If the string comes in hex-UCS-2, len needs to be a multiple of 4 */ - len = strlen (str); - if ((len < 4) || ((len % 4) != 0)) - possibly_hex = FALSE; - else { - const gchar *p = str; - - /* All chars in the string must be hex */ - while (*p && possibly_hex) - possibly_hex = isxdigit (*p++); - } - - /* If hex, then we expect hex-encoded UCS-2 */ - if (possibly_hex) { - utf8 = mm_modem_charset_hex_to_utf8 (str, charset); - if (utf8) { - g_free (str); - break; - } - } - - /* If not hex, then it might be raw UCS-2 (very unlikely) or ASCII/UTF-8 - * (much more likely). Try to convert to UTF-8 and if that fails, use - * the partial conversion length to re-convert the part of the string - * that is UTF-8, if any. - */ - utf8 = g_convert (str, strlen (str), - "UTF-8", "UTF-8", - &bread, &bwritten, NULL); - - /* Valid conversion, or we didn't get enough valid UTF-8 */ - if (utf8 || (bwritten <= 2)) { - g_free (str); - break; - } - - /* Last try; chop off the original string at the conversion failure - * location and get what we can. - */ - str[bread] = '\0'; - utf8 = g_convert (str, strlen (str), - "UTF-8", "UTF-8", - NULL, NULL, NULL); - g_free (str); - break; - } - - /* If the given charset is ASCII or UTF8, we really expect the final string - * already here */ - case MM_MODEM_CHARSET_IRA: - case MM_MODEM_CHARSET_UTF8: - utf8 = str; - break; - - default: - g_assert_not_reached (); - } - - /* Validate UTF-8 always before returning. This result will be exposed in DBus - * very likely... */ - if (utf8 && !g_utf8_validate (utf8, -1, NULL)) { - /* Better return NULL than an invalid UTF-8 string */ - g_free (utf8); - utf8 = NULL; - } - - return utf8; -} - -/* We do all our best to convert the given string, which comes in UTF-8, to the - * specified charset. It may be that the output string needs to be the hex - * representation of the charset-encoded string, so we need to cope with that - * case. */ -gchar * -mm_utf8_take_and_convert_to_charset (gchar *str, - MMModemCharset charset) -{ - gchar *encoded = NULL; - - if (!str) - return NULL; - - /* Validate UTF-8 always before converting */ - if (!g_utf8_validate (str, -1, NULL)) { - /* Better return NULL than an invalid encoded string */ - g_free (str); - return NULL; - } - - switch (charset) { - case MM_MODEM_CHARSET_UNKNOWN: - g_warn_if_reached (); - encoded = str; - break; - - case MM_MODEM_CHARSET_GSM: - /* This is WRONG! GSM may have embedded NULs (character @)! */ - encoded = mm_modem_charset_str_from_utf8 (str, MM_MODEM_CHARSET_GSM, FALSE, NULL); - g_free (str); - break; - - case MM_MODEM_CHARSET_8859_1: - case MM_MODEM_CHARSET_PCCP437: - case MM_MODEM_CHARSET_PCDN: { - const gchar *iconv_to; - GError *error = NULL; - - iconv_to = charset_iconv_from (charset); - encoded = g_convert (str, strlen (str), - iconv_to, "UTF-8", - NULL, NULL, &error); - if (!encoded || error) { - g_clear_error (&error); - encoded = NULL; - } - - g_free (str); - break; - } - - case MM_MODEM_CHARSET_UCS2: - case MM_MODEM_CHARSET_UTF16: { - const gchar *iconv_to; - gsize encoded_len = 0; - GError *error = NULL; - gchar *hex; - - iconv_to = charset_iconv_from (charset); - encoded = g_convert (str, strlen (str), - iconv_to, "UTF-8", - NULL, &encoded_len, &error); - if (!encoded || error) { - g_clear_error (&error); - encoded = NULL; - } - - /* Get hex representation of the string */ - hex = mm_utils_bin2hexstr ((guint8 *)encoded, encoded_len); - g_free (encoded); - encoded = hex; - g_free (str); - break; - } - - /* If the given charset is ASCII or UTF8, we really expect the final string - * already here. */ - case MM_MODEM_CHARSET_IRA: - case MM_MODEM_CHARSET_UTF8: - encoded = str; - break; - - default: - g_assert_not_reached (); - } - - return encoded; -} - /*****************************************************************************/ /* Main conversion functions */ diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 37b39d7e..9cae5ddf 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -57,11 +57,6 @@ guint8 *mm_charset_gsm_pack (const guint8 *src, guint8 start_offset, /* in bits */ guint32 *out_packed_len); -gchar *mm_charset_take_and_convert_to_utf8 (gchar *str, - MMModemCharset charset); -gchar *mm_utf8_take_and_convert_to_charset (gchar *str, - MMModemCharset charset); - /*****************************************************************************************/ /* From 2e51229c6fb0e235ea0bc41997abb3220d54f974 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 09:14:21 +0100 Subject: [PATCH 597/675] charsets: remove charset_hex_to_utf8() No longer used, replaced by the new common conversion methods. (cherry picked from commit c84454c1b00da7d33cc4fd917be4be6756317488) --- src/mm-charsets.c | 41 ----------------------------------------- src/mm-charsets.h | 6 ------ 2 files changed, 47 deletions(-) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index c131ad41..ed351a81 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -87,47 +87,6 @@ mm_modem_charset_to_string (MMModemCharset charset) return settings ? settings->gsm_name : NULL; } -static const gchar * -charset_iconv_from (MMModemCharset charset) -{ - const CharsetSettings *settings; - - settings = lookup_charset_settings (charset); - return settings ? settings->iconv_name : NULL; -} - -gchar * -mm_modem_charset_hex_to_utf8 (const gchar *src, - MMModemCharset charset) -{ - const gchar *iconv_from; - g_autofree guint8 *unconverted = NULL; - g_autofree gchar *converted = NULL; - g_autoptr(GError) error = NULL; - gsize unconverted_len = 0; - - g_return_val_if_fail (src != NULL, NULL); - g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); - - iconv_from = charset_iconv_from (charset); - g_return_val_if_fail (iconv_from != NULL, FALSE); - - unconverted = mm_utils_hexstr2bin (src, -1, &unconverted_len, NULL); - if (!unconverted) - return NULL; - - if (charset == MM_MODEM_CHARSET_UTF8 || charset == MM_MODEM_CHARSET_IRA) - return g_steal_pointer (&unconverted); - - converted = g_convert ((const gchar *)unconverted, unconverted_len, - "UTF-8", iconv_from, - NULL, NULL, &error); - if (!converted || error) - return NULL; - - return g_steal_pointer (&converted); -} - /******************************************************************************/ /* GSM 03.38 encoding conversion stuff */ diff --git a/src/mm-charsets.h b/src/mm-charsets.h index 9cae5ddf..6db481cd 100644 --- a/src/mm-charsets.h +++ b/src/mm-charsets.h @@ -37,12 +37,6 @@ MMModemCharset mm_modem_charset_from_string (const gchar *string); /*****************************************************************************************/ -/* Take a string in hex representation ("00430052" or "A4BE11" for example) - * and convert it from the given character set to UTF-8. - */ -gchar *mm_modem_charset_hex_to_utf8 (const gchar *src, - MMModemCharset charset); - /* Checks whether conversion to the given charset may be done without errors */ gboolean mm_charset_can_convert_to (const gchar *utf8, MMModemCharset charset); From 8a1f79bd5d5e2e0f1aa1b00901cbd84aa8e8729f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 14 Feb 2021 22:23:07 +0100 Subject: [PATCH 598/675] charsets: define common translit fallback character (cherry picked from commit 8a8e00168b02c5064f01d5da20a97c7268ba1e2b) --- src/mm-charsets.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mm-charsets.c b/src/mm-charsets.c index ed351a81..5430e253 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -27,6 +27,9 @@ #include "mm-charsets.h" #include "mm-log.h" +/* Common fallback character when transliteration is enabled */ +static const gchar *translit_fallback = "?"; + /******************************************************************************/ /* Expected charset settings */ @@ -209,13 +212,12 @@ utf8_to_gsm_def_char (const gchar *utf8, static gboolean translit_gsm_nul_byte (GByteArray *gsm) { - static const gchar *replacement = "?"; - guint i; - guint n_replaces = 0; + guint i; + guint n_replaces = 0; for (i = 0; i < gsm->len; i++) { if (gsm->data[i] == 0x00) { - utf8_to_gsm_def_char (replacement, 1, &gsm->data[i]); + utf8_to_gsm_def_char (translit_fallback, strlen (translit_fallback), &gsm->data[i]); n_replaces++; } } @@ -333,7 +335,7 @@ charset_gsm_unpacked_to_utf8 (const guint8 *gsm, if (ulen) g_byte_array_append (utf8, &uchars[0], ulen); else if (translit) - g_byte_array_append (utf8, (guint8 *) "?", 1); + g_byte_array_append (utf8, (guint8 *) translit_fallback, strlen (translit_fallback)); else { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, "Invalid conversion from GSM7"); @@ -690,7 +692,7 @@ charset_iconv_from_utf8 (const gchar *utf8, } encoded = (guint8 *) g_convert_with_fallback (utf8, -1, - settings->iconv_name, "UTF-8", "?", + settings->iconv_name, "UTF-8", translit_fallback, NULL, &bytes_written, error); if (encoded) { if (out_size) @@ -812,7 +814,7 @@ charset_iconv_to_utf8 (const guint8 *data, } utf8 = g_convert_with_fallback ((const gchar *) data, len, - "UTF-8", settings->iconv_name, "?", + "UTF-8", settings->iconv_name, translit_fallback, NULL, NULL, error); if (utf8) return g_steal_pointer (&utf8); From b69da9d037d4857ad22a5efdb3bb9d1f494e4f21 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 18 Mar 2021 11:20:02 +0100 Subject: [PATCH 599/675] base-modem: plug leaks when organizing ports The GLists maintained in the logic need to be explicitly freed (just the lists, not the list contents) if we exit early on error or if we end up deciding that the specific ports are available but unsupported by the plugin (e.g. if a plugin that doesn't support net ports finds net ports in the modem). ==225333== 24 bytes in 1 blocks are definitely lost in loss record 2,024 of 5,525 ==225333== at 0x483E77F: malloc (vg_replace_malloc.c:307) ==225333== by 0x506C539: g_malloc (in /usr/lib/libglib-2.0.so.0.6600.7) ==225333== by 0x508DC8F: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.6600.7) ==225333== by 0x50636B4: g_list_append (in /usr/lib/libglib-2.0.so.0.6600.7) ==225333== by 0x17E671: mm_base_modem_organize_ports (mm-base-modem.c:1298) ==225333== by 0x1E4409: mm_plugin_create_modem (mm-plugin.c:1094) ==225333== by 0x162C81: mm_device_create_modem (mm-device.c:481) ==225333== by 0x15DE60: device_support_check_ready (mm-base-manager.c:218) ==225333== by 0x4EA8173: ??? (in /usr/lib/libgio-2.0.so.0.6600.7) ==225333== by 0x4EAC6E8: ??? (in /usr/lib/libgio-2.0.so.0.6600.7) ==225333== by 0x16730F: device_context_run_ready (mm-plugin-manager.c:1533) ==225333== by 0x4EA8173: ??? (in /usr/lib/libgio-2.0.so.0.6600.7) (cherry picked from commit ab007a449638eeacaf6f626b707842af5274db95) --- src/mm-base-modem.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index e5030dcb..33b626b9 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -912,15 +912,17 @@ mm_base_modem_organize_ports (MMBaseModem *self, MMPortSerialGps *gps = NULL; MMPortSerial *audio = NULL; MMPortSerialAt *data_at_primary = NULL; - GList *data_at = NULL; - GList *data_net = NULL; + GList *l; + /* These lists don't keep full references, so they should be + * g_list_free()-ed on error exits */ + g_autoptr(GList) data_at = NULL; + g_autoptr(GList) data_net = NULL; #if defined WITH_QMI - GList *qmi = NULL; + g_autoptr(GList) qmi = NULL; #endif #if defined WITH_MBIM - GList *mbim = NULL; + g_autoptr(GList) mbim = NULL; #endif - GList *l; g_return_val_if_fail (MM_IS_BASE_MODEM (self), FALSE); @@ -1144,26 +1146,27 @@ mm_base_modem_organize_ports (MMBaseModem *self, /* Build the final list of data ports, NET ports preferred */ if (data_net) { g_list_foreach (data_net, (GFunc)g_object_ref, NULL); - self->priv->data = g_list_concat (self->priv->data, data_net); + self->priv->data = g_list_concat (self->priv->data, g_steal_pointer (&data_net)); } + if (data_at_primary) self->priv->data = g_list_append (self->priv->data, g_object_ref (data_at_primary)); if (data_at) { g_list_foreach (data_at, (GFunc)g_object_ref, NULL); - self->priv->data = g_list_concat (self->priv->data, data_at); + self->priv->data = g_list_concat (self->priv->data, g_steal_pointer (&data_at)); } #if defined WITH_QMI if (qmi) { g_list_foreach (qmi, (GFunc)g_object_ref, NULL); - self->priv->qmi = qmi; + self->priv->qmi = g_steal_pointer (&qmi); } #endif #if defined WITH_MBIM if (mbim) { g_list_foreach (mbim, (GFunc)g_object_ref, NULL); - self->priv->mbim = mbim; + self->priv->mbim = g_steal_pointer (&mbim); } #endif From 6c0d96129702e4babdd98255dacaa278633ecd0a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 23 Mar 2021 15:36:58 +0100 Subject: [PATCH 600/675] kerneldevice,udev: don't use autoptr in GUdev types The autoptr support in all GUdev types was introduced in commit 272533131c6ed38479a88805, included in libgudev 232. In the MM 1.16 branch we depend on libgudev 147, so avoid implicitly bumping the required version. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/349 --- src/kerneldevice/mm-kernel-device-udev.c | 30 +++++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/kerneldevice/mm-kernel-device-udev.c b/src/kerneldevice/mm-kernel-device-udev.c index f75104bd..a6bf1a71 100644 --- a/src/kerneldevice/mm-kernel-device-udev.c +++ b/src/kerneldevice/mm-kernel-device-udev.c @@ -81,7 +81,7 @@ static void preload_contents_platform (MMKernelDeviceUdev *self, const gchar *platform) { - g_autoptr(GUdevDevice) iter = NULL; + GUdevDevice *iter; iter = g_object_ref (self->priv->device); while (iter) { @@ -102,17 +102,19 @@ preload_contents_platform (MMKernelDeviceUdev *self, g_clear_object (&iter); iter = parent; } + + g_clear_object (&iter); } static void preload_contents_pcmcia (MMKernelDeviceUdev *self) { - g_autoptr(GUdevDevice) iter = NULL; - gboolean pcmcia_subsystem_found = FALSE; + GUdevDevice *iter; + gboolean pcmcia_subsystem_found = FALSE; iter = g_object_ref (self->priv->device); while (iter) { - g_autoptr(GUdevDevice) parent = NULL; + GUdevDevice *parent; /* Store the first driver found */ if (!self->priv->driver) @@ -133,18 +135,21 @@ preload_contents_pcmcia (MMKernelDeviceUdev *self) self->priv->product = udev_device_get_sysfs_attr_as_hex (iter, "card_id"); self->priv->physdev = g_object_ref (iter); /* stop traversing as soon as the physical device is found */ + g_clear_object (&parent); break; } g_clear_object (&iter); - iter = g_steal_pointer (&parent); + iter = parent; } + + g_clear_object (&iter); } static void preload_contents_pci (MMKernelDeviceUdev *self) { - g_autoptr(GUdevDevice) iter = NULL; + GUdevDevice *iter; iter = g_object_ref (self->priv->device); while (iter) { @@ -170,12 +175,14 @@ preload_contents_pci (MMKernelDeviceUdev *self) g_clear_object (&iter); iter = parent; } + + g_clear_object (&iter); } static void preload_contents_usb (MMKernelDeviceUdev *self) { - g_autoptr(GUdevDevice) iter = NULL; + GUdevDevice *iter; iter = g_object_ref (self->priv->device); while (iter) { @@ -204,12 +211,14 @@ preload_contents_usb (MMKernelDeviceUdev *self) g_clear_object (&iter); iter = parent; } + + g_clear_object (&iter); } static gchar * find_device_bus_subsystem (MMKernelDeviceUdev *self) { - g_autoptr(GUdevDevice) iter = NULL; + GUdevDevice *iter; iter = g_object_ref (self->priv->device); while (iter) { @@ -224,8 +233,10 @@ find_device_bus_subsystem (MMKernelDeviceUdev *self) (g_strcmp0 (subsys, "pci") == 0) || (g_strcmp0 (subsys, "platform") == 0) || (g_strcmp0 (subsys, "pnp") == 0) || - (g_strcmp0 (subsys, "sdio") == 0)) + (g_strcmp0 (subsys, "sdio") == 0)) { + g_clear_object (&iter); return g_strdup (subsys); + } parent = g_udev_device_get_parent (iter); g_clear_object (&iter); @@ -233,6 +244,7 @@ find_device_bus_subsystem (MMKernelDeviceUdev *self) } /* no more parents to check */ + g_clear_object (&iter); return NULL; } From 70f4677c211ccbb278eff65dc56a5ea9b0b34085 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 21 Mar 2021 11:24:18 +0100 Subject: [PATCH 601/675] cinterion: allow '*' in Prov/Cfg response E.g. in a Cinterion PLS8-E (REVISION 04.004) to match the following line: ^SCFG: "MEopMode/Prov/Cfg","fallback*" Fix suggested by Jan Mazura. See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/347 (cherry picked from commit 5285e958abcd734de73a13011b5243bcfdf4d20c) --- plugins/cinterion/mm-modem-helpers-cinterion.c | 2 +- plugins/cinterion/tests/test-modem-helpers-cinterion.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index cf18ea69..9e34a69f 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -1515,7 +1515,7 @@ mm_cinterion_provcfg_response_to_cid (const gchar *response, g_autoptr(GMatchInfo) match_info = NULL; g_autofree gchar *mno = NULL; - r = g_regex_new ("\\^SCFG:\\s*\"MEopMode/Prov/Cfg\",\\s*\"([0-9a-zA-Z]*)\"", 0, 0, NULL); + r = g_regex_new ("\\^SCFG:\\s*\"MEopMode/Prov/Cfg\",\\s*\"([0-9a-zA-Z*]*)\"", 0, 0, NULL); g_assert (r != NULL); if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, error)) diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c index 1227a70f..25e08473 100644 --- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c +++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c @@ -1636,6 +1636,11 @@ static const ProvcfgResponseTest provcfg_response_tests[] = { .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"tmode\"", .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, .expected_cid = 2, + }, + { + .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"fallback*\"", + .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .expected_cid = 1, } }; From efef1132101345f48bfe9102ddebed194b3c6cd6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 21 Mar 2021 13:05:27 +0100 Subject: [PATCH 602/675] cinterion: make sure FALSE sets GError in provcfg_response_to_cid() The g_regex_match_full() method may return FALSE without setting the GError, so that case needs to be considered. Reported by Jan Mazura. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/347 (cherry picked from commit d01bca493dad933b9df51bec1254c79089ffa1c7) --- .../cinterion/mm-modem-helpers-cinterion.c | 14 +++++++++- .../tests/test-modem-helpers-cinterion.c | 27 +++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index 9e34a69f..d397e423 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -1514,12 +1514,24 @@ mm_cinterion_provcfg_response_to_cid (const gchar *response, g_autoptr(GRegex) r = NULL; g_autoptr(GMatchInfo) match_info = NULL; g_autofree gchar *mno = NULL; + GError *inner_error = NULL; r = g_regex_new ("\\^SCFG:\\s*\"MEopMode/Prov/Cfg\",\\s*\"([0-9a-zA-Z*]*)\"", 0, 0, NULL); g_assert (r != NULL); - if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, error)) + g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); + + if (inner_error) { + g_prefix_error (&inner_error, "Failed to match Prov/Cfg response: "); + g_propagate_error (error, inner_error); + return FALSE; + } + + if (!g_match_info_matches (match_info)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't match Prov/Cfg response"); return FALSE; + } mno = mm_get_string_unquoted_from_match_info (match_info, 1); if (mno && modem_family == MM_CINTERION_MODEM_FAMILY_IMT) { diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c index 25e08473..8ea7d909 100644 --- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c +++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c @@ -1602,45 +1602,57 @@ test_smoni_response_to_signal (void) typedef struct { const gchar *str; MMCinterionModemFamily modem_family; - gdouble expected_cid; + gboolean success; + guint expected_cid; } ProvcfgResponseTest; - static const ProvcfgResponseTest provcfg_response_tests[] = { { .str = "^SCFG: \"MEopMode/Prov/Cfg\",\"vdfde\"", .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .success = TRUE, .expected_cid = 1, }, { .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"attus\"", .modem_family = MM_CINTERION_MODEM_FAMILY_IMT, + .success = TRUE, .expected_cid = 1, }, { .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"2\"", .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .success = TRUE, .expected_cid = 3, }, { .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"vzwdcus\"", .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .success = TRUE, .expected_cid = 3, }, { .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"tmode\"", .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .success = TRUE, .expected_cid = 2, }, { .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"fallback*\"", .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .success = TRUE, .expected_cid = 1, + }, + { + /* commas not allowed by the regex */ + .str = "* ^SCFG: \"MEopMode/Prov/Cfg\",\"something,with,commas\"", + .modem_family = MM_CINTERION_MODEM_FAMILY_DEFAULT, + .success = FALSE, } }; @@ -1660,9 +1672,14 @@ test_provcfg_response (void) NULL, &cid, &error); - g_assert_no_error (error); - g_assert (result); - g_assert_cmpuint (cid, ==, provcfg_response_tests[i].expected_cid); + if (provcfg_response_tests[i].success) { + g_assert_no_error (error); + g_assert (result); + g_assert_cmpuint (cid, ==, provcfg_response_tests[i].expected_cid); + } else { + g_assert (error); + g_assert (!result); + } } } From c5a86261cc1352d040313efa47247821a8d792cf Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 21 Mar 2021 13:44:16 +0100 Subject: [PATCH 603/675] cinterion: make sure FALSE sets GError in parse_smong_response() The g_regex_match_full() method may return FALSE without setting the GError, so that case needs to be considered. In addition to that, the following g_assert() was not doing what it should have been, as it was comparing the address of the variable and not the variable itself; rework the code to avoid that as well: g_assert (access_tech != MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN); (cherry picked from commit 634682b602dd51efbda42a8b2e8764b9bb0024e2) --- .../cinterion/mm-modem-helpers-cinterion.c | 48 +++++++++---------- .../tests/test-modem-helpers-cinterion.c | 29 +++++++++-- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index d397e423..67da6120 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -940,19 +940,23 @@ mm_cinterion_parse_sgauth_response (const gchar *response, /*****************************************************************************/ /* ^SMONG response parser */ -static MMModemAccessTechnology -get_access_technology_from_smong_gprs_status (guint gprs_status, - GError **error) +static gboolean +get_access_technology_from_smong_gprs_status (guint gprs_status, + MMModemAccessTechnology *out, + GError **error) { switch (gprs_status) { case 0: - return MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; + *out = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; + return TRUE; case 1: case 2: - return MM_MODEM_ACCESS_TECHNOLOGY_GPRS; + *out = MM_MODEM_ACCESS_TECHNOLOGY_GPRS; + return TRUE; case 3: case 4: - return MM_MODEM_ACCESS_TECHNOLOGY_EDGE; + *out = MM_MODEM_ACCESS_TECHNOLOGY_EDGE; + return TRUE; default: break; } @@ -963,7 +967,7 @@ get_access_technology_from_smong_gprs_status (guint gprs_status, "Couldn't get network capabilities, " "unsupported GPRS status value: '%u'", gprs_status); - return MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; + return FALSE; } gboolean @@ -971,9 +975,10 @@ mm_cinterion_parse_smong_response (const gchar *response, MMModemAccessTechnology *access_tech, GError **error) { - GError *inner_error = NULL; - GMatchInfo *match_info = NULL; - GRegex *regex; + guint value = 0; + GError *inner_error = NULL; + g_autoptr(GMatchInfo) match_info = NULL; + g_autoptr(GRegex) regex; /* The AT^SMONG command returns a cell info table, where the second * column identifies the "GPRS status", which is exactly what we want. @@ -992,26 +997,21 @@ mm_cinterion_parse_smong_response (const gchar *response, 0, NULL); g_assert (regex); - if (g_regex_match_full (regex, response, strlen (response), 0, 0, &match_info, &inner_error)) { - guint value = 0; - - if (!mm_get_uint_from_match_info (match_info, 2, &value)) - inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Couldn't read 'GPRS status' field from AT^SMONG response"); - else if (access_tech) - *access_tech = get_access_technology_from_smong_gprs_status (value, &inner_error); - } - - g_match_info_free (match_info); - g_regex_unref (regex); + g_regex_match_full (regex, response, strlen (response), 0, 0, &match_info, &inner_error); if (inner_error) { + g_prefix_error (&inner_error, "Failed to match AT^SMONG response: "); g_propagate_error (error, inner_error); return FALSE; } - g_assert (access_tech != MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN); - return TRUE; + if (!g_match_info_matches (match_info) || !mm_get_uint_from_match_info (match_info, 2, &value)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Couldn't read 'GPRS status' field from AT^SMONG response"); + return FALSE; + } + + return get_access_technology_from_smong_gprs_status (value, access_tech, error); } /*****************************************************************************/ diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c index 8ea7d909..efd19b38 100644 --- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c +++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c @@ -1134,6 +1134,7 @@ test_sind_response_simstatus (void) static void common_test_smong_response (const gchar *response, + gboolean success, MMModemAccessTechnology expected_access_tech) { GError *error = NULL; @@ -1141,10 +1142,15 @@ common_test_smong_response (const gchar *response, MMModemAccessTechnology access_tech; res = mm_cinterion_parse_smong_response (response, &access_tech, &error); - g_assert_no_error (error); - g_assert (res == TRUE); - g_assert_cmpuint (access_tech, ==, expected_access_tech); + if (success) { + g_assert_no_error (error); + g_assert (res); + g_assert_cmpuint (access_tech, ==, expected_access_tech); + } else { + g_assert (error); + g_assert (!res); + } } static void @@ -1155,7 +1161,7 @@ test_smong_response_tc63i (void) "GPRS Monitor\r\n" "BCCH G PBCCH PAT MCC MNC NOM TA RAC # Cell #\r\n" "0073 1 - - 262 02 2 00 01\r\n"; - common_test_smong_response (response, MM_MODEM_ACCESS_TECHNOLOGY_GPRS); + common_test_smong_response (response, TRUE, MM_MODEM_ACCESS_TECHNOLOGY_GPRS); } static void @@ -1167,7 +1173,19 @@ test_smong_response_other (void) "\r\n" "BCCH G PBCCH PAT MCC MNC NOM TA RAC # Cell #\r\n" " 44 1 - - 234 10 - - - \r\n"; - common_test_smong_response (response, MM_MODEM_ACCESS_TECHNOLOGY_GPRS); + common_test_smong_response (response, TRUE, MM_MODEM_ACCESS_TECHNOLOGY_GPRS); +} + +static void +test_smong_response_no_match (void) +{ + const gchar *response = + "\r\n" + "GPRS Monitor\r\n" + "\r\n" + "BCCH K PBCCH PAT MCC MNC NOM TA RAC # Cell #\r\n" + " 44 1 - - 234 10 - - - \r\n"; + common_test_smong_response (response, FALSE, MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN); } /*****************************************************************************/ @@ -1757,6 +1775,7 @@ int main (int argc, char **argv) g_test_add_func ("/MM/cinterion/sind/response/simstatus", test_sind_response_simstatus); g_test_add_func ("/MM/cinterion/smong/response/tc63i", test_smong_response_tc63i); g_test_add_func ("/MM/cinterion/smong/response/other", test_smong_response_other); + g_test_add_func ("/MM/cinterion/smong/response/no-match", test_smong_response_no_match); g_test_add_func ("/MM/cinterion/slcc/urc/empty", test_slcc_urc_empty); g_test_add_func ("/MM/cinterion/slcc/urc/single", test_slcc_urc_single); g_test_add_func ("/MM/cinterion/slcc/urc/multiple", test_slcc_urc_multiple); From eed71a6048de040816f81dcf2031ece6fd7eb679 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 12 Mar 2021 17:44:44 +0100 Subject: [PATCH 604/675] base-bearer: ignore forced disconnections If using PPP, ModemManager is never in charge of deciding when the connection is finished, because that would end up making ModemManager try to use the TTY port while pppd is still using it. When the modem goes unregistered for some time, we should not force the disconnection of the bearer object, we still need to wait for pppd to tell us the modem is disconnected. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/331 (cherry picked from commit 3e58fbe547115bd875754806340b3bb39cc7b053) --- src/mm-base-bearer.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mm-base-bearer.c b/src/mm-base-bearer.c index 163f0bd7..7510fe19 100644 --- a/src/mm-base-bearer.c +++ b/src/mm-base-bearer.c @@ -1321,6 +1321,11 @@ mm_base_bearer_disconnect_force (MMBaseBearer *self) self->priv->status == MM_BEARER_STATUS_DISCONNECTED) return; + if (self->priv->ignore_disconnection_reports) { + mm_obj_dbg (self, "disconnection should be forced but it's explicitly ignored"); + return; + } + mm_obj_dbg (self, "forcing disconnection"); /* If currently connecting, try to cancel that operation. */ From 99bffc03cff060a752c0c9a4af0e7d06847c0c00 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 24 Mar 2021 11:00:22 +0100 Subject: [PATCH 605/675] libmm-glib,bearer-properties: fix 'allowed-auth' comparison (cherry picked from commit 4b19b9693f03ab48c6707508d27b24e38294e022) --- libmm-glib/mm-bearer-properties.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c index 4305cec7..4c8729f0 100644 --- a/libmm-glib/mm-bearer-properties.c +++ b/libmm-glib/mm-bearer-properties.c @@ -752,7 +752,7 @@ mm_bearer_properties_cmp (MMBearerProperties *a, return FALSE; if (!cmp_ip_type (a->priv->ip_type, b->priv->ip_type, flags)) return FALSE; - if (!cmp_allowed_auth (a->priv->allowed_auth, a->priv->allowed_auth, flags)) + if (!cmp_allowed_auth (a->priv->allowed_auth, b->priv->allowed_auth, flags)) return FALSE; if (!cmp_str (a->priv->user, b->priv->user, flags)) return FALSE; From 15cd1d7003c6a4942e31c57a658029ba36c27c2f Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Tue, 16 Mar 2021 19:28:09 +0100 Subject: [PATCH 606/675] quectel: ignore QGPSURC QGPSURCs are not ignored and causes calls to be rejected in some cases (cherry picked from commit 192e067f97153125fe9d3362c750146a5a7215cf) --- .../quectel/mm-broadband-modem-qmi-quectel.c | 10 ++++ plugins/quectel/mm-broadband-modem-quectel.c | 10 ++++ plugins/quectel/mm-shared-quectel.c | 48 ++++++++++++++++++- plugins/quectel/mm-shared-quectel.h | 7 ++- 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/plugins/quectel/mm-broadband-modem-qmi-quectel.c b/plugins/quectel/mm-broadband-modem-qmi-quectel.c index 9548c46c..60ac668d 100644 --- a/plugins/quectel/mm-broadband-modem-qmi-quectel.c +++ b/plugins/quectel/mm-broadband-modem-qmi-quectel.c @@ -75,6 +75,12 @@ peek_parent_modem_interface (MMSharedQuectel *self) return iface_modem_parent; } +static MMBroadbandModemClass * +peek_parent_broadband_modem_class (MMSharedQuectel *self) +{ + return MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_qmi_quectel_parent_class); +} + static void iface_modem_firmware_init (MMIfaceModemFirmware *iface) { @@ -113,9 +119,13 @@ shared_quectel_init (MMSharedQuectel *iface) { iface->peek_parent_modem_interface = peek_parent_modem_interface; iface->peek_parent_modem_location_interface = peek_parent_modem_location_interface; + iface->peek_parent_broadband_modem_class = peek_parent_broadband_modem_class; } static void mm_broadband_modem_qmi_quectel_class_init (MMBroadbandModemQmiQuectelClass *klass) { + MMBroadbandModemClass *broadband_modem_class = MM_BROADBAND_MODEM_CLASS (klass); + + broadband_modem_class->setup_ports = mm_shared_quectel_setup_ports; } diff --git a/plugins/quectel/mm-broadband-modem-quectel.c b/plugins/quectel/mm-broadband-modem-quectel.c index ae2b7234..e205b33d 100644 --- a/plugins/quectel/mm-broadband-modem-quectel.c +++ b/plugins/quectel/mm-broadband-modem-quectel.c @@ -75,6 +75,12 @@ peek_parent_modem_interface (MMSharedQuectel *self) return iface_modem_parent; } +static MMBroadbandModemClass * +peek_parent_broadband_modem_class (MMSharedQuectel *self) +{ + return MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_quectel_parent_class); +} + static void iface_modem_firmware_init (MMIfaceModemFirmware *iface) { @@ -113,9 +119,13 @@ shared_quectel_init (MMSharedQuectel *iface) { iface->peek_parent_modem_interface = peek_parent_modem_interface; iface->peek_parent_modem_location_interface = peek_parent_modem_location_interface; + iface->peek_parent_broadband_modem_class = peek_parent_broadband_modem_class; } static void mm_broadband_modem_quectel_class_init (MMBroadbandModemQuectelClass *klass) { + MMBroadbandModemClass *broadband_modem_class = MM_BROADBAND_MODEM_CLASS (klass); + + broadband_modem_class->setup_ports = mm_shared_quectel_setup_ports; } diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index 0274fbe1..61373db6 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -43,13 +43,22 @@ typedef enum { } FeatureSupport; typedef struct { + MMBroadbandModemClass *broadband_modem_class_parent; MMIfaceModem *iface_modem_parent; MMIfaceModemLocation *iface_modem_location_parent; MMModemLocationSource provided_sources; MMModemLocationSource enabled_sources; FeatureSupport qgps_supported; + GRegex *qgpsurc_regex; } Private; +static void +private_free (Private *priv) +{ + g_regex_unref (priv->qgpsurc_regex); + g_slice_free (Private, priv); +} + static Private * get_private (MMSharedQuectel *self) { @@ -65,6 +74,10 @@ get_private (MMSharedQuectel *self) priv->provided_sources = MM_MODEM_LOCATION_SOURCE_NONE; priv->enabled_sources = MM_MODEM_LOCATION_SOURCE_NONE; priv->qgps_supported = FEATURE_SUPPORT_UNKNOWN; + priv->qgpsurc_regex = g_regex_new ("\\r\\n\\+QGPSURC:.*", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + + g_assert (MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_broadband_modem_class); + priv->broadband_modem_class_parent = MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_broadband_modem_class (self); g_assert (MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_modem_location_interface); priv->iface_modem_location_parent = MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_modem_location_interface (self); @@ -72,11 +85,44 @@ get_private (MMSharedQuectel *self) g_assert (MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_modem_interface); priv->iface_modem_parent = MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_modem_interface (self); - g_object_set_qdata (G_OBJECT (self), private_quark, priv); + g_object_set_qdata_full (G_OBJECT (self), private_quark, priv, (GDestroyNotify)private_free); } return priv; } +/*****************************************************************************/ +/* Setup ports (Broadband modem class) */ + +void +mm_shared_quectel_setup_ports (MMBroadbandModem *self) +{ + Private *priv; + MMPortSerialAt *ports[2]; + guint i; + + priv = get_private (MM_SHARED_QUECTEL (self)); + g_assert (priv->broadband_modem_class_parent); + g_assert (priv->broadband_modem_class_parent->setup_ports); + + /* Parent setup always first */ + priv->broadband_modem_class_parent->setup_ports (self); + + ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); + + /* Enable/disable unsolicited events in given port */ + for (i = 0; i < G_N_ELEMENTS (ports); i++) { + if (!ports[i]) + continue; + + /* Ignore +QGPSURC */ + mm_port_serial_at_add_unsolicited_msg_handler ( + ports[i], + priv->qgpsurc_regex, + NULL, NULL, NULL); + } +} + /*****************************************************************************/ /* Firmware update settings loading (Firmware interface) */ diff --git a/plugins/quectel/mm-shared-quectel.h b/plugins/quectel/mm-shared-quectel.h index 1a49c29b..f9266c06 100644 --- a/plugins/quectel/mm-shared-quectel.h +++ b/plugins/quectel/mm-shared-quectel.h @@ -37,12 +37,15 @@ typedef struct _MMSharedQuectel MMSharedQuectel; struct _MMSharedQuectel { GTypeInterface g_iface; - MMIfaceModem * (* peek_parent_modem_interface) (MMSharedQuectel *self); - MMIfaceModemLocation * (* peek_parent_modem_location_interface) (MMSharedQuectel *self); + MMBroadbandModemClass * (* peek_parent_broadband_modem_class) (MMSharedQuectel *self); + MMIfaceModem * (* peek_parent_modem_interface) (MMSharedQuectel *self); + MMIfaceModemLocation * (* peek_parent_modem_location_interface) (MMSharedQuectel *self); }; GType mm_shared_quectel_get_type (void); +void mm_shared_quectel_setup_ports (MMBroadbandModem *self); + void mm_shared_quectel_firmware_load_update_settings (MMIfaceModemFirmware *self, GAsyncReadyCallback callback, gpointer user_data); From b0021c3e8c02ed595e651dd4a7561cdeaef647c0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 24 Mar 2021 21:47:54 +0100 Subject: [PATCH 607/675] iface-modem: avoid lock info update if no interface skeleton available Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/351 (cherry picked from commit 96d83392a850b84888661f68cb170dd87fcd3c85) --- src/mm-iface-modem.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 2e9a3004..1436bf4f 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -3670,9 +3670,6 @@ mm_iface_modem_update_lock_info (MMIfaceModem *self, GTask *task; ctx = g_slice_new0 (UpdateLockInfoContext); - g_object_get (self, - MM_IFACE_MODEM_DBUS_SKELETON, &ctx->skeleton, - NULL); /* If the given lock is known, we will avoid re-asking for it */ ctx->lock = known_lock; @@ -3680,6 +3677,19 @@ mm_iface_modem_update_lock_info (MMIfaceModem *self, task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, ctx, (GDestroyNotify)update_lock_info_context_free); + g_object_get (self, + MM_IFACE_MODEM_DBUS_SKELETON, &ctx->skeleton, + NULL); + + if (!ctx->skeleton) { + g_task_return_new_error (task, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't get interface skeleton"); + g_object_unref (task); + return; + } + update_lock_info_context_step (task); } From 124c2c672b773a366decec223aa8bec33f8bbd80 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 24 Mar 2021 21:50:42 +0100 Subject: [PATCH 608/675] iface-modem: avoid check for SIM swap if no interface skeleton available (cherry picked from commit 9f7bbf28d210a4986f2d0d353e4e37024bc91c4a) --- src/mm-iface-modem.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 1436bf4f..7a84a6d2 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -98,7 +98,14 @@ mm_iface_modem_check_for_sim_swap (MMIfaceModem *self, MM_IFACE_MODEM_DBUS_SKELETON, &skeleton, NULL); - g_assert (skeleton); + if (!skeleton) { + g_task_return_new_error (task, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't get interface skeleton"); + g_object_unref (task); + return; + } primary_slot = mm_gdbus_modem_get_primary_sim_slot (MM_GDBUS_MODEM (skeleton)); g_object_unref (skeleton); From ab6033e9582ec79a8e0c0a7735a4dbad0e3f8a6b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 8 Apr 2021 22:40:20 +0200 Subject: [PATCH 609/675] libmm-glib,bearer-properties: fix usage of CMP_FLAGS_NO_RM_PROTOCOL (cherry picked from commit 3d665d22093b985f6860170bca8d33a5562056d1) --- libmm-glib/mm-bearer-properties.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c index 4c8729f0..41b12f5d 100644 --- a/libmm-glib/mm-bearer-properties.c +++ b/libmm-glib/mm-bearer-properties.c @@ -764,8 +764,10 @@ mm_bearer_properties_cmp (MMBearerProperties *a, if (a->priv->allow_roaming_set != b->priv->allow_roaming_set) return FALSE; } - if (a->priv->rm_protocol != b->priv->rm_protocol) - return FALSE; + if (!(flags & MM_BEARER_PROPERTIES_CMP_FLAGS_NO_RM_PROTOCOL)) { + if (a->priv->rm_protocol != b->priv->rm_protocol) + return FALSE; + } return TRUE; } From b793fdc1c7a8a57a8e229f12861de0375174b152 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 8 Apr 2021 22:24:04 +0200 Subject: [PATCH 610/675] iface-modem-time: fix invalid read when loading network timezone fails ==226546== Invalid read of size 4 ==226546== at 0x5068CB7: g_error_matches (in /usr/lib/libglib-2.0.so.0.6600.7) ==226546== by 0x1BAC86: load_network_timezone_ready (mm-iface-modem-time.c:218) ==226546== by 0x4EA827E: g_simple_async_result_complete (in /usr/lib/libgio-2.0.so.0.6600.7) ==226546== by 0x17AE2C: at_command_ready (mm-base-modem-at.c:538) ==226546== by 0x4EA827E: g_simple_async_result_complete (in /usr/lib/libgio-2.0.so.0.6600.7) ==226546== by 0x24B475: serial_command_ready (mm-port-serial-at.c:378) ==226546== by 0x4EA827E: g_simple_async_result_complete (in /usr/lib/libgio-2.0.so.0.6600.7) ==226546== by 0x244F94: command_context_complete_and_free (mm-port-serial.c:141) ==226546== by 0x246861: port_serial_got_response (mm-port-serial.c:755) ==226546== by 0x246923: port_serial_timed_out (mm-port-serial.c:785) ==226546== by 0x50863C3: ??? (in /usr/lib/libglib-2.0.so.0.6600.7) ==226546== by 0x5085B83: g_main_context_dispatch (in /usr/lib/libglib-2.0.so.0.6600.7) (cherry picked from commit b766ded3ca58cee202bd4567dd5530f04dc2290d) --- src/mm-iface-modem-time.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mm-iface-modem-time.c b/src/mm-iface-modem-time.c index f02bc34e..5770e7b7 100644 --- a/src/mm-iface-modem-time.c +++ b/src/mm-iface-modem-time.c @@ -194,7 +194,7 @@ static void load_network_timezone_ready (MMIfaceModemTime *self, GAsyncResult *res) { - GError *error = NULL; + g_autoptr(GError) error = NULL; MMNetworkTimezone *tz; /* Finish the async operation */ @@ -203,7 +203,6 @@ load_network_timezone_ready (MMIfaceModemTime *self, NetworkTimezoneContext *ctx; mm_obj_dbg (self, "couldn't load network timezone: %s", error->message); - g_error_free (error); /* Note: may be NULL if the polling has been removed while processing the async operation */ ctx = (NetworkTimezoneContext *) g_object_get_qdata (G_OBJECT (self), network_timezone_context_quark); From 2ed8ee5257e6479f12008b84cf93a196a75ba273 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 12 Apr 2021 23:06:22 +0200 Subject: [PATCH 611/675] kerneldevice: fix segfault when processing event for non-existing port ModemManager[6954]: [1618260091.319919] [br0] invalid sysfs path read for net/br0 ** ERROR:kerneldevice/mm-kernel-device-generic.c:235:ptr_array_add_sysfs_attribute_link_basename: assertion failed: (array && sysfs_path && attribute) Bail out! ERROR:kerneldevice/mm-kernel-device-generic.c:235:ptr_array_add_sysfs_attribute_link_basename: assertion failed: (array && sysfs_path && attribute) Thread 1 "ModemManager" received signal SIGABRT, Aborted. (gdb) bt #0 0x00007ffff7438ef5 in raise () at /usr/lib/libc.so.6 #1 0x00007ffff7422862 in abort () at /usr/lib/libc.so.6 #2 0x00007ffff76c2084 in () at /usr/lib/libglib-2.0.so.0 #3 0x00007ffff771d85d in g_assertion_message_expr () at /usr/lib/libglib-2.0.so.0 #4 0x00005555556a5337 in ptr_array_add_sysfs_attribute_link_basename (array=0x5555557de520, sysfs_path=0x0, attribute=0x555555703bd8 "driver", out_value=0x0) at kerneldevice/mm-kernel-device-generic.c:235 #5 0x00005555556a542b in preload_contents_other (self=0x5555557a6c60) at kerneldevice/mm-kernel-device-generic.c:255 #6 0x00005555556a6485 in preload_contents (self=0x5555557a6c60) at kerneldevice/mm-kernel-device-generic.c:517 #7 0x00005555556a7fb6 in check_preload (self=0x5555557a6c60) at kerneldevice/mm-kernel-device-generic.c:980 #8 0x00005555556a855f in initable_init (initable=0x5555557a6c60, cancellable=0x0, error=0x7fffffffe5c8) at kerneldevice/mm-kernel-device-generic.c:1127 #9 0x00007ffff78a2f41 in g_initable_new_valist () at /usr/lib/libgio-2.0.so.0 #10 0x00007ffff78a2ffa in g_initable_new () at /usr/lib/libgio-2.0.so.0 #11 0x00005555556a8205 in mm_kernel_device_generic_new_with_rules (props=0x5555557a5fa0, rules=0x7fffec001e30, error=0x7fffffffe5c8) at kerneldevice/mm-kernel-device-generic.c:1042 #12 0x00005555556a827d in mm_kernel_device_generic_new (props=0x5555557a5fa0, error=0x7fffffffe5c8) at kerneldevice/mm-kernel-device-generic.c:1063 #13 0x00005555555aba9c in handle_kernel_event (self=0x555555793220, properties=0x5555557a5fa0, error=0x7fffffffe5c8) at mm-base-manager.c:414 (cherry picked from commit 3d5a994ca8d8e766fd87a85d346c5b21f5e6c53e) --- src/kerneldevice/mm-kernel-device-generic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kerneldevice/mm-kernel-device-generic.c b/src/kerneldevice/mm-kernel-device-generic.c index eeae0bc6..aae85adb 100644 --- a/src/kerneldevice/mm-kernel-device-generic.c +++ b/src/kerneldevice/mm-kernel-device-generic.c @@ -474,8 +474,10 @@ preload_contents (MMKernelDeviceGeneric *self) return; preload_sysfs_path (self); - bus_subsys = find_device_bus_subsystem (self); + if (!self->priv->sysfs_path) + return; + bus_subsys = find_device_bus_subsystem (self); if (g_strcmp0 (bus_subsys, "usb") == 0) preload_contents_usb (self); else if (g_strcmp0 (bus_subsys, "pcmcia") == 0) From 5a3dd6d4da2afa4df83781465cd5975ba337d6f5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 12 Apr 2021 23:37:19 +0200 Subject: [PATCH 612/675] cli: avoid attempting to setup timeout on NULL proxy mm_manager_get_proxy() may actually return NULL if creating the internal GDBusProxy for the Manager interface fails. (cherry picked from commit 5a735317f7c0c42b2ddce52dbf1fa1edfc1c41f4) --- cli/mmcli.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/mmcli.c b/cli/mmcli.c index 05644519..2e1cc727 100644 --- a/cli/mmcli.c +++ b/cli/mmcli.c @@ -188,7 +188,8 @@ mmcli_force_sync_operation (void) void mmcli_force_operation_timeout (GDBusProxy *proxy) { - g_dbus_proxy_set_default_timeout (proxy, timeout * 1000); + if (proxy) + g_dbus_proxy_set_default_timeout (proxy, timeout * 1000); } gint From 1cd612aab46e442075defeab7f0ce8ba97ba11d1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 21 Apr 2021 11:33:53 +0200 Subject: [PATCH 613/675] build: disable gtkdocize in autoreconf We have a custom modified gtk-doc.make file in our sources, which disables the gtkdoc-rebase on local install step, so we don't want autoreconf to copy a different one when we're bootstrapping. (cherry picked from commit 4ae623c37b5eb395c79b49a044958c09fd6d23a7) --- autogen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogen.sh b/autogen.sh index df07fc40..7460d254 100755 --- a/autogen.sh +++ b/autogen.sh @@ -14,7 +14,7 @@ PKG_NAME=ModemManager } (cd $srcdir; - autoreconf --force --install --verbose + GTKDOCIZE="true" autoreconf --force --install --verbose ) if test -z "$NOCONFIGURE"; then From 0325cd530c35e0854b3f2a6624c7fdc4cad69995 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 21 Apr 2021 11:20:53 +0200 Subject: [PATCH 614/675] NEWS: update for 1.16.4 --- NEWS | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/NEWS b/NEWS index 942d02df..e904c24f 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,54 @@ +ModemManager 1.16.4 +------------------------------------------- + + * Fix build when using libgudev < 232, which is when autoptr support was + introduced in the GUdev* types. We'll keep the 1.16.x branch depending on + libgudev 147, and only bump the requirement in git master. + + * This version comes with an overall rework of the charset encoding handling + inside the ModemManager daemon, which was already available in git master + for some time and has been proved to be very useful. + ** The charset conversion is now strict, except for a few cases where we + would try to do our best (e.g. operator name normalization). + ** The charset methods are cleaned up, with clear distinction between the + ones that allow NUL-finished C strings and the ones that may have valid + embedded NUL bytes. + ** The //TRANSLIT extension is completely avoided, as not all implementations + out there have it (e.g. unavailable in musl libc), and we now use + g_convert_with_fallback() instead where appropriate. + + * Modem interface: + ** Fixed crash triggered when attempting to update lock info on an already + removed DBus skeleton. + + * Time interface: + ** Fixed invalid memory read when loading network timezone fails. + + * Base bearer: + ** Ignored forced disconnections after some time unregistered when PPP is + being used, so that we don't end up hijacking the TTY while pppd is using + it. + + * Kernel device: + ** Fix segfault when processing event for non-existing port. + + * QMI: + ** Fixed allowed modes setup when using the "Acquisition Order Preference" + TLV in the "NAS System Selection Preference" messages. 3GPP+3GPP2 + multimode devices like the MC73xx series were affected. + + * libmm-glib: + ** Fixed comparison of 'allowed auth' and 'rm protocol' settings in bearer + properties. + + * Plugins: + ** cinterion: allow '*' in Prov/Cfg response. + ** cinterion: fixed several FALSE returns without GError set. + ** quectel: ignore +QGPSURC URCs. + + * Several other minor improvements and fixes. + ModemManager 1.16.2 ------------------------------------------- From e0048b690cfd93da4fa47be110008bac260462a8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 21 Apr 2021 11:21:08 +0200 Subject: [PATCH 615/675] release: bump version to 1.16.4 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 450b3902..c9e7746d 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ dnl m4_define([mm_major_version], [1]) m4_define([mm_minor_version], [16]) -m4_define([mm_micro_version], [3]) +m4_define([mm_micro_version], [4]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From 7a3d9ab290f1ea916248163ac55746caf0a04f53 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 21 Apr 2021 11:53:17 +0200 Subject: [PATCH 616/675] build: post-release version bump to 1.16.5 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index c9e7746d..3952cbb3 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ dnl m4_define([mm_major_version], [1]) m4_define([mm_minor_version], [16]) -m4_define([mm_micro_version], [4]) +m4_define([mm_micro_version], [5]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From b593df29bc8165d3afc771d2c9c4587a3bdf0a11 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 28 Apr 2021 21:58:36 +0200 Subject: [PATCH 617/675] broadband-modem-mbim: fix build with libmbim >= 1.25.3 --- src/mm-broadband-modem-mbim.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index df9fc15a..a4dfedc6 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -3614,6 +3614,9 @@ device_notification_cb (MbimDevice *device, case MBIM_SERVICE_INTEL_FIRMWARE_UPDATE: #if MBIM_CHECK_VERSION (1,25,1) case MBIM_SERVICE_MS_SAR: +#endif +#if MBIM_CHECK_VERSION (1,25,3) + case MBIM_SERVICE_QDU: #endif default: /* Ignore */ From 722ae98ba6f920815cf534869bc9b1a8ebdd80f5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 3 May 2021 22:09:41 +0200 Subject: [PATCH 618/675] foxconn: don't assume parent location is available If ModemManager is not built with QMI support, the generic MBIM modem object will not have any location support, so we cannot assume that iface_modem_location_parent will be valid and that it will have all load_location_capabilities(), enable_location_gathering() and disable_location_gathering() implemented. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/362 (cherry picked from commit e1567c30df5a0bf320b654cd85942bdff5db6144) --- .../mm-broadband-modem-foxconn-t77w968.c | 113 ++++++++++++------ 1 file changed, 79 insertions(+), 34 deletions(-) diff --git a/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c b/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c index 95db6ee7..2288cd09 100644 --- a/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c +++ b/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c @@ -172,6 +172,26 @@ location_load_capabilities_finish (MMIfaceModemLocation *self, return (MMModemLocationSource)value; } +static void +custom_location_load_capabilities (GTask *task, + MMModemLocationSource sources) +{ + MMBroadbandModemFoxconnT77w968 *self; + + self = g_task_get_source_object (task); + + /* If we have a GPS port and an AT port, enable unmanaged GPS support */ + if (mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)) && + mm_base_modem_peek_port_gps (MM_BASE_MODEM (self))) { + self->priv->unmanaged_gps_support = FEATURE_SUPPORTED; + sources |= MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED; + } + + /* So we're done, complete */ + g_task_return_int (task, sources); + g_object_unref (task); +} + static void parent_load_capabilities_ready (MMIfaceModemLocation *self, GAsyncResult *res, @@ -187,16 +207,7 @@ parent_load_capabilities_ready (MMIfaceModemLocation *self, return; } - /* If we have a GPS port and an AT port, enable unmanaged GPS support */ - if (mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)) && - mm_base_modem_peek_port_gps (MM_BASE_MODEM (self))) { - MM_BROADBAND_MODEM_FOXCONN_T77W968 (self)->priv->unmanaged_gps_support = FEATURE_SUPPORTED; - sources |= MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED; - } - - /* So we're done, complete */ - g_task_return_int (task, sources); - g_object_unref (task); + custom_location_load_capabilities (task, sources); } static void @@ -208,10 +219,18 @@ location_load_capabilities (MMIfaceModemLocation *self, task = g_task_new (self, NULL, callback, user_data); - /* Chain up parent's setup */ - iface_modem_location_parent->load_capabilities (self, - (GAsyncReadyCallback)parent_load_capabilities_ready, - task); + /* Chain up parent's setup, if any. If MM is built without QMI support, + * the MBIM modem won't have any location capabilities. */ + if (iface_modem_location_parent && + iface_modem_location_parent->load_capabilities && + iface_modem_location_parent->load_capabilities_finish) { + iface_modem_location_parent->load_capabilities (self, + (GAsyncReadyCallback)parent_load_capabilities_ready, + task); + return; + } + + custom_location_load_capabilities (task, MM_MODEM_LOCATION_SOURCE_NONE); } /*****************************************************************************/ @@ -248,10 +267,19 @@ parent_disable_location_gathering (GTask *task) self = MM_IFACE_MODEM_LOCATION (g_task_get_source_object (task)); source = GPOINTER_TO_UINT (g_task_get_task_data (task)); - iface_modem_location_parent->disable_location_gathering (self, - source, - (GAsyncReadyCallback)parent_disable_location_gathering_ready, - task); + if (iface_modem_location_parent && + iface_modem_location_parent->disable_location_gathering && + iface_modem_location_parent->disable_location_gathering_finish) { + iface_modem_location_parent->disable_location_gathering ( + self, + source, + (GAsyncReadyCallback)parent_disable_location_gathering_ready, + task); + return; + } + + g_task_return_boolean (task, TRUE); + g_object_unref (task); } static void @@ -323,22 +351,15 @@ unmanaged_gps_enabled_ready (MMBaseModem *self, } static void -parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, - GAsyncResult *res, - GTask *task) +custom_enable_location_gathering (GTask *task) { - MMBroadbandModemFoxconnT77w968 *self = MM_BROADBAND_MODEM_FOXCONN_T77W968 (_self); - GError *error = NULL; + MMBroadbandModemFoxconnT77w968 *self; MMModemLocationSource source; - if (!iface_modem_location_parent->enable_location_gathering_finish (_self, res, &error)) { - g_task_return_error (task, error); - g_object_unref (task); - return; - } + self = g_task_get_source_object (task); + source = GPOINTER_TO_UINT (g_task_get_task_data (task)); /* We only support Unmanaged GPS at this level */ - source = GPOINTER_TO_UINT (g_task_get_task_data (task)); if ((self->priv->unmanaged_gps_support != FEATURE_SUPPORTED) || (source != MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) { g_task_return_boolean (task, TRUE); @@ -346,7 +367,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, return; } - mm_base_modem_at_command (MM_BASE_MODEM (_self), + mm_base_modem_at_command (MM_BASE_MODEM (self), "^NV=30007,01,\"01\"", 3, FALSE, @@ -354,6 +375,22 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self, task); } +static void +parent_enable_location_gathering_ready (MMIfaceModemLocation *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + if (!iface_modem_location_parent->enable_location_gathering_finish (self, res, &error)) { + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + custom_enable_location_gathering (task); +} + static void enable_location_gathering (MMIfaceModemLocation *self, MMModemLocationSource source, @@ -366,10 +403,18 @@ enable_location_gathering (MMIfaceModemLocation *self, g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL); /* Chain up parent's gathering enable */ - iface_modem_location_parent->enable_location_gathering (self, - source, - (GAsyncReadyCallback)parent_enable_location_gathering_ready, - task); + if (iface_modem_location_parent && + iface_modem_location_parent->enable_location_gathering && + iface_modem_location_parent->enable_location_gathering_finish) { + iface_modem_location_parent->enable_location_gathering ( + self, + source, + (GAsyncReadyCallback)parent_enable_location_gathering_ready, + task); + return; + } + + custom_enable_location_gathering (task); } /*****************************************************************************/ From 0dbaacf04e52cc2e4b8351e1c325e136ba2541cf Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Thu, 8 Apr 2021 10:07:45 +0200 Subject: [PATCH 619/675] CI: make use of ci-templates full list of benefits at: https://freedesktop.pages.freedesktop.org/ci-templates/templates.html#why-use-the-ci-templates But the main ones are: - reproducible (just download the container and run the `script` part to be in the same environment the CI was running) - no more before script that pulls hundreds of MB and spend useless time. Signed-off-by: Benjamin Tissoires (cherry picked from commit 01f2109ae0bb8ac9a966f69f88ec2b526b68269b) --- .gitlab-ci.yml | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a8371f75..f031fd08 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,14 +1,38 @@ -image: gcc +include: + - project: freedesktop/ci-templates + ref: 290b79e0e78eab67a83766f4e9691be554fc4afd + file: + - templates/debian.yml stages: + - container prep - build -before_script: - - apt update || true - - apt -y install autoconf automake libtool libgettextpo-dev libgirepository1.0-dev libglib2.0-dev libgudev-1.0-dev python3-dbus python3-gi autopoint xsltproc dbus autoconf-archive gettext +.common_variables: + variables: + FDO_UPSTREAM_REPO: mobile-broadband/ModemManager + FDO_DISTRIBUTION_VERSION: 'buster' + FDO_DISTRIBUTION_TAG: '2020-04-08.4' + FDO_DISTRIBUTION_PACKAGES: ca-certificates git gcc autoconf automake libtool libgettextpo-dev libgirepository1.0-dev libglib2.0-dev libgudev-1.0-dev python3-dbus python3-gi autopoint xsltproc dbus autoconf-archive gettext + gtk-doc-tools libglib2.0-doc gobject-introspection libsystemd-dev libpolkit-gobject-1-dev valac + +build container: + extends: + - .fdo.container-build@debian + - .common_variables + stage: container prep + only: + - master + - branches + - merge_requests + - tags + - pushes build-no-qmi: stage: build + extends: + - .fdo.distribution-image@debian + - .common_variables only: - master - merge_requests @@ -30,6 +54,9 @@ build-no-qmi: build-no-mbim: stage: build + extends: + - .fdo.distribution-image@debian + - .common_variables only: - master - merge_requests @@ -51,6 +78,9 @@ build-no-mbim: build-no-qmi-no-mbim: stage: build + extends: + - .fdo.distribution-image@debian + - .common_variables only: - master - merge_requests @@ -65,6 +95,9 @@ build-no-qmi-no-mbim: build-qmi-newest-commands: stage: build + extends: + - .fdo.distribution-image@debian + - .common_variables only: - master - merge_requests @@ -86,6 +119,9 @@ build-qmi-newest-commands: build-single-plugins: stage: build + extends: + - .fdo.distribution-image@debian + - .common_variables only: - schedules script: @@ -117,6 +153,9 @@ build-single-plugins: build-default: stage: build + extends: + - .fdo.distribution-image@debian + - .common_variables only: - master - branches @@ -125,7 +164,6 @@ build-default: - schedules - pushes script: - - apt -y install gtk-doc-tools libglib2.0-doc gobject-introspection libsystemd-dev libpolkit-gobject-1-dev valac - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git - pushd libmbim - NOCONFIGURE=1 ./autogen.sh From b877baaa4baae077e54260c3b705ec89a4a35acf Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 28 Apr 2021 21:21:34 +0200 Subject: [PATCH 620/675] ci: use latest ubuntu LTS by default (cherry picked from commit d9072562cd8d03dc72f072a78e73c24fe4193b8a) --- .gitlab-ci.yml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f031fd08..2d1a4b7b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ include: - project: freedesktop/ci-templates ref: 290b79e0e78eab67a83766f4e9691be554fc4afd file: - - templates/debian.yml + - templates/ubuntu.yml stages: - container prep @@ -11,14 +11,18 @@ stages: .common_variables: variables: FDO_UPSTREAM_REPO: mobile-broadband/ModemManager - FDO_DISTRIBUTION_VERSION: 'buster' - FDO_DISTRIBUTION_TAG: '2020-04-08.4' - FDO_DISTRIBUTION_PACKAGES: ca-certificates git gcc autoconf automake libtool libgettextpo-dev libgirepository1.0-dev libglib2.0-dev libgudev-1.0-dev python3-dbus python3-gi autopoint xsltproc dbus autoconf-archive gettext - gtk-doc-tools libglib2.0-doc gobject-introspection libsystemd-dev libpolkit-gobject-1-dev valac + FDO_DISTRIBUTION_VERSION: '20.04' + FDO_DISTRIBUTION_TAG: '2021-04-28.2' + FDO_DISTRIBUTION_PACKAGES: ca-certificates git gcc autoconf automake libtool + libgettextpo-dev libgirepository1.0-dev libglib2.0-dev + libgudev-1.0-dev python3-dbus python3-gi autopoint + xsltproc dbus autoconf-archive gettext gtk-doc-tools + libglib2.0-doc gobject-introspection libsystemd-dev + libpolkit-gobject-1-dev valac build container: extends: - - .fdo.container-build@debian + - .fdo.container-build@ubuntu - .common_variables stage: container prep only: @@ -31,7 +35,7 @@ build container: build-no-qmi: stage: build extends: - - .fdo.distribution-image@debian + - .fdo.distribution-image@ubuntu - .common_variables only: - master @@ -55,7 +59,7 @@ build-no-qmi: build-no-mbim: stage: build extends: - - .fdo.distribution-image@debian + - .fdo.distribution-image@ubuntu - .common_variables only: - master @@ -79,7 +83,7 @@ build-no-mbim: build-no-qmi-no-mbim: stage: build extends: - - .fdo.distribution-image@debian + - .fdo.distribution-image@ubuntu - .common_variables only: - master @@ -96,7 +100,7 @@ build-no-qmi-no-mbim: build-qmi-newest-commands: stage: build extends: - - .fdo.distribution-image@debian + - .fdo.distribution-image@ubuntu - .common_variables only: - master @@ -120,7 +124,7 @@ build-qmi-newest-commands: build-single-plugins: stage: build extends: - - .fdo.distribution-image@debian + - .fdo.distribution-image@ubuntu - .common_variables only: - schedules @@ -154,7 +158,7 @@ build-single-plugins: build-default: stage: build extends: - - .fdo.distribution-image@debian + - .fdo.distribution-image@ubuntu - .common_variables only: - master From 021c3dd6f11dc86103493ea08c9a60fc584d8c2a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 28 Apr 2021 21:27:22 +0200 Subject: [PATCH 621/675] ci: disable introspection and gtk-doc in all tests that don't need it The template image we're using already contains all the necessary build deps to enable introspection and gtk-doc, so we need to explicitly disable them where we don't need them, or otherwise they'll be automatically enabled as the deps are found. (cherry picked from commit 4593eec17385c190747df48155f95d71c591102e) --- .gitlab-ci.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2d1a4b7b..b383de98 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,12 +46,12 @@ build-no-qmi: - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git - pushd libmbim - NOCONFIGURE=1 ./autogen.sh - - ./configure --prefix=/usr + - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection - make - make install - popd - NOCONFIGURE=1 ./autogen.sh - - ./configure --prefix=/tmp/build-no-qmi --disable-gtk-doc --without-qmi + - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection --without-qmi - make - make check - make install @@ -75,7 +75,7 @@ build-no-mbim: - make install - popd - NOCONFIGURE=1 ./autogen.sh - - ./configure --prefix=/tmp/build-no-mbim --disable-gtk-doc --without-mbim + - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection --without-mbim - make - make check - make install @@ -92,7 +92,7 @@ build-no-qmi-no-mbim: - schedules script: - NOCONFIGURE=1 ./autogen.sh - - ./configure --prefix=/tmp/build-no-qmi-no-mbim --disable-gtk-doc --without-qmi --without-mbim + - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection --without-qmi --without-mbim - make - make check - make install @@ -111,12 +111,12 @@ build-qmi-newest-commands: - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git - pushd libqmi - NOCONFIGURE=1 ./autogen.sh - - ./configure --prefix=/usr --disable-mbim-qmux --enable-collection=basic + - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection --disable-mbim-qmux --enable-collection=basic - make - make install - popd - NOCONFIGURE=1 ./autogen.sh - - ./configure --prefix=/tmp/build-qmi-newest-commands --disable-gtk-doc --without-mbim CFLAGS="-DWITH_NEWEST_QMI_COMMANDS" + - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection --without-mbim CFLAGS="-DWITH_NEWEST_QMI_COMMANDS" - make - make check - make install @@ -132,7 +132,7 @@ build-single-plugins: - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git - pushd libmbim - NOCONFIGURE=1 ./autogen.sh - - ./configure --prefix=/usr + - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection - make - make install - popd @@ -150,7 +150,7 @@ build-single-plugins: novatel novatel-lte option option-hso pantech qcom-soc quectel samsung sierra-legacy sierra simtech telit thuraya tplink ublox via wavecom x22x zte; do - ./configure --prefix=/usr --disable-gtk-doc --disable-all-plugins --enable-plugin-$plugin; + ./configure --prefix=/usr --disable-gtk-doc --disable-introspection --disable-all-plugins --enable-plugin-$plugin; make; make clean; done @@ -171,7 +171,7 @@ build-default: - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git - pushd libmbim - NOCONFIGURE=1 ./autogen.sh - - ./configure --prefix=/usr + - ./configure --prefix=/usr --disable-gtk-doc --enable-introspection - make - make install - popd @@ -183,7 +183,7 @@ build-default: - make install - popd - NOCONFIGURE=1 ./autogen.sh - - ./configure --prefix=/usr --enable-gtk-doc --with-polkit=strict --with-suspend-resume=systemd --with-systemdsystemunitdir=/lib/systemd/system + - ./configure --prefix=/usr --enable-gtk-doc --enable-introspection --with-polkit=strict --with-suspend-resume=systemd --with-systemdsystemunitdir=/lib/systemd/system - make - make check - make install From 3cec1a0104cbae3406bca9198f552f303efd6c12 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 28 Apr 2021 22:41:06 +0200 Subject: [PATCH 622/675] tools: disable stub tester if no introspection enabled TEST: test-stub... /MM/stub/modem/interface: dbus-daemon[48020]: [session uid=0 pid=48020] Activating service name='org.freedesktop.ModemManager1' requested by ':1.0' (uid=0 pid=48005 comm="/builds/mobile-broadband/ModemManager/tools/tests/") Traceback (most recent call last): File "/builds/mobile-broadband/ModemManager/tools/test-modemmanager-service.py", line 7, in gi.require_version('ModemManager', '1.0') File "/usr/lib/python3/dist-packages/gi/__init__.py", line 129, in require_version raise ValueError('Namespace %s not available' % namespace) ValueError: Namespace ModemManager not available dbus-daemon[48020]: [session uid=0 pid=48020] Activated service 'org.freedesktop.ModemManager1' failed: Process org.freedesktop.ModemManager1 exited with status 1 (cherry picked from commit 7b7bbdd999d00446966f100212bc469970e769a3) --- tools/tests/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am index c91675bf..f84a8fec 100644 --- a/tools/tests/Makefile.am +++ b/tools/tests/Makefile.am @@ -31,7 +31,10 @@ test_stub_CPPFLAGS = \ -DTEST_SERVICES=\""$(abs_top_builddir)/tools/tests/services"\" \ $(NULL) +# only run the test if introspection was enabled +if HAVE_INTROSPECTION TEST_PROGS += $(noinst_PROGRAMS) +endif test-wrapper.sh: test-wrapper.sh.in @sed \ From fead7038b963efd16fcf7df62064d0983bf9cd2e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 4 May 2021 00:30:11 +0200 Subject: [PATCH 623/675] ci: stable 1.16 branch relies on libqmi 1.28 and libmbim 1.24 So make all CI pipelines on the stable branch run with those specific libqmi and libmbim branches. --- .gitlab-ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b383de98..f569cf64 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -43,7 +43,7 @@ build-no-qmi: - tags - schedules script: - - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git + - git clone --depth 1 --branch mbim-1-24 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git - pushd libmbim - NOCONFIGURE=1 ./autogen.sh - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection @@ -67,7 +67,7 @@ build-no-mbim: - tags - schedules script: - - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git + - git clone --depth 1 --branch qmi-1-28 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git - pushd libqmi - NOCONFIGURE=1 ./autogen.sh - ./configure --prefix=/usr --disable-mbim-qmux --enable-collection=basic @@ -108,7 +108,7 @@ build-qmi-newest-commands: - tags - schedules script: - - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git + - git clone --depth 1 --branch qmi-1-28 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git - pushd libqmi - NOCONFIGURE=1 ./autogen.sh - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection --disable-mbim-qmux --enable-collection=basic @@ -129,14 +129,14 @@ build-single-plugins: only: - schedules script: - - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git + - git clone --depth 1 --branch mbim-1-24 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git - pushd libmbim - NOCONFIGURE=1 ./autogen.sh - ./configure --prefix=/usr --disable-gtk-doc --disable-introspection - make - make install - popd - - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git + - git clone --depth 1 --branch qmi-1-28 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git - pushd libqmi - NOCONFIGURE=1 ./autogen.sh - ./configure --prefix=/usr --enable-mbim-qmux --enable-collection=basic @@ -168,14 +168,14 @@ build-default: - schedules - pushes script: - - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git + - git clone --depth 1 --branch mbim-1-24 https://gitlab.freedesktop.org/mobile-broadband/libmbim.git - pushd libmbim - NOCONFIGURE=1 ./autogen.sh - ./configure --prefix=/usr --disable-gtk-doc --enable-introspection - make - make install - popd - - git clone --depth 1 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git + - git clone --depth 1 --branch qmi-1-28 https://gitlab.freedesktop.org/mobile-broadband/libqmi.git - pushd libqmi - NOCONFIGURE=1 ./autogen.sh - ./configure --prefix=/usr --enable-mbim-qmux --enable-collection=basic From 17a09e23f96c5ea7dbd8605aa4211ea161ba7dd4 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 15 May 2021 00:34:44 +0200 Subject: [PATCH 624/675] build: require libqmi 1.28.4 We're going to use add support for the transfer-route MT messages in the stable MM 1.16 branch, so we should make sure the related QMI messages have been added to the basic collection, as already done in libqmi 1.28.4. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3952cbb3..05d55406 100644 --- a/configure.ac +++ b/configure.ac @@ -401,7 +401,7 @@ dnl----------------------------------------------------------------------------- dnl QMI support (enabled by default) dnl -LIBQMI_VERSION=1.28.0 +LIBQMI_VERSION=1.28.4 AC_ARG_WITH(qmi, AS_HELP_STRING([--without-qmi], [Build without QMI support]), [], [with_qmi=yes]) AM_CONDITIONAL(WITH_QMI, test "x$with_qmi" = "xyes") From 78d294da18eb11ba44bc2ccd189a522c3721e3bb Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Sat, 17 Apr 2021 00:53:27 -0700 Subject: [PATCH 625/675] broadband-modem-qmi: Handle transfer-route MT messages This handles transfer-route MT messages, automatically ACKing any that need to be ACKed. Based on work by Angus Ainslie and Elias Rudberg (cherry picked from commit 205e9edf3edddfa73b1a9b8ddaff4e3779a20e61) --- src/mm-broadband-modem-qmi.c | 74 +++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index b910a585..e4fc6e5d 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -6082,6 +6082,21 @@ wms_indication_raw_read_ready (QmiClientWms *client, indication_raw_read_context_free (ctx); } +static void +wms_send_ack_ready (QmiClientWms *client, + GAsyncResult *res, + MMBroadbandModemQmi *self) +{ + g_autoptr(QmiMessageWmsSendAckOutput) output = NULL; + g_autoptr(GError) error= NULL; + + output = qmi_client_wms_send_ack_finish (client, res, &error); + if (!output) { + mm_obj_dbg (self, "QMI operation failed: '%s'", error->message); + } + g_object_unref (self); +} + static void messaging_event_report_indication_cb (QmiClientNas *client, QmiIndicationWmsEventReportOutput *output, @@ -6089,8 +6104,65 @@ messaging_event_report_indication_cb (QmiClientNas *client, { QmiWmsStorageType storage; guint32 memory_index; + QmiWmsAckIndicator ack_ind; + guint32 transaction_id; + QmiWmsMessageFormat msg_format; + QmiWmsMessageTagType tag; + GArray *raw_data = NULL; + + /* Handle transfer-route MT messages */ + if (qmi_indication_wms_event_report_output_get_transfer_route_mt_message ( + output, + &ack_ind, + &transaction_id, + &msg_format, + &raw_data, + NULL)) { + mm_obj_dbg (self, "Got transfer-route MT message"); + /* If this is the first of a multi-part message, send an ACK to get the + * second part */ + if (ack_ind == QMI_WMS_ACK_INDICATOR_SEND) { + g_autoptr(QmiMessageWmsSendAckInput) ack_input = NULL; + QmiWmsMessageProtocol message_protocol; + /* Need to ack message */ + mm_obj_dbg (self, "Need to ACK indicator"); + switch (msg_format) { + case QMI_WMS_MESSAGE_FORMAT_CDMA: + message_protocol = QMI_WMS_MESSAGE_PROTOCOL_CDMA; + break; + case QMI_WMS_MESSAGE_FORMAT_MWI: + case QMI_WMS_MESSAGE_FORMAT_GSM_WCDMA_POINT_TO_POINT: + case QMI_WMS_MESSAGE_FORMAT_GSM_WCDMA_BROADCAST: + default: + message_protocol = QMI_WMS_MESSAGE_PROTOCOL_WCDMA; + break; + } + ack_input = qmi_message_wms_send_ack_input_new(); + qmi_message_wms_send_ack_input_set_information (ack_input, + transaction_id, + message_protocol, + TRUE, + NULL); + qmi_client_wms_send_ack (QMI_CLIENT_WMS (client), + ack_input, + 180, + NULL, + (GAsyncReadyCallback)wms_send_ack_ready, + g_object_ref (self)); + } - /* Currently ignoring transfer-route MT messages */ + /* Defaults for transfer-route messages, which are not stored anywhere */ + storage = QMI_WMS_STORAGE_TYPE_NONE; + memory_index = 0; + tag = QMI_WMS_MESSAGE_TAG_TYPE_MT_NOT_READ; + add_new_read_sms_part (MM_IFACE_MODEM_MESSAGING (self), + storage, + memory_index, + tag, + msg_format, + raw_data); + return; + } if (qmi_indication_wms_event_report_output_get_mt_message ( output, From 2b0e0ed48566c7b94e1d3520af1707d0f958c6b8 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Fri, 16 Apr 2021 20:42:15 -0700 Subject: [PATCH 626/675] sms-part-3gpp: add flag for indicating PDU is transfer-route message When the message is a transfer-route MT, there is no SMSC address to parse out. This flag allows indicating when the PDU is one such message. (cherry picked from commit 43c39d5226484eba99211b2fa1add2ae5b398ebf) --- src/mm-broadband-modem-mbim.c | 1 + src/mm-broadband-modem-qmi.c | 5 +++++ src/mm-sms-part-3gpp.c | 42 +++++++++++++++++++---------------- src/mm-sms-part-3gpp.h | 1 + 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index a4dfedc6..1da66c74 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -5364,6 +5364,7 @@ add_sms_part (MMBroadbandModemMbim *self, pdu->pdu_data, pdu->pdu_data_size, self, + FALSE, &error); if (part) { mm_obj_dbg (self, "correctly parsed PDU (%d)", pdu->message_index); diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index e4fc6e5d..3fc4f412 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -5637,6 +5637,7 @@ add_new_read_sms_part (MMIfaceModemMessaging *self, guint32 index, QmiWmsMessageTagType tag, QmiWmsMessageFormat format, + gboolean transfer_route, GArray *data) { MMSmsPart *part = NULL; @@ -5657,6 +5658,7 @@ add_new_read_sms_part (MMIfaceModemMessaging *self, (guint8 *)data->data, data->len, self, + transfer_route, &error); break; case QMI_WMS_MESSAGE_FORMAT_MWI: @@ -5723,6 +5725,7 @@ wms_raw_read_ready (QmiClientWms *client, message->memory_index, tag, format, + FALSE, data); } @@ -6073,6 +6076,7 @@ wms_indication_raw_read_ready (QmiClientWms *client, ctx->memory_index, tag, format, + FALSE, data); } @@ -6160,6 +6164,7 @@ messaging_event_report_indication_cb (QmiClientNas *client, memory_index, tag, msg_format, + TRUE, raw_data); return; } diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c index fbf8e114..51f2cfeb 100644 --- a/src/mm-sms-part-3gpp.c +++ b/src/mm-sms-part-3gpp.c @@ -355,7 +355,7 @@ mm_sms_part_3gpp_new_from_pdu (guint index, return NULL; } - return mm_sms_part_3gpp_new_from_binary_pdu (index, pdu, pdu_len, log_object, error); + return mm_sms_part_3gpp_new_from_binary_pdu (index, pdu, pdu_len, log_object, FALSE, error); } MMSmsPart * @@ -363,6 +363,7 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, const guint8 *pdu, gsize pdu_len, gpointer log_object, + gboolean transfer_route, GError **error) { MMSmsPart *sms_part; @@ -404,25 +405,28 @@ mm_sms_part_3gpp_new_from_binary_pdu (guint index, offset = 0; - /* ---------------------------------------------------------------------- */ - /* SMSC, in address format, precedes the TPDU - * First byte represents the number of BYTES for the address value */ - PDU_SIZE_CHECK (1, "cannot read SMSC address length"); - smsc_addr_size_bytes = pdu[offset++]; - if (smsc_addr_size_bytes > 0) { - PDU_SIZE_CHECK (offset + smsc_addr_size_bytes, "cannot read SMSC address"); - /* SMSC may not be given in DELIVER PDUs */ - address = sms_decode_address (&pdu[1], 2 * (smsc_addr_size_bytes - 1), error); - if (!address) { - g_prefix_error (error, "Couldn't read SMSC address: "); - mm_sms_part_free (sms_part); - return NULL; - } - mm_sms_part_take_smsc (sms_part, g_steal_pointer (&address)); - mm_obj_dbg (log_object, " SMSC address parsed: '%s'", mm_sms_part_get_smsc (sms_part)); - offset += smsc_addr_size_bytes; + if (!transfer_route) { + /* ---------------------------------------------------------------------- */ + /* SMSC, in address format, precedes the TPDU + * First byte represents the number of BYTES for the address value */ + PDU_SIZE_CHECK (1, "cannot read SMSC address length"); + smsc_addr_size_bytes = pdu[offset++]; + if (smsc_addr_size_bytes > 0) { + PDU_SIZE_CHECK (offset + smsc_addr_size_bytes, "cannot read SMSC address"); + /* SMSC may not be given in DELIVER PDUs */ + address = sms_decode_address (&pdu[1], 2 * (smsc_addr_size_bytes - 1), error); + if (!address) { + g_prefix_error (error, "Couldn't read SMSC address: "); + mm_sms_part_free (sms_part); + return NULL; + } + mm_sms_part_take_smsc (sms_part, g_steal_pointer (&address)); + mm_obj_dbg (log_object, " SMSC address parsed: '%s'", mm_sms_part_get_smsc (sms_part)); + offset += smsc_addr_size_bytes; + } else + mm_obj_dbg (log_object, " no SMSC address given"); } else - mm_obj_dbg (log_object, " no SMSC address given"); + mm_obj_dbg (log_object, " This is a transfer-route message"); /* ---------------------------------------------------------------------- */ diff --git a/src/mm-sms-part-3gpp.h b/src/mm-sms-part-3gpp.h index bef416fa..c6f4cf3f 100644 --- a/src/mm-sms-part-3gpp.h +++ b/src/mm-sms-part-3gpp.h @@ -30,6 +30,7 @@ MMSmsPart *mm_sms_part_3gpp_new_from_binary_pdu (guint index, const guint8 *pdu, gsize pdu_len, gpointer log_object, + gboolean transfer_route, GError **error); guint8 *mm_sms_part_3gpp_get_submit_pdu (MMSmsPart *part, guint *out_pdulen, From 84388c162dd08677fc98a54c011c2ef4aa6639c6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 18 May 2021 11:28:18 +0200 Subject: [PATCH 627/675] core: drop "volatile" for g_once_init_enter locations This fixes a few (fatal in gcc 11) warnings. See https://gitlab.gnome.org/GNOME/glib/-/issues/600 (cherry picked from commit 268cab885b62526bb97794cb6b9e8b0f97084841) --- build-aux/mm-enums-template.c | 8 +++--- build-aux/mm-errors-template.c | 8 +++--- src/mm-log.c | 2 +- src/mm-private-boxed-types.c | 48 +++++++++++++++++----------------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/build-aux/mm-enums-template.c b/build-aux/mm-enums-template.c index 567ce5d5..2a7f264b 100644 --- a/build-aux/mm-enums-template.c +++ b/build-aux/mm-enums-template.c @@ -24,16 +24,16 @@ static const G@Type@Value @enum_name@_values[] = { GType @enum_name@_get_type (void) { - static volatile gsize g_define_type_id__volatile = 0; + static gsize g_define_type_id_initialized = 0; - if (g_once_init_enter (&g_define_type_id__volatile)) { + if (g_once_init_enter (&g_define_type_id_initialized)) { GType g_define_type_id = g_@type@_register_static (g_intern_static_string ("@EnumName@"), @enum_name@_values); - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); } - return g_define_type_id__volatile; + return g_define_type_id_initialized; } /** diff --git a/build-aux/mm-errors-template.c b/build-aux/mm-errors-template.c index 3b3127f5..8370adf1 100644 --- a/build-aux/mm-errors-template.c +++ b/build-aux/mm-errors-template.c @@ -12,9 +12,9 @@ GType @enum_name@_get_type (void) { - static volatile gsize g_define_type_id__volatile = 0; + static gsize g_define_type_id_initialized = 0; - if (g_once_init_enter (&g_define_type_id__volatile)) + if (g_once_init_enter (&g_define_type_id_initialized)) { static const G@Type@Value values[] = { /*** END value-header ***/ @@ -28,10 +28,10 @@ GType }; GType g_define_type_id = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values); - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); } - return g_define_type_id__volatile; + return g_define_type_id_initialized; } /*** END value-tail ***/ diff --git a/src/mm-log.c b/src/mm-log.c index 8945b891..c59af2e0 100644 --- a/src/mm-log.c +++ b/src/mm-log.c @@ -76,7 +76,7 @@ static const LogDesc level_descs[] = { }; static GString *msgbuf = NULL; -static volatile gsize msgbuf_once = 0; +static gsize msgbuf_once = 0; static int mm_to_syslog_priority (MMLogLevel level) diff --git a/src/mm-private-boxed-types.c b/src/mm-private-boxed-types.c index a94dd2c4..1c510bb8 100644 --- a/src/mm-private-boxed-types.c +++ b/src/mm-private-boxed-types.c @@ -37,18 +37,18 @@ uint16_array_copy (guint16 *array) GType mm_uint16_array_get_type (void) { - static volatile gsize g_define_type_id__volatile = 0; + static gsize g_define_type_id_initialized = 0; - if (g_once_init_enter (&g_define_type_id__volatile)) { + if (g_once_init_enter (&g_define_type_id_initialized)) { GType g_define_type_id = g_boxed_type_register_static (g_intern_static_string ("MMUint16Array"), (GBoxedCopyFunc) uint16_array_copy, (GBoxedFreeFunc) g_free); - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); } - return g_define_type_id__volatile; + return g_define_type_id_initialized; } static mm_uint16_pair * @@ -72,18 +72,18 @@ uint16_pair_array_copy (mm_uint16_pair *array) GType mm_uint16_pair_array_get_type (void) { - static volatile gsize g_define_type_id__volatile = 0; + static gsize g_define_type_id_initialized = 0; - if (g_once_init_enter (&g_define_type_id__volatile)) { + if (g_once_init_enter (&g_define_type_id_initialized)) { GType g_define_type_id = g_boxed_type_register_static (g_intern_static_string ("MMUint16PairArray"), (GBoxedCopyFunc) uint16_pair_array_copy, (GBoxedFreeFunc) g_free); - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); } - return g_define_type_id__volatile; + return g_define_type_id_initialized; } static void @@ -122,18 +122,18 @@ str_pair_array_copy (mm_str_pair *array) GType mm_str_pair_array_get_type (void) { - static volatile gsize g_define_type_id__volatile = 0; + static gsize g_define_type_id_initialized = 0; - if (g_once_init_enter (&g_define_type_id__volatile)) { + if (g_once_init_enter (&g_define_type_id_initialized)) { GType g_define_type_id = g_boxed_type_register_static (g_intern_static_string ("MMStrPairArray"), (GBoxedCopyFunc) str_pair_array_copy, (GBoxedFreeFunc) str_pair_array_free); - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); } - return g_define_type_id__volatile; + return g_define_type_id_initialized; } static gpointer * @@ -157,18 +157,18 @@ pointer_array_copy (gpointer *array) GType mm_pointer_array_get_type (void) { - static volatile gsize g_define_type_id__volatile = 0; + static gsize g_define_type_id_initialized = 0; - if (g_once_init_enter (&g_define_type_id__volatile)) { + if (g_once_init_enter (&g_define_type_id_initialized)) { GType g_define_type_id = g_boxed_type_register_static (g_intern_static_string ("MMPointerArray"), (GBoxedCopyFunc) pointer_array_copy, (GBoxedFreeFunc) g_free); - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); } - return g_define_type_id__volatile; + return g_define_type_id_initialized; } static GPtrArray * @@ -186,18 +186,18 @@ object_array_free (GPtrArray *object_array) GType mm_object_array_get_type (void) { - static volatile gsize g_define_type_id__volatile = 0; + static gsize g_define_type_id_initialized = 0; - if (g_once_init_enter (&g_define_type_id__volatile)) { + if (g_once_init_enter (&g_define_type_id_initialized)) { GType g_define_type_id = g_boxed_type_register_static (g_intern_static_string ("MMObjectArray"), (GBoxedCopyFunc) object_array_copy, (GBoxedFreeFunc) object_array_free); - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); } - return g_define_type_id__volatile; + return g_define_type_id_initialized; } static void @@ -223,16 +223,16 @@ async_method_copy (MMAsyncMethod *original) GType mm_async_method_get_type (void) { - static volatile gsize g_define_type_id__volatile = 0; + static gsize g_define_type_id_initialized = 0; - if (g_once_init_enter (&g_define_type_id__volatile)) { + if (g_once_init_enter (&g_define_type_id_initialized)) { GType g_define_type_id = g_boxed_type_register_static (g_intern_static_string ("MMAsyncMethod"), (GBoxedCopyFunc) async_method_copy, (GBoxedFreeFunc) async_method_free); - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); } - return g_define_type_id__volatile; + return g_define_type_id_initialized; } From a746c58e30dc8a44885294b382f8c6e7390d0998 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 18 May 2021 12:07:45 +0200 Subject: [PATCH 628/675] libmm-glib: remove unused cmp_allow_roaming() method mm-bearer-properties.c:725:1: warning: 'cmp_allow_roaming' defined but not used [-Wunused-function] cmp_allow_roaming (gboolean a, ^~~~~~~~~~~~~~~~~ (cherry picked from commit a325acd6b1ae3376bb0f9f3eb83ce44617115a55) --- libmm-glib/mm-bearer-properties.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c index 41b12f5d..cf4529ed 100644 --- a/libmm-glib/mm-bearer-properties.c +++ b/libmm-glib/mm-bearer-properties.c @@ -721,25 +721,6 @@ cmp_allowed_auth (MMBearerAllowedAuth a, return FALSE; } -static gboolean -cmp_allow_roaming (gboolean a, - gboolean a_set, - gboolean b, - gboolean b_set, - MMBearerPropertiesCmpFlags flags) -{ - /* Strict match */ - if (a == b && a_set == b_set) - return TRUE; - /* Additional loose match UNSET == */ - if (flags & MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE) { - if ((a == MM_BEARER_ALLOWED_AUTH_UNKNOWN && b == MM_BEARER_ALLOWED_AUTH_NONE) || - (b == MM_BEARER_ALLOWED_AUTH_UNKNOWN && a == MM_BEARER_ALLOWED_AUTH_NONE)) - return TRUE; - } - return FALSE; -} - /** * mm_bearer_properties_cmp: (skip) */ From 6005b93902a40a27648101933fe2c2cbbe80aac1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 18 May 2021 12:24:39 +0200 Subject: [PATCH 629/675] libmm-glib: drop default timeout checks in Command() The g_dbus_proxy_get_default_timeout() is by default -1 unless explicitly updated, so the check doesn't make any sense really. We didn't see any warning produced because mmcli provides an explicit timeout of 30s, so it was never the default -1. (cherry picked from commit 21ff48ed7d56837567aff3e396acf3bfd24cbc02) --- libmm-glib/mm-modem.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libmm-glib/mm-modem.c b/libmm-glib/mm-modem.c index 38300d49..8837daff 100644 --- a/libmm-glib/mm-modem.c +++ b/libmm-glib/mm-modem.c @@ -2867,8 +2867,6 @@ mm_modem_command (MMModem *self, g_return_if_fail (MM_IS_MODEM (self)); - if (g_dbus_proxy_get_default_timeout (G_DBUS_PROXY (self)) < timeout) - g_warning ("Requested command timeout is shorter than the default DBus timeout"); mm_gdbus_modem_call_command (MM_GDBUS_MODEM (self), cmd, timeout, cancellable, callback, user_data); } @@ -2902,9 +2900,6 @@ mm_modem_command_sync (MMModem *self, g_return_val_if_fail (MM_IS_MODEM (self), NULL); - if (g_dbus_proxy_get_default_timeout (G_DBUS_PROXY (self)) < timeout) - g_warning ("Requested command timeout is shorter than the default DBus timeout"); - if (!mm_gdbus_modem_call_command_sync (MM_GDBUS_MODEM (self), cmd, timeout, &result, cancellable, error)) return NULL; From f59095a3bef82cc066788c1c8df0947bca7d1408 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 18 May 2021 14:29:41 +0200 Subject: [PATCH 630/675] libmm-glib,common-helpers: avoid signed vs unsigned comparisons mm-common-helpers.c: In function 'mm_get_int_from_str': mm-common-helpers.c:1349:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (eol == num) ^~ mm-common-helpers.c: In function 'mm_utils_hexstr2bin': mm-common-helpers.c:1718:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (i = 0; i < len; i += 2) { ^ (cherry picked from commit d661d822f7fc2b31884eb10a586501765250ec2e) --- libmm-glib/mm-common-helpers.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 43fff922..1c41ac97 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1320,6 +1320,7 @@ mm_get_int_from_str (const gchar *str, gint *out) { glong num; + guint i; guint eol = 0; if (!str) @@ -1332,10 +1333,10 @@ mm_get_int_from_str (const gchar *str, if (!str[0]) return FALSE; - for (num = 0; str[num]; num++) { - if (str[num] != '+' && str[num] != '-' && !g_ascii_isdigit (str[num])) { + for (i = 0; str[i]; i++) { + if (str[i] != '+' && str[i] != '-' && !g_ascii_isdigit (str[i])) { /* ignore \r\n at the end of the string */ - if ((str[num] == '\r') || (str[num] == '\n')) { + if ((str[i] == '\r') || (str[i] == '\n')) { eol++; continue; } @@ -1346,7 +1347,7 @@ mm_get_int_from_str (const gchar *str, return FALSE; } /* if all characters were eol, the string is not parseable */ - if (eol == num) + if (eol == i) return FALSE; errno = 0; @@ -1694,7 +1695,7 @@ mm_utils_hexstr2bin (const gchar *hex, { const gchar *ipos = hex; g_autofree guint8 *buf = NULL; - gsize i; + gssize i; gint a; guint8 *opos; From 7b77bedae49457718bece5cf1a262ab561b6af5a Mon Sep 17 00:00:00 2001 From: Loic Poulain Date: Wed, 16 Dec 2020 13:59:27 +0100 Subject: [PATCH 631/675] udev: add wwan port devices as valid candidates The new Linux WWAN subsystem exposes the various WWAN control ports as character devices. WWAN port device naming follows the following convention: wwanXpYP, where X is the wwan device index, Y the port index and P the port type/protocol. Signed-off-by: Loic Poulain (cherry picked from commit aaf8c17e3592cf401913543452002e1e227a8d05) --- src/80-mm-candidate.rules | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/80-mm-candidate.rules b/src/80-mm-candidate.rules index 7e7988e5..a0891bfc 100644 --- a/src/80-mm-candidate.rules +++ b/src/80-mm-candidate.rules @@ -16,5 +16,9 @@ KERNEL=="rfcomm*", DEVPATH=="*/virtual/*", GOTO="mm_candidate_end" SUBSYSTEM=="tty", ENV{ID_MM_CANDIDATE}="1" SUBSYSTEM=="net", ENV{ID_MM_CANDIDATE}="1" KERNEL=="cdc-wdm[0-9]*", SUBSYSTEM=="usbmisc", ENV{ID_MM_CANDIDATE}="1" - +SUBSYSTEM=="wwan", ENV{ID_MM_CANDIDATE}="1" +SUBSYSTEM=="wwan", KERNEL=="*MBIM", ENV{ID_MM_PORT_TYPE_MBIM}="1" +SUBSYSTEM=="wwan", KERNEL=="*QMI", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="wwan", KERNEL=="*AT", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +SUBSYSTEM=="wwan", KERNEL=="*QCDM", ENV{ID_MM_PORT_TYPE_QCDM}="1" LABEL="mm_candidate_end" From 33cbe975acc78e0b08c70553875c292b2d26fef2 Mon Sep 17 00:00:00 2001 From: Loic Poulain Date: Wed, 16 Dec 2020 14:01:53 +0100 Subject: [PATCH 632/675] filter: Add wwan port devices Allow WWAN control ports. Signed-off-by: Loic Poulain (cherry picked from commit b1db6527cf9d4801e48dfe6e9fe8124532269159) --- src/mm-filter.c | 8 ++++++++ src/mm-filter.h | 13 +++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/mm-filter.c b/src/mm-filter.c index 870ae7b8..c801a74b 100644 --- a/src/mm-filter.c +++ b/src/mm-filter.c @@ -206,6 +206,13 @@ mm_filter_port (MMFilter *self, return TRUE; } + /* If this is a wwan port/device, we always allow it */ + if ((self->priv->enabled_rules & MM_FILTER_RULE_WWAN) && + (g_strcmp0 (subsystem, "wwan") == 0)) { + mm_obj_dbg (self, "(%s/%s) port allowed: wwan device", subsystem, name); + return TRUE; + } + /* If this is a tty device, we may allow it */ if ((self->priv->enabled_rules & MM_FILTER_RULE_TTY) && (g_strcmp0 (subsystem, "tty") == 0)) { @@ -457,6 +464,7 @@ mm_filter_new (MMFilterRule enabled_rules, mm_obj_dbg (self, " net devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_NET)); mm_obj_dbg (self, " usbmisc devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_USBMISC)); mm_obj_dbg (self, " rpmsg devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_RPMSG)); + mm_obj_dbg (self, " wwan devices allowed: %s", RULE_ENABLED_STR (MM_FILTER_RULE_WWAN)); if (self->priv->enabled_rules & MM_FILTER_RULE_TTY) { mm_obj_dbg (self, " tty devices:"); mm_obj_dbg (self, " blacklist applied: %s", RULE_ENABLED_STR (MM_FILTER_RULE_TTY_BLACKLIST)); diff --git a/src/mm-filter.h b/src/mm-filter.h index 8d2e0e22..145f8296 100644 --- a/src/mm-filter.h +++ b/src/mm-filter.h @@ -63,6 +63,7 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_TTY_ACM_INTERFACE = 1 << 13, MM_FILTER_RULE_TTY_WITH_NET = 1 << 14, MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN = 1 << 15, + MM_FILTER_RULE_WWAN = 1 << 16, } MMFilterRule; #define MM_FILTER_RULE_ALL \ @@ -81,7 +82,8 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_TTY_DRIVER | \ MM_FILTER_RULE_TTY_ACM_INTERFACE | \ MM_FILTER_RULE_TTY_WITH_NET | \ - MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN) + MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN | \ + MM_FILTER_RULE_WWAN) /* This is the legacy ModemManager policy that tries to automatically probe * device ports unless they're blacklisted in some way or another. */ @@ -96,7 +98,8 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_TTY_BLACKLIST | \ MM_FILTER_RULE_TTY_MANUAL_SCAN_ONLY | \ MM_FILTER_RULE_TTY_PLATFORM_DRIVER | \ - MM_FILTER_RULE_TTY_DEFAULT_ALLOWED) + MM_FILTER_RULE_TTY_DEFAULT_ALLOWED | \ + MM_FILTER_RULE_WWAN) /* This is a stricter policy which will only automatically probe device ports * if they are allowed by any of the automatic whitelist rules. */ @@ -113,7 +116,8 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_TTY_DRIVER | \ MM_FILTER_RULE_TTY_ACM_INTERFACE | \ MM_FILTER_RULE_TTY_WITH_NET | \ - MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN) + MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN | \ + MM_FILTER_RULE_WWAN) /* This is equivalent to the strict policy, but also applying the device * blacklists explicitly */ @@ -132,7 +136,8 @@ typedef enum { /*< underscore_name=mm_filter_rule >*/ MM_FILTER_RULE_TTY_DRIVER | \ MM_FILTER_RULE_TTY_ACM_INTERFACE | \ MM_FILTER_RULE_TTY_WITH_NET | \ - MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN) + MM_FILTER_RULE_TTY_DEFAULT_FORBIDDEN | \ + MM_FILTER_RULE_WWAN) /* This policy only allows using device ports explicitly whitelisted via * udev rules. i.e. ModemManager won't do any kind of automatic probing. */ From f27ce401d173eb3f3574e34818f296f3f6fa6634 Mon Sep 17 00:00:00 2001 From: Loic Poulain Date: Wed, 16 Dec 2020 15:11:48 +0100 Subject: [PATCH 633/675] base: Add support for wwan subsystem Add support for the Linux wwan subsystem that started to expose control channel as character devices (e.g. /dev/wwan0p1MBIM...). Signed-off-by: Loic Poulain (cherry picked from commit 6db2e8f04da458488c374f1a6f6979ce7fe9b67d) --- src/mm-base-modem.c | 26 ++++++++++++++++++++++++++ src/mm-plugin.c | 9 +++++++++ src/mm-port-probe.c | 9 ++++++++- src/mm-port.h | 3 ++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index 33b626b9..926d0712 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -251,6 +251,30 @@ base_modem_create_rpmsg_port (MMBaseModem *self, return NULL; } +static MMPort * +base_modem_create_wwan_port (MMBaseModem *self, + const gchar *name, + MMPortType ptype) +{ +#if defined WITH_QMI + if (ptype == MM_PORT_TYPE_QMI) + return MM_PORT (mm_port_qmi_new (name, MM_PORT_SUBSYS_WWAN)); +#endif + +#if defined WITH_MBIM + if (ptype == MM_PORT_TYPE_MBIM) + return MM_PORT (mm_port_mbim_new (name, MM_PORT_SUBSYS_WWAN)); +#endif + + if (ptype == MM_PORT_TYPE_QCDM) + return MM_PORT (mm_port_serial_qcdm_new (name, MM_PORT_SUBSYS_WWAN)); + + if (ptype == MM_PORT_TYPE_AT) + return MM_PORT (mm_port_serial_at_new (name, MM_PORT_SUBSYS_WWAN)); + + return NULL; +} + static MMPort * base_modem_create_virtual_port (MMBaseModem *self, const gchar *name) @@ -296,6 +320,8 @@ mm_base_modem_grab_port (MMBaseModem *self, port = base_modem_create_rpmsg_port (self, name, ptype); else if (g_str_equal (subsys, "virtual")) port = base_modem_create_virtual_port (self, name); + else if (g_str_equal (subsys, "wwan")) + port = base_modem_create_wwan_port (self, name, ptype); if (!port) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, diff --git a/src/mm-plugin.c b/src/mm-plugin.c index 13b46a75..820f570e 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -786,6 +786,15 @@ mm_plugin_supports_port (MMPlugin *self, probe_run_flags |= MM_PORT_PROBE_AT; if (self->priv->qmi) probe_run_flags |= MM_PORT_PROBE_QMI; + } else if (g_str_equal (mm_kernel_device_get_subsystem (port), "wwan")) { + if (self->priv->mbim) + probe_run_flags |= MM_PORT_PROBE_MBIM; + if (self->priv->qmi) + probe_run_flags |= MM_PORT_PROBE_QMI; + if (self->priv->qcdm) + probe_run_flags |= MM_PORT_PROBE_QCDM; + if (self->priv->at) + probe_run_flags |= MM_PORT_PROBE_AT; } /* For potential AT ports, check for more things */ diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c index d4bffb3e..ef5b4c94 100644 --- a/src/mm-port-probe.c +++ b/src/mm-port-probe.c @@ -730,6 +730,8 @@ serial_probe_qcdm (MMPortProbe *self) gint len; guint8 marker = 0x7E; PortProbeRunContext *ctx; + MMPortSubsys subsys = MM_PORT_SUBSYS_TTY; + g_assert (self->priv->task); ctx = g_task_get_task_data (self->priv->task); @@ -752,8 +754,11 @@ serial_probe_qcdm (MMPortProbe *self) g_object_unref (ctx->serial); } + if (g_str_equal (mm_kernel_device_get_subsystem (self->priv->port), "wwan")) + subsys = MM_PORT_SUBSYS_WWAN; + /* Open the QCDM port */ - ctx->serial = MM_PORT_SERIAL (mm_port_serial_qcdm_new (mm_kernel_device_get_name (self->priv->port), MM_PORT_SUBSYS_TTY)); + ctx->serial = MM_PORT_SERIAL (mm_port_serial_qcdm_new (mm_kernel_device_get_name (self->priv->port), subsys)); if (!ctx->serial) { port_probe_task_return_error (self, g_error_new (MM_CORE_ERROR, @@ -1281,6 +1286,8 @@ serial_open_at (MMPortProbe *self) subsys = MM_PORT_SUBSYS_USBMISC; else if (g_str_equal (mm_kernel_device_get_subsystem (self->priv->port), "rpmsg")) subsys = MM_PORT_SUBSYS_RPMSG; + else if (g_str_equal (mm_kernel_device_get_subsystem (self->priv->port), "wwan")) + subsys = MM_PORT_SUBSYS_WWAN; ctx->serial = MM_PORT_SERIAL (mm_port_serial_at_new (mm_kernel_device_get_name (self->priv->port), subsys)); if (!ctx->serial) { diff --git a/src/mm-port.h b/src/mm-port.h index 8295d264..3fe920cc 100644 --- a/src/mm-port.h +++ b/src/mm-port.h @@ -29,7 +29,8 @@ typedef enum { /*< underscore_name=mm_port_subsys >*/ MM_PORT_SUBSYS_USBMISC, MM_PORT_SUBSYS_UNIX, MM_PORT_SUBSYS_RPMSG, - MM_PORT_SUBSYS_LAST = MM_PORT_SUBSYS_RPMSG /*< skip >*/ + MM_PORT_SUBSYS_WWAN, + MM_PORT_SUBSYS_LAST = MM_PORT_SUBSYS_WWAN /*< skip >*/ } MMPortSubsys; typedef enum { /*< underscore_name=mm_port_type >*/ From 60606f1231ade45fffe02b3c72238af7ba024195 Mon Sep 17 00:00:00 2001 From: Loic Poulain Date: Wed, 16 Dec 2020 15:49:42 +0100 Subject: [PATCH 634/675] broadband-modem-qmi: Add MHI QMI port peek support For MHI data port (mhi-net), simply return the primary QMI port. Signed-off-by: Loic Poulain (cherry picked from commit 6895ca836b29dba55f5afd46925967e7795fd43b) --- src/mm-broadband-modem-qmi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 3fc4f412..b291a1c8 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -246,7 +246,7 @@ peek_port_qmi_for_data (MMBroadbandModemQmi *self, g_assert (mm_port_get_subsys (data) == MM_PORT_SUBSYS_NET); net_port_driver = mm_kernel_device_get_driver (mm_port_peek_kernel_device (data)); - if (g_strcmp0 (net_port_driver, "qmi_wwan") != 0) { + if (g_strcmp0 (net_port_driver, "qmi_wwan") != 0 && g_strcmp0 (net_port_driver, "mhi_net")) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, @@ -256,6 +256,9 @@ peek_port_qmi_for_data (MMBroadbandModemQmi *self, return NULL; } + if (!g_strcmp0 (net_port_driver, "mhi_net")) + return mm_broadband_modem_qmi_peek_port_qmi (self); + net_port_parent_path = mm_kernel_device_get_interface_sysfs_path (mm_port_peek_kernel_device (data)); if (!net_port_parent_path) { g_set_error (error, From ba18704cc63c0be201b79eedb9561e2dc1fe0d67 Mon Sep 17 00:00:00 2001 From: Loic Poulain Date: Wed, 16 Dec 2020 17:07:31 +0100 Subject: [PATCH 635/675] plugins: generic: Add 'wwan' subsystem support wwan is a new subsystem for WWAN devices, allowing to expose the WWAN device and its ports in a generic way. The sysfs hierarchy for such device is /sys/class/wwanX /sys/class/wwanX/wwanXpYP Where X is the WWAN device index, Y the port index and P the control protocol name (QMI, MBIM...). A control port is also exposed as character device in /dev. Signed-off-by: Loic Poulain (cherry picked from commit fefbf4d3029ce8e1f2ed9db2bc8288e13989b05a) --- plugins/generic/mm-plugin-generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/generic/mm-plugin-generic.c b/plugins/generic/mm-plugin-generic.c index f4c73421..e18b8854 100644 --- a/plugins/generic/mm-plugin-generic.c +++ b/plugins/generic/mm-plugin-generic.c @@ -91,7 +91,7 @@ create_modem (MMPlugin *self, G_MODULE_EXPORT MMPlugin * mm_plugin_create (void) { - static const gchar *subsystems[] = { "tty", "net", "usbmisc", NULL }; + static const gchar *subsystems[] = { "tty", "net", "usbmisc", "wwan", NULL }; return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_GENERIC, From b7f0f2ca7c6e61fcf08786909ba0992d0de36ce6 Mon Sep 17 00:00:00 2001 From: Loic Poulain Date: Tue, 20 Apr 2021 15:04:11 +0200 Subject: [PATCH 636/675] qmi: Increase qmi_device_open timeout SDX55 modem can take slighlty more than 25 seconds to start all its services from cold boot/reset (including QMI services), causing QMI port opening timeout error. This patch increases the qmi_device_open timeout from 25 seconds to 45 seconds to prevent such issue. Signed-off-by: Loic Poulain (cherry picked from commit e57c59bf88615129efc0241957749102ea8af90d) --- src/mm-port-qmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-port-qmi.c b/src/mm-port-qmi.c index e3d99f7f..af407bd4 100644 --- a/src/mm-port-qmi.c +++ b/src/mm-port-qmi.c @@ -541,7 +541,7 @@ port_open_step (GTask *task) qmi_device_open (ctx->device, (QMI_DEVICE_OPEN_FLAGS_VERSION_INFO | QMI_DEVICE_OPEN_FLAGS_PROXY), - 25, + 45, g_task_get_cancellable (task), (GAsyncReadyCallback) qmi_device_open_first_ready, task); From 3fb5f80283bd2013073fb71c592e5d63efca39e2 Mon Sep 17 00:00:00 2001 From: Freedom Liu Date: Mon, 26 Apr 2021 15:19:37 +0800 Subject: [PATCH 637/675] foxconn: change modem-foxconn-t77w968 to modem-mbim-foxconn Named the object in a more generic way. (cherry picked from commit c31488608a331f4d16dacb923a5611c52f57f1cb) --- plugins/Makefile.am | 8 +-- plugins/dell/mm-plugin-dell.c | 12 ++--- .../mm-broadband-modem-foxconn-t77w968.h | 49 ------------------- ...68.c => mm-broadband-modem-mbim-foxconn.c} | 44 ++++++++--------- .../foxconn/mm-broadband-modem-mbim-foxconn.h | 49 +++++++++++++++++++ ...g.conf => mm-foxconn-carrier-mapping.conf} | 0 plugins/foxconn/mm-plugin-foxconn.c | 12 ++--- plugins/tests/test-keyfiles.c | 6 +-- 8 files changed, 90 insertions(+), 90 deletions(-) delete mode 100644 plugins/foxconn/mm-broadband-modem-foxconn-t77w968.h rename plugins/foxconn/{mm-broadband-modem-foxconn-t77w968.c => mm-broadband-modem-mbim-foxconn.c} (91%) create mode 100644 plugins/foxconn/mm-broadband-modem-mbim-foxconn.h rename plugins/foxconn/{mm-foxconn-t77w968-carrier-mapping.conf => mm-foxconn-carrier-mapping.conf} (100%) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index df78beb3..77c34715 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -429,8 +429,8 @@ if WITH_MBIM pkglib_LTLIBRARIES += libmm-shared-foxconn.la libmm_shared_foxconn_la_SOURCES = \ foxconn/mm-shared.c \ - foxconn/mm-broadband-modem-foxconn-t77w968.c \ - foxconn/mm-broadband-modem-foxconn-t77w968.h \ + foxconn/mm-broadband-modem-mbim-foxconn.c \ + foxconn/mm-broadband-modem-mbim-foxconn.h \ $(NULL) libmm_shared_foxconn_la_CPPFLAGS = \ $(SHARED_COMMON_COMPILER_FLAGS) \ @@ -716,11 +716,11 @@ libmm_plugin_foxconn_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) dist_udevrules_DATA += foxconn/77-mm-foxconn-port-types.rules -dist_pkgdata_DATA += foxconn/mm-foxconn-t77w968-carrier-mapping.conf +dist_pkgdata_DATA += foxconn/mm-foxconn-carrier-mapping.conf AM_CFLAGS += \ -DTESTUDEVRULESDIR_FOXCONN=\"${srcdir}/foxconn\" \ - -DTESTKEYFILE_FOXCONN_T77W968=\"${srcdir}/foxconn/mm-foxconn-t77w968-carrier-mapping.conf\" \ + -DTESTKEYFILE_FOXCONN=\"${srcdir}/foxconn/mm-foxconn-carrier-mapping.conf\" \ $(NULL) endif diff --git a/plugins/dell/mm-plugin-dell.c b/plugins/dell/mm-plugin-dell.c index 36c21cf9..01914fb8 100644 --- a/plugins/dell/mm-plugin-dell.c +++ b/plugins/dell/mm-plugin-dell.c @@ -45,7 +45,7 @@ #if defined WITH_MBIM #include "mm-broadband-modem-mbim.h" #include "mm-broadband-modem-mbim-xmm.h" -#include "mm-broadband-modem-foxconn-t77w968.h" +#include "mm-broadband-modem-mbim-foxconn.h" #endif #define MAX_PORT_PROBE_TIMEOUTS 3 @@ -396,11 +396,11 @@ create_modem (MMPlugin *self, /* Specific implementation for the DW5821e */ if (vendor == 0x413c && (product == 0x81d7 || product == 0x81e0)) { mm_obj_dbg (self, "MBIM-powered DW5821e (T77W968) modem found..."); - return MM_BASE_MODEM (mm_broadband_modem_foxconn_t77w968_new (uid, - drivers, - mm_plugin_get_name (self), - vendor, - product)); + return MM_BASE_MODEM (mm_broadband_modem_mbim_foxconn_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); } if (mm_port_probe_list_is_xmm (probes)) { diff --git a/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.h b/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.h deleted file mode 100644 index 9d145033..00000000 --- a/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2018-2019 Aleksander Morgado - */ - -#ifndef MM_BROADBAND_MODEM_FOXCONN_T77W968_H -#define MM_BROADBAND_MODEM_FOXCONN_T77W968_H - -#include "mm-broadband-modem-mbim.h" - -#define MM_TYPE_BROADBAND_MODEM_FOXCONN_T77W968 (mm_broadband_modem_foxconn_t77w968_get_type ()) -#define MM_BROADBAND_MODEM_FOXCONN_T77W968(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_FOXCONN_T77W968, MMBroadbandModemFoxconnT77w968)) -#define MM_BROADBAND_MODEM_FOXCONN_T77W968_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_FOXCONN_T77W968, MMBroadbandModemFoxconnT77w968Class)) -#define MM_IS_BROADBAND_MODEM_FOXCONN_T77W968(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_FOXCONN_T77W968)) -#define MM_IS_BROADBAND_MODEM_FOXCONN_T77W968_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_FOXCONN_T77W968)) -#define MM_BROADBAND_MODEM_FOXCONN_T77W968_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_FOXCONN_T77W968, MMBroadbandModemFoxconnT77w968Class)) - -typedef struct _MMBroadbandModemFoxconnT77w968 MMBroadbandModemFoxconnT77w968; -typedef struct _MMBroadbandModemFoxconnT77w968Class MMBroadbandModemFoxconnT77w968Class; -typedef struct _MMBroadbandModemFoxconnT77w968Private MMBroadbandModemFoxconnT77w968Private; - -struct _MMBroadbandModemFoxconnT77w968 { - MMBroadbandModemMbim parent; - MMBroadbandModemFoxconnT77w968Private *priv; -}; - -struct _MMBroadbandModemFoxconnT77w968Class{ - MMBroadbandModemMbimClass parent; -}; - -GType mm_broadband_modem_foxconn_t77w968_get_type (void); - -MMBroadbandModemFoxconnT77w968 *mm_broadband_modem_foxconn_t77w968_new (const gchar *device, - const gchar **driver, - const gchar *plugin, - guint16 vendor_id, - guint16 product_id); - -#endif /* MM_BROADBAND_MODEM_FOXCONN_T77W968_H */ diff --git a/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c similarity index 91% rename from plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c rename to plugins/foxconn/mm-broadband-modem-mbim-foxconn.c index 2288cd09..b1d197a3 100644 --- a/plugins/foxconn/mm-broadband-modem-foxconn-t77w968.c +++ b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c @@ -31,7 +31,7 @@ #include "mm-base-modem-at.h" #include "mm-iface-modem.h" #include "mm-iface-modem-location.h" -#include "mm-broadband-modem-foxconn-t77w968.h" +#include "mm-broadband-modem-mbim-foxconn.h" #if defined WITH_QMI # include "mm-iface-modem-firmware.h" @@ -46,7 +46,7 @@ static void iface_modem_firmware_init (MMIfaceModemFirmware *iface); static MMIfaceModemLocation *iface_modem_location_parent; -G_DEFINE_TYPE_EXTENDED (MMBroadbandModemFoxconnT77w968, mm_broadband_modem_foxconn_t77w968, MM_TYPE_BROADBAND_MODEM_MBIM, 0, +G_DEFINE_TYPE_EXTENDED (MMBroadbandModemMbimFoxconn, mm_broadband_modem_mbim_foxconn, MM_TYPE_BROADBAND_MODEM_MBIM, 0, #if defined WITH_QMI G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init) #endif @@ -58,7 +58,7 @@ typedef enum { FEATURE_SUPPORTED } FeatureSupport; -struct _MMBroadbandModemFoxconnT77w968Private { +struct _MMBroadbandModemMbimFoxconnPrivate { FeatureSupport unmanaged_gps_support; }; @@ -131,7 +131,7 @@ firmware_load_update_settings (MMIfaceModemFirmware *self, NULL); if (!client) { g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Unable to load T77w968 version info: no QMI DMS client available"); + "Unable to load version info: no QMI DMS client available"); g_object_unref (task); return; } @@ -159,7 +159,7 @@ firmware_load_update_settings (MMIfaceModemFirmware *self, static MMModemLocationSource location_load_capabilities_finish (MMIfaceModemLocation *self, GAsyncResult *res, - GError **error) + GError **error) { GError *inner_error = NULL; gssize value; @@ -176,7 +176,7 @@ static void custom_location_load_capabilities (GTask *task, MMModemLocationSource sources) { - MMBroadbandModemFoxconnT77w968 *self; + MMBroadbandModemMbimFoxconn *self; self = g_task_get_source_object (task); @@ -304,8 +304,8 @@ disable_location_gathering (MMIfaceModemLocation *_self, GAsyncReadyCallback callback, gpointer user_data) { - MMBroadbandModemFoxconnT77w968 *self = MM_BROADBAND_MODEM_FOXCONN_T77W968 (_self); - GTask *task; + MMBroadbandModemMbimFoxconn *self = MM_BROADBAND_MODEM_MBIM_FOXCONN (_self); + GTask *task; task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL); @@ -353,8 +353,8 @@ unmanaged_gps_enabled_ready (MMBaseModem *self, static void custom_enable_location_gathering (GTask *task) { - MMBroadbandModemFoxconnT77w968 *self; - MMModemLocationSource source; + MMBroadbandModemMbimFoxconn *self; + MMModemLocationSource source; self = g_task_get_source_object (task); source = GPOINTER_TO_UINT (g_task_get_task_data (task)); @@ -419,14 +419,14 @@ enable_location_gathering (MMIfaceModemLocation *self, /*****************************************************************************/ -MMBroadbandModemFoxconnT77w968 * -mm_broadband_modem_foxconn_t77w968_new (const gchar *device, - const gchar **drivers, - const gchar *plugin, - guint16 vendor_id, - guint16 product_id) +MMBroadbandModemMbimFoxconn * +mm_broadband_modem_mbim_foxconn_new (const gchar *device, + const gchar **drivers, + const gchar *plugin, + guint16 vendor_id, + guint16 product_id) { - return g_object_new (MM_TYPE_BROADBAND_MODEM_FOXCONN_T77W968, + return g_object_new (MM_TYPE_BROADBAND_MODEM_MBIM_FOXCONN, MM_BASE_MODEM_DEVICE, device, MM_BASE_MODEM_DRIVERS, drivers, MM_BASE_MODEM_PLUGIN, plugin, @@ -436,15 +436,15 @@ mm_broadband_modem_foxconn_t77w968_new (const gchar *device, MM_IFACE_MODEM_SIM_HOT_SWAP_CONFIGURED, FALSE, MM_IFACE_MODEM_PERIODIC_SIGNAL_CHECK_DISABLED, TRUE, MM_IFACE_MODEM_LOCATION_ALLOW_GPS_UNMANAGED_ALWAYS, TRUE, - MM_IFACE_MODEM_CARRIER_CONFIG_MAPPING, PKGDATADIR "/mm-foxconn-t77w968-carrier-mapping.conf", + MM_IFACE_MODEM_CARRIER_CONFIG_MAPPING, PKGDATADIR "/mm-foxconn-carrier-mapping.conf", NULL); } static void -mm_broadband_modem_foxconn_t77w968_init (MMBroadbandModemFoxconnT77w968 *self) +mm_broadband_modem_mbim_foxconn_init (MMBroadbandModemMbimFoxconn *self) { /* Initialize private data */ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_BROADBAND_MODEM_FOXCONN_T77W968, MMBroadbandModemFoxconnT77w968Private); + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MM_TYPE_BROADBAND_MODEM_MBIM_FOXCONN, MMBroadbandModemMbimFoxconnPrivate); self->priv->unmanaged_gps_support = FEATURE_SUPPORT_UNKNOWN; } @@ -473,9 +473,9 @@ iface_modem_firmware_init (MMIfaceModemFirmware *iface) #endif static void -mm_broadband_modem_foxconn_t77w968_class_init (MMBroadbandModemFoxconnT77w968Class *klass) +mm_broadband_modem_mbim_foxconn_class_init (MMBroadbandModemMbimFoxconnClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (object_class, sizeof (MMBroadbandModemFoxconnT77w968Private)); + g_type_class_add_private (object_class, sizeof (MMBroadbandModemMbimFoxconnPrivate)); } diff --git a/plugins/foxconn/mm-broadband-modem-mbim-foxconn.h b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.h new file mode 100644 index 00000000..374599e4 --- /dev/null +++ b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.h @@ -0,0 +1,49 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2018-2019 Aleksander Morgado + */ + +#ifndef MM_BROADBAND_MODEM_MBIM_FOXCONN_H +#define MM_BROADBAND_MODEM_MBIM_FOXCONN_H + +#include "mm-broadband-modem-mbim.h" + +#define MM_TYPE_BROADBAND_MODEM_MBIM_FOXCONN (mm_broadband_modem_mbim_foxconn_get_type ()) +#define MM_BROADBAND_MODEM_MBIM_FOXCONN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_MBIM_FOXCONN, MMBroadbandModemMbimFoxconn)) +#define MM_BROADBAND_MODEM_MBIM_FOXCONN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_MBIM_FOXCONN, MMBroadbandModemMbimFoxconnClass)) +#define MM_IS_BROADBAND_MODEM_MBIM_FOXCONN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_MBIM_FOXCONN)) +#define MM_IS_BROADBAND_MODEM_MBIM_FOXCONN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_MBIM_FOXCONN)) +#define MM_BROADBAND_MODEM_MBIM_FOXCONN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_MBIM_FOXCONN, MMBroadbandModemMbimFoxconnClass)) + +typedef struct _MMBroadbandModemMbimFoxconn MMBroadbandModemMbimFoxconn; +typedef struct _MMBroadbandModemMbimFoxconnClass MMBroadbandModemMbimFoxconnClass; +typedef struct _MMBroadbandModemMbimFoxconnPrivate MMBroadbandModemMbimFoxconnPrivate; + +struct _MMBroadbandModemMbimFoxconn { + MMBroadbandModemMbim parent; + MMBroadbandModemMbimFoxconnPrivate *priv; +}; + +struct _MMBroadbandModemMbimFoxconnClass{ + MMBroadbandModemMbimClass parent; +}; + +GType mm_broadband_modem_mbim_foxconn_get_type (void); + +MMBroadbandModemMbimFoxconn *mm_broadband_modem_mbim_foxconn_new (const gchar *device, + const gchar **driver, + const gchar *plugin, + guint16 vendor_id, + guint16 product_id); + +#endif /* MM_BROADBAND_MODEM_MBIM_FOXCONN_H */ diff --git a/plugins/foxconn/mm-foxconn-t77w968-carrier-mapping.conf b/plugins/foxconn/mm-foxconn-carrier-mapping.conf similarity index 100% rename from plugins/foxconn/mm-foxconn-t77w968-carrier-mapping.conf rename to plugins/foxconn/mm-foxconn-carrier-mapping.conf diff --git a/plugins/foxconn/mm-plugin-foxconn.c b/plugins/foxconn/mm-plugin-foxconn.c index 19071c0b..b8e3017e 100644 --- a/plugins/foxconn/mm-plugin-foxconn.c +++ b/plugins/foxconn/mm-plugin-foxconn.c @@ -34,7 +34,7 @@ #endif #if defined WITH_MBIM -#include "mm-broadband-modem-foxconn-t77w968.h" +#include "mm-broadband-modem-mbim-foxconn.h" #endif G_DEFINE_TYPE (MMPluginFoxconn, mm_plugin_foxconn, MM_TYPE_PLUGIN) @@ -69,11 +69,11 @@ create_modem (MMPlugin *self, /* Specific implementation for the T77W968 */ if (product == 0xe0b4 || product == 0xe0b5) { mm_obj_dbg (self, "MBIM-powered T77W968 modem found..."); - return MM_BASE_MODEM (mm_broadband_modem_foxconn_t77w968_new (uid, - drivers, - mm_plugin_get_name (self), - vendor, - product)); + return MM_BASE_MODEM (mm_broadband_modem_mbim_foxconn_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); } mm_obj_dbg (self, "MBIM-powered Foxconn-branded modem found..."); diff --git a/plugins/tests/test-keyfiles.c b/plugins/tests/test-keyfiles.c index d528cac9..0914291f 100644 --- a/plugins/tests/test-keyfiles.c +++ b/plugins/tests/test-keyfiles.c @@ -56,9 +56,9 @@ test_dummy (void) #if defined ENABLE_PLUGIN_FOXCONN static void -test_foxconn_t77w968 (void) +test_foxconn (void) { - common_test (TESTKEYFILE_FOXCONN_T77W968); + common_test (TESTKEYFILE_FOXCONN); } #endif @@ -72,7 +72,7 @@ int main (int argc, char **argv) g_test_add_func ("/MM/test-keyfiles/dummy", test_dummy); #if defined ENABLE_PLUGIN_FOXCONN - g_test_add_func ("/MM/test-keyfiles/foxconn/t77w968", test_foxconn_t77w968); + g_test_add_func ("/MM/test-keyfiles/foxconn", test_foxconn); #endif return g_test_run (); From 8904436e126d0c408003b0f6b5b78b2c0c3c1977 Mon Sep 17 00:00:00 2001 From: Freedom Liu Date: Mon, 26 Apr 2021 15:29:36 +0800 Subject: [PATCH 638/675] foxconn: add support for the T99W175 module 0x0489 is the vendor ID of T77W968, 0x105b is the vendor ID of T99W175. {0x105b, 0xe0b0},{0x105b, 0xe0b1} is T99W175 PCI device, used by Dell. {0x105b, 0xe0ab} is T99W175 PCI device, used by Lenovo. If the modem has an mbim port, create a MbimFoxconn object, regardless of what the product ID is. The firmware version format in the T99W175 was selected to have firmware version + carrier config version + apps version. (cherry picked from commit 47ea5c98f4d05a2113b7533fec86ac6003171c85) --- .../foxconn/mm-broadband-modem-mbim-foxconn.c | 15 +++++++--- plugins/foxconn/mm-plugin-foxconn.c | 29 +++++++------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c index b1d197a3..7f051e1c 100644 --- a/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c +++ b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c @@ -137,10 +137,17 @@ firmware_load_update_settings (MMIfaceModemFirmware *self, } input = qmi_message_dms_foxconn_get_firmware_version_input_new (); - qmi_message_dms_foxconn_get_firmware_version_input_set_version_type ( - input, - QMI_DMS_FOXCONN_FIRMWARE_VERSION_TYPE_FIRMWARE_MCFG, - NULL); + /* 0x105b is the T99W175 module, T99W175 needs to compare the apps version. */ + if (mm_base_modem_get_vendor_id (MM_BASE_MODEM (self)) == 0x105b) + qmi_message_dms_foxconn_get_firmware_version_input_set_version_type ( + input, + QMI_DMS_FOXCONN_FIRMWARE_VERSION_TYPE_FIRMWARE_MCFG_APPS, + NULL); + else + qmi_message_dms_foxconn_get_firmware_version_input_set_version_type ( + input, + QMI_DMS_FOXCONN_FIRMWARE_VERSION_TYPE_FIRMWARE_MCFG, + NULL); qmi_client_dms_foxconn_get_firmware_version ( QMI_CLIENT_DMS (client), input, diff --git a/plugins/foxconn/mm-plugin-foxconn.c b/plugins/foxconn/mm-plugin-foxconn.c index b8e3017e..0eef97ef 100644 --- a/plugins/foxconn/mm-plugin-foxconn.c +++ b/plugins/foxconn/mm-plugin-foxconn.c @@ -66,22 +66,12 @@ create_modem (MMPlugin *self, #if defined WITH_MBIM if (mm_port_probe_list_has_mbim_port (probes)) { - /* Specific implementation for the T77W968 */ - if (product == 0xe0b4 || product == 0xe0b5) { - mm_obj_dbg (self, "MBIM-powered T77W968 modem found..."); - return MM_BASE_MODEM (mm_broadband_modem_mbim_foxconn_new (uid, - drivers, - mm_plugin_get_name (self), - vendor, - product)); - } - mm_obj_dbg (self, "MBIM-powered Foxconn-branded modem found..."); - return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid, - drivers, - mm_plugin_get_name (self), - vendor, - product)); + return MM_BASE_MODEM (mm_broadband_modem_mbim_foxconn_new (uid, + drivers, + mm_plugin_get_name (self), + vendor, + product)); } #endif @@ -98,14 +88,17 @@ create_modem (MMPlugin *self, G_MODULE_EXPORT MMPlugin * mm_plugin_create (void) { - static const gchar *subsystems[] = { "tty", "net", "usbmisc", NULL }; - static const guint16 vendors[] = { 0x0489, 0 }; + static const gchar *subsystems[] = { "tty", "net", "usbmisc", "wwan", NULL }; + static const guint16 vendor_ids[] = { + 0x0489, /* usb vid */ + 0x105b, /* pci vid */ + 0 }; return MM_PLUGIN ( g_object_new (MM_TYPE_PLUGIN_FOXCONN, MM_PLUGIN_NAME, MM_MODULE_NAME, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, - MM_PLUGIN_ALLOWED_VENDOR_IDS, vendors, + MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids, MM_PLUGIN_ALLOWED_AT, TRUE, MM_PLUGIN_ALLOWED_QCDM, TRUE, MM_PLUGIN_ALLOWED_QMI, TRUE, From da23f9cd7a7642e8cf8245952a7403bb30fca1b8 Mon Sep 17 00:00:00 2001 From: Freedom Liu Date: Fri, 30 Apr 2021 01:52:12 +0000 Subject: [PATCH 639/675] foxconn: add new MBIM QDU firmware update method support Based on the QDU service newly added in libmbim, T99W175 module (vid: 0x105b) supports MBIM QDU based update. (cherry picked from commit 35b1672b85d23e0961c33fc7aebc17d0e2d26c81) --- include/ModemManager-enums.h | 2 ++ .../foxconn/mm-broadband-modem-mbim-foxconn.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h index 7f1be95a..426e0e3f 100644 --- a/include/ModemManager-enums.h +++ b/include/ModemManager-enums.h @@ -1515,6 +1515,7 @@ typedef enum { /*< underscore_name=mm_call_direction >*/ * @MM_MODEM_FIRMWARE_UPDATE_METHOD_NONE: No method specified. * @MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT: Device supports fastboot-based update. * @MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC: Device supports QMI PDC based update. + * @MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU: Device supports MBIM QDU based update. Since 1.18. * * Type of firmware update method supported by the module. * @@ -1524,6 +1525,7 @@ typedef enum { /*< underscore_name=mm_modem_firmware_update_method >*/ MM_MODEM_FIRMWARE_UPDATE_METHOD_NONE = 0, MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT = 1 << 0, MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC = 1 << 1, + MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU = 1 << 2, } MMModemFirmwareUpdateMethod; #endif /* _MODEMMANAGER_ENUMS_H_ */ diff --git a/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c index 7f051e1c..1e845a9b 100644 --- a/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c +++ b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c @@ -89,15 +89,24 @@ foxconn_get_firmware_version_ready (QmiClientDms *client, GError *error = NULL; MMFirmwareUpdateSettings *update_settings = NULL; const gchar *str; + MMIfaceModemFirmware *self; output = qmi_client_dms_foxconn_get_firmware_version_finish (client, res, &error); if (!output || !qmi_message_dms_foxconn_get_firmware_version_output_get_result (output, &error)) goto out; - /* Create update settings now */ - update_settings = mm_firmware_update_settings_new (MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT | - MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC); - mm_firmware_update_settings_set_fastboot_at (update_settings, "AT^FASTBOOT"); + /* Create update settings now: + * 0x105b is the T99W175 module, T99W175 supports QDU, + * else support FASTBOOT and QMI PDC. + */ + self = g_task_get_source_object (task); + if (mm_base_modem_get_vendor_id (MM_BASE_MODEM (self)) == 0x105b) + update_settings = mm_firmware_update_settings_new (MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU); + else { + update_settings = mm_firmware_update_settings_new (MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT | + MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC); + mm_firmware_update_settings_set_fastboot_at (update_settings, "AT^FASTBOOT"); + } qmi_message_dms_foxconn_get_firmware_version_output_get_version (output, &str, NULL); mm_firmware_update_settings_set_version (update_settings, str); From 2cb38c568ff1fb26b23bad5e8a2851547448c30e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 21 May 2021 23:46:28 +0200 Subject: [PATCH 640/675] api: QDU update method defined in MM 1.16.6 already --- include/ModemManager-enums.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h index 426e0e3f..f544c61d 100644 --- a/include/ModemManager-enums.h +++ b/include/ModemManager-enums.h @@ -1515,7 +1515,7 @@ typedef enum { /*< underscore_name=mm_call_direction >*/ * @MM_MODEM_FIRMWARE_UPDATE_METHOD_NONE: No method specified. * @MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT: Device supports fastboot-based update. * @MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC: Device supports QMI PDC based update. - * @MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU: Device supports MBIM QDU based update. Since 1.18. + * @MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU: Device supports MBIM QDU based update. Since 1.16.6. * * Type of firmware update method supported by the module. * From 8308b24347d8bc88cddfcb13cbbf624d6577b3fa Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Mon, 31 May 2021 16:56:30 +0200 Subject: [PATCH 641/675] quectel: ignore QLWURC QLWURCs are not ignored and causes calls to be rejected in some cases (cherry picked from commit c00eff43ac6eda070645d77edc8da71facd972a3) --- plugins/quectel/mm-shared-quectel.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index 61373db6..bf31fed7 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -50,12 +50,14 @@ typedef struct { MMModemLocationSource enabled_sources; FeatureSupport qgps_supported; GRegex *qgpsurc_regex; + GRegex *qlwurc_regex; } Private; static void private_free (Private *priv) { g_regex_unref (priv->qgpsurc_regex); + g_regex_unref (priv->qlwurc_regex); g_slice_free (Private, priv); } @@ -75,6 +77,7 @@ get_private (MMSharedQuectel *self) priv->enabled_sources = MM_MODEM_LOCATION_SOURCE_NONE; priv->qgps_supported = FEATURE_SUPPORT_UNKNOWN; priv->qgpsurc_regex = g_regex_new ("\\r\\n\\+QGPSURC:.*", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + priv->qlwurc_regex = g_regex_new ("\\r\\n\\+QLWURC:.*", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); g_assert (MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_broadband_modem_class); priv->broadband_modem_class_parent = MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_broadband_modem_class (self); @@ -120,6 +123,12 @@ mm_shared_quectel_setup_ports (MMBroadbandModem *self) ports[i], priv->qgpsurc_regex, NULL, NULL, NULL); + + /* Ignore +QLWURC */ + mm_port_serial_at_add_unsolicited_msg_handler ( + ports[i], + priv->qlwurc_regex, + NULL, NULL, NULL); } } From e903a840ed87074a35581f5e5faf8fba3436c135 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 1 Jun 2021 09:36:53 +0200 Subject: [PATCH 642/675] broadband-modem-mbim: skip switch() when selecting MBIM services Having a switch() for the MBIM services when processing indications forces us to update it on every new MBIM service added to libmbim, because we build with -Wswitch-enum by default. This warning type is extremely useful, and we should not stop using it, so let's simplify a bit the indication handling code and skip using a switch(). There are right now only 4 different service indications expected, so it shouldn't be a big deal. (cherry picked from commit e25a585c9fd8c3f58ec01723843fe3c08c30c1ad) --- src/mm-broadband-modem-mbim.c | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 1da66c74..4ae3d44c 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -3588,40 +3588,14 @@ device_notification_cb (MbimDevice *device, mbim_cid_get_printable (service, mbim_message_indicate_status_get_cid (notification))); - switch (service) { - case MBIM_SERVICE_BASIC_CONNECT: + if (service == MBIM_SERVICE_BASIC_CONNECT) basic_connect_notification (self, notification); - break; - case MBIM_SERVICE_MS_BASIC_CONNECT_EXTENSIONS: + else if (service == MBIM_SERVICE_MS_BASIC_CONNECT_EXTENSIONS) ms_basic_connect_extensions_notification (self, notification); - break; - case MBIM_SERVICE_SMS: + else if (service == MBIM_SERVICE_SMS) sms_notification (self, notification); - break; - case MBIM_SERVICE_USSD: + else if (service == MBIM_SERVICE_USSD) ussd_notification (self, notification); - break; - case MBIM_SERVICE_INVALID: - case MBIM_SERVICE_PHONEBOOK: - case MBIM_SERVICE_STK: - case MBIM_SERVICE_AUTH: - case MBIM_SERVICE_DSS: - case MBIM_SERVICE_MS_FIRMWARE_ID: - case MBIM_SERVICE_MS_HOST_SHUTDOWN: - case MBIM_SERVICE_PROXY_CONTROL: - case MBIM_SERVICE_QMI: - case MBIM_SERVICE_ATDS: - case MBIM_SERVICE_INTEL_FIRMWARE_UPDATE: -#if MBIM_CHECK_VERSION (1,25,1) - case MBIM_SERVICE_MS_SAR: -#endif -#if MBIM_CHECK_VERSION (1,25,3) - case MBIM_SERVICE_QDU: -#endif - default: - /* Ignore */ - break; - } } static void From 8c4708939e396c5e1aeeac99f5f197d4c7440cea Mon Sep 17 00:00:00 2001 From: Felipe Borges Date: Thu, 27 May 2021 15:05:55 +0200 Subject: [PATCH 643/675] cinterion: avoid maybe-uninitialized warning by GCC 10 Reported at https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1371 (cherry picked from commit 0b8607bc5dc4cce16ebb7c6a7bd71dfb3032d978) --- plugins/cinterion/mm-modem-helpers-cinterion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index 67da6120..b63b67c1 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -978,7 +978,7 @@ mm_cinterion_parse_smong_response (const gchar *response, guint value = 0; GError *inner_error = NULL; g_autoptr(GMatchInfo) match_info = NULL; - g_autoptr(GRegex) regex; + g_autoptr(GRegex) regex = NULL; /* The AT^SMONG command returns a cell info table, where the second * column identifies the "GPRS status", which is exactly what we want. From a8f65a16c753eef05fbd4bd15372116f1a9343c5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 2 Jun 2021 09:56:00 +0200 Subject: [PATCH 644/675] shared-qmi: add missing g_autoptr() NULL initializer (cherry picked from commit eefcf9204f2de801092b1d14d86c7012420e97af) --- src/mm-shared-qmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 84d93d92..4d9ca5cc 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -3688,7 +3688,7 @@ static void uim_refresh_complete (QmiClientUim *client, QmiUimSessionType session_type) { - g_autoptr(QmiMessageUimRefreshCompleteInput) refresh_complete_input; + g_autoptr(QmiMessageUimRefreshCompleteInput) refresh_complete_input = NULL; GArray *dummy_aid; dummy_aid = g_array_new (FALSE, FALSE, sizeof (guint8)); From 7fc8f67af9b5fe30e3b1f96b56ed781af2d44bc2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 23 May 2021 00:38:09 +0200 Subject: [PATCH 645/675] broadband-modem: check if skeleton exists when creating device id The logic that creates the device identifier uses some fields that are exposed in DBus (e.g. model, manufacturer...). We should not attempt to load any of that info if the DBus skeleton for the Modem interface is no longer available, as e.g. the device may have gone away already. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/374 (cherry picked from commit 3da3623e11f90e45951118119da6f842053fd133) --- src/mm-broadband-modem-mbim.c | 16 ++++++++++------ src/mm-broadband-modem-qmi.c | 16 ++++++++++------ src/mm-broadband-modem.c | 36 ++++++++++++++++++++++++----------- src/mm-broadband-modem.h | 7 ++++--- 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 4ae3d44c..434f4f74 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -814,15 +814,19 @@ modem_load_device_identifier (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - gchar *device_identifier; - GTask *task; + gchar *device_identifier; + GTask *task; + GError *error = NULL; + + task = g_task_new (self, NULL, callback, user_data); /* Just use dummy ATI/ATI1 replies, all the other internal info should be * enough for uniqueness */ - device_identifier = mm_broadband_modem_create_device_identifier (MM_BROADBAND_MODEM (self), "", ""); - - task = g_task_new (self, NULL, callback, user_data); - g_task_return_pointer (task, device_identifier, g_free); + device_identifier = mm_broadband_modem_create_device_identifier (MM_BROADBAND_MODEM (self), "", "", &error); + if (!device_identifier) + g_task_return_error (task, error); + else + g_task_return_pointer (task, device_identifier, g_free); g_object_unref (task); } diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index b291a1c8..ab695725 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -703,17 +703,21 @@ modem_load_device_identifier (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - gchar *device_identifier; - GTask *task; + gchar *device_identifier; + GTask *task; + GError *error = NULL; + + task = g_task_new (self, NULL, callback, user_data); mm_obj_dbg (self, "loading device identifier..."); /* Just use dummy ATI/ATI1 replies, all the other internal info should be * enough for uniqueness */ - device_identifier = mm_broadband_modem_create_device_identifier (MM_BROADBAND_MODEM (self), "", ""); - - task = g_task_new (self, NULL, callback, user_data); - g_task_return_pointer (task, device_identifier, g_free); + device_identifier = mm_broadband_modem_create_device_identifier (MM_BROADBAND_MODEM (self), "", "", &error); + if (!device_identifier) + g_task_return_error (task, error); + else + g_task_return_pointer (task, device_identifier, g_free); g_object_unref (task); } diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index a25883ac..e2f4398b 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -1121,9 +1121,9 @@ modem_load_device_identifier_finish (MMIfaceModem *self, GAsyncResult *res, GError **error) { - GError *inner_error = NULL; - gpointer ctx = NULL; - gchar *device_identifier; + GError *inner_error = NULL; + gpointer ctx = NULL; + gchar *device_identifier; mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, &ctx, &inner_error); if (inner_error) { @@ -1132,10 +1132,16 @@ modem_load_device_identifier_finish (MMIfaceModem *self, } g_assert (ctx != NULL); - device_identifier = (mm_broadband_modem_create_device_identifier ( - MM_BROADBAND_MODEM (self), - ((DeviceIdentifierContext *)ctx)->ati, - ((DeviceIdentifierContext *)ctx)->ati1)); + device_identifier = mm_broadband_modem_create_device_identifier ( + MM_BROADBAND_MODEM (self), + ((DeviceIdentifierContext *)ctx)->ati, + ((DeviceIdentifierContext *)ctx)->ati1, + &inner_error); + if (!device_identifier) { + g_propagate_error (error, inner_error); + return NULL; + } + mm_obj_dbg (self, "loaded device identifier: %s", device_identifier); return device_identifier; } @@ -11913,10 +11919,18 @@ mm_broadband_modem_get_current_charset (MMBroadbandModem *self) /*****************************************************************************/ gchar * -mm_broadband_modem_create_device_identifier (MMBroadbandModem *self, - const gchar *ati, - const gchar *ati1) -{ +mm_broadband_modem_create_device_identifier (MMBroadbandModem *self, + const gchar *ati, + const gchar *ati1, + GError **error) +{ + /* do nothing if device has gone already */ + if (!self->priv->modem_dbus_skeleton) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Modem interface skeleton unavailable"); + return NULL; + } + return (mm_create_device_identifier ( mm_base_modem_get_vendor_id (MM_BASE_MODEM (self)), mm_base_modem_get_product_id (MM_BASE_MODEM (self)), diff --git a/src/mm-broadband-modem.h b/src/mm-broadband-modem.h index 1f5acac3..2ba05799 100644 --- a/src/mm-broadband-modem.h +++ b/src/mm-broadband-modem.h @@ -104,9 +104,10 @@ MMModemCharset mm_broadband_modem_get_current_charset (MMBroadbandModem *self); /* Create a unique device identifier string using the ATI and ATI1 replies and some * additional internal info */ -gchar *mm_broadband_modem_create_device_identifier (MMBroadbandModem *self, - const gchar *ati, - const gchar *ati1); +gchar *mm_broadband_modem_create_device_identifier (MMBroadbandModem *self, + const gchar *ati, + const gchar *ati1, + GError **error); /* Locking/unlocking SMS storages */ void mm_broadband_modem_lock_sms_storages (MMBroadbandModem *self, From 812463c9a82c3e921a392bf06789194ccad42cc5 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 22 May 2021 00:46:55 +0200 Subject: [PATCH 646/675] shared-qmi: trivial coding style update (cherry picked from commit ec8bf7f0e39435f98d322d09a36b0d3e171a9ae7) --- src/mm-shared-qmi.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mm-shared-qmi.h b/src/mm-shared-qmi.h index 9af00b9d..624b79b9 100644 --- a/src/mm-shared-qmi.h +++ b/src/mm-shared-qmi.h @@ -179,12 +179,12 @@ void mm_shared_qmi_set_primary_sim_slot (MMIfaceMode gboolean mm_shared_qmi_set_primary_sim_slot_finish (MMIfaceModem *self, GAsyncResult *res, GError **error); -void mm_shared_qmi_setup_sim_hot_swap (MMIfaceModem *self, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean mm_shared_qmi_setup_sim_hot_swap_finish (MMIfaceModem *self, - GAsyncResult *res, - GError **error); +void mm_shared_qmi_setup_sim_hot_swap (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_shared_qmi_setup_sim_hot_swap_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error); /* Shared QMI location support */ From 977452e155163983e4638c39a82dfad9d847904b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 25 May 2021 15:42:11 +0200 Subject: [PATCH 647/675] base-manager: ensure all GUdevDevices have subsystem and name set Under certain rare conditions (e.g. race between querying devices of a given subsystem and the kernel tearing those devices down), the subsystem reported for a GUdevDevice seems to be NULL. So, ensure both subsystem and name are set on the GUdevDevice before we process them. The issue has been observed on GUdevDevices listed by g_udev_client_query_by_subsystem(), not on the ones asynchronously reported via uevents, but we add the validity check on both places for consistency. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/343 (cherry picked from commit 940063419a1c2eb9f6e197d60b4c7cb42702de8d) --- src/mm-base-manager.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/mm-base-manager.c b/src/mm-base-manager.c index 130e5ad1..851c1d6e 100644 --- a/src/mm-base-manager.c +++ b/src/mm-base-manager.c @@ -433,6 +433,17 @@ handle_uevent (MMBaseManager *self, const gchar *action, GUdevDevice *device) { + const gchar *subsystem; + const gchar *name; + + subsystem = g_udev_device_get_subsystem (device); + name = g_udev_device_get_name (device); + + /* Valid udev devices must have subsystem and name set; if they don't have + * both things, we silently ignore them. */ + if (!subsystem || !name) + return; + if (g_str_equal (action, "add") || g_str_equal (action, "move") || g_str_equal (action, "change")) { g_autoptr(MMKernelDevice) kernel_device = NULL; @@ -442,7 +453,7 @@ handle_uevent (MMBaseManager *self, } if (g_str_equal (action, "remove")) { - device_removed (self, g_udev_device_get_subsystem (device), g_udev_device_get_name (device)); + device_removed (self, subsystem, name); return; } } @@ -456,11 +467,20 @@ typedef struct { static gboolean start_device_added_idle (StartDeviceAdded *ctx) { - MMKernelDevice *kernel_device; + const gchar *subsystem; + const gchar *name; + + subsystem = g_udev_device_get_subsystem (ctx->device); + name = g_udev_device_get_name (ctx->device); - kernel_device = mm_kernel_device_udev_new (ctx->device); - device_added (ctx->self, kernel_device, FALSE, ctx->manual_scan); - g_object_unref (kernel_device); + /* Valid udev devices must have subsystem and name set; if they don't have + * both things, we silently ignore them. */ + if (subsystem && name) { + g_autoptr(MMKernelDevice) kernel_device = NULL; + + kernel_device = mm_kernel_device_udev_new (ctx->device); + device_added (ctx->self, kernel_device, FALSE, ctx->manual_scan); + } g_object_unref (ctx->self); g_object_unref (ctx->device); From 148a6c6e46dedc5cd391e326f4c0a60ce39bea84 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 19 May 2021 13:02:42 +0200 Subject: [PATCH 648/675] iface-modem: new optional FCC unlock step in the power state update There are devices that come locked before they can be put online. Until now we had a specific implementation for this in the generic QMI modem, but we should have it in a more generic way for any kind of modem. (cherry picked from commit 6ca75c76db277b89325e1888ac445cbfebe33039) --- src/mm-iface-modem.c | 352 +++++++++++++++++++++---------------------- src/mm-iface-modem.h | 8 + 2 files changed, 180 insertions(+), 180 deletions(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 7a84a6d2..9bc421c9 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -3703,249 +3703,231 @@ mm_iface_modem_update_lock_info (MMIfaceModem *self, /*****************************************************************************/ /* Set power state sequence */ +typedef enum { + SET_POWER_STATE_STEP_FIRST, + SET_POWER_STATE_STEP_LOAD, + SET_POWER_STATE_STEP_CHECK, + SET_POWER_STATE_STEP_UPDATE, + SET_POWER_STATE_STEP_FCC_UNLOCK, + SET_POWER_STATE_STEP_AFTER_UPDATE, + SET_POWER_STATE_STEP_LAST, +} SetPowerStateStep; + typedef struct { - MmGdbusModem *skeleton; - MMModemPowerState power_state; - MMModemPowerState previous_cached_power_state; - MMModemPowerState previous_real_power_state; + SetPowerStateStep step; + MmGdbusModem *skeleton; + GError *saved_error; + gboolean fcc_unlock_attempted; + MMModemPowerState requested_power_state; + MMModemPowerState previous_cached_power_state; + MMModemPowerState previous_real_power_state; + + void (*requested_power_setup) (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (*requested_power_setup_finish) (MMIfaceModem *self, + GAsyncResult *res, + GError **error); } SetPowerStateContext; static void set_power_state_context_free (SetPowerStateContext *ctx) { + g_assert (!ctx->saved_error); if (ctx->skeleton) g_object_unref (ctx->skeleton); g_slice_free (SetPowerStateContext, ctx); } gboolean -mm_iface_modem_set_power_state_finish (MMIfaceModem *self, - GAsyncResult *res, - GError **error) +mm_iface_modem_set_power_state_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } +static void set_power_state_step (GTask *task); + static void modem_after_power_up_ready (MMIfaceModem *self, GAsyncResult *res, - GTask *task) + GTask *task) { - GError *error = NULL; + SetPowerStateContext *ctx; - MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_power_up_finish (self, res, &error); - if (error) - g_task_return_error (task, error); - else - g_task_return_boolean (task, TRUE); - g_object_unref (task); + ctx = g_task_get_task_data (task); + g_assert (!ctx->saved_error); + MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_power_up_finish (self, res, &ctx->saved_error); + if (ctx->saved_error) + mm_obj_dbg (self, "failure running after power up step: %s", ctx->saved_error->message); + + ctx->step++; + set_power_state_step (task); } static void -modem_power_up_ready (MMIfaceModem *self, - GAsyncResult *res, - GTask *task) +fcc_unlock_ready (MMIfaceModem *self, + GAsyncResult *res, + GTask *task) { SetPowerStateContext *ctx; - GError *error = NULL; + g_autoptr(GError) error = NULL; ctx = g_task_get_task_data (task); + if (!MM_IFACE_MODEM_GET_INTERFACE (self)->fcc_unlock_finish (self, res, &error)) + mm_obj_dbg (self, "couldn't run FCC unlock: %s", error->message); - MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_up_finish (self, res, &error); - if (error) { - /* If the real and cached ones are different, set the real one */ - if (ctx->previous_cached_power_state != ctx->previous_real_power_state) - mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->previous_real_power_state); - g_task_return_error (task, error); - g_object_unref (task); - return; - } - - mm_obj_dbg (self, "set in full-power mode..."); - mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->power_state); - - /* If we have something to do just after power-up, do it */ - if (MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_power_up && - MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_power_up_finish) { - MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_power_up ( - self, - (GAsyncReadyCallback)modem_after_power_up_ready, - task); - return; - } - - /* Otherwise, we're done */ - g_task_return_boolean (task, TRUE); - g_object_unref (task); + /* always retry, even on reported error */ + ctx->step = SET_POWER_STATE_STEP_UPDATE; + set_power_state_step (task); } static void -modem_power_down_ready (MMIfaceModem *self, - GAsyncResult *res, - GTask *task) +requested_power_setup_ready (MMIfaceModem *self, + GAsyncResult *res, + GTask *task) { SetPowerStateContext *ctx; - GError *error = NULL; ctx = g_task_get_task_data (task); + g_assert (!ctx->saved_error); + if (!ctx->requested_power_setup_finish (self, res, &ctx->saved_error)) + mm_obj_dbg (self, "couldn't update power state: %s", ctx->saved_error->message); - MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_down_finish (self, res, &error); - if (error) { - /* If the real and cached ones are different, set the real one */ - if (ctx->previous_cached_power_state != ctx->previous_real_power_state) - mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->previous_real_power_state); - g_task_return_error (task, error); - } else { - mm_obj_dbg (self, "set in low-power mode..."); - mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->power_state); - g_task_return_boolean (task, TRUE); - } - - g_object_unref (task); + ctx->step++; + set_power_state_step (task); } static void -modem_power_off_ready (MMIfaceModem *self, - GAsyncResult *res, - GTask *task) +set_power_state_load_ready (MMIfaceModem *self, + GAsyncResult *res, + GTask *task) { SetPowerStateContext *ctx; - GError *error = NULL; + g_autoptr(GError) error = NULL; ctx = g_task_get_task_data (task); - MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_off_finish (self, res, &error); + ctx->previous_real_power_state = MM_IFACE_MODEM_GET_INTERFACE (self)->load_power_state_finish (self, res, &error); if (error) { - /* If the real and cached ones are different, set the real one */ - if (ctx->previous_cached_power_state != ctx->previous_real_power_state) - mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->previous_real_power_state); - g_task_return_error (task, error); - } else { - mm_obj_info (self, "powered off... may no longer be accessible"); - mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->power_state); - g_task_return_boolean (task, TRUE); + mm_obj_dbg (self, "couldn't reload current power state: %s", error->message); + /* Default to the cached one */ + ctx->previous_real_power_state = ctx->previous_cached_power_state; } - g_object_unref (task); + ctx->step++; + set_power_state_step (task); } static void -set_power_state (GTask *task) +set_power_state_step (GTask *task) { - MMIfaceModem *self; + MMIfaceModem *self; SetPowerStateContext *ctx; self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); + ctx = g_task_get_task_data (task); - /* Already done if we're in the desired power state */ - if (ctx->previous_real_power_state == ctx->power_state) { - mm_obj_dbg (self, "no need to change power state: already in '%s' power state", - mm_modem_power_state_get_string (ctx->power_state)); - /* If the real and cached ones are different, set the real one */ - if (ctx->previous_cached_power_state != ctx->previous_real_power_state) - mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->previous_real_power_state); - g_task_return_boolean (task, TRUE); - g_object_unref (task); - return; - } + switch (ctx->step) { + case SET_POWER_STATE_STEP_FIRST: + ctx->step++; + /* fall-through */ - /* Fully powering off the modem? */ - if (ctx->power_state == MM_MODEM_POWER_STATE_OFF) { - /* Error if unsupported */ - if (!MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_off || - !MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_off_finish) { - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_UNSUPPORTED, - "Powering off is not supported by this modem"); - g_object_unref (task); + case SET_POWER_STATE_STEP_LOAD: + /* We cannot really rely on the power state value that we had cached before, + * as the real power status of the modem may also be changed by rfkill. So, + * before updating the current power state, re-check which is the real power + * state. */ + if (MM_IFACE_MODEM_GET_INTERFACE (self)->load_power_state && + MM_IFACE_MODEM_GET_INTERFACE (self)->load_power_state_finish) { + MM_IFACE_MODEM_GET_INTERFACE (self)->load_power_state (self, (GAsyncReadyCallback)set_power_state_load_ready, task); return; } + /* If there is no way to load power state, just keep on assuming the cached + * one is also the real one */ + ctx->previous_real_power_state = ctx->previous_cached_power_state; + ctx->step++; + /* fall-through */ - MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_off ( - MM_IFACE_MODEM (self), - (GAsyncReadyCallback)modem_power_off_ready, - task); - return; - } - - /* Going into low power mode? */ - if (ctx->power_state == MM_MODEM_POWER_STATE_LOW) { - /* Error if unsupported */ - if (!MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_down || - !MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_down_finish) { - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_UNSUPPORTED, - "Going into low-power mode is not supported by this modem"); - g_object_unref (task); + case SET_POWER_STATE_STEP_CHECK: + /* Already done if we're in the desired power state */ + if (ctx->previous_real_power_state == ctx->requested_power_state) { + mm_obj_dbg (self, "no need to change power state: already '%s'", + mm_modem_power_state_get_string (ctx->requested_power_state)); + ctx->step = SET_POWER_STATE_STEP_LAST; + set_power_state_step (task); return; } + ctx->step++; + /* fall-through */ - MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_down ( - MM_IFACE_MODEM (self), - (GAsyncReadyCallback)modem_power_down_ready, - task); + case SET_POWER_STATE_STEP_UPDATE: + mm_obj_dbg (self, "updating power state: '%s'...", mm_modem_power_state_get_string (ctx->requested_power_state)); + ctx->requested_power_setup (self, (GAsyncReadyCallback)requested_power_setup_ready, task); return; - } - /* Going out of low power mode? */ - if (ctx->power_state == MM_MODEM_POWER_STATE_ON) { - /* Error if unsupported */ - if (!MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_up || - !MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_up_finish) { - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_UNSUPPORTED, - "Going into full-power mode is not supported by this modem"); - g_object_unref (task); + case SET_POWER_STATE_STEP_FCC_UNLOCK: + /* The FCC unlock operation and update retry should only be done + * if requested by the implementation with MM_CORE_ERROR_RETRY. */ + if ((ctx->requested_power_state == MM_MODEM_POWER_STATE_ON) && + ctx->saved_error && + g_error_matches (ctx->saved_error, MM_CORE_ERROR, MM_CORE_ERROR_RETRY) && + !ctx->fcc_unlock_attempted && + MM_IFACE_MODEM_GET_INTERFACE (self)->fcc_unlock && + MM_IFACE_MODEM_GET_INTERFACE (self)->fcc_unlock_finish) { + mm_obj_dbg (self, "attempting fcc unlock..."); + ctx->fcc_unlock_attempted = TRUE; + g_clear_error (&ctx->saved_error); + MM_IFACE_MODEM_GET_INTERFACE (self)->fcc_unlock (self, (GAsyncReadyCallback)fcc_unlock_ready, task); return; } + ctx->step++; + /* fall-through */ - MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_up ( - MM_IFACE_MODEM (self), - (GAsyncReadyCallback)modem_power_up_ready, - task); - return; - } - - g_assert_not_reached (); -} - -static void -set_power_state_load_ready (MMIfaceModem *self, - GAsyncResult *res, - GTask *task) -{ - SetPowerStateContext *ctx; - GError *error = NULL; + case SET_POWER_STATE_STEP_AFTER_UPDATE: + if ((ctx->requested_power_state == MM_MODEM_POWER_STATE_ON) && + !ctx->saved_error && + MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_power_up && + MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_power_up_finish) { + mm_obj_dbg (self, "running after power up operation..."); + MM_IFACE_MODEM_GET_INTERFACE (self)->modem_after_power_up (self, (GAsyncReadyCallback)modem_after_power_up_ready, task); + return; + } + ctx->step++; + /* fall-through */ - ctx = g_task_get_task_data (task); + case SET_POWER_STATE_STEP_LAST: + if (ctx->saved_error) { + /* If the real and cached ones are different, set the real one */ + if (ctx->previous_cached_power_state != ctx->previous_real_power_state) + mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->previous_real_power_state); + g_task_return_error (task, g_steal_pointer (&ctx->saved_error)); + } else { + mm_obj_info (self, "power state updated: %s", mm_modem_power_state_get_string (ctx->requested_power_state)); + mm_gdbus_modem_set_power_state (ctx->skeleton, ctx->requested_power_state); + g_task_return_boolean (task, TRUE); + } + g_object_unref (task); + return; - ctx->previous_real_power_state = MM_IFACE_MODEM_GET_INTERFACE (self)->load_power_state_finish (self, res, &error); - if (error) { - mm_obj_dbg (self, "couldn't reload current power state: %s", error->message); - g_error_free (error); - /* Default to the cached one */ - ctx->previous_real_power_state = ctx->previous_cached_power_state; + default: + g_assert_not_reached (); } - - /* And keep on */ - set_power_state (task); } void -mm_iface_modem_set_power_state (MMIfaceModem *self, - MMModemPowerState power_state, - GAsyncReadyCallback callback, - gpointer user_data) +mm_iface_modem_set_power_state (MMIfaceModem *self, + MMModemPowerState power_state, + GAsyncReadyCallback callback, + gpointer user_data) { SetPowerStateContext *ctx; - GTask *task; + GTask *task; ctx = g_slice_new0 (SetPowerStateContext); - ctx->power_state = power_state; + ctx->step = SET_POWER_STATE_STEP_FIRST; + ctx->requested_power_state = power_state; task = g_task_new (self, NULL, callback, user_data); g_task_set_task_data (task, ctx, (GDestroyNotify)set_power_state_context_free); @@ -3961,26 +3943,36 @@ mm_iface_modem_set_power_state (MMIfaceModem *self, g_object_unref (task); return; } - ctx->previous_cached_power_state = mm_gdbus_modem_get_power_state (ctx->skeleton); - /* We cannot really rely on the power state value that we had cached before, - * as the real power status of the modem may also be changed by rfkill. So, - * before updating the current power state, re-check which is the real power - * state. */ - if (MM_IFACE_MODEM_GET_INTERFACE (self)->load_power_state && - MM_IFACE_MODEM_GET_INTERFACE (self)->load_power_state_finish) { - MM_IFACE_MODEM_GET_INTERFACE (self)->load_power_state ( - self, - (GAsyncReadyCallback)set_power_state_load_ready, - task); + /* Setup requested operation */ + switch (ctx->requested_power_state) { + case MM_MODEM_POWER_STATE_OFF: + ctx->requested_power_setup = MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_off; + ctx->requested_power_setup_finish = MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_off_finish; + break; + case MM_MODEM_POWER_STATE_LOW: + ctx->requested_power_setup = MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_down; + ctx->requested_power_setup_finish = MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_down_finish; + break; + case MM_MODEM_POWER_STATE_ON: + ctx->requested_power_setup = MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_up; + ctx->requested_power_setup_finish = MM_IFACE_MODEM_GET_INTERFACE (self)->modem_power_up_finish; + break; + case MM_MODEM_POWER_STATE_UNKNOWN: + default: + g_assert_not_reached (); + } + + /* Error if unsupported */ + if (!ctx->requested_power_setup || !ctx->requested_power_setup_finish) { + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "Requested power transition is not supported by this modem"); + g_object_unref (task); return; } - /* If there is no way to load power state, just keep on assuming the cached - * one is also the real one */ - ctx->previous_real_power_state = ctx->previous_cached_power_state; - set_power_state (task); + set_power_state_step (task); } /*****************************************************************************/ diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index 66d43ac0..84495db7 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -269,6 +269,14 @@ struct _MMIfaceModem { GAsyncResult *res, GError **error); + /* Asynchronous FCC unlock operation */ + void (* fcc_unlock) (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (* fcc_unlock_finish) (MMIfaceModem *self, + GAsyncResult *res, + GError **error); + /* Asynchronous modem power-up operation */ void (*modem_power_up) (MMIfaceModem *self, GAsyncReadyCallback callback, From 7b53ccbcf59160ac4f3590d460603c54a296dc97 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 19 May 2021 15:12:17 +0200 Subject: [PATCH 649/675] broadband-modem-qmi: setup FCC unlock step Use the new generic FCC unlock step instead of implementing it within the operating mode setup logic. The operation is implemented in the MMSharedQmi interface as it will also be used by the MBIM modem object. (cherry picked from commit b9596c81879b8eeae3f2e1bab5c31007e5824c1f) --- src/mm-broadband-modem-qmi.c | 240 ++++++++--------------------------- src/mm-shared-qmi.c | 50 ++++++++ src/mm-shared-qmi.h | 6 + 3 files changed, 112 insertions(+), 184 deletions(-) diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index ab695725..b8240c69 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -1633,98 +1633,37 @@ load_signal_quality (MMIfaceModem *self, /*****************************************************************************/ /* Powering up the modem (Modem interface) */ -typedef enum { - SET_OPERATING_MODE_STEP_FIRST, - SET_OPERATING_MODE_STEP_FCC_AUTH, - SET_OPERATING_MODE_STEP_RETRY, - SET_OPERATING_MODE_STEP_LAST -} SetOperatingModeStep; - -typedef struct { - QmiClientDms *client; - QmiMessageDmsSetOperatingModeInput *input; - SetOperatingModeStep step; -} SetOperatingModeContext; - -static void -set_operating_mode_context_free (SetOperatingModeContext *ctx) -{ - g_object_unref (ctx->client); - qmi_message_dms_set_operating_mode_input_unref (ctx->input); - g_slice_free (SetOperatingModeContext, ctx); -} - static gboolean -modem_power_up_down_off_finish (MMIfaceModem *self, - GAsyncResult *res, - GError **error) +modem_power_up_down_off_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_boolean (G_TASK (res), error); } -static void set_operating_mode_context_step (GTask *task); - -static void -dms_set_fcc_authentication_ready (QmiClientDms *client, - GAsyncResult *res, - GTask *task) -{ - MMBroadbandModemQmi *self; - SetOperatingModeContext *ctx; - QmiMessageDmsSetFccAuthenticationOutput *output = NULL; - GError *error = NULL; - - self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); - - output = qmi_client_dms_set_fcc_authentication_finish (client, res, &error); - if (!output || !qmi_message_dms_set_fcc_authentication_output_get_result (output, &error)) { - /* No hard errors */ - mm_obj_dbg (self, "couldn't set FCC authentication: %s", error->message); - g_error_free (error); - } - - if (output) - qmi_message_dms_set_fcc_authentication_output_unref (output); - - /* Retry Set Operating Mode */ - ctx->step++; - set_operating_mode_context_step (task); -} - static void dms_set_operating_mode_ready (QmiClientDms *client, GAsyncResult *res, - GTask *task) + GTask *task) { - MMBroadbandModemQmi *self; - SetOperatingModeContext *ctx; - QmiMessageDmsSetOperatingModeOutput *output = NULL; - GError *error = NULL; + MMBroadbandModemQmi *self; + QmiDmsOperatingMode mode; + GError *error = NULL; + g_autoptr(QmiMessageDmsSetOperatingModeOutput) output = NULL; self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); + mode = GPOINTER_TO_UINT (g_task_get_task_data (task)); output = qmi_client_dms_set_operating_mode_finish (client, res, &error); if (!output) { - /* If unsupported, just go out without errors */ + g_prefix_error (&error, "QMI operation failed: "); + /* If unsupported, just complete without errors */ if (g_error_matches (error, QMI_CORE_ERROR, QMI_CORE_ERROR_UNSUPPORTED)) { - mm_obj_dbg (self, "device doesn't support operating mode setting; ignoring power update."); - g_error_free (error); - ctx->step = SET_OPERATING_MODE_STEP_LAST; - set_operating_mode_context_step (task); - return; + mm_obj_dbg (self, "device doesn't support operating mode setting: ignoring power update"); + g_clear_error (&error); } - - g_prefix_error (&error, "QMI operation failed: "); - g_task_return_error (task, error); - g_object_unref (task); - return; - } - - if (!qmi_message_dms_set_operating_mode_output_get_result (output, &error)) { - QmiDmsOperatingMode mode; - + } else if (!qmi_message_dms_set_operating_mode_output_get_result (output, &error)) { + g_prefix_error (&error, "Couldn't set operating mode: "); /* * Some new devices, like the Dell DW5770, will return an internal error when * trying to bring the power mode to online. @@ -1733,143 +1672,74 @@ dms_set_operating_mode_ready (QmiClientDms *client, * transition" instead when trying to bring the power mode to online. * * We can avoid this by sending the magic "DMS Set FCC Auth" message before - * retrying. + * retrying. Notify this to upper layers with the special MM_CORE_ERROR_RETRY + * error. */ - if (ctx->step == SET_OPERATING_MODE_STEP_FIRST && - qmi_message_dms_set_operating_mode_input_get_mode (ctx->input, &mode, NULL) && - mode == QMI_DMS_OPERATING_MODE_ONLINE && - (g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_INTERNAL) || - g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_INVALID_TRANSITION))) { - g_error_free (error); - /* Go on to FCC auth */ - ctx->step++; - set_operating_mode_context_step (task); - qmi_message_dms_set_operating_mode_output_unref (output); - return; + if ((mode == QMI_DMS_OPERATING_MODE_ONLINE) && + ((g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_INTERNAL) || + g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_INVALID_TRANSITION)))) { + g_clear_error (&error); + error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_RETRY, "FCC unlock may be needed"); } - - g_prefix_error (&error, "Couldn't set operating mode: "); - g_task_return_error (task, error); - g_object_unref (task); - qmi_message_dms_set_operating_mode_output_unref (output); - return; } - qmi_message_dms_set_operating_mode_output_unref (output); - - /* Good! we're done, go to last step */ - ctx->step = SET_OPERATING_MODE_STEP_LAST; - set_operating_mode_context_step (task); -} - -static void -set_operating_mode_context_step (GTask *task) -{ - MMBroadbandModemQmi *self; - SetOperatingModeContext *ctx; - - self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); - - switch (ctx->step) { - case SET_OPERATING_MODE_STEP_FIRST: - mm_obj_dbg (self, "setting device operating mode..."); - qmi_client_dms_set_operating_mode (QMI_CLIENT_DMS (ctx->client), - ctx->input, - 20, - NULL, - (GAsyncReadyCallback)dms_set_operating_mode_ready, - task); - return; - case SET_OPERATING_MODE_STEP_FCC_AUTH: - mm_obj_dbg (self, "setting FCC auth..."); - qmi_client_dms_set_fcc_authentication (QMI_CLIENT_DMS (ctx->client), - NULL, - 5, - NULL, - (GAsyncReadyCallback)dms_set_fcc_authentication_ready, - task); - return; - case SET_OPERATING_MODE_STEP_RETRY: - mm_obj_dbg (self, "setting device operating mode (retry)..."); - qmi_client_dms_set_operating_mode (QMI_CLIENT_DMS (ctx->client), - ctx->input, - 20, - NULL, - (GAsyncReadyCallback)dms_set_operating_mode_ready, - task); - return; - case SET_OPERATING_MODE_STEP_LAST: - /* Good! */ + if (error) + g_task_return_error (task, error); + else g_task_return_boolean (task, TRUE); - g_object_unref (task); - return; - default: - g_assert_not_reached (); - } + g_object_unref (task); } static void -common_power_up_down_off (MMIfaceModem *self, - QmiDmsOperatingMode mode, - GAsyncReadyCallback callback, - gpointer user_data) +common_power_up_down_off (MMIfaceModem *self, + QmiDmsOperatingMode mode, + GAsyncReadyCallback callback, + gpointer user_data) { - SetOperatingModeContext *ctx; - GTask *task; - QmiClient *client = NULL; + GTask *task; + QmiClient *client = NULL; + g_autoptr(QmiMessageDmsSetOperatingModeInput) input = NULL; if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), QMI_SERVICE_DMS, &client, callback, user_data)) return; - /* Setup context */ - ctx = g_slice_new0 (SetOperatingModeContext); - ctx->client = g_object_ref (client); - ctx->input = qmi_message_dms_set_operating_mode_input_new (); - qmi_message_dms_set_operating_mode_input_set_mode (ctx->input, mode, NULL); - ctx->step = SET_OPERATING_MODE_STEP_FIRST; - task = g_task_new (self, NULL, callback, user_data); - g_task_set_task_data (task, - ctx, - (GDestroyNotify)set_operating_mode_context_free); + g_task_set_task_data (task, GUINT_TO_POINTER (mode), NULL); - set_operating_mode_context_step (task); + input = qmi_message_dms_set_operating_mode_input_new (); + qmi_message_dms_set_operating_mode_input_set_mode (input, mode, NULL); + qmi_client_dms_set_operating_mode (QMI_CLIENT_DMS (client), + input, + 20, + NULL, + (GAsyncReadyCallback)dms_set_operating_mode_ready, + task); } static void -modem_power_off (MMIfaceModem *self, - GAsyncReadyCallback callback, - gpointer user_data) +modem_power_off (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) { - common_power_up_down_off (self, - QMI_DMS_OPERATING_MODE_OFFLINE, - callback, - user_data); + common_power_up_down_off (self, QMI_DMS_OPERATING_MODE_OFFLINE, callback, user_data); } static void -modem_power_down (MMIfaceModem *self, - GAsyncReadyCallback callback, - gpointer user_data) +modem_power_down (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) { - common_power_up_down_off (self, - QMI_DMS_OPERATING_MODE_LOW_POWER, - callback, - user_data); + common_power_up_down_off (self, QMI_DMS_OPERATING_MODE_LOW_POWER, callback, user_data); } static void -modem_power_up (MMIfaceModem *self, - GAsyncReadyCallback callback, - gpointer user_data) +modem_power_up (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) { - common_power_up_down_off (self, - QMI_DMS_OPERATING_MODE_ONLINE, - callback, - user_data); + common_power_up_down_off (self, QMI_DMS_OPERATING_MODE_ONLINE, callback, user_data); } /*****************************************************************************/ @@ -10207,6 +10077,8 @@ iface_modem_init (MMIfaceModem *iface) /* Enabling/disabling */ iface->modem_power_up = modem_power_up; iface->modem_power_up_finish = modem_power_up_down_off_finish; + iface->fcc_unlock = mm_shared_qmi_fcc_unlock; + iface->fcc_unlock_finish = mm_shared_qmi_fcc_unlock_finish; iface->modem_after_power_up = NULL; iface->modem_after_power_up_finish = NULL; iface->modem_power_down = modem_power_down; diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index 4d9ca5cc..a2f25095 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -4114,6 +4114,56 @@ mm_shared_qmi_setup_sim_hot_swap (MMIfaceModem *self, task); } +/*****************************************************************************/ +/* FCC unlock (Modem interface) */ + +gboolean +mm_shared_qmi_fcc_unlock_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +dms_set_fcc_authentication_ready (QmiClientDms *client, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + g_autoptr(QmiMessageDmsSetFccAuthenticationOutput) output = NULL; + + output = qmi_client_dms_set_fcc_authentication_finish (client, res, &error); + if (!output || !qmi_message_dms_set_fcc_authentication_output_get_result (output, &error)) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +void +mm_shared_qmi_fcc_unlock (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + QmiClient *client = NULL; + + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_DMS, &client, + callback, user_data)) + return; + + task = g_task_new (self, NULL, callback, user_data); + + qmi_client_dms_set_fcc_authentication (QMI_CLIENT_DMS (client), + NULL, + 5, + NULL, + (GAsyncReadyCallback)dms_set_fcc_authentication_ready, + task); +} + /*****************************************************************************/ /* Location: Set SUPL server */ diff --git a/src/mm-shared-qmi.h b/src/mm-shared-qmi.h index 624b79b9..3c2bdc42 100644 --- a/src/mm-shared-qmi.h +++ b/src/mm-shared-qmi.h @@ -185,6 +185,12 @@ void mm_shared_qmi_setup_sim_hot_swap (MMIfaceMode gboolean mm_shared_qmi_setup_sim_hot_swap_finish (MMIfaceModem *self, GAsyncResult *res, GError **error); +void mm_shared_qmi_fcc_unlock (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mm_shared_qmi_fcc_unlock_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error); /* Shared QMI location support */ From edaa6413f6585132fcc6d4851f96e1a54c1d1be1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 21 May 2021 15:48:31 +0200 Subject: [PATCH 650/675] broadband-modem-mbim: setup FCC unlock step Use the new generic FCC unlock step instead of implementing it within the power up setup logic. (cherry picked from commit 76f24256174039a75926cdc0ce3a6b1f03ea10ee) --- src/mm-broadband-modem-mbim.c | 219 +++++----------------------------- 1 file changed, 30 insertions(+), 189 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 434f4f74..e7f6e1da 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -1497,36 +1497,6 @@ modem_load_power_state (MMIfaceModem *self, /*****************************************************************************/ /* Power up (Modem interface) */ -typedef enum { - POWER_UP_CONTEXT_STEP_FIRST, -#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED - POWER_UP_CONTEXT_STEP_FCC_AUTH, - POWER_UP_CONTEXT_STEP_RETRY, -#endif - POWER_UP_CONTEXT_STEP_LAST, -} PowerUpContextStep; - -typedef struct { - MbimDevice *device; - PowerUpContextStep step; -#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED - QmiClient *qmi_client_dms; - GError *saved_error; -#endif -} PowerUpContext; - -static void -power_up_context_free (PowerUpContext *ctx) -{ -#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED - g_clear_object (&ctx->qmi_client_dms); - if (ctx->saved_error) - g_error_free (ctx->saved_error); -#endif - g_object_unref (ctx->device); - g_slice_free (PowerUpContext, ctx); -} - static gboolean power_up_finish (MMIfaceModem *self, GAsyncResult *res, @@ -1535,72 +1505,18 @@ power_up_finish (MMIfaceModem *self, return g_task_propagate_boolean (G_TASK (res), error); } -static void power_up_context_step (GTask *task); - -#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED - -static void -set_fcc_authentication_ready (QmiClientDms *qmi_client_dms, - GAsyncResult *res, - GTask *task) -{ - MMBroadbandModemMbim *self; - PowerUpContext *ctx; - QmiMessageDmsSetFccAuthenticationOutput *output; - GError *error = NULL; - - self = g_task_get_source_object (task); - ctx = g_task_get_task_data (task); - - output = qmi_client_dms_set_fcc_authentication_finish (qmi_client_dms, res, &error); - if (!output || !qmi_message_dms_set_fcc_authentication_output_get_result (output, &error)) { - mm_obj_dbg (self, "couldn't set FCC auth: %s", error->message); - g_error_free (error); - g_assert (ctx->saved_error); - g_task_return_error (task, ctx->saved_error); - ctx->saved_error = NULL; - g_object_unref (task); - goto out; - } - - ctx->step++; - power_up_context_step (task); - -out: - if (output) - qmi_message_dms_set_fcc_authentication_output_unref (output); -} - static void -set_radio_state_fcc_auth (GTask *task) -{ - PowerUpContext *ctx; - - ctx = g_task_get_task_data (task); - g_assert (ctx->qmi_client_dms); - - qmi_client_dms_set_fcc_authentication (QMI_CLIENT_DMS (ctx->qmi_client_dms), - NULL, - 10, - NULL, /* cancellable */ - (GAsyncReadyCallback)set_fcc_authentication_ready, - task); -} - -#endif - -static void -radio_state_set_up_ready (MbimDevice *device, +radio_state_set_up_ready (MbimDevice *device, GAsyncResult *res, - GTask *task) + GTask *task) { - PowerUpContext *ctx; - MbimMessage *response; - GError *error = NULL; - MbimRadioSwitchState hardware_radio_state; - MbimRadioSwitchState software_radio_state; + MMBroadbandModemMbim *self; + g_autoptr(MbimMessage) response = NULL; + g_autoptr(GError) error = NULL; + MbimRadioSwitchState hardware_radio_state; + MbimRadioSwitchState software_radio_state; - ctx = g_task_get_task_data (task); + self = g_task_get_source_object (task); response = mbim_device_command_finish (device, res, &error); if (response && @@ -1611,96 +1527,27 @@ radio_state_set_up_ready (MbimDevice *device, &software_radio_state, &error)) { if (hardware_radio_state == MBIM_RADIO_SWITCH_STATE_OFF) - error = g_error_new (MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, + error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Cannot power-up: hardware radio switch is OFF"); else if (software_radio_state == MBIM_RADIO_SWITCH_STATE_OFF) - error = g_error_new (MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, + error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Cannot power-up: sotware radio switch is OFF"); } - if (response) - mbim_message_unref (response); - /* Nice! we're done, quick exit */ if (!error) { - ctx->step = POWER_UP_CONTEXT_STEP_LAST; - power_up_context_step (task); - return; - } - -#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED - /* Only the first attempt isn't fatal, if we have a QMI DMS client */ - if ((ctx->step == POWER_UP_CONTEXT_STEP_FIRST) && ctx->qmi_client_dms) { - MMBroadbandModemMbim *self; - - /* Warn and keep, will retry */ - self = g_task_get_source_object (task); - mm_obj_warn (self, "%s", error->message); - g_assert (!ctx->saved_error); - ctx->saved_error = error; - ctx->step++; - power_up_context_step (task); - return; - } -#endif - - /* Fatal */ - g_task_return_error (task, error); - g_object_unref (task); -} - -static void -set_radio_state_up (GTask *task) -{ - PowerUpContext *ctx; - MbimMessage *message; - - ctx = g_task_get_task_data (task); - message = mbim_message_radio_state_set_new (MBIM_RADIO_SWITCH_STATE_ON, NULL); - mbim_device_command (ctx->device, - message, - 20, - NULL, - (GAsyncReadyCallback)radio_state_set_up_ready, - task); - mbim_message_unref (message); -} - -static void -power_up_context_step (GTask *task) -{ - PowerUpContext *ctx; - - ctx = g_task_get_task_data (task); - - switch (ctx->step) { - case POWER_UP_CONTEXT_STEP_FIRST: - set_radio_state_up (task); - return; - -#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED - - case POWER_UP_CONTEXT_STEP_FCC_AUTH: - set_radio_state_fcc_auth (task); - return; - - case POWER_UP_CONTEXT_STEP_RETRY: - set_radio_state_up (task); - return; - -#endif - - case POWER_UP_CONTEXT_STEP_LAST: - /* Good! */ g_task_return_boolean (task, TRUE); g_object_unref (task); return; - - default: - g_assert_not_reached (); } + + /* The SDX55 returns "Operation not allowed", but not really sure about other + * older devices. The original logic in the MBIM implemetation triggered a retry + * for any kind of error, so let's do the same for now. */ + mm_obj_warn (self, "%s", error->message); + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_RETRY, + "FCC unlock may be needed"); + g_object_unref (task); } static void @@ -1708,30 +1555,22 @@ modem_power_up (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - PowerUpContext *ctx; - MbimDevice *device; - GTask *task; + MbimDevice *device; + GTask *task; + g_autoptr(MbimMessage) message = NULL; if (!peek_device (self, &device, callback, user_data)) return; - ctx = g_slice_new0 (PowerUpContext); - ctx->device = g_object_ref (device); - ctx->step = POWER_UP_CONTEXT_STEP_FIRST; - -#if defined WITH_QMI && QMI_MBIM_QMUX_SUPPORTED - ctx->qmi_client_dms = mm_shared_qmi_peek_client (MM_SHARED_QMI (self), - QMI_SERVICE_DMS, - MM_PORT_QMI_FLAG_DEFAULT, - NULL); - if (ctx->qmi_client_dms) - g_object_ref (ctx->qmi_client_dms); -#endif - task = g_task_new (self, NULL, callback, user_data); - g_task_set_task_data (task, ctx, (GDestroyNotify)power_up_context_free); - power_up_context_step (task); + message = mbim_message_radio_state_set_new (MBIM_RADIO_SWITCH_STATE_ON, NULL); + mbim_device_command (device, + message, + 20, + NULL, + (GAsyncReadyCallback)radio_state_set_up_ready, + task); } /*****************************************************************************/ @@ -5667,6 +5506,8 @@ iface_modem_init (MMIfaceModem *iface) iface->load_current_bands_finish = mm_shared_qmi_load_current_bands_finish; iface->set_current_bands = mm_shared_qmi_set_current_bands; iface->set_current_bands_finish = mm_shared_qmi_set_current_bands_finish; + iface->fcc_unlock = mm_shared_qmi_fcc_unlock; + iface->fcc_unlock_finish = mm_shared_qmi_fcc_unlock_finish; #endif /* Additional actions */ From 2886b08522e7c29d5d9ffa9d186129bbe1fffbba Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 3 Jun 2021 13:04:53 +0200 Subject: [PATCH 651/675] build: require libqmi 1.28.6 for Foxconn FCC unlock support --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 05d55406..8ce81248 100644 --- a/configure.ac +++ b/configure.ac @@ -401,7 +401,7 @@ dnl----------------------------------------------------------------------------- dnl QMI support (enabled by default) dnl -LIBQMI_VERSION=1.28.4 +LIBQMI_VERSION=1.28.6 AC_ARG_WITH(qmi, AS_HELP_STRING([--without-qmi], [Build without QMI support]), [], [with_qmi=yes]) AM_CONDITIONAL(WITH_QMI, test "x$with_qmi" = "xyes") From 374f80f5c37ddff2ea74781ca85da1e283f23035 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 19 May 2021 15:37:47 +0200 Subject: [PATCH 652/675] foxconn: setup FCC unlock step Use the new "DMS Foxconn Set FCC authentication" command to request the modem unlock during a power up operation. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/373 (cherry picked from commit 9fdbbc6929cb61d4168e1696a94e5b2f07bc578e) --- .../foxconn/mm-broadband-modem-mbim-foxconn.c | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c index 1e845a9b..c035b69c 100644 --- a/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c +++ b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c @@ -41,6 +41,7 @@ static void iface_modem_location_init (MMIfaceModemLocation *iface); #if defined WITH_QMI +static void iface_modem_init (MMIfaceModem *iface); static void iface_modem_firmware_init (MMIfaceModemFirmware *iface); #endif @@ -48,6 +49,7 @@ static MMIfaceModemLocation *iface_modem_location_parent; G_DEFINE_TYPE_EXTENDED (MMBroadbandModemMbimFoxconn, mm_broadband_modem_mbim_foxconn, MM_TYPE_BROADBAND_MODEM_MBIM, 0, #if defined WITH_QMI + G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init) G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_FIRMWARE, iface_modem_firmware_init) #endif G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, iface_modem_location_init)) @@ -62,6 +64,62 @@ struct _MMBroadbandModemMbimFoxconnPrivate { FeatureSupport unmanaged_gps_support; }; + +#if defined WITH_QMI + +/*****************************************************************************/ +/* FCC unlock (Modem interface) */ + +static gboolean +fcc_unlock_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +dms_foxconn_set_fcc_authentication_ready (QmiClientDms *client, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + g_autoptr(QmiMessageDmsFoxconnSetFccAuthenticationOutput) output = NULL; + + output = qmi_client_dms_foxconn_set_fcc_authentication_finish (client, res, &error); + if (!output || !qmi_message_dms_foxconn_set_fcc_authentication_output_get_result (output, &error)) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void +fcc_unlock (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + QmiClient *client = NULL; + g_autoptr(QmiMessageDmsFoxconnSetFccAuthenticationInput) input = NULL; + + if (!mm_shared_qmi_ensure_client (MM_SHARED_QMI (self), + QMI_SERVICE_DMS, &client, + callback, user_data)) + return; + + task = g_task_new (self, NULL, callback, user_data); + + input = qmi_message_dms_foxconn_set_fcc_authentication_input_new (); + qmi_message_dms_foxconn_set_fcc_authentication_input_set_value (input, 0x00, NULL); + qmi_client_dms_foxconn_set_fcc_authentication (QMI_CLIENT_DMS (client), + input, + 5, + NULL, + (GAsyncReadyCallback)dms_foxconn_set_fcc_authentication_ready, + task); +} + /*****************************************************************************/ /* Firmware update settings * @@ -70,8 +128,6 @@ struct _MMBroadbandModemMbimFoxconnPrivate { * report. */ -#if defined WITH_QMI - static MMFirmwareUpdateSettings * firmware_load_update_settings_finish (MMIfaceModemFirmware *self, GAsyncResult *res, @@ -479,6 +535,13 @@ iface_modem_location_init (MMIfaceModemLocation *iface) #if defined WITH_QMI +static void +iface_modem_init (MMIfaceModem *iface) +{ + iface->fcc_unlock = fcc_unlock; + iface->fcc_unlock_finish = fcc_unlock_finish; +} + static void iface_modem_firmware_init (MMIfaceModemFirmware *iface) { From cc4e32610f7372a54fe150cfd8b19e62d269a7b0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 4 Jun 2021 12:13:33 +0200 Subject: [PATCH 653/675] Revert "api: QDU update method defined in MM 1.16.6 already" This reverts commit 2cb38c568ff1fb26b23bad5e8a2851547448c30e. --- include/ModemManager-enums.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h index f544c61d..426e0e3f 100644 --- a/include/ModemManager-enums.h +++ b/include/ModemManager-enums.h @@ -1515,7 +1515,7 @@ typedef enum { /*< underscore_name=mm_call_direction >*/ * @MM_MODEM_FIRMWARE_UPDATE_METHOD_NONE: No method specified. * @MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT: Device supports fastboot-based update. * @MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC: Device supports QMI PDC based update. - * @MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU: Device supports MBIM QDU based update. Since 1.16.6. + * @MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU: Device supports MBIM QDU based update. Since 1.18. * * Type of firmware update method supported by the module. * From b610ea14019e4645a29a87b51be08d712b243f03 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 4 Jun 2021 12:14:02 +0200 Subject: [PATCH 654/675] Revert "foxconn: add new MBIM QDU firmware update method support" This reverts commit da23f9cd7a7642e8cf8245952a7403bb30fca1b8. The stable 1.16 branch does not build-depend on any libmbim git master version, so we should not report the QDU firmware update method as supported in MM at this point. It would not have been a big problem if we did expose the QDU firmware update method, because the logic in fwupd checks the MM and libmbim versions separately, but I think it's better to skip reporting QDU as supported ourselves for consistency with the minimum libmbim version we require. --- include/ModemManager-enums.h | 2 -- .../foxconn/mm-broadband-modem-mbim-foxconn.c | 17 ++++------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h index 426e0e3f..7f1be95a 100644 --- a/include/ModemManager-enums.h +++ b/include/ModemManager-enums.h @@ -1515,7 +1515,6 @@ typedef enum { /*< underscore_name=mm_call_direction >*/ * @MM_MODEM_FIRMWARE_UPDATE_METHOD_NONE: No method specified. * @MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT: Device supports fastboot-based update. * @MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC: Device supports QMI PDC based update. - * @MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU: Device supports MBIM QDU based update. Since 1.18. * * Type of firmware update method supported by the module. * @@ -1525,7 +1524,6 @@ typedef enum { /*< underscore_name=mm_modem_firmware_update_method >*/ MM_MODEM_FIRMWARE_UPDATE_METHOD_NONE = 0, MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT = 1 << 0, MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC = 1 << 1, - MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU = 1 << 2, } MMModemFirmwareUpdateMethod; #endif /* _MODEMMANAGER_ENUMS_H_ */ diff --git a/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c index c035b69c..23780f48 100644 --- a/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c +++ b/plugins/foxconn/mm-broadband-modem-mbim-foxconn.c @@ -145,24 +145,15 @@ foxconn_get_firmware_version_ready (QmiClientDms *client, GError *error = NULL; MMFirmwareUpdateSettings *update_settings = NULL; const gchar *str; - MMIfaceModemFirmware *self; output = qmi_client_dms_foxconn_get_firmware_version_finish (client, res, &error); if (!output || !qmi_message_dms_foxconn_get_firmware_version_output_get_result (output, &error)) goto out; - /* Create update settings now: - * 0x105b is the T99W175 module, T99W175 supports QDU, - * else support FASTBOOT and QMI PDC. - */ - self = g_task_get_source_object (task); - if (mm_base_modem_get_vendor_id (MM_BASE_MODEM (self)) == 0x105b) - update_settings = mm_firmware_update_settings_new (MM_MODEM_FIRMWARE_UPDATE_METHOD_MBIM_QDU); - else { - update_settings = mm_firmware_update_settings_new (MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT | - MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC); - mm_firmware_update_settings_set_fastboot_at (update_settings, "AT^FASTBOOT"); - } + /* Create update settings now */ + update_settings = mm_firmware_update_settings_new (MM_MODEM_FIRMWARE_UPDATE_METHOD_FASTBOOT | + MM_MODEM_FIRMWARE_UPDATE_METHOD_QMI_PDC); + mm_firmware_update_settings_set_fastboot_at (update_settings, "AT^FASTBOOT"); qmi_message_dms_foxconn_get_firmware_version_output_get_version (output, &str, NULL); mm_firmware_update_settings_set_version (update_settings, str); From f62b4ec0f604710435da1e03d1324f8a0e9aba8f Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 6 Jun 2021 12:11:08 +0200 Subject: [PATCH 655/675] core: skip suggesting FCC unlock may be needed This message is too specific, and there are a lot of cases where it wouldn't apply. E.g. when a MBIM module is stuck in low power mode due to some other reason (like hardware rfkill), this message would pop up to the users and completely confuse them. (cherry picked from commit 464c0d464c758387ac3d35f4e148db2c4368edba) --- src/mm-broadband-modem-mbim.c | 3 +-- src/mm-broadband-modem-qmi.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index e7f6e1da..027ca931 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -1545,8 +1545,7 @@ radio_state_set_up_ready (MbimDevice *device, * older devices. The original logic in the MBIM implemetation triggered a retry * for any kind of error, so let's do the same for now. */ mm_obj_warn (self, "%s", error->message); - g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_RETRY, - "FCC unlock may be needed"); + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_RETRY, "Invalid transition"); g_object_unref (task); } diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index b8240c69..bc61461d 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -1679,7 +1679,7 @@ dms_set_operating_mode_ready (QmiClientDms *client, ((g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_INTERNAL) || g_error_matches (error, QMI_PROTOCOL_ERROR, QMI_PROTOCOL_ERROR_INVALID_TRANSITION)))) { g_clear_error (&error); - error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_RETRY, "FCC unlock may be needed"); + error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_RETRY, "Invalid transition"); } } From 5e3babb3a12371cd0cb6578c97b2090db3b95d0b Mon Sep 17 00:00:00 2001 From: Loic Poulain Date: Wed, 12 May 2021 13:18:00 +0200 Subject: [PATCH 656/675] udev: Do not consider USB WWAN ports as valid candidates For now WWAN subsystem support has only been validated for PCI/MHI based devices and extra patches for USB based devices (qmi_wwan, cdc-mbim...) may be required, so do not consider WWAN ports being on USB bus. Signed-off-by: Loic Poulain (cherry picked from commit c39d1d2fbc62dca759efcf8dc5b80c69a45269de) --- src/80-mm-candidate.rules | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/80-mm-candidate.rules b/src/80-mm-candidate.rules index a0891bfc..38b34db5 100644 --- a/src/80-mm-candidate.rules +++ b/src/80-mm-candidate.rules @@ -16,9 +16,13 @@ KERNEL=="rfcomm*", DEVPATH=="*/virtual/*", GOTO="mm_candidate_end" SUBSYSTEM=="tty", ENV{ID_MM_CANDIDATE}="1" SUBSYSTEM=="net", ENV{ID_MM_CANDIDATE}="1" KERNEL=="cdc-wdm[0-9]*", SUBSYSTEM=="usbmisc", ENV{ID_MM_CANDIDATE}="1" + +# For now WWAN subsystem has only been validated with PCI-based devices +SUBSYSTEMS=="usb", GOTO="mm_candidate_end" SUBSYSTEM=="wwan", ENV{ID_MM_CANDIDATE}="1" SUBSYSTEM=="wwan", KERNEL=="*MBIM", ENV{ID_MM_PORT_TYPE_MBIM}="1" SUBSYSTEM=="wwan", KERNEL=="*QMI", ENV{ID_MM_PORT_TYPE_QMI}="1" SUBSYSTEM=="wwan", KERNEL=="*AT", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" SUBSYSTEM=="wwan", KERNEL=="*QCDM", ENV{ID_MM_PORT_TYPE_QCDM}="1" + LABEL="mm_candidate_end" From 3762fb1737892b06ab435b5c70c394dca3f994b8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 6 Jun 2021 14:45:27 +0200 Subject: [PATCH 657/675] udev: only flag as candidates the wwan ports, not the full device Explicitly ignore the "wwan_dev" device as it is not associated with separate ports (which is what MM needs), but with the whole device instead. See https://lists.freedesktop.org/archives/modemmanager-devel/2021-May/008629.html (cherry picked from commit ac18b5ac5bf841cd3a619a9e07137c332558d6c4) --- src/80-mm-candidate.rules | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/80-mm-candidate.rules b/src/80-mm-candidate.rules index 38b34db5..afa524a4 100644 --- a/src/80-mm-candidate.rules +++ b/src/80-mm-candidate.rules @@ -17,8 +17,12 @@ SUBSYSTEM=="tty", ENV{ID_MM_CANDIDATE}="1" SUBSYSTEM=="net", ENV{ID_MM_CANDIDATE}="1" KERNEL=="cdc-wdm[0-9]*", SUBSYSTEM=="usbmisc", ENV{ID_MM_CANDIDATE}="1" -# For now WWAN subsystem has only been validated with PCI-based devices +# WWAN subsystem port handling +# - All USB devices ignored for now, only PCI devices expected +# - Only "wwan_port" device types processed (single ports); we fully ignore +# the "wwan_dev" device type (full device, not just one port) SUBSYSTEMS=="usb", GOTO="mm_candidate_end" +SUBSYSTEM=="wwan", ENV{DEVTYPE}=="wwan_dev", GOTO="mm_candidate_end" SUBSYSTEM=="wwan", ENV{ID_MM_CANDIDATE}="1" SUBSYSTEM=="wwan", KERNEL=="*MBIM", ENV{ID_MM_PORT_TYPE_MBIM}="1" SUBSYSTEM=="wwan", KERNEL=="*QMI", ENV{ID_MM_PORT_TYPE_QMI}="1" From e7a683b525f2908082e7926f8192e6811e9bea69 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 3 Jun 2021 13:24:42 +0200 Subject: [PATCH 658/675] NEWS: update for 1.16.6 --- NEWS | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/NEWS b/NEWS index e904c24f..f7dde983 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,30 @@ +ModemManager 1.16.6 +------------------------------------------- + + * Build: + ** Require libqmi >= 1.28.6 (for the optional QMI support). + ** Fix error with GCC 11 and -Wincompatible-pointer-types. + ** Fix warning with GCC 11 and -Wmaybe-uninitialized. + + * QMI: + ** Increased device open timeout to 45s. + ** Added support to handle transfer-route messages. + + * Base manager: + ** Added support for Qualcomm based PCI devices in the new WWAN subsystem in + kernel 5.13. + ** Fix segfault on rare conditions when ports reported don't have a proper + subsystem or name. + ** Fix segfault when trying to create device id after device is already gone. + + * plugins: + ** foxconn: added support for the T99W175 module. + ** foxconn: fix segfault when attempting to use parent location support. + ** quectel: ignore QLWURC URCs. + + * Several other minor improvements and fixes. + ModemManager 1.16.4 ------------------------------------------- From a7b37461441f66ca1f54c1e83473dbd6e4191852 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 3 Jun 2021 13:25:11 +0200 Subject: [PATCH 659/675] release: bump version to 1.16.6 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 8ce81248..366d765a 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ dnl m4_define([mm_major_version], [1]) m4_define([mm_minor_version], [16]) -m4_define([mm_micro_version], [5]) +m4_define([mm_micro_version], [6]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From 859df95e546a5aa562a74c71ee8d924d3c6e0244 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sun, 6 Jun 2021 15:53:57 +0200 Subject: [PATCH 660/675] build: post-release version bump to 1.16.7 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 366d765a..4b86500b 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ dnl m4_define([mm_major_version], [1]) m4_define([mm_minor_version], [16]) -m4_define([mm_micro_version], [6]) +m4_define([mm_micro_version], [7]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From 1a5e0609dce59c0a49a8698f0e8cb198483124c8 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Wed, 9 Jun 2021 13:49:08 +0200 Subject: [PATCH 661/675] udev: Match WWAN "type" attribute instead of device name Recent changes in the WWAN framework in the kernel changed the WWAN port names from e.g. "wwan0p1AT" and "wwan0p2QMI" to "wwan0at0" and "wwan0qmi0" [1, 2]. This means that the udev rules no longer match since AT/QMI are now lower-case and no longer at the end of the name. However, recently additionally a "type" sysfs attribute was added for all WWAN ports [3], which makes it much more reliable to match the WWAN port names without relying on their exact device name. Add some additional udev rules to apply the port hints based on the "type" sysfs attributes. This fixes the port enumeration on newer Linux kernels that include the aforementioned commits. Note that we still need to keep the old udev rules for now since Linux 5.13 does not have the "type" attribute yet. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=392c26f7f133b9f09e5f58db1ce6ef4b3b4df49f [2]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=f458709ff40b0d992fec496952f79c7820dd3fde [3]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=b3e22e10fdda8e7be3830289a4a63ae8b88d450c (cherry picked from commit 4282c8d843a144f20f0e1bd9f632751af7a5ff70) --- src/80-mm-candidate.rules | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/80-mm-candidate.rules b/src/80-mm-candidate.rules index afa524a4..d33c232e 100644 --- a/src/80-mm-candidate.rules +++ b/src/80-mm-candidate.rules @@ -24,6 +24,12 @@ KERNEL=="cdc-wdm[0-9]*", SUBSYSTEM=="usbmisc", ENV{ID_MM_CANDIDATE}="1" SUBSYSTEMS=="usb", GOTO="mm_candidate_end" SUBSYSTEM=="wwan", ENV{DEVTYPE}=="wwan_dev", GOTO="mm_candidate_end" SUBSYSTEM=="wwan", ENV{ID_MM_CANDIDATE}="1" +SUBSYSTEM=="wwan", ATTR{type}=="AT", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" +SUBSYSTEM=="wwan", ATTR{type}=="MBIM", ENV{ID_MM_PORT_TYPE_MBIM}="1" +SUBSYSTEM=="wwan", ATTR{type}=="QMI", ENV{ID_MM_PORT_TYPE_QMI}="1" +SUBSYSTEM=="wwan", ATTR{type}=="QCDM", ENV{ID_MM_PORT_TYPE_QCDM}="1" + +# Linux 5.13 does not have "type" attribute yet, match kernel name instead SUBSYSTEM=="wwan", KERNEL=="*MBIM", ENV{ID_MM_PORT_TYPE_MBIM}="1" SUBSYSTEM=="wwan", KERNEL=="*QMI", ENV{ID_MM_PORT_TYPE_QMI}="1" SUBSYSTEM=="wwan", KERNEL=="*AT", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" From a165074c76b3edd13d9aa3163d65f19a5a23e9fa Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Wed, 9 Jun 2021 14:51:18 +0200 Subject: [PATCH 662/675] udev: Ignore WWAN "FIREHOSE" ports FIREHOSE ports are used for firmware updates which are done independently from ModemManager, so we should ignore those ports. A similar change was originally made by Loic Poulain here: https://gitlab.freedesktop.org/loicpoulain/ModemManager/-/commit/32b0eb79cdbb37afe33abb72fd948be3cbaf6a2d (cherry picked from commit 43d705ab933ee021ff1c4c0ea5075db205be7a40) --- src/80-mm-candidate.rules | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/80-mm-candidate.rules b/src/80-mm-candidate.rules index d33c232e..2688092b 100644 --- a/src/80-mm-candidate.rules +++ b/src/80-mm-candidate.rules @@ -21,6 +21,7 @@ KERNEL=="cdc-wdm[0-9]*", SUBSYSTEM=="usbmisc", ENV{ID_MM_CANDIDATE}="1" # - All USB devices ignored for now, only PCI devices expected # - Only "wwan_port" device types processed (single ports); we fully ignore # the "wwan_dev" device type (full device, not just one port) +# - FIREHOSE ports are used for firmware updates and not managed by ModemManager SUBSYSTEMS=="usb", GOTO="mm_candidate_end" SUBSYSTEM=="wwan", ENV{DEVTYPE}=="wwan_dev", GOTO="mm_candidate_end" SUBSYSTEM=="wwan", ENV{ID_MM_CANDIDATE}="1" @@ -28,11 +29,13 @@ SUBSYSTEM=="wwan", ATTR{type}=="AT", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" SUBSYSTEM=="wwan", ATTR{type}=="MBIM", ENV{ID_MM_PORT_TYPE_MBIM}="1" SUBSYSTEM=="wwan", ATTR{type}=="QMI", ENV{ID_MM_PORT_TYPE_QMI}="1" SUBSYSTEM=="wwan", ATTR{type}=="QCDM", ENV{ID_MM_PORT_TYPE_QCDM}="1" +SUBSYSTEM=="wwan", ATTR{type}=="FIREHOSE", ENV{ID_MM_PORT_IGNORE}="1" # Linux 5.13 does not have "type" attribute yet, match kernel name instead SUBSYSTEM=="wwan", KERNEL=="*MBIM", ENV{ID_MM_PORT_TYPE_MBIM}="1" SUBSYSTEM=="wwan", KERNEL=="*QMI", ENV{ID_MM_PORT_TYPE_QMI}="1" SUBSYSTEM=="wwan", KERNEL=="*AT", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1" SUBSYSTEM=="wwan", KERNEL=="*QCDM", ENV{ID_MM_PORT_TYPE_QCDM}="1" +SUBSYSTEM=="wwan", KERNEL=="*FIREHOSE", ENV{ID_MM_PORT_IGNORE}="1" LABEL="mm_candidate_end" From 9f6c75b31f4e84984ad51b4091614f8a4361d27d Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 11 Mar 2021 10:43:05 +0100 Subject: [PATCH 663/675] bearer-mbim: session id 0 by default in all non-multiplexed connections The original logic in the MBIM modem would assume that if we had more than one network interface in the same modem, we could connect multiple data interfaces, each one with a different session. That logic is actually wrong, when using the master (non-multiplexed) network interface we should always use session id 0, which is the one holding all non-VLAN-tagged traffic. So, remove the logic that automatically creates new bearers with a different session id, as that is really wrong. (cherry picked from commit e5305498b7ddbc5e419cf51fc0c30aa6593a40d2) --- src/mm-bearer-mbim.c | 64 +------------------------ src/mm-bearer-mbim.h | 3 +- src/mm-broadband-modem-mbim.c | 90 +++++------------------------------ 3 files changed, 16 insertions(+), 141 deletions(-) diff --git a/src/mm-bearer-mbim.c b/src/mm-bearer-mbim.c index 55064b30..1dd9d8d5 100644 --- a/src/mm-bearer-mbim.c +++ b/src/mm-bearer-mbim.c @@ -34,18 +34,9 @@ G_DEFINE_TYPE (MMBearerMbim, mm_bearer_mbim, MM_TYPE_BASE_BEARER) -enum { - PROP_0, - PROP_SESSION_ID, - PROP_LAST -}; - -static GParamSpec *properties[PROP_LAST]; - struct _MMBearerMbimPrivate { /* The session ID for this bearer */ guint32 session_id; - MMPort *data; }; @@ -1426,8 +1417,7 @@ report_connection_status (MMBaseBearer *self, MMBaseBearer * mm_bearer_mbim_new (MMBroadbandModemMbim *modem, - MMBearerProperties *config, - guint32 session_id) + MMBearerProperties *config) { MMBaseBearer *bearer; @@ -1435,9 +1425,8 @@ mm_bearer_mbim_new (MMBroadbandModemMbim *modem, * and that means that the object is not async-initable, so we just use * g_object_new() here */ bearer = g_object_new (MM_TYPE_BEARER_MBIM, - MM_BASE_BEARER_MODEM, modem, + MM_BASE_BEARER_MODEM, modem, MM_BASE_BEARER_CONFIG, config, - MM_BEARER_MBIM_SESSION_ID, (guint)session_id, NULL); /* Only export valid bearers */ @@ -1446,43 +1435,6 @@ mm_bearer_mbim_new (MMBroadbandModemMbim *modem, return bearer; } -static void -set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MMBearerMbim *self = MM_BEARER_MBIM (object); - - switch (prop_id) { - case PROP_SESSION_ID: - self->priv->session_id = g_value_get_uint (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MMBearerMbim *self = MM_BEARER_MBIM (object); - - switch (prop_id) { - case PROP_SESSION_ID: - g_value_set_uint (value, self->priv->session_id); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - static void mm_bearer_mbim_init (MMBearerMbim *self) { @@ -1512,8 +1464,6 @@ mm_bearer_mbim_class_init (MMBearerMbimClass *klass) /* Virtual methods */ object_class->dispose = dispose; - object_class->get_property = get_property; - object_class->set_property = set_property; base_bearer_class->connect = _connect; base_bearer_class->connect_finish = connect_finish; @@ -1524,14 +1474,4 @@ mm_bearer_mbim_class_init (MMBearerMbimClass *klass) base_bearer_class->reload_stats_finish = reload_stats_finish; base_bearer_class->load_connection_status = NULL; base_bearer_class->load_connection_status_finish = NULL; - - properties[PROP_SESSION_ID] = - g_param_spec_uint (MM_BEARER_MBIM_SESSION_ID, - "Session ID", - "Session ID to use with this bearer", - 0, - 255, - 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (object_class, PROP_SESSION_ID, properties[PROP_SESSION_ID]); } diff --git a/src/mm-bearer-mbim.h b/src/mm-bearer-mbim.h index 0d97d8d9..3da599a6 100644 --- a/src/mm-bearer-mbim.h +++ b/src/mm-bearer-mbim.h @@ -53,8 +53,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (MMBearerMbim, g_object_unref) /* MBIM bearer creation implementation. * NOTE it is *not* a broadband bearer, so not async-initable */ MMBaseBearer *mm_bearer_mbim_new (MMBroadbandModemMbim *modem, - MMBearerProperties *config, - guint32 session_id); + MMBearerProperties *config); guint32 mm_bearer_mbim_get_session_id (MMBearerMbim *self); diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c index 027ca931..2156a792 100644 --- a/src/mm-broadband-modem-mbim.c +++ b/src/mm-broadband-modem-mbim.c @@ -1806,93 +1806,29 @@ modem_reset (MMIfaceModem *_self, /* Create Bearer (Modem interface) */ static MMBaseBearer * -modem_create_bearer_finish (MMIfaceModem *self, - GAsyncResult *res, - GError **error) +modem_create_bearer_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) { return g_task_propagate_pointer (G_TASK (res), error); } -typedef struct { - guint32 session_id; - gboolean found; -} FindSessionId; - static void -bearer_list_session_id_foreach (MMBaseBearer *bearer, - gpointer user_data) +modem_create_bearer (MMIfaceModem *self, + MMBearerProperties *properties, + GAsyncReadyCallback callback, + gpointer user_data) { - FindSessionId *ctx = user_data; - - if (!ctx->found && - MM_IS_BEARER_MBIM (bearer) && - mm_bearer_mbim_get_session_id (MM_BEARER_MBIM (bearer)) == ctx->session_id) - ctx->found = TRUE; -} - -static gint -find_next_bearer_session_id (MMBroadbandModemMbim *self) -{ - MMBearerList *bearer_list; - guint i; - - g_object_get (self, - MM_IFACE_MODEM_BEARER_LIST, &bearer_list, - NULL); - - if (!bearer_list) - return 0; - - for (i = 0; i <= 255; i++) { - FindSessionId ctx; - - ctx.session_id = i; - ctx.found = FALSE; - - mm_bearer_list_foreach (bearer_list, - bearer_list_session_id_foreach, - &ctx); - - if (!ctx.found) { - g_object_unref (bearer_list); - return (gint)i; - } - } - - /* no valid session id found */ - g_object_unref (bearer_list); - return -1; -} - -static void -modem_create_bearer (MMIfaceModem *_self, - MMBearerProperties *properties, - GAsyncReadyCallback callback, - gpointer user_data) -{ - MMBroadbandModemMbim *self = MM_BROADBAND_MODEM_MBIM (_self); MMBaseBearer *bearer; - GTask *task; - gint session_id; - - task = g_task_new (self, NULL, callback, user_data); + GTask *task; - /* Find a new session ID */ - session_id = find_next_bearer_session_id (self); - if (session_id < 0) { - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Not enough session IDs"); - g_object_unref (task); - return; - } + /* Note: the session id to be used by the bearer will always be 0 + * for non-multiplexed sessions, bound to the non-VLAN-tagged traffic + * managed by the master network interface */ - /* We just create a MMBearerMbim */ + task = g_task_new (self, NULL, callback, user_data); mm_obj_dbg (self, "creating MBIM bearer in MBIM modem"); - bearer = mm_bearer_mbim_new (self, - properties, - (guint)session_id); + bearer = mm_bearer_mbim_new (MM_BROADBAND_MODEM_MBIM (self), properties); g_task_return_pointer (task, bearer, g_object_unref); g_object_unref (task); } From 24f9cdce192a149d211b5442416fa89050432688 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 24 Jun 2021 15:53:50 +0200 Subject: [PATCH 664/675] mmcli,messaging: fix leak when printing supported storages (cherry picked from commit ce50d9c483639d7a7e62addab3eecba177c80a6a) --- cli/mmcli-modem-messaging.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/mmcli-modem-messaging.c b/cli/mmcli-modem-messaging.c index 535cc909..513c6975 100644 --- a/cli/mmcli-modem-messaging.c +++ b/cli/mmcli-modem-messaging.c @@ -215,6 +215,7 @@ print_messaging_status (void) mm_modem_messaging_get_supported_storages (ctx->modem_messaging, &supported, &supported_len); if (supported) supported_str = mm_common_build_sms_storages_string (supported, supported_len); + g_free (supported); mmcli_output_string_take (MMC_F_MESSAGING_SUPPORTED_STORAGES, supported_str); mmcli_output_string (MMC_F_MESSAGING_DEFAULT_STORAGES, mm_sms_storage_get_string ( From 4425e24592c2a2664162faa67356ca7434d3b6f2 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 25 Jun 2021 10:36:25 +0200 Subject: [PATCH 665/675] libmm-glib,3gpp: fix initial-eps-bearer-settings property updates (cherry picked from commit fefd59e3ce26f8248f94d40f2fb1f68085ca36ee) --- libmm-glib/mm-modem-3gpp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmm-glib/mm-modem-3gpp.c b/libmm-glib/mm-modem-3gpp.c index 1cfb419d..bf557b8d 100644 --- a/libmm-glib/mm-modem-3gpp.c +++ b/libmm-glib/mm-modem-3gpp.c @@ -709,7 +709,7 @@ ensure_internal_initial_eps_bearer_settings (MMModem3gpp *self, /* No need to clear this signal connection when freeing self */ self->priv->initial_eps_bearer_settings_id = g_signal_connect (self, - "notify::initial-eps-bearer-properties", + "notify::initial-eps-bearer-settings", G_CALLBACK (initial_eps_bearer_settings_updated), NULL); } From 1d02a43fe1f420f3e0445e8f787d99cbb8153fc3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 24 Jun 2021 15:40:21 +0200 Subject: [PATCH 666/675] libmm-glib,messaging: avoid array cleanup in get_supported_storages() If we return a reference to the internal array in ensure_internal_supported_storages() and then we free the array unconditionally in the caller, the next time we call it, the array would be valid, but it would be fully empty. (cherry picked from commit dfeaec99ceb3ec5b6fd6ec7add1ce81978d68cfb) --- libmm-glib/mm-modem-messaging.c | 44 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/libmm-glib/mm-modem-messaging.c b/libmm-glib/mm-modem-messaging.c index cc912a05..2f23f8a1 100644 --- a/libmm-glib/mm-modem-messaging.c +++ b/libmm-glib/mm-modem-messaging.c @@ -115,10 +115,13 @@ supported_storages_updated (MMModemMessaging *self, g_mutex_unlock (&self->priv->supported_storages_mutex); } -static void -ensure_internal_supported_storages (MMModemMessaging *self, - GArray **dup) +static gboolean +ensure_internal_supported_storages (MMModemMessaging *self, + MMSmsStorage **dup_storages, + guint *dup_storages_n) { + gboolean ret; + g_mutex_lock (&self->priv->supported_storages_mutex); { /* If this is the first time ever asking for the array, setup the @@ -140,10 +143,24 @@ ensure_internal_supported_storages (MMModemMessaging *self, NULL); } - if (dup && self->priv->supported_storages) - *dup = g_array_ref (self->priv->supported_storages); + if (!self->priv->supported_storages) + ret = FALSE; + else { + ret = TRUE; + + if (dup_storages && dup_storages_n) { + *dup_storages_n = self->priv->supported_storages->len; + if (self->priv->supported_storages->len > 0) { + *dup_storages = g_malloc (sizeof (MMSmsStorage) * self->priv->supported_storages->len); + memcpy (*dup_storages, self->priv->supported_storages->data, sizeof (MMSmsStorage) * self->priv->supported_storages->len); + } else + *dup_storages = NULL; + } + } } g_mutex_unlock (&self->priv->supported_storages_mutex); + + return ret; } /** @@ -165,19 +182,11 @@ mm_modem_messaging_get_supported_storages (MMModemMessaging *self, MMSmsStorage **storages, guint *n_storages) { - GArray *array = NULL; - g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), FALSE); g_return_val_if_fail (storages != NULL, FALSE); g_return_val_if_fail (n_storages != NULL, FALSE); - ensure_internal_supported_storages (self, &array); - if (!array) - return FALSE; - - *n_storages = array->len; - *storages = (MMSmsStorage *)g_array_free (array, FALSE); - return TRUE; + return ensure_internal_supported_storages (self, storages, n_storages); } /** @@ -194,16 +203,15 @@ mm_modem_messaging_get_supported_storages (MMModemMessaging *self, * Since: 1.0 */ gboolean -mm_modem_messaging_peek_supported_storages (MMModemMessaging *self, +mm_modem_messaging_peek_supported_storages (MMModemMessaging *self, const MMSmsStorage **storages, - guint *n_storages) + guint *n_storages) { g_return_val_if_fail (MM_IS_MODEM_MESSAGING (self), FALSE); g_return_val_if_fail (storages != NULL, FALSE); g_return_val_if_fail (n_storages != NULL, FALSE); - ensure_internal_supported_storages (self, NULL); - if (!self->priv->supported_storages) + if (!ensure_internal_supported_storages (self, NULL, NULL)) return FALSE; *n_storages = self->priv->supported_storages->len; From 990b8d8795d88f497d70a594aecdd9bb93a69c39 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 24 Jun 2021 15:39:50 +0200 Subject: [PATCH 667/675] libmm-glib,modem: add missing input argument checks (cherry picked from commit 059f13ffd33d6cf8c981119dd40e63e7abc2fe59) --- libmm-glib/mm-modem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libmm-glib/mm-modem.c b/libmm-glib/mm-modem.c index 8837daff..68ef375f 100644 --- a/libmm-glib/mm-modem.c +++ b/libmm-glib/mm-modem.c @@ -334,6 +334,8 @@ mm_modem_get_supported_capabilities (MMModem *self, guint *n_capabilities) { g_return_val_if_fail (MM_IS_MODEM (self), FALSE); + g_return_val_if_fail (capabilities != NULL, FALSE); + g_return_val_if_fail (n_capabilities != NULL, FALSE); return ensure_internal_supported_capabilities (self, capabilities, n_capabilities); } From f74c09c1f7f69633b2d82858bc54791d103af6a0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 30 Jun 2021 22:31:17 +0200 Subject: [PATCH 668/675] cinterion: fix double free when loading initial EPS context The properties object stored in the context is being returned as task result; so we should make sure that object is no longer left in the context so that it's not freed twice. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/395 (cherry picked from commit e1fbc1ccb74ba9c788d88c5f19fb89200a6478f6) --- plugins/cinterion/mm-broadband-modem-cinterion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 7eeb8ade..b14974fd 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -1686,7 +1686,7 @@ common_load_initial_eps_step (GTask *task) return; case COMMON_LOAD_INITIAL_EPS_STEP_LAST: - g_task_return_pointer (task, ctx->properties, g_object_unref); + g_task_return_pointer (task, g_steal_pointer (&ctx->properties), g_object_unref); g_object_unref (task); return; From 95a845911cadc4ec354a07ab79b5c739fa185415 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 9 Jul 2021 10:45:09 +0200 Subject: [PATCH 669/675] iface-modem: don't fail enabling if modem_power_up() isn't implemented There are modems (e.g. Nokia, Thuraya, Iridium) which don't require or don't support power management, and therefore there is no way to either load or update the power status. In those modems we just assume ON is the current and only value (set in the skeleton during initialization) and so when we attempt to update the power state to ON during enabling, the logic should not break. Fix the logic by making sure the requested_power_setup() function pointers are only checked for validity after ensuring we're not already in the desired power state. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/398 (cherry picked from commit 63f3dcb2fe3dee42fe223751c5394a751e7ecc42) --- src/mm-iface-modem.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 9bc421c9..ad28fcf7 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -3864,6 +3864,15 @@ set_power_state_step (GTask *task) case SET_POWER_STATE_STEP_UPDATE: mm_obj_dbg (self, "updating power state: '%s'...", mm_modem_power_state_get_string (ctx->requested_power_state)); + + /* Error if unsupported */ + if (!ctx->requested_power_setup || !ctx->requested_power_setup_finish) { + g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "Requested power transition is not supported by this modem"); + g_object_unref (task); + return; + } + ctx->requested_power_setup (self, (GAsyncReadyCallback)requested_power_setup_ready, task); return; @@ -3964,14 +3973,6 @@ mm_iface_modem_set_power_state (MMIfaceModem *self, g_assert_not_reached (); } - /* Error if unsupported */ - if (!ctx->requested_power_setup || !ctx->requested_power_setup_finish) { - g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, - "Requested power transition is not supported by this modem"); - g_object_unref (task); - return; - } - set_power_state_step (task); } From 34a109adb7a1246d91a884c8b734034a3c61172a Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 17 Jun 2021 15:06:41 +0000 Subject: [PATCH 670/675] tools: fix signal type in service test The signal definition is: So the first two arguments need to be adjusted. Without this change, the test was failing for me: (/build/source/tools/tests/.libs/lt-test-stub:77030): GLib-GObject-CRITICAL **: 15:05:35.276: ../gobject/gsignal.c:3167: value for 'gint' parameter 0 for signal "state-changed" is of type 'guint' (cherry picked from commit a8f086bfb3be65de133365b55595a9800ecaa681) --- tools/test-modemmanager-service.py | 4 ++-- tools/tests/test-stub.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/test-modemmanager-service.py b/tools/test-modemmanager-service.py index e45b5fa4..2ca18b9f 100755 --- a/tools/test-modemmanager-service.py +++ b/tools/test-modemmanager-service.py @@ -339,7 +339,7 @@ def Command(self, cmd, timeout): def PropertiesChanged(self, changed): pass - @dbus.service.signal(IFACE_MODEM, signature='uuu') + @dbus.service.signal(IFACE_MODEM, signature='iiu') def StateChanged(self, old_state, new_state, reason): pass @@ -406,7 +406,7 @@ def AddModem(self, add_sim, iccid): self.modem = Modem(self.bus, add_sim, iccid) return dbus.ObjectPath(self.modem.path) - @dbus.service.method(IFACE_TEST, in_signature='uuu', out_signature='') + @dbus.service.method(IFACE_TEST, in_signature='iiu', out_signature='') def EmitStateChanged(self, old_state, new_state, reason): if self.modem is not None: self.modem.StateChanged(old_state, new_state, reason) diff --git a/tools/tests/test-stub.c b/tools/tests/test-stub.c index 5687feca..b88b2a34 100644 --- a/tools/tests/test-stub.c +++ b/tools/tests/test-stub.c @@ -206,7 +206,7 @@ set_modem_state (TestData *tdata, GError *error = NULL; GVariant *ret = NULL; GVariant *old_state_variant = NULL; - guint old_state = 0; + gint old_state = 0; g_assert_nonnull (tdata->mm_modem_prop_proxy); @@ -222,7 +222,7 @@ set_modem_state (TestData *tdata, &error); g_assert_no_error (error); g_variant_get (ret, "(v)", &old_state_variant); - old_state = (guint)g_variant_get_int32 (old_state_variant); + old_state = g_variant_get_int32 (old_state_variant); g_variant_unref (ret); g_variant_unref (old_state_variant); @@ -256,7 +256,7 @@ set_modem_state (TestData *tdata, /* Emit state change signal */ g_dbus_proxy_call (tdata->mm_proxy, "EmitStateChanged", - g_variant_new ("(uuu)", old_state, state, reason), + g_variant_new ("(iiu)", old_state, state, reason), G_DBUS_CALL_FLAGS_NO_AUTO_START, 1000, NULL, From ec1029922b9174dab3e7e53addaba829559e886e Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 12 Jul 2021 11:43:45 +0200 Subject: [PATCH 671/675] NEWS: update for 1.16.8 --- NEWS | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/NEWS b/NEWS index f7dde983..7c6945ca 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,29 @@ +ModemManager 1.16.8 +------------------------------------------- + + * MBIM: + ** Fixed wrong session id management when multiple bearers are created. + + * Modem interface: + ** Fixed the enabling operation on multiple plugins that don't have explicit + power up/down operations. + + * libmm-glib: + ** Modem interface: added missing input argument checks. + ** Messaging interface: fixed get_supported_storages() handling when it's + called several consecutive times. + ** 3GPP interface: fixed initial EPS bearer settings property updates. + + * plugins: + ** cinterion: fixed double free when loading initial EPS context. + + * udev: + ** Explicitly ignore "FIREHOSE" WWAN ports. + ** Add support to match WWAN type via sysfs attributes. + + * Several other minor improvements and fixes. + ModemManager 1.16.6 ------------------------------------------- From cc616ed45ea8ec80492e2ae7b107589f59a3f9c1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 12 Jul 2021 11:45:09 +0200 Subject: [PATCH 672/675] release: bump version to 1.16.8 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4b86500b..f5d7ab97 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ dnl m4_define([mm_major_version], [1]) m4_define([mm_minor_version], [16]) -m4_define([mm_micro_version], [7]) +m4_define([mm_micro_version], [8]) m4_define([mm_version], [mm_major_version.mm_minor_version.mm_micro_version]) From 92b238d50d23f1c72ffee577e426116818dd7684 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 1 Aug 2021 13:40:07 +0200 Subject: [PATCH 673/675] src/mm-filter: mm_dbg -> mm_obj_dbg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Will fail to build otherwise: mm-filter.c: In function 'mm_filter_port': mm-filter.c:245:13: warning: implicit declaration of function 'mm_dbg' [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-function-declaration-Wimplicit-function-declaration8;;] 245 | mm_dbg ("[filter] (%s/%s): XMM7360 TTY command port allowed", subsystem, name); | ^~~~~~ mm-filter.c:245:13: warning: nested extern declaration of 'mm_dbg' [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wnested-externs-Wnested-externs8;;] […] /nix/store/hy3lz2vfv9qq2v5jz9nzlx6mmiaq79rj-binutils-2.35.1/bin/ld: ModemManager-mm-filter.o: in function `mm_filter_port': /build/ModemManager-1.16.8/src/mm-filter.c:245: undefined reference to `mm_dbg' collect2: error: ld returned 1 exit status --- src/mm-filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mm-filter.c b/src/mm-filter.c index 4d428dc4..b82d1264 100644 --- a/src/mm-filter.c +++ b/src/mm-filter.c @@ -242,7 +242,7 @@ mm_filter_port (MMFilter *self, physdev_subsystem = mm_kernel_device_get_physdev_subsystem (port); /* Special rule for XMM7360 main tty port which would be filtered out by the platform driver otherwise */ if (!g_strcmp0 (physdev_subsystem, "pci") && !g_strcmp0 (name, "ttyXMM1")) { - mm_dbg ("[filter] (%s/%s): XMM7360 TTY command port allowed", subsystem, name); + mm_obj_dbg (self, "(%s/%s): XMM7360 TTY command port allowed", subsystem, name); return TRUE; } if ((self->priv->enabled_rules & MM_FILTER_RULE_TTY_PLATFORM_DRIVER) && From a086175d39708e102c9ea4231aa394b6b3eb488f Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 1 Aug 2021 14:18:01 +0200 Subject: [PATCH 674/675] xmm7360: mm_dbg -> mm_obj_dbg --- plugins/xmm7360/mm-bearer-xmm7360.c | 10 +++++----- plugins/xmm7360/mm-broadband-modem-xmm7360.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/xmm7360/mm-bearer-xmm7360.c b/plugins/xmm7360/mm-bearer-xmm7360.c index 4fe043ca..dbde8cb9 100644 --- a/plugins/xmm7360/mm-bearer-xmm7360.c +++ b/plugins/xmm7360/mm-bearer-xmm7360.c @@ -96,7 +96,7 @@ _connect (MMBaseBearer *_self, "No valid data port found to launch connection"); } - mm_dbg ("XMM7360 Bearer: data port grabbed, now trying to connect!"); + mm_obj_dbg (self, "XMM7360 Bearer: data port grabbed, now trying to connect!"); /* Check whether we have an APN */ apn = mm_bearer_properties_get_apn (mm_base_bearer_peek_config (_self)); @@ -124,7 +124,7 @@ _connect (MMBaseBearer *_self, return; } - mm_dbg ("XMM7360 Bearer: after attach APN config!"); + mm_obj_dbg (self, "XMM7360 Bearer: after attach APN config!"); if(xmm7360_net_attach(rpc, &status) != 0) { g_task_report_new_error ( @@ -137,7 +137,7 @@ _connect (MMBaseBearer *_self, "could not attach to net!"); return; } - mm_dbg ("XMM7360 Bearer: after net attach!"); + mm_obj_dbg (self, "XMM7360 Bearer: after net attach!"); if(status == (gint32)0xffffffff) { while(!rpc->attach_allowed) { xmm7360_rpc_pump(rpc, NULL); @@ -167,7 +167,7 @@ _connect (MMBaseBearer *_self, } } - mm_dbg ("XMM7360 Bearer: attached to net, waiting shortly before getting ip config!"); + mm_obj_dbg (self, "XMM7360 Bearer: attached to net, waiting shortly before getting ip config!"); // ugly: wait 1 seconds before fetching IP config sleep(1); @@ -184,7 +184,7 @@ _connect (MMBaseBearer *_self, return; } - mm_dbg ("XMM7360 Bearer: IP config fetched!"); + mm_obj_dbg (self, "XMM7360 Bearer: IP config fetched!"); if(xmm7360_establish_connection(rpc) != 0) { g_task_report_new_error ( diff --git a/plugins/xmm7360/mm-broadband-modem-xmm7360.c b/plugins/xmm7360/mm-broadband-modem-xmm7360.c index 0c0d60e5..8b46d172 100644 --- a/plugins/xmm7360/mm-broadband-modem-xmm7360.c +++ b/plugins/xmm7360/mm-broadband-modem-xmm7360.c @@ -84,7 +84,7 @@ mm_broadband_modem_xmm7360_init (MMBroadbandModemXmm7360 *self) return; } - mm_dbg ("Initializing XMM7360 modem!"); + mm_obj_dbg (self, "Initializing XMM7360 modem!"); /* lots of synchronous calls, this has to be improved for sure */ xmm7360_rpc_execute(rpc, UtaMsSmsInit, FALSE, NULL, NULL); xmm7360_rpc_execute(rpc, UtaMsCbsInit, FALSE, NULL, NULL); @@ -110,7 +110,7 @@ mm_broadband_modem_xmm7360_init (MMBroadbandModemXmm7360 *self) xmm7360_rpc_pump(rpc, NULL); } - mm_dbg ("Successfully initialized XMM7360 modem!"); + mm_obj_dbg (self, "Successfully initialized XMM7360 modem!"); } static void @@ -164,4 +164,4 @@ MMBaseBearer * xmm7360_create_bearer_finish (MMIfaceModem *self, GError **error) { return g_task_propagate_pointer (G_TASK (res), error); -} \ No newline at end of file +} From c08db038cfccb5471c14784576c2b5f6fdafc143 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 1 Aug 2021 14:56:32 +0200 Subject: [PATCH 675/675] xmm7360: mm_err -> mm_obj_err --- plugins/xmm7360/mm-broadband-modem-xmm7360.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/xmm7360/mm-broadband-modem-xmm7360.c b/plugins/xmm7360/mm-broadband-modem-xmm7360.c index 8b46d172..6f5b73e5 100644 --- a/plugins/xmm7360/mm-broadband-modem-xmm7360.c +++ b/plugins/xmm7360/mm-broadband-modem-xmm7360.c @@ -79,7 +79,7 @@ mm_broadband_modem_xmm7360_init (MMBroadbandModemXmm7360 *self) /* initialize modem RPC */ rpc = &self->priv->rpc; if(xmm7360_rpc_init(rpc) != 0) { - mm_err ("Failed to initialize XMM7360 RPC!"); + mm_obj_err (self, "Failed to initialize XMM7360 RPC!"); /* TODO: handle rpc initialization error */ return; }