summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2015-12-27 22:53:33 +0100
committerAleksander Morgado <aleksander@aleksander.es>2015-12-29 17:22:19 +0100
commit5b855661905f0afe1576e85608d32ac38a5743a6 (patch)
tree6294845a6f2ca72f369e733dc8bc7921db4d04bd
parentad84b21b363e1fbe0428a669f37b7b87a2c442a2 (diff)
downloadlibqmi-5b855661905f0afe1576e85608d32ac38a5743a6.tar.gz
qmicli: new '--get-expected-data-format' & '--set-expected-data-format' actions
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.
-rw-r--r--src/qmicli/qmicli-helpers.c21
-rw-r--r--src/qmicli/qmicli-helpers.h2
-rw-r--r--src/qmicli/qmicli.c76
3 files changed, 98 insertions, 1 deletions
diff --git a/src/qmicli/qmicli-helpers.c b/src/qmicli/qmicli-helpers.c
index a2ca5d32..511adf5e 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 975b5079..1dcb95c9 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 855cb0a0..4960c782 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);
}