aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-07-05 11:42:38 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-05 11:42:38 +0200
commita369585eb56a18b750f081f291fecb705fb313c3 (patch)
tree05468c5eb19de4797997a2225bf5094930fbe400
parent51b886c926aed74edf2bdaa08b63ed1da56e0c2a (diff)
downloadexternal_libqmi-a369585eb56a18b750f081f291fecb705fb313c3.zip
external_libqmi-a369585eb56a18b750f081f291fecb705fb313c3.tar.gz
external_libqmi-a369585eb56a18b750f081f291fecb705fb313c3.tar.bz2
cli: new `--device-set-instance-id' action
This action is generic as it does not require additional service-specific client allocations, it just uses the implicit CTL client.
-rw-r--r--cli/qmicli.c122
1 files changed, 109 insertions, 13 deletions
diff --git a/cli/qmicli.c b/cli/qmicli.c
index d24dabe..b8822d9 100644
--- a/cli/qmicli.c
+++ b/cli/qmicli.c
@@ -46,6 +46,7 @@ static gboolean operation_status;
/* Main options */
static gchar *device_str;
+static gchar *device_set_instance_id_str;
static gboolean device_open_version_info_flag;
static gboolean device_open_sync_flag;
static gchar *client_cid_str;
@@ -59,6 +60,10 @@ static GOptionEntry main_entries[] = {
"Specify device path",
"[PATH]"
},
+ { "device-set-instance-id", 0, 0, G_OPTION_ARG_STRING, &device_set_instance_id_str,
+ "Set instance ID",
+ "[Instance ID]"
+ },
{ "device-open-version-info", 0, 0, G_OPTION_ARG_NONE, &device_open_version_info_flag,
"Run version info check when opening device",
NULL
@@ -177,6 +182,26 @@ print_version_and_exit (void)
exit (EXIT_SUCCESS);
}
+static gboolean
+generic_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = !!device_set_instance_id_str;
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many generic actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
/*****************************************************************************/
/* Running asynchronously */
@@ -208,6 +233,12 @@ qmicli_async_operation_done (gboolean reported_operation_status)
cancellable = NULL;
}
+ /* If no client was allocated (e.g. generic action), just quit */
+ if (!client) {
+ g_main_loop_quit (loop);
+ return;
+ }
+
if (!client_no_release_cid_flag)
flags |= QMI_DEVICE_RELEASE_CLIENT_FLAGS_RELEASE_CID;
else
@@ -255,21 +286,10 @@ allocate_client_ready (QmiDevice *device,
}
static void
-device_open_ready (QmiDevice *device,
- GAsyncResult *res)
+device_allocate_client (QmiDevice *device)
{
- GError *error = NULL;
guint8 cid = QMI_CID_NONE;
- if (!qmi_device_open_finish (device, res, &error)) {
- g_printerr ("error: couldn't open the QmiDevice: %s\n",
- error->message);
- exit (EXIT_FAILURE);
- }
-
- g_debug ("QMI Device at '%s' ready",
- qmi_device_get_path_display (device));
-
if (client_cid_str) {
guint32 cid32;
@@ -296,6 +316,78 @@ device_open_ready (QmiDevice *device,
}
static void
+set_instance_id_ready (QmiDevice *device,
+ GAsyncResult *res)
+{
+ GError *error = NULL;
+ guint16 link_id;
+
+ if (!qmi_device_set_instance_id_finish (device, res, &link_id, &error)) {
+ g_printerr ("error: couldn't set instance ID: %s\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("[%s] Instance ID set:\n"
+ "\tLink ID: '%" G_GUINT16_FORMAT "'\n",
+ qmi_device_get_path_display (device),
+ link_id);
+
+ /* We're done now */
+ qmicli_async_operation_done (TRUE);
+}
+
+static void
+device_set_instance_id (QmiDevice *device)
+{
+ gint instance_id;
+
+ if (g_str_equal (device_set_instance_id_str, "0"))
+ instance_id = 0;
+ else {
+ instance_id = atoi (device_set_instance_id_str);
+ if (instance_id == 0) {
+ g_printerr ("error: invalid instance ID given: '%s'\n", device_set_instance_id_str);
+ exit (EXIT_FAILURE);
+ } else if (instance_id < 0 || instance_id > G_MAXUINT8) {
+ g_printerr ("error: given instance ID is out of range [0,%u]: '%s'\n",
+ G_MAXUINT8,
+ device_set_instance_id_str);
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ g_debug ("Setting instance ID '%d'...", instance_id);
+ qmi_device_set_instance_id (device,
+ (guint8)instance_id,
+ 10,
+ cancellable,
+ (GAsyncReadyCallback)set_instance_id_ready,
+ NULL);
+}
+
+static void
+device_open_ready (QmiDevice *device,
+ GAsyncResult *res)
+{
+ GError *error = NULL;
+
+ if (!qmi_device_open_finish (device, res, &error)) {
+ g_printerr ("error: couldn't open the QmiDevice: %s\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_debug ("QMI Device at '%s' ready",
+ qmi_device_get_path_display (device));
+
+ if (device_set_instance_id_str)
+ device_set_instance_id (device);
+ else
+ device_allocate_client (device);
+}
+
+static void
device_new_ready (GObject *unused,
GAsyncResult *res)
{
@@ -369,8 +461,12 @@ int main (int argc, char **argv)
signal (SIGHUP, signals_handler);
signal (SIGTERM, signals_handler);
+ /* Generic options? */
+ if (generic_options_enabled ()) {
+ service = QMI_SERVICE_CTL;
+ }
/* DMS options? */
- if (qmicli_dms_options_enabled ()) {
+ else if (qmicli_dms_options_enabled ()) {
service = QMI_SERVICE_DMS;
}
/* WDS options? */