Debian Codegraph @

src/qmicli/qmicli-wda.c

raw
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * qmicli -- Command line interface to control QMI devices
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Copyright (C) 2014-2017 Aleksander Morgado <[email protected]>
19 */
20
21 #include "config.h"
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <locale.h>
26 #include <string.h>
27
28 #include <glib.h>
29 #include <gio/gio.h>
30
31 #include <libqmi-glib.h>
32
33 #include "qmicli.h"
34 #include "qmicli-helpers.h"
35
36 #if defined HAVE_QMI_SERVICE_WDA
37
38 #define QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAMS_UNDEFINED 0xFFFFFFFF
39 #define QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAM_SIZE_UNDEFINED 0xFFFFFFFF
40 #define QMI_WDA_ENDPOINT_INTERFACE_NUMBER_UNDEFINED -1
41 #define QMI_WDA_LOOPBACK_REPLICATION_FACTOR_UNDEFINED 0
42
43 /* Context */
44 typedef struct {
45 QmiDevice *device;
46 QmiClientWda *client;
47 GCancellable *cancellable;
48 } Context;
49 static Context *ctx;
50
51 /* Options */
52 static gchar *set_data_format_str;
53 static gchar *get_data_format_str;
54 static gchar *set_loopback_configuration_str;
55 static gboolean get_data_format_flag;
56 static gboolean get_supported_messages_flag;
57 static gboolean noop_flag;
58
59 #if defined HAVE_QMI_MESSAGE_WDA_GET_DATA_FORMAT
60
61 static gboolean
62 parse_get_data_format (const gchar *option_name,
63 const gchar *value,
64 gpointer data,
65 GError **error)
66 {
67 get_data_format_flag = TRUE;
68 if (value && value[0])
69 get_data_format_str = g_strdup (value);
70 return TRUE;
71 }
72
73 #endif
74
75 static GOptionEntry entries[] = {
76 #if defined HAVE_QMI_MESSAGE_WDA_SET_DATA_FORMAT
77 { "wda-set-data-format", 0, 0, G_OPTION_ARG_STRING, &set_data_format_str,
78 "Set data format (allowed keys: link-layer-protocol (802-3|raw-ip), ul-protocol (disabled|tlp|qc-ncm|mbim|rndis|qmap|qmapv5), dl-protocol (disabled|tlp|qc-ncm|mbim|rndis|qmap|qmapv5), dl-datagram-max-size, dl-max-datagrams, ep-type (undefined|hsusb|pcie|embedded), ep-iface-number, ul-datagram-max-size, ul-max-datagrams)",
79 "[\"key=value,...\"]"
80 },
81 #endif
82 #if defined HAVE_QMI_MESSAGE_WDA_GET_DATA_FORMAT
83 { "wda-get-data-format", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, parse_get_data_format,
84 "Get data format (allowed keys: ep-type (undefined|hsusb|pcie|embedded), ep-iface-number); also allows empty key list",
85 "[\"key=value,...\"]"
86 },
87 #endif
88 #if defined HAVE_QMI_MESSAGE_WDA_GET_SUPPORTED_MESSAGES
89 { "wda-get-supported-messages", 0, 0, G_OPTION_ARG_NONE, &get_supported_messages_flag,
90 "Get supported messages",
91 NULL
92 },
93 #endif
94 #if defined HAVE_QMI_MESSAGE_WDA_LOOPBACK_CONFIGURATION
95 { "wda-set-loopback-configuration", 0, 0, G_OPTION_ARG_STRING, &set_loopback_configuration_str,
96 "Set loopback configuration (allowed keys: state (enabled|disabled), replication-factor);",
97 "[\"key=value,...\"]"
98 },
99 #endif
100 { "wda-noop", 0, 0, G_OPTION_ARG_NONE, &noop_flag,
101 "Just allocate or release a WDA client. Use with `--client-no-release-cid' and/or `--client-cid'",
102 NULL
103 },
104 { NULL, 0, 0, 0, NULL, NULL, NULL }
105 };
106
107 GOptionGroup *
108 qmicli_wda_get_option_group (void)
109 {
110 GOptionGroup *group;
111
112 group = g_option_group_new ("wda",
113 "WDA options:",
114 "Show Wireless Data Administrative options",
115 NULL,
116 NULL);
117 g_option_group_add_entries (group, entries);
118
119 return group;
120 }
121
122 gboolean
123 qmicli_wda_options_enabled (void)
124 {
125 static guint n_actions = 0;
126 static gboolean checked = FALSE;
127
128 if (checked)
129 return !!n_actions;
130
131 n_actions = (!!set_data_format_str +
132 get_data_format_flag +
133 get_supported_messages_flag +
134 !!set_loopback_configuration_str +
135 noop_flag);
136
137 if (n_actions > 1) {
138 g_printerr ("error: too many WDA actions requested\n");
139 exit (EXIT_FAILURE);
140 }
141
142 checked = TRUE;
143 return !!n_actions;
144 }
145
146 static void
147 context_free (Context *context)
148 {
149 if (!context)
150 return;
151
152 if (context->client)
153 g_object_unref (context->client);
154 g_object_unref (context->cancellable);
155 g_object_unref (context->device);
156 g_slice_free (Context, context);
157 }
158
159 static void
160 operation_shutdown (gboolean operation_status)
161 {
162 /* Cleanup context and finish async operation */
163 context_free (ctx);
164 qmicli_async_operation_done (operation_status, FALSE);
165 }
166
167 static gboolean
168 noop_cb (gpointer unused)
169 {
170 operation_shutdown (TRUE);
171 return FALSE;
172 }
173
174 #if defined HAVE_QMI_MESSAGE_WDA_GET_DATA_FORMAT
175
176 typedef struct {
177 QmiDataEndpointType endpoint_type;
178 gint endpoint_iface_number;
179 } GetDataFormatProperties;
180
181 static gboolean
182 get_data_format_properties_handle (const gchar *key,
183 const gchar *value,
184 GError **error,
185 gpointer user_data)
186 {
187 GetDataFormatProperties *props = (GetDataFormatProperties *)user_data;
188
189 if (!value || !value[0]) {
190 g_set_error (error,
191 QMI_CORE_ERROR,
192 QMI_CORE_ERROR_FAILED,
193 "key '%s' requires a value",
194 key);
195 return FALSE;
196 }
197
198 if (g_ascii_strcasecmp (key, "ep-type") == 0) {
199 if (!qmicli_read_data_endpoint_type_from_string (value, &(props->endpoint_type))) {
200 g_set_error (error,
201 QMI_CORE_ERROR,
202 QMI_CORE_ERROR_FAILED,
203 "Unrecognized Endpoint Type '%s'",
204 value);
205 return FALSE;
206 }
207 return TRUE;
208 }
209
210 if (g_ascii_strcasecmp (key, "ep-iface-number") == 0) {
211 props->endpoint_iface_number = atoi (value);
212 return TRUE;
213 }
214
215 g_set_error (error,
216 QMI_CORE_ERROR,
217 QMI_CORE_ERROR_FAILED,
218 "Unrecognized option '%s'",
219 key);
220 return FALSE;
221 }
222
223 static QmiMessageWdaGetDataFormatInput *
224 get_data_format_input_create (const gchar *str)
225 {
226 g_autoptr(QmiMessageWdaGetDataFormatInput) input = NULL;
227 g_autoptr(GError) error = NULL;
228 GetDataFormatProperties props = {
229 .endpoint_type = QMI_DATA_ENDPOINT_TYPE_UNDEFINED,
230 .endpoint_iface_number = QMI_WDA_ENDPOINT_INTERFACE_NUMBER_UNDEFINED,
231 };
232
233 input = qmi_message_wda_get_data_format_input_new ();
234
235 if (!qmicli_parse_key_value_string (str,
236 &error,
237 get_data_format_properties_handle,
238 &props)) {
239 g_printerr ("error: could not parse input string '%s'\n", error->message);
240 return NULL;
241 }
242
243 if ((props.endpoint_type == QMI_DATA_ENDPOINT_TYPE_UNDEFINED) ^
244 (props.endpoint_iface_number == QMI_WDA_ENDPOINT_INTERFACE_NUMBER_UNDEFINED)) {
245 g_printerr ("error: endpoint type and interface number must be both set or both unset\n");
246 return NULL;
247 }
248
249 if ((props.endpoint_type != QMI_DATA_ENDPOINT_TYPE_UNDEFINED) &&
250 (props.endpoint_iface_number != QMI_WDA_ENDPOINT_INTERFACE_NUMBER_UNDEFINED) &&
251 !qmi_message_wda_get_data_format_input_set_endpoint_info (
252 input,
253 props.endpoint_type,
254 props.endpoint_iface_number,
255 &error)) {
256 g_printerr ("error: could not set peripheral endpoint id: %s\n", error->message);
257 return NULL;
258 }
259
260 return g_steal_pointer (&input);
261 }
262
263 static void
264 get_data_format_ready (QmiClientWda *client,
265 GAsyncResult *res)
266 {
267 QmiMessageWdaGetDataFormatOutput *output;
268 GError *error = NULL;
269 gboolean qos_format;
270 QmiWdaLinkLayerProtocol link_layer_protocol;
271 QmiWdaDataAggregationProtocol data_aggregation_protocol;
272 guint32 ndp_signature;
273 guint32 data_aggregation_max_size;
274 guint32 data_aggregation_max_datagrams;
275
276 output = qmi_client_wda_get_data_format_finish (client, res, &error);
277 if (!output) {
278 g_printerr ("error: operation failed: %s\n", error->message);
279 g_error_free (error);
280 operation_shutdown (FALSE);
281 return;
282 }
283
284 if (!qmi_message_wda_get_data_format_output_get_result (output, &error)) {
285 g_printerr ("error: couldn't get data format: %s\n", error->message);
286 g_error_free (error);
287 qmi_message_wda_get_data_format_output_unref (output);
288 operation_shutdown (FALSE);
289 return;
290 }
291
292 g_print ("[%s] Successfully got data format\n",
293 qmi_device_get_path_display (ctx->device));
294
295 if (qmi_message_wda_get_data_format_output_get_qos_format (
296 output,
297 &qos_format,
298 NULL))
299 g_print (" QoS flow header: %s\n", qos_format ? "yes" : "no");
300
301 if (qmi_message_wda_get_data_format_output_get_link_layer_protocol (
302 output,
303 &link_layer_protocol,
304 NULL))
305 g_print (" Link layer protocol: '%s'\n",
306 qmi_wda_link_layer_protocol_get_string (link_layer_protocol));
307
308 if (qmi_message_wda_get_data_format_output_get_uplink_data_aggregation_protocol (
309 output,
310 &data_aggregation_protocol,
311 NULL))
312 g_print (" Uplink data aggregation protocol: '%s'\n",
313 qmi_wda_data_aggregation_protocol_get_string (data_aggregation_protocol));
314
315 if (qmi_message_wda_get_data_format_output_get_downlink_data_aggregation_protocol (
316 output,
317 &data_aggregation_protocol,
318 NULL))
319 g_print ("Downlink data aggregation protocol: '%s'\n",
320 qmi_wda_data_aggregation_protocol_get_string (data_aggregation_protocol));
321
322 if (qmi_message_wda_get_data_format_output_get_ndp_signature (
323 output,
324 &ndp_signature,
325 NULL))
326 g_print (" NDP signature: '%u'\n", ndp_signature);
327
328 if (qmi_message_wda_get_data_format_output_get_downlink_data_aggregation_max_datagrams (
329 output,
330 &data_aggregation_max_datagrams,
331 NULL))
332 g_print ("Downlink data aggregation max datagrams: '%u'\n", data_aggregation_max_datagrams);
333
334 if (qmi_message_wda_get_data_format_output_get_downlink_data_aggregation_max_size (
335 output,
336 &data_aggregation_max_size,
337 NULL))
338 g_print ("Downlink data aggregation max size: '%u'\n", data_aggregation_max_size);
339
340 qmi_message_wda_get_data_format_output_unref (output);
341 operation_shutdown (TRUE);
342 }
343
344 #endif /* HAVE_QMI_MESSAGE_WDA_GET_DATA_FORMAT */
345
346 #if defined HAVE_QMI_MESSAGE_WDA_SET_DATA_FORMAT
347
348 static void
349 set_data_format_ready (QmiClientWda *client,
350 GAsyncResult *res)
351 {
352 QmiMessageWdaSetDataFormatOutput *output;
353 GError *error = NULL;
354 gboolean qos_format;
355 QmiWdaLinkLayerProtocol link_layer_protocol;
356 QmiWdaDataAggregationProtocol data_aggregation_protocol;
357 guint32 ndp_signature;
358 guint32 dl_data_aggregation_max_datagrams;
359 guint32 dl_data_aggregation_max_size;
360 guint32 ul_data_aggregation_max_datagrams;
361 guint32 ul_data_aggregation_max_size;
362
363 output = qmi_client_wda_set_data_format_finish (client, res, &error);
364 if (!output) {
365 g_printerr ("error: operation failed: %s\n", error->message);
366 g_error_free (error);
367 operation_shutdown (FALSE);
368 return;
369 }
370
371 if (!qmi_message_wda_set_data_format_output_get_result (output, &error)) {
372 g_printerr ("error: couldn't set data format: %s\n", error->message);
373 g_error_free (error);
374 qmi_message_wda_set_data_format_output_unref (output);
375 operation_shutdown (FALSE);
376 return;
377 }
378
379 g_print ("[%s] Successfully set data format\n",
380 qmi_device_get_path_display (ctx->device));
381
382 if (qmi_message_wda_set_data_format_output_get_qos_format (
383 output,
384 &qos_format,
385 NULL))
386 g_print (" QoS flow header: %s\n", qos_format ? "yes" : "no");
387
388 if (qmi_message_wda_set_data_format_output_get_link_layer_protocol (
389 output,
390 &link_layer_protocol,
391 NULL))
392 g_print (" Link layer protocol: '%s'\n",
393 qmi_wda_link_layer_protocol_get_string (link_layer_protocol));
394
395 if (qmi_message_wda_set_data_format_output_get_uplink_data_aggregation_protocol (
396 output,
397 &data_aggregation_protocol,
398 NULL))
399 g_print (" Uplink data aggregation protocol: '%s'\n",
400 qmi_wda_data_aggregation_protocol_get_string (data_aggregation_protocol));
401
402 if (qmi_message_wda_set_data_format_output_get_downlink_data_aggregation_protocol (
403 output,
404 &data_aggregation_protocol,
405 NULL))
406 g_print (" Downlink data aggregation protocol: '%s'\n",
407 qmi_wda_data_aggregation_protocol_get_string (data_aggregation_protocol));
408
409 if (qmi_message_wda_set_data_format_output_get_ndp_signature (
410 output,
411 &ndp_signature,
412 NULL))
413 g_print (" NDP signature: '%u'\n", ndp_signature);
414
415 if (qmi_message_wda_set_data_format_output_get_downlink_data_aggregation_max_datagrams (
416 output,
417 &dl_data_aggregation_max_datagrams,
418 NULL))
419 g_print ("Downlink data aggregation max datagrams: '%u'\n", dl_data_aggregation_max_datagrams);
420
421 if (qmi_message_wda_set_data_format_output_get_downlink_data_aggregation_max_size (
422 output,
423 &dl_data_aggregation_max_size,
424 NULL))
425 g_print (" Downlink data aggregation max size: '%u'\n", dl_data_aggregation_max_size);
426
427 if (qmi_message_wda_set_data_format_output_get_uplink_data_aggregation_max_datagrams (
428 output,
429 &ul_data_aggregation_max_datagrams,
430 NULL))
431 g_print (" Uplink data aggregation max datagrams: '%u'\n", ul_data_aggregation_max_datagrams);
432
433 if (qmi_message_wda_set_data_format_output_get_uplink_data_aggregation_max_size (
434 output,
435 &ul_data_aggregation_max_size,
436 NULL))
437 g_print (" Uplink data aggregation max size: '%u'\n", ul_data_aggregation_max_size);
438
439 qmi_message_wda_set_data_format_output_unref (output);
440 operation_shutdown (TRUE);
441 }
442
443 typedef struct {
444 QmiWdaLinkLayerProtocol link_layer_protocol;
445 QmiWdaDataAggregationProtocol ul_protocol;
446 QmiWdaDataAggregationProtocol dl_protocol;
447 guint32 dl_datagram_max_size;
448 guint32 dl_max_datagrams;
449 QmiDataEndpointType endpoint_type;
450 gint endpoint_iface_number;
451 guint32 ul_datagram_max_size;
452 guint32 ul_max_datagrams;
453 } SetDataFormatProperties;
454
455
456 static gboolean
457 set_data_format_properties_handle (const gchar *key,
458 const gchar *value,
459 GError **error,
460 gpointer user_data)
461 {
462 SetDataFormatProperties *props = (SetDataFormatProperties *)user_data;
463
464 if (!value || !value[0]) {
465 g_set_error (error,
466 QMI_CORE_ERROR,
467 QMI_CORE_ERROR_FAILED,
468 "key '%s' requires a value",
469 key);
470 return FALSE;
471 }
472
473 if (g_ascii_strcasecmp (key, "link-layer-protocol") == 0) {
474 if (!qmicli_read_wda_link_layer_protocol_from_string (value, &(props->link_layer_protocol))) {
475 g_set_error (error,
476 QMI_CORE_ERROR,
477 QMI_CORE_ERROR_FAILED,
478 "Unrecognized Link Layer Protocol '%s'",
479 value);
480 return FALSE;
481 }
482 return TRUE;
483 }
484
485 if (g_ascii_strcasecmp (key, "ul-protocol") == 0) {
486 if (!qmicli_read_wda_data_aggregation_protocol_from_string (value, &(props->ul_protocol))) {
487 g_set_error (error,
488 QMI_CORE_ERROR,
489 QMI_CORE_ERROR_FAILED,
490 "Unrecognized Data Aggregation Protocol '%s'",
491 value);
492 return FALSE;
493 }
494 return TRUE;
495 }
496
497 if (g_ascii_strcasecmp (key, "dl-protocol") == 0) {
498 if (!qmicli_read_wda_data_aggregation_protocol_from_string (value, &(props->dl_protocol))) {
499 g_set_error (error,
500 QMI_CORE_ERROR,
501 QMI_CORE_ERROR_FAILED,
502 "Unrecognized Data Aggregation Protocol '%s'",
503 value);
504 return FALSE;
505 }
506 return TRUE;
507 }
508
509 if (g_ascii_strcasecmp (key, "dl-datagram-max-size") == 0) {
510 props->dl_datagram_max_size = atoi(value);
511 return TRUE;
512 }
513
514 if (g_ascii_strcasecmp (key, "dl-max-datagrams") == 0) {
515 props->dl_max_datagrams = atoi(value);
516 return TRUE;
517 }
518
519 if (g_ascii_strcasecmp (key, "ep-type") == 0) {
520 if (!qmicli_read_data_endpoint_type_from_string (value, &(props->endpoint_type))) {
521 g_set_error (error,
522 QMI_CORE_ERROR,
523 QMI_CORE_ERROR_FAILED,
524 "Unrecognized Endpoint Type '%s'",
525 value);
526 return FALSE;
527 }
528 return TRUE;
529 }
530
531 if (g_ascii_strcasecmp (key, "ep-iface-number") == 0) {
532 props->endpoint_iface_number = atoi(value);
533 return TRUE;
534 }
535
536 if (g_ascii_strcasecmp (key, "ul-datagram-max-size") == 0) {
537 props->ul_datagram_max_size = atoi(value);
538 return TRUE;
539 }
540
541 if (g_ascii_strcasecmp (key, "ul-max-datagrams") == 0) {
542 props->ul_max_datagrams = atoi(value);
543 return TRUE;
544 }
545
546 g_set_error (error,
547 QMI_CORE_ERROR,
548 QMI_CORE_ERROR_FAILED,
549 "Unrecognized option '%s'",
550 key);
551 return FALSE;
552 }
553
554 static QmiMessageWdaSetDataFormatInput *
555 set_data_format_input_create (const gchar *str)
556 {
557 QmiMessageWdaSetDataFormatInput *input = NULL;
558 GError *error = NULL;
559 SetDataFormatProperties props = {
560 .link_layer_protocol = QMI_WDA_LINK_LAYER_PROTOCOL_UNKNOWN,
561 .ul_protocol = QMI_WDA_DATA_AGGREGATION_PROTOCOL_DISABLED,
562 .dl_protocol = QMI_WDA_DATA_AGGREGATION_PROTOCOL_DISABLED,
563 .dl_datagram_max_size = QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAM_SIZE_UNDEFINED,
564 .dl_max_datagrams = QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAMS_UNDEFINED,
565 .endpoint_type = QMI_DATA_ENDPOINT_TYPE_UNDEFINED,
566 .endpoint_iface_number = QMI_WDA_ENDPOINT_INTERFACE_NUMBER_UNDEFINED,
567 .ul_datagram_max_size = QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAM_SIZE_UNDEFINED,
568 .ul_max_datagrams = QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAMS_UNDEFINED,
569 };
570
571 input = qmi_message_wda_set_data_format_input_new ();
572
573 /* New key=value format */
574 if (strchr (str, '=')) {
575 if (!qmicli_parse_key_value_string (str,
576 &error,
577 set_data_format_properties_handle,
578 &props)) {
579 g_printerr ("error: could not parse input string '%s'\n", error->message);
580 g_error_free (error);
581 goto error_out;
582 }
583
584 if (!qmi_message_wda_set_data_format_input_set_uplink_data_aggregation_protocol (
585 input,
586 props.ul_protocol,
587 &error)) {
588 g_printerr ("error: could not set Upload data aggregation protocol '%d': %s\n",
589 props.ul_protocol, error->message);
590 g_error_free (error);
591 goto error_out;
592 }
593
594 if (!qmi_message_wda_set_data_format_input_set_downlink_data_aggregation_protocol (
595 input,
596 props.dl_protocol,
597 &error)) {
598 g_printerr ("error: could not set Download data aggregation protocol '%d': %s\n",
599 props.dl_protocol, error->message);
600 g_error_free (error);
601 goto error_out;
602 }
603
604 if (props.dl_datagram_max_size != QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAM_SIZE_UNDEFINED &&
605 !qmi_message_wda_set_data_format_input_set_downlink_data_aggregation_max_size (
606 input,
607 props.dl_datagram_max_size,
608 &error)) {
609 g_printerr ("error: could not set Download data aggregation max size %d: %s\n",
610 props.dl_datagram_max_size, error->message);
611 g_error_free (error);
612 goto error_out;
613 }
614
615 if (props.dl_max_datagrams != QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAMS_UNDEFINED &&
616 !qmi_message_wda_set_data_format_input_set_downlink_data_aggregation_max_datagrams (
617 input,
618 props.dl_max_datagrams,
619 &error)) {
620 g_printerr ("error: could not set Download data aggregation max datagrams %d: %s\n",
621 props.dl_max_datagrams, error->message);
622 g_error_free (error);
623 goto error_out;
624 }
625
626 if ((props.endpoint_type == QMI_DATA_ENDPOINT_TYPE_UNDEFINED) ^
627 (props.endpoint_iface_number == QMI_WDA_ENDPOINT_INTERFACE_NUMBER_UNDEFINED)) {
628 g_printerr ("error: endpoint type and interface number must be both set or both unset\n");
629 goto error_out;
630 }
631
632 if ((props.endpoint_type != QMI_DATA_ENDPOINT_TYPE_UNDEFINED) &&
633 (props.endpoint_iface_number != QMI_WDA_ENDPOINT_INTERFACE_NUMBER_UNDEFINED) &&
634 !qmi_message_wda_set_data_format_input_set_endpoint_info (
635 input,
636 props.endpoint_type,
637 props.endpoint_iface_number,
638 &error)) {
639 g_printerr ("error: could not set peripheral endpoint id: %s\n", error->message);
640 g_error_free (error);
641 goto error_out;
642 }
643
644 if (props.ul_datagram_max_size != QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAM_SIZE_UNDEFINED &&
645 !qmi_message_wda_set_data_format_input_set_uplink_data_aggregation_max_size (
646 input,
647 props.ul_datagram_max_size,
648 &error)) {
649 g_printerr ("error: could not set Upload data aggregation max size %d: %s\n",
650 props.ul_datagram_max_size, error->message);
651 g_error_free (error);
652 goto error_out;
653 }
654
655 if (props.ul_max_datagrams != QMI_WDA_AGGREGATION_PROTOCOL_MAX_DATAGRAMS_UNDEFINED &&
656 !qmi_message_wda_set_data_format_input_set_uplink_data_aggregation_max_datagrams (
657 input,
658 props.ul_max_datagrams,
659 &error)) {
660 g_printerr ("error: could not set Upload data aggregation max datagrams %d: %s\n",
661 props.ul_max_datagrams, error->message);
662 g_error_free (error);
663 goto error_out;
664 }
665 }
666 /* Old non key=value format, like this:
667 * "[(raw-ip|802-3)]"
668 */
669 else {
670 if (!qmicli_read_wda_link_layer_protocol_from_string (str, &(props.link_layer_protocol))) {
671 g_printerr ("Unrecognized Link Layer Protocol '%s'\n", str);
672 goto error_out;
673 }
674 }
675
676 if (props.link_layer_protocol == QMI_WDA_LINK_LAYER_PROTOCOL_UNKNOWN) {
677 g_printerr ("error: Link Layer Protocol value is missing\n");
678 goto error_out;
679 }
680
681 if (!qmi_message_wda_set_data_format_input_set_link_layer_protocol (
682 input,
683 props.link_layer_protocol,
684 &error)) {
685 g_printerr ("error: couldn't create input data bundle: '%s'\n",
686 error->message);
687 g_error_free (error);
688 goto error_out;
689 }
690
691 return input;
692
693 error_out:
694 qmi_message_wda_set_data_format_input_unref (input);
695 return NULL;
696 }
697
698 #endif /* HAVE_QMI_MESSAGE_WDA_SET_DATA_FORMAT */
699
700 #if defined HAVE_QMI_MESSAGE_WDA_GET_SUPPORTED_MESSAGES
701
702 static void
703 get_supported_messages_ready (QmiClientWda *client,
704 GAsyncResult *res)
705 {
706 QmiMessageWdaGetSupportedMessagesOutput *output;
707 GError *error = NULL;
708 GArray *bytearray = NULL;
709 gchar *str;
710
711 output = qmi_client_wda_get_supported_messages_finish (client, res, &error);
712 if (!output) {
713 g_printerr ("error: operation failed: %s\n", error->message);
714 g_error_free (error);
715 operation_shutdown (FALSE);
716 return;
717 }
718
719 if (!qmi_message_wda_get_supported_messages_output_get_result (output, &error)) {
720 g_printerr ("error: couldn't get supported WDA messages: %s\n", error->message);
721 g_error_free (error);
722 qmi_message_wda_get_supported_messages_output_unref (output);
723 operation_shutdown (FALSE);
724 return;
725 }
726
727 g_print ("[%s] Successfully got supported WDA messages:\n",
728 qmi_device_get_path_display (ctx->device));
729
730 qmi_message_wda_get_supported_messages_output_get_list (output, &bytearray, NULL);
731 str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL,
732 bytearray ? bytearray->len : 0);
733 g_print ("%s", str);
734 g_free (str);
735
736 qmi_message_wda_get_supported_messages_output_unref (output);
737 operation_shutdown (TRUE);
738 }
739
740 #endif /* HAVE_QMI_MESSAGE_WDA_GET_SUPPORTED_MESSAGES */
741
742 #if defined HAVE_QMI_MESSAGE_WDA_LOOPBACK_CONFIGURATION
743 typedef struct {
744 QmiWdaLoopBackState loopback_state;
745 guint32 replication_factor;
746 } SetLoopbackConfigurationProperties;
747
748
749 static gboolean
750 set_loopback_configuration_properties_handle (const gchar *key,
751 const gchar *value,
752 GError **error,
753 gpointer user_data)
754 {
755 SetLoopbackConfigurationProperties *props = (SetLoopbackConfigurationProperties *)user_data;
756
757 if (!value || !value[0]) {
758 g_set_error (error,
759 QMI_CORE_ERROR,
760 QMI_CORE_ERROR_FAILED,
761 "key '%s' requires a value",
762 key);
763 return FALSE;
764 }
765
766 if (g_ascii_strcasecmp (key, "state") == 0) {
767 if (!qmicli_read_wda_loop_back_state_from_string (value, &(props->loopback_state))) {
768 g_set_error (error,
769 QMI_CORE_ERROR,
770 QMI_CORE_ERROR_FAILED,
771 "Unrecognized Loopback state '%s'",
772 value);
773 return FALSE;
774 }
775 return TRUE;
776 }
777
778 if (g_ascii_strcasecmp (key, "replication-factor") == 0) {
779 props->replication_factor = atoi (value);
780 return TRUE;
781 }
782
783 g_set_error (error,
784 QMI_CORE_ERROR,
785 QMI_CORE_ERROR_FAILED,
786 "Unrecognized option '%s'",
787 key);
788 return FALSE;
789 }
790
791 static QmiMessageWdaLoopbackConfigurationInput *
792 set_loopback_configuration_input_create (const gchar *str)
793 {
794 QmiMessageWdaLoopbackConfigurationInput *input = NULL;
795 GError *error = NULL;
796 SetLoopbackConfigurationProperties props = {
797 .loopback_state = QMI_WDA_LOOPBACK_DISABLED,
798 .replication_factor = QMI_WDA_LOOPBACK_REPLICATION_FACTOR_UNDEFINED,
799 };
800
801 input = qmi_message_wda_loopback_configuration_input_new ();
802
803 if (!qmicli_parse_key_value_string (str,
804 &error,
805 set_loopback_configuration_properties_handle,
806 &props)) {
807 g_printerr ("error: could not parse input string '%s'\n", error->message);
808 g_error_free (error);
809 goto error_out;
810 }
811
812 if (props.replication_factor == QMI_WDA_LOOPBACK_REPLICATION_FACTOR_UNDEFINED) {
813 g_printerr ("error: 'replication-factor' is mandatory\n");
814 goto error_out;
815 }
816
817 if (!qmi_message_wda_loopback_configuration_input_set_loopback_state (
818 input,
819 props.loopback_state,
820 &error)) {
821 g_printerr ("error: could not set Loopback state '%d': %s\n",
822 props.loopback_state, error->message);
823 g_error_free (error);
824 goto error_out;
825 }
826
827 if (!qmi_message_wda_loopback_configuration_input_set_replication_factor (
828 input,
829 props.replication_factor,
830 &error)) {
831 g_printerr ("error: could not set Loopback replication factor '%d': %s\n",
832 props.replication_factor, error->message);
833 g_error_free (error);
834 goto error_out;
835 }
836
837 return input;
838
839 error_out:
840 qmi_message_wda_loopback_configuration_input_unref (input);
841 return NULL;
842 }
843
844 static void
845 set_loopback_configuration_ready (QmiClientWda *client,
846 GAsyncResult *res)
847 {
848 QmiMessageWdaLoopbackConfigurationOutput *output;
849 GError *error = NULL;
850
851 output = qmi_client_wda_loopback_configuration_finish (client, res, &error);
852 if (!output) {
853 g_printerr ("error: operation failed: %s\n", error->message);
854 g_error_free (error);
855 operation_shutdown (FALSE);
856 return;
857 }
858
859 if (!qmi_message_wda_loopback_configuration_output_get_result (output, &error)) {
860 g_printerr ("error: couldn't set loopback configuration: %s\n", error->message);
861 g_error_free (error);
862 qmi_message_wda_loopback_configuration_output_unref (output);
863 operation_shutdown (FALSE);
864 return;
865 }
866
867 g_print ("[%s] Successfully set loopback configuration\n",
868 qmi_device_get_path_display (ctx->device));
869
870 qmi_message_wda_loopback_configuration_output_unref (output);
871 operation_shutdown (TRUE);
872 }
873 #endif /* HAVE_QMI_MESSAGE_WDA_LOOPBACK_CONFIGURATION */
874
875 void
876 qmicli_wda_run (QmiDevice *device,
877 QmiClientWda *client,
878 GCancellable *cancellable)
879 {
880 /* Initialize context */
881 ctx = g_slice_new (Context);
882 ctx->device = g_object_ref (device);
883 ctx->client = g_object_ref (client);
884 ctx->cancellable = g_object_ref (cancellable);
885
886 #if defined HAVE_QMI_MESSAGE_WDA_SET_DATA_FORMAT
887 if (set_data_format_str) {
888 QmiMessageWdaSetDataFormatInput *input;
889
890 input = set_data_format_input_create (set_data_format_str);
891 if (!input) {
892 operation_shutdown (FALSE);
893 return;
894 }
895
896 g_debug ("Asynchronously setting data format...");
897 qmi_client_wda_set_data_format (ctx->client,
898 input,
899 10,
900 ctx->cancellable,
901 (GAsyncReadyCallback)set_data_format_ready,
902 NULL);
903 qmi_message_wda_set_data_format_input_unref (input);
904 return;
905 }
906 #endif
907
908 #if defined HAVE_QMI_MESSAGE_WDA_GET_DATA_FORMAT
909 if (get_data_format_flag) {
910 g_autoptr(QmiMessageWdaGetDataFormatInput) input = NULL;
911
912 if (get_data_format_str) {
913 input = get_data_format_input_create (get_data_format_str);
914 if (!input) {
915 operation_shutdown (FALSE);
916 return;
917 }
918 }
919
920 g_debug ("Asynchronously getting data format...");
921 qmi_client_wda_get_data_format (ctx->client,
922 input,
923 10,
924 ctx->cancellable,
925 (GAsyncReadyCallback)get_data_format_ready,
926 NULL);
927 return;
928 }
929 #endif
930
931 #if defined HAVE_QMI_MESSAGE_WDA_GET_SUPPORTED_MESSAGES
932 if (get_supported_messages_flag) {
933 g_debug ("Asynchronously getting supported WDA messages...");
934 qmi_client_wda_get_supported_messages (ctx->client,
935 NULL,
936 10,
937 ctx->cancellable,
938 (GAsyncReadyCallback)get_supported_messages_ready,
939 NULL);
940 return;
941 }
942 #endif
943
944 #if defined HAVE_QMI_MESSAGE_WDA_LOOPBACK_CONFIGURATION
945 if (set_loopback_configuration_str) {
946 QmiMessageWdaLoopbackConfigurationInput *input;
947
948 input = set_loopback_configuration_input_create (set_loopback_configuration_str);
949 if (!input) {
950 operation_shutdown (FALSE);
951 return;
952 }
953
954 g_debug ("Asynchronously setting loopback configuration...");
955 qmi_client_wda_loopback_configuration (ctx->client,
956 input,
957 10,
958 ctx->cancellable,
959 (GAsyncReadyCallback)set_loopback_configuration_ready,
960 NULL);
961
962 qmi_message_wda_loopback_configuration_input_unref (input);
963 return;
964 }
965 #endif
966
967 /* Just client allocate/release? */
968 if (noop_flag) {
969 g_idle_add (noop_cb, NULL);
970 return;
971 }
972
973 g_warn_if_reached ();
974 }
975
976 #endif /* HAVE_QMI_SERVICE_WDA */