[PATCH 2/3] qmicli: new '--get-expected-data-format' & '--set-expected-data-format' actions
Aleksander Morgado
aleksander at aleksander.es
Tue Dec 29 08:39:20 PST 2015
These new actions allow to query or update the data format expected by the
kernel in the WWAN interface associated to the cdc-wdm device used.
---
src/qmicli/qmicli-helpers.c | 21 +++++++++++++
src/qmicli/qmicli-helpers.h | 2 ++
src/qmicli/qmicli.c | 76 ++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 98 insertions(+), 1 deletion(-)
diff --git a/src/qmicli/qmicli-helpers.c b/src/qmicli/qmicli-helpers.c
index a2ca5d3..511adf5 100644
--- a/src/qmicli/qmicli-helpers.c
+++ b/src/qmicli/qmicli-helpers.c
@@ -371,6 +371,27 @@ qmicli_read_net_open_flags_from_string (const gchar *str,
}
gboolean
+qmicli_read_expected_data_format_from_string (const gchar *str,
+ QmiDeviceExpectedDataFormat *out)
+{
+ GType type;
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+
+ type = qmi_device_expected_data_format_get_type ();
+ enum_class = G_ENUM_CLASS (g_type_class_ref (type));
+ enum_value = g_enum_get_value_by_nick (enum_class, str);
+
+ if (enum_value)
+ *out = (QmiDeviceExpectedDataFormat)enum_value->value;
+ else
+ g_printerr ("error: invalid expected data format value given: '%s'\n", str);
+
+ g_type_class_unref (enum_class);
+ return !!enum_value;
+}
+
+gboolean
qmicli_read_link_layer_protocol_from_string (const gchar *str,
QmiWdaLinkLayerProtocol *out)
{
diff --git a/src/qmicli/qmicli-helpers.h b/src/qmicli/qmicli-helpers.h
index 975b507..1dcb95c 100644
--- a/src/qmicli/qmicli-helpers.h
+++ b/src/qmicli/qmicli-helpers.h
@@ -47,6 +47,8 @@ gboolean qmicli_read_radio_interface_from_string (const gchar *str,
QmiNasRadioInterface *out);
gboolean qmicli_read_net_open_flags_from_string (const gchar *str,
QmiDeviceOpenFlags *out);
+gboolean qmicli_read_expected_data_format_from_string (const gchar *str,
+ QmiDeviceExpectedDataFormat *out);
gboolean qmicli_read_link_layer_protocol_from_string (const gchar *str,
QmiWdaLinkLayerProtocol *out);
gboolean qmicli_read_autoconnect_setting_from_string (const gchar *str,
diff --git a/src/qmicli/qmicli.c b/src/qmicli/qmicli.c
index 855cb0a..4960c78 100644
--- a/src/qmicli/qmicli.c
+++ b/src/qmicli/qmicli.c
@@ -49,6 +49,8 @@ static gboolean operation_status;
static gchar *device_str;
static gboolean get_service_version_info_flag;
static gboolean get_wwan_iface_flag;
+static gboolean get_expected_data_format_flag;
+static gchar *set_expected_data_format_str;
static gchar *device_set_instance_id_str;
static gboolean device_open_version_info_flag;
static gboolean device_open_sync_flag;
@@ -69,6 +71,14 @@ static GOptionEntry main_entries[] = {
"Get the WWAN iface name associated with this control port",
NULL
},
+ { "get-expected-data-format", 'e', 0, G_OPTION_ARG_NONE, &get_expected_data_format_flag,
+ "Get the expected data format in the WWAN iface",
+ NULL
+ },
+ { "set-expected-data-format", 'E', 0, G_OPTION_ARG_STRING, &set_expected_data_format_str,
+ "Set the expected data format in the WWAN iface",
+ "[802-3|raw-ip]"
+ },
{ "get-service-version-info", 0, 0, G_OPTION_ARG_NONE, &get_service_version_info_flag,
"Get service version info",
NULL
@@ -214,7 +224,9 @@ generic_options_enabled (void)
n_actions = (!!device_set_instance_id_str +
get_service_version_info_flag +
- get_wwan_iface_flag);
+ get_wwan_iface_flag +
+ get_expected_data_format_flag +
+ !!set_expected_data_format_str);
if (n_actions > 1) {
g_printerr ("error: too many generic actions requested\n");
@@ -459,6 +471,64 @@ device_get_service_version_info (QmiDevice *dev)
}
static gboolean
+device_set_expected_data_format_cb (QmiDevice *dev)
+{
+ QmiDeviceExpectedDataFormat expected;
+ GError *error = NULL;
+
+ if (!qmicli_read_expected_data_format_from_string (set_expected_data_format_str, &expected) ||
+ expected == QMI_DEVICE_EXPECTED_DATA_FORMAT_UNKNOWN)
+ g_printerr ("error: invalid requested data format: %s", set_expected_data_format_str);
+ else if (!qmi_device_set_expected_data_format (dev, expected, &error)) {
+ g_printerr ("error: cannot set expected data format: %s\n", error->message);
+ g_error_free (error);
+ } else
+ g_print ("[%s] expected data format set to: %s\n",
+ qmi_device_get_path_display (dev),
+ qmi_device_expected_data_format_get_string (expected));
+
+ /* We're done now */
+ qmicli_async_operation_done (!error);
+
+ g_object_unref (dev);
+ return FALSE;
+}
+
+static void
+device_set_expected_data_format (QmiDevice *dev)
+{
+ g_debug ("Setting expected WWAN data format this control port...");
+ g_idle_add ((GSourceFunc) device_set_expected_data_format_cb, g_object_ref (dev));
+}
+
+static gboolean
+device_get_expected_data_format_cb (QmiDevice *dev)
+{
+ QmiDeviceExpectedDataFormat expected;
+ GError *error = NULL;
+
+ expected = qmi_device_get_expected_data_format (dev, &error);
+ if (expected == QMI_DEVICE_EXPECTED_DATA_FORMAT_UNKNOWN) {
+ g_printerr ("error: cannot get expected data format: %s\n", error->message);
+ g_error_free (error);
+ } else
+ g_print ("%s\n", qmi_device_expected_data_format_get_string (expected));
+
+ /* We're done now */
+ qmicli_async_operation_done (!error);
+
+ g_object_unref (dev);
+ return FALSE;
+}
+
+static void
+device_get_expected_data_format (QmiDevice *dev)
+{
+ g_debug ("Getting expected WWAN data format this control port...");
+ g_idle_add ((GSourceFunc) device_get_expected_data_format_cb, g_object_ref (dev));
+}
+
+static gboolean
device_get_wwan_iface_cb (QmiDevice *dev)
{
const gchar *wwan_iface;
@@ -504,6 +574,10 @@ device_open_ready (QmiDevice *dev,
device_get_service_version_info (dev);
else if (get_wwan_iface_flag)
device_get_wwan_iface (dev);
+ else if (get_expected_data_format_flag)
+ device_get_expected_data_format (dev);
+ else if (set_expected_data_format_str)
+ device_set_expected_data_format (dev);
else
device_allocate_client (dev);
}
--
2.6.4
More information about the libqmi-devel
mailing list