Debian Codegraph @

src/qmicli/qmicli-wds.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) 2015 Velocloud Inc.
19 * Copyright (C) 2012-2017 Aleksander Morgado <[email protected]>
20 */
21
22 #include "config.h"
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <locale.h>
27 #include <string.h>
28 #include <arpa/inet.h>
29
30 #include <glib.h>
31 #include <gio/gio.h>
32
33 #include <libqmi-glib.h>
34
35 #include "qmicli.h"
36 #include "qmicli-helpers.h"
37
38 #if defined HAVE_QMI_SERVICE_WDS
39
40 #undef VALIDATE_MASK_NONE
41 #define VALIDATE_MASK_NONE(str) (str ? str : "none")
42
43 #define QMI_WDS_MUX_ID_UNDEFINED 0xFF
44 #define QMI_WDS_ENDPOINT_INTERFACE_NUMBER_UNDEFINED -1
45
46 /* Context */
47 typedef struct {
48 QmiDevice *device;
49 QmiClientWds *client;
50 GCancellable *cancellable;
51
52 /* Helpers for the wds-start-network command */
53 gulong network_started_id;
54 guint packet_status_timeout_id;
55 guint32 packet_data_handle;
56 } Context;
57 static Context *ctx;
58
59 /* Options */
60 static gchar *start_network_str;
61 static gboolean follow_network_flag;
62 static gchar *stop_network_str;
63 static gboolean get_current_settings_flag;
64 static gboolean get_packet_service_status_flag;
65 static gboolean get_packet_statistics_flag;
66 static gboolean get_data_bearer_technology_flag;
67 static gboolean get_current_data_bearer_technology_flag;
68 static gboolean go_dormant_flag;
69 static gboolean go_active_flag;
70 static gboolean get_dormancy_status_flag;
71 static gchar *create_profile_str;
72 static gchar *swi_create_profile_indexed_str;
73 static gchar *modify_profile_str;
74 static gchar *delete_profile_str;
75 static gchar *get_profile_list_str;
76 static gchar *get_default_profile_num_str; /* deprecated */
77 static gchar *get_default_profile_number_str;
78 static gchar *set_default_profile_num_str; /* deprecated */
79 static gchar *set_default_profile_number_str;
80 static gchar *get_default_settings_str;
81 static gboolean get_autoconnect_settings_flag;
82 static gchar *set_autoconnect_settings_str;
83 static gboolean get_supported_messages_flag;
84 static gboolean reset_flag;
85 static gboolean noop_flag;
86 static gchar *bind_data_port_str;
87 static gchar *bind_mux_str;
88 static gchar *set_ip_family_str;
89 static gboolean get_channel_rates_flag;
90 static gboolean get_lte_attach_parameters_flag;
91 static gboolean get_max_lte_attach_pdn_number_flag;
92 static gboolean get_lte_attach_pdn_list_flag;
93 static gchar *set_lte_attach_pdn_list_str;
94
95 static GOptionEntry entries[] = {
96 #if defined HAVE_QMI_MESSAGE_WDS_START_NETWORK
97 { "wds-start-network", 0, 0, G_OPTION_ARG_STRING, &start_network_str,
98 "Start network (allowed keys: apn, 3gpp-profile, 3gpp2-profile, auth (PAP|CHAP|BOTH), username, password, autoconnect=yes, ip-type (4|6))",
99 "[\"key=value,...\"]"
100 },
101 # if defined HAVE_QMI_MESSAGE_WDS_STOP_NETWORK && defined HAVE_QMI_MESSAGE_WDS_GET_PACKET_SERVICE_STATUS
102 { "wds-follow-network", 0, 0, G_OPTION_ARG_NONE, &follow_network_flag,
103 "Follow the network status until disconnected. Use with `--wds-start-network'",
104 NULL
105 },
106 # endif
107 #endif
108 #if defined HAVE_QMI_MESSAGE_WDS_STOP_NETWORK
109 { "wds-stop-network", 0, 0, G_OPTION_ARG_STRING, &stop_network_str,
110 "Stop network",
111 "[Packet data handle] OR [disable-autoconnect]",
112 },
113 #endif
114 #if defined HAVE_QMI_MESSAGE_WDS_GET_CURRENT_SETTINGS
115 { "wds-get-current-settings", 0, 0, G_OPTION_ARG_NONE, &get_current_settings_flag,
116 "Get current settings",
117 NULL
118 },
119 #endif
120 #if defined HAVE_QMI_MESSAGE_WDS_GET_PACKET_SERVICE_STATUS
121 { "wds-get-packet-service-status", 0, 0, G_OPTION_ARG_NONE, &get_packet_service_status_flag,
122 "Get packet service status",
123 NULL
124 },
125 #endif
126 #if defined HAVE_QMI_MESSAGE_WDS_GET_PACKET_STATISTICS
127 { "wds-get-packet-statistics", 0, 0, G_OPTION_ARG_NONE, &get_packet_statistics_flag,
128 "Get packet statistics",
129 NULL
130 },
131 #endif
132 #if defined HAVE_QMI_MESSAGE_WDS_GET_DATA_BEARER_TECHNOLOGY
133 { "wds-get-data-bearer-technology", 0, 0, G_OPTION_ARG_NONE, &get_data_bearer_technology_flag,
134 "Get data bearer technology",
135 NULL
136 },
137 #endif
138 #if defined HAVE_QMI_MESSAGE_WDS_GET_CURRENT_DATA_BEARER_TECHNOLOGY
139 { "wds-get-current-data-bearer-technology", 0, 0, G_OPTION_ARG_NONE, &get_current_data_bearer_technology_flag,
140 "Get current data bearer technology",
141 NULL
142 },
143 #endif
144 #if defined HAVE_QMI_MESSAGE_WDS_GO_DORMANT
145 { "wds-go-dormant", 0, 0, G_OPTION_ARG_NONE, &go_dormant_flag,
146 "Make the active data connection go dormant",
147 NULL
148 },
149 #endif
150 #if defined HAVE_QMI_MESSAGE_WDS_GO_ACTIVE
151 { "wds-go-active", 0, 0, G_OPTION_ARG_NONE, &go_active_flag,
152 "Make the active data connection go active",
153 NULL
154 },
155 #endif
156 #if defined HAVE_QMI_MESSAGE_WDS_GET_DORMANCY_STATUS
157 { "wds-get-dormancy-status", 0, 0, G_OPTION_ARG_NONE, &get_dormancy_status_flag,
158 "Get the dormancy status of the active data connection",
159 NULL
160 },
161 #endif
162 #if defined HAVE_QMI_MESSAGE_WDS_CREATE_PROFILE
163 { "wds-create-profile", 0, 0, G_OPTION_ARG_STRING, &create_profile_str,
164 "Create new profile using first available profile index (optional keys: name, apn, pdp-type (IP|PPP|IPV6|IPV4V6), auth (NONE|PAP|CHAP|BOTH), username, password, context-num, no-roaming=yes, disabled=yes)",
165 "[\"(3gpp|3gpp2)[,key=value,...]\"]"
166 },
167 #endif
168 #if defined HAVE_QMI_MESSAGE_WDS_SWI_CREATE_PROFILE_INDEXED
169 { "wds-swi-create-profile-indexed", 0, 0, G_OPTION_ARG_STRING, &swi_create_profile_indexed_str,
170 "Create new profile at specified profile index [Sierra Wireless specific] (optional keys: name, apn, pdp-type (IP|PPP|IPV6|IPV4V6), auth (NONE|PAP|CHAP|BOTH), username, password, context-num, no-roaming=yes, disabled=yes)",
171 "[\"(3gpp|3gpp2),#[,key=value,...]\"]"
172 },
173 #endif
174 #if defined HAVE_QMI_MESSAGE_WDS_MODIFY_PROFILE
175 { "wds-modify-profile", 0, 0, G_OPTION_ARG_STRING, &modify_profile_str,
176 "Modify existing profile (optional keys: name, apn, pdp-type (IP|PPP|IPV6|IPV4V6), auth (NONE|PAP|CHAP|BOTH), username, password, context-num, no-roaming=yes, disabled=yes)",
177 "[\"(3gpp|3gpp2),#,key=value,...\"]"
178 },
179 #endif
180 #if defined HAVE_QMI_MESSAGE_WDS_DELETE_PROFILE
181 { "wds-delete-profile", 0, 0, G_OPTION_ARG_STRING, &delete_profile_str,
182 "Delete existing profile",
183 "[(3gpp|3gpp2),#]"
184 },
185 #endif
186 #if defined HAVE_QMI_MESSAGE_WDS_GET_PROFILE_LIST && defined HAVE_QMI_MESSAGE_WDS_GET_PROFILE_SETTINGS
187 { "wds-get-profile-list", 0, 0, G_OPTION_ARG_STRING, &get_profile_list_str,
188 "Get profile list",
189 "[3gpp|3gpp2]"
190 },
191 #endif
192 #if defined HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_PROFILE_NUMBER
193 { "wds-get-default-profile-number", 0, 0, G_OPTION_ARG_STRING, &get_default_profile_number_str,
194 "Get default profile number",
195 "[3gpp|3gpp2]"
196 },
197 #endif
198 #if defined HAVE_QMI_MESSAGE_WDS_SET_DEFAULT_PROFILE_NUMBER
199 { "wds-set-default-profile-number", 0, 0, G_OPTION_ARG_STRING, &set_default_profile_number_str,
200 "Set default profile number",
201 "[(3gpp|3gpp2),#]"
202 },
203 #endif
204 #if defined HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_SETTINGS
205 { "wds-get-default-settings", 0, 0, G_OPTION_ARG_STRING, &get_default_settings_str,
206 "Get default settings",
207 "[3gpp|3gpp2]"
208 },
209 #endif
210 #if defined HAVE_QMI_MESSAGE_WDS_GET_AUTOCONNECT_SETTINGS
211 { "wds-get-autoconnect-settings", 0, 0, G_OPTION_ARG_NONE, &get_autoconnect_settings_flag,
212 "Get autoconnect settings",
213 NULL
214 },
215 #endif
216 #if defined HAVE_QMI_MESSAGE_WDS_SET_AUTOCONNECT_SETTINGS
217 { "wds-set-autoconnect-settings", 0, 0, G_OPTION_ARG_STRING, &set_autoconnect_settings_str,
218 "Set autoconnect settings (roaming settings optional)",
219 "[(enabled|disabled|paused)[,(roaming-allowed|home-only)]]"
220 },
221 #endif
222 #if defined HAVE_QMI_MESSAGE_WDS_GET_SUPPORTED_MESSAGES
223 { "wds-get-supported-messages", 0, 0, G_OPTION_ARG_NONE, &get_supported_messages_flag,
224 "Get supported messages",
225 NULL
226 },
227 #endif
228 #if defined HAVE_QMI_MESSAGE_WDS_RESET
229 { "wds-reset", 0, 0, G_OPTION_ARG_NONE, &reset_flag,
230 "Reset the service state",
231 NULL
232 },
233 #endif
234 #if defined HAVE_QMI_MESSAGE_WDS_BIND_DATA_PORT
235 { "wds-bind-data-port", 0, 0, G_OPTION_ARG_STRING, &bind_data_port_str,
236 "Bind data port to controller device to be used with `--client-no-release-cid'",
237 "[a2-mux-rmnet0-7|#]"
238 },
239 #endif
240 #if defined HAVE_QMI_MESSAGE_WDS_BIND_MUX_DATA_PORT
241 { "wds-bind-mux-data-port", 0, 0, G_OPTION_ARG_STRING, &bind_mux_str,
242 "Bind qmux data port to controller device (allowed keys: mux-id, ep-type (undefined|hsusb|pcie|embedded|bam-dmux), ep-iface-number) to be used with `--client-no-release-cid'",
243 "[\"key=value,...\"]"
244 },
245 #endif
246 #if defined HAVE_QMI_MESSAGE_WDS_SET_IP_FAMILY
247 { "wds-set-ip-family", 0, 0, G_OPTION_ARG_STRING, &set_ip_family_str,
248 "Set IP family",
249 "[4|6]"
250 },
251 #endif
252 #if defined HAVE_QMI_MESSAGE_WDS_GET_CHANNEL_RATES
253 { "wds-get-channel-rates", 0, 0, G_OPTION_ARG_NONE, &get_channel_rates_flag,
254 "Get channel data rates",
255 NULL
256 },
257 #endif
258 #if defined HAVE_QMI_MESSAGE_WDS_GET_LTE_ATTACH_PARAMETERS
259 { "wds-get-lte-attach-parameters", 0, 0, G_OPTION_ARG_NONE, &get_lte_attach_parameters_flag,
260 "Get LTE attach parameters",
261 NULL
262 },
263 #endif
264 #if defined HAVE_QMI_MESSAGE_WDS_GET_MAX_LTE_ATTACH_PDN_NUMBER
265 { "wds-get-max-lte-attach-pdn-num", 0, 0, G_OPTION_ARG_NONE, &get_max_lte_attach_pdn_number_flag,
266 "Get the maximum number of LTE attach PDN",
267 NULL
268 },
269 #endif
270 #if defined HAVE_QMI_MESSAGE_WDS_GET_LTE_ATTACH_PDN_LIST
271 { "wds-get-lte-attach-pdn-list", 0, 0, G_OPTION_ARG_NONE, &get_lte_attach_pdn_list_flag,
272 "Get the list of LTE attach PDN",
273 NULL
274 },
275 #endif
276 #if defined HAVE_QMI_MESSAGE_WDS_SET_LTE_ATTACH_PDN_LIST
277 { "wds-set-lte-attach-pdn-list", 0, 0, G_OPTION_ARG_STRING, &set_lte_attach_pdn_list_str,
278 "Set the list of LTE attach PDN",
279 "[#,#,...]"
280 },
281 #endif
282 { "wds-noop", 0, 0, G_OPTION_ARG_NONE, &noop_flag,
283 "Just allocate or release a WDS client. Use with `--client-no-release-cid' and/or `--client-cid'",
284 NULL
285 },
286 /* deprecated entries (hidden in --help) */
287 #if defined HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_PROFILE_NUMBER
288 { "wds-get-default-profile-num", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &get_default_profile_num_str,
289 "Get default profile number",
290 "[3gpp|3gpp2]"
291 },
292 #endif
293 #if defined HAVE_QMI_MESSAGE_WDS_SET_DEFAULT_PROFILE_NUMBER
294 { "wds-set-default-profile-num", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &set_default_profile_num_str,
295 "Set default profile number",
296 "[(3gpp|3gpp2),#]"
297 },
298 #endif
299 { NULL, 0, 0, 0, NULL, NULL, NULL }
300 };
301
302 GOptionGroup *
303 qmicli_wds_get_option_group (void)
304 {
305 GOptionGroup *group;
306
307 group = g_option_group_new ("wds",
308 "WDS options:",
309 "Show Wireless Data Service options",
310 NULL,
311 NULL);
312 g_option_group_add_entries (group, entries);
313
314 return group;
315 }
316
317 gboolean
318 qmicli_wds_options_enabled (void)
319 {
320 static guint n_actions = 0;
321 static gboolean checked = FALSE;
322
323 if (checked)
324 return !!n_actions;
325
326 n_actions = (!!start_network_str +
327 !!stop_network_str +
328 !!bind_data_port_str +
329 !!bind_mux_str +
330 !!set_ip_family_str +
331 get_current_settings_flag +
332 get_packet_service_status_flag +
333 get_packet_statistics_flag +
334 get_data_bearer_technology_flag +
335 get_current_data_bearer_technology_flag +
336 go_dormant_flag +
337 go_active_flag +
338 get_dormancy_status_flag +
339 !!create_profile_str +
340 !!swi_create_profile_indexed_str +
341 !!modify_profile_str +
342 !!delete_profile_str +
343 !!get_profile_list_str +
344 !!get_default_profile_num_str +
345 !!get_default_profile_number_str +
346 !!set_default_profile_num_str +
347 !!set_default_profile_number_str +
348 !!get_default_settings_str +
349 get_autoconnect_settings_flag +
350 !!set_autoconnect_settings_str +
351 get_supported_messages_flag +
352 reset_flag +
353 !!get_channel_rates_flag +
354 get_lte_attach_parameters_flag +
355 get_max_lte_attach_pdn_number_flag +
356 get_lte_attach_pdn_list_flag +
357 !!set_lte_attach_pdn_list_str +
358 noop_flag);
359
360 if (n_actions > 1) {
361 g_printerr ("error: too many WDS actions requested\n");
362 exit (EXIT_FAILURE);
363 } else if (n_actions == 0 &&
364 follow_network_flag) {
365 g_printerr ("error: `--wds-follow-network' must be used with `--wds-start-network'\n");
366 exit (EXIT_FAILURE);
367 }
368
369 checked = TRUE;
370 return !!n_actions;
371 }
372
373 static void
374 context_free (Context *context)
375 {
376 if (!context)
377 return;
378
379 if (context->client)
380 g_object_unref (context->client);
381 if (context->network_started_id)
382 g_cancellable_disconnect (context->cancellable, context->network_started_id);
383 if (context->packet_status_timeout_id)
384 g_source_remove (context->packet_status_timeout_id);
385 g_object_unref (context->cancellable);
386 g_object_unref (context->device);
387 g_slice_free (Context, context);
388 }
389
390 static void
391 operation_shutdown (gboolean operation_status)
392 {
393 /* Cleanup context and finish async operation */
394 context_free (ctx);
395 qmicli_async_operation_done (operation_status, FALSE);
396 }
397
398 #if defined HAVE_QMI_MESSAGE_WDS_START_NETWORK || defined HAVE_QMI_MESSAGE_WDS_STOP_NETWORK
399
400 static void
401 stop_network_ready (QmiClientWds *client,
402 GAsyncResult *res)
403 {
404 GError *error = NULL;
405 QmiMessageWdsStopNetworkOutput *output;
406
407 output = qmi_client_wds_stop_network_finish (client, res, &error);
408 if (!output) {
409 g_printerr ("error: operation failed: %s\n",
410 error->message);
411 g_error_free (error);
412 operation_shutdown (FALSE);
413 return;
414 }
415
416 if (!qmi_message_wds_stop_network_output_get_result (output, &error)) {
417 g_printerr ("error: couldn't stop network: %s\n", error->message);
418 g_error_free (error);
419 qmi_message_wds_stop_network_output_unref (output);
420 operation_shutdown (FALSE);
421 return;
422 }
423
424 #undef VALIDATE_UNKNOWN
425 #define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
426
427 g_print ("[%s] Network stopped\n",
428 qmi_device_get_path_display (ctx->device));
429 qmi_message_wds_stop_network_output_unref (output);
430 operation_shutdown (TRUE);
431 }
432
433 static void
434 internal_stop_network (GCancellable *cancellable,
435 guint32 packet_data_handle,
436 gboolean disable_autoconnect)
437 {
438 QmiMessageWdsStopNetworkInput *input;
439
440 input = qmi_message_wds_stop_network_input_new ();
441 qmi_message_wds_stop_network_input_set_packet_data_handle (input, packet_data_handle, NULL);
442 if (disable_autoconnect)
443 qmi_message_wds_stop_network_input_set_disable_autoconnect (input, TRUE, NULL);
444
445 g_print ("Network cancelled... releasing resources\n");
446 qmi_client_wds_stop_network (ctx->client,
447 input,
448 120,
449 ctx->cancellable,
450 (GAsyncReadyCallback)stop_network_ready,
451 NULL);
452 qmi_message_wds_stop_network_input_unref (input);
453 }
454
455 #endif /* HAVE_QMI_MESSAGE_WDS_START_NETWORK
456 * HAVE_QMI_MESSAGE_WDS_STOP_NETWORK */
457
458 #if defined HAVE_QMI_MESSAGE_WDS_START_NETWORK
459
460 #if defined HAVE_QMI_MESSAGE_WDS_STOP_NETWORK && defined HAVE_QMI_MESSAGE_WDS_GET_PACKET_SERVICE_STATUS
461
462 static void
463 network_cancelled (GCancellable *cancellable)
464 {
465 ctx->network_started_id = 0;
466
467 /* Remove the timeout right away */
468 if (ctx->packet_status_timeout_id) {
469 g_source_remove (ctx->packet_status_timeout_id);
470 ctx->packet_status_timeout_id = 0;
471 }
472
473 g_print ("Network cancelled... releasing resources\n");
474 internal_stop_network (cancellable, ctx->packet_data_handle, FALSE);
475 }
476
477 static void
478 timeout_get_packet_service_status_ready (QmiClientWds *client,
479 GAsyncResult *res)
480 {
481 GError *error = NULL;
482 QmiMessageWdsGetPacketServiceStatusOutput *output;
483 QmiWdsConnectionStatus status;
484
485 output = qmi_client_wds_get_packet_service_status_finish (client, res, &error);
486 if (!output) {
487 g_printerr ("error: operation failed: %s\n",
488 error->message);
489 g_error_free (error);
490 return;
491 }
492
493 if (!qmi_message_wds_get_packet_service_status_output_get_result (output, &error)) {
494 g_printerr ("error: couldn't get packet service status: %s\n", error->message);
495 g_error_free (error);
496 qmi_message_wds_get_packet_service_status_output_unref (output);
497 return;
498 }
499
500 qmi_message_wds_get_packet_service_status_output_get_connection_status (
501 output,
502 &status,
503 NULL);
504
505 g_print ("[%s] Connection status: '%s'\n",
506 qmi_device_get_path_display (ctx->device),
507 qmi_wds_connection_status_get_string (status));
508 qmi_message_wds_get_packet_service_status_output_unref (output);
509
510 /* If packet service checks detect disconnection, halt --wds-follow-network */
511 if (status != QMI_WDS_CONNECTION_STATUS_CONNECTED) {
512 g_print ("[%s] Stopping after detecting disconnection\n",
513 qmi_device_get_path_display (ctx->device));
514 internal_stop_network (NULL, ctx->packet_data_handle, FALSE);
515 }
516 }
517
518 static gboolean
519 packet_status_timeout (void)
520 {
521 qmi_client_wds_get_packet_service_status (ctx->client,
522 NULL,
523 10,
524 ctx->cancellable,
525 (GAsyncReadyCallback)timeout_get_packet_service_status_ready,
526 NULL);
527
528 return TRUE;
529 }
530
531 #endif /* HAVE_QMI_MESSAGE_WDS_STOP_NETWORK
532 * HAVE_QMI_MESSAGE_WDS_GET_PACKET_SERVICE_STATUS */
533
534 typedef struct {
535 gchar *apn;
536 guint8 profile_index_3gpp;
537 guint8 profile_index_3gpp2;
538 QmiWdsAuthentication auth;
539 gboolean auth_set;
540 QmiWdsIpFamily ip_type;
541 gchar *username;
542 gchar *password;
543 gboolean autoconnect;
544 gboolean autoconnect_set;
545 } StartNetworkProperties;
546
547 static gboolean
548 start_network_properties_handle (const gchar *key,
549 const gchar *value,
550 GError **error,
551 gpointer user_data)
552 {
553 StartNetworkProperties *props = user_data;
554
555 if (!value || !value[0]) {
556 g_set_error (error,
557 QMI_CORE_ERROR,
558 QMI_CORE_ERROR_FAILED,
559 "key '%s' required a value",
560 key);
561 return FALSE;
562 }
563
564 if (g_ascii_strcasecmp (key, "apn") == 0 && !props->apn) {
565 props->apn = g_strdup (value);
566 return TRUE;
567 }
568
569 if (g_ascii_strcasecmp (key, "3gpp-profile") == 0 && !props->profile_index_3gpp) {
570 props->profile_index_3gpp = atoi (value);
571 return TRUE;
572 }
573
574 if (g_ascii_strcasecmp (key, "3gpp2-profile") == 0 && !props->profile_index_3gpp2) {
575 props->profile_index_3gpp2 = atoi (value);
576 return TRUE;
577 }
578
579 if (g_ascii_strcasecmp (key, "auth") == 0 && !props->auth_set) {
580 if (!qmicli_read_authentication_from_string (value, &(props->auth))) {
581 g_set_error (error,
582 QMI_CORE_ERROR,
583 QMI_CORE_ERROR_FAILED,
584 "unknown auth protocol '%s'",
585 value);
586 return FALSE;
587 }
588 props->auth_set = TRUE;
589 return TRUE;
590 }
591
592 if (g_ascii_strcasecmp (key, "username") == 0 && !props->username) {
593 props->username = g_strdup (value);
594 return TRUE;
595 }
596
597 if (g_ascii_strcasecmp (key, "password") == 0 && !props->password) {
598 props->password = g_strdup (value);
599 return TRUE;
600 }
601
602 if (g_ascii_strcasecmp (key, "autoconnect") == 0 && !props->autoconnect_set) {
603 if (!qmicli_read_yes_no_from_string (value, &(props->autoconnect))) {
604 g_set_error (error,
605 QMI_CORE_ERROR,
606 QMI_CORE_ERROR_FAILED,
607 "unknown autoconnect setup '%s'",
608 value);
609 return FALSE;
610 }
611 props->autoconnect_set = TRUE;
612 return TRUE;
613 }
614
615 if (g_ascii_strcasecmp (key, "ip-type") == 0 && props->ip_type == QMI_WDS_IP_FAMILY_UNSPECIFIED) {
616 switch (atoi (value)) {
617 case 4:
618 props->ip_type = QMI_WDS_IP_FAMILY_IPV4;
619 break;
620 case 6:
621 props->ip_type = QMI_WDS_IP_FAMILY_IPV6;
622 break;
623 default:
624 g_set_error (error,
625 QMI_CORE_ERROR,
626 QMI_CORE_ERROR_FAILED,
627 "unknown IP type '%s' (not 4 or 6)",
628 value);
629 return FALSE;
630 }
631 return TRUE;
632 }
633
634 g_set_error (error,
635 QMI_CORE_ERROR,
636 QMI_CORE_ERROR_FAILED,
637 "unrecognized or duplicate option '%s'",
638 key);
639 return FALSE;
640 }
641
642 static gboolean
643 start_network_input_create (const gchar *str,
644 QmiMessageWdsStartNetworkInput **input,
645 GError **error)
646 {
647 g_autofree gchar *aux_auth_str = NULL;
648 const gchar *ip_type_str = NULL;
649 gchar **split = NULL;
650 StartNetworkProperties props = {
651 .auth = QMI_WDS_AUTHENTICATION_NONE,
652 .ip_type = QMI_WDS_IP_FAMILY_UNSPECIFIED,
653 };
654 gboolean success = FALSE;
655
656 g_assert (input && !*input);
657
658 /* An empty string is totally valid (i.e. no TLVs) */
659 if (!str[0])
660 return TRUE;
661
662 /* New key=value format */
663 if (strchr (str, '=')) {
664 GError *parse_error = NULL;
665
666 if (!qmicli_parse_key_value_string (str,
667 &parse_error,
668 start_network_properties_handle,
669 &props)) {
670 g_set_error (error,
671 QMI_CORE_ERROR,
672 QMI_CORE_ERROR_FAILED,
673 "couldn't parse input string: %s",
674 parse_error->message);
675 g_error_free (parse_error);
676 goto out;
677 }
678 }
679 /* Old non key=value format, like this:
680 * "[(APN),(PAP|CHAP|BOTH),(Username),(Password)]"
681 */
682 else {
683 /* Parse input string into the expected fields */
684 split = g_strsplit (str, ",", 0);
685
686 props.apn = g_strdup (split[0]);
687
688 if (props.apn && split[1]) {
689 if (!qmicli_read_authentication_from_string (split[1], &(props.auth))) {
690 g_set_error (error,
691 QMI_CORE_ERROR,
692 QMI_CORE_ERROR_FAILED,
693 "unknown auth protocol '%s'",
694 split[1]);
695 goto out;
696 }
697 props.auth_set = TRUE;
698 }
699
700 props.username = (props.auth_set ? g_strdup (split[2]) : NULL);
701 props.password = (props.username ? g_strdup (split[3]) : NULL);
702 }
703
704 /* Create input bundle */
705 *input = qmi_message_wds_start_network_input_new ();
706
707 /* Set APN */
708 if (props.apn)
709 qmi_message_wds_start_network_input_set_apn (*input, props.apn, NULL);
710
711 /* Set 3GPP profile */
712 if (props.profile_index_3gpp > 0)
713 qmi_message_wds_start_network_input_set_profile_index_3gpp (*input, props.profile_index_3gpp, NULL);
714
715 /* Set 3GPP2 profile */
716 if (props.profile_index_3gpp2 > 0)
717 qmi_message_wds_start_network_input_set_profile_index_3gpp2 (*input, props.profile_index_3gpp2, NULL);
718
719 /* Set IP Type */
720 if (props.ip_type != 0) {
721 qmi_message_wds_start_network_input_set_ip_family_preference (*input, props.ip_type, NULL);
722 if (props.ip_type == QMI_WDS_IP_FAMILY_IPV4)
723 ip_type_str = "4";
724 else if (props.ip_type == QMI_WDS_IP_FAMILY_IPV6)
725 ip_type_str = "6";
726 }
727
728 /* Set authentication method */
729 if (props.auth_set) {
730 aux_auth_str = qmi_wds_authentication_build_string_from_mask (props.auth);
731 qmi_message_wds_start_network_input_set_authentication_preference (*input, props.auth, NULL);
732 }
733
734 /* Set username, avoid empty strings */
735 if (props.username && props.username[0])
736 qmi_message_wds_start_network_input_set_username (*input, props.username, NULL);
737
738 /* Set password, avoid empty strings */
739 if (props.password && props.password[0])
740 qmi_message_wds_start_network_input_set_password (*input, props.password, NULL);
741
742 /* Set autoconnect */
743 if (props.autoconnect_set)
744 qmi_message_wds_start_network_input_set_enable_autoconnect (*input, props.autoconnect, NULL);
745
746 success = TRUE;
747
748 g_debug ("Network start parameters set (apn: '%s', 3gpp_profile: '%u', 3gpp2_profile: '%u', auth: '%s', ip-type: '%s', username: '%s', password: '%s', autoconnect: '%s')",
749 props.apn ? props.apn : "unspecified",
750 props.profile_index_3gpp,
751 props.profile_index_3gpp2,
752 aux_auth_str ? aux_auth_str : "unspecified",
753 ip_type_str ? ip_type_str : "unspecified",
754 (props.username && props.username[0]) ? props.username : "unspecified",
755 (props.password && props.password[0]) ? props.password : "unspecified",
756 props.autoconnect_set ? (props.autoconnect ? "yes" : "no") : "unspecified");
757
758 out:
759 g_strfreev (split);
760 g_free (props.apn);
761 g_free (props.username);
762 g_free (props.password);
763
764 return success;
765 }
766
767 static void
768 start_network_ready (QmiClientWds *client,
769 GAsyncResult *res)
770 {
771 GError *error = NULL;
772 QmiMessageWdsStartNetworkOutput *output;
773
774 output = qmi_client_wds_start_network_finish (client, res, &error);
775 if (!output) {
776 g_printerr ("error: operation failed: %s\n",
777 error->message);
778 g_error_free (error);
779 operation_shutdown (FALSE);
780 return;
781 }
782
783 if (!qmi_message_wds_start_network_output_get_result (output, &error)) {
784 g_printerr ("error: couldn't start network: %s\n", error->message);
785 if (g_error_matches (error,
786 QMI_PROTOCOL_ERROR,
787 QMI_PROTOCOL_ERROR_CALL_FAILED)) {
788 QmiWdsCallEndReason cer;
789 QmiWdsVerboseCallEndReasonType verbose_cer_type;
790 gint16 verbose_cer_reason;
791
792 if (qmi_message_wds_start_network_output_get_call_end_reason (
793 output,
794 &cer,
795 NULL))
796 g_printerr ("call end reason (%u): %s\n",
797 cer,
798 qmi_wds_call_end_reason_get_string (cer));
799
800 if (qmi_message_wds_start_network_output_get_verbose_call_end_reason (
801 output,
802 &verbose_cer_type,
803 &verbose_cer_reason,
804 NULL))
805 g_printerr ("verbose call end reason (%u,%d): [%s] %s\n",
806 verbose_cer_type,
807 verbose_cer_reason,
808 qmi_wds_verbose_call_end_reason_type_get_string (verbose_cer_type),
809 qmi_wds_verbose_call_end_reason_get_string (verbose_cer_type, verbose_cer_reason));
810 }
811
812 g_error_free (error);
813 qmi_message_wds_start_network_output_unref (output);
814 operation_shutdown (FALSE);
815 return;
816 }
817
818 qmi_message_wds_start_network_output_get_packet_data_handle (output, &ctx->packet_data_handle, NULL);
819 qmi_message_wds_start_network_output_unref (output);
820
821 #undef VALIDATE_UNKNOWN
822 #define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
823
824 g_print ("[%s] Network started\n"
825 "\tPacket data handle: '%u'\n",
826 qmi_device_get_path_display (ctx->device),
827 (guint)ctx->packet_data_handle);
828
829 #if defined HAVE_QMI_MESSAGE_WDS_STOP_NETWORK && defined HAVE_QMI_MESSAGE_WDS_GET_PACKET_SERVICE_STATUS
830 if (follow_network_flag) {
831 g_print ("\nCtrl+C will stop the network\n");
832 ctx->network_started_id = g_cancellable_connect (ctx->cancellable,
833 G_CALLBACK (network_cancelled),
834 NULL,
835 NULL);
836
837 ctx->packet_status_timeout_id = g_timeout_add_seconds (20,
838 (GSourceFunc)packet_status_timeout,
839 NULL);
840 return;
841 }
842 #endif
843
844 /* Nothing else to do */
845 operation_shutdown (TRUE);
846 }
847
848 #endif /* HAVE_QMI_MESSAGE_WDS_START_NETWORK */
849
850 #if defined HAVE_QMI_MESSAGE_WDS_GET_CURRENT_SETTINGS
851
852 static void
853 get_current_settings_ready (QmiClientWds *client,
854 GAsyncResult *res)
855 {
856 GError *error = NULL;
857 QmiMessageWdsGetCurrentSettingsOutput *output;
858 QmiWdsIpFamily ip_family = QMI_WDS_IP_FAMILY_UNSPECIFIED;
859 guint32 mtu = 0;
860 GArray *array;
861 guint32 addr = 0;
862 struct in_addr in_addr_val;
863 struct in6_addr in6_addr_val;
864 gchar buf4[INET_ADDRSTRLEN];
865 gchar buf6[INET6_ADDRSTRLEN];
866 guint8 prefix = 0;
867 guint i;
868
869 output = qmi_client_wds_get_current_settings_finish (client, res, &error);
870 if (!output) {
871 g_printerr ("error: operation failed: %s\n", error->message);
872 g_error_free (error);
873 operation_shutdown (FALSE);
874 return;
875 }
876
877 if (!qmi_message_wds_get_current_settings_output_get_result (output, &error)) {
878 g_printerr ("error: couldn't get current settings: %s\n", error->message);
879 g_error_free (error);
880 qmi_message_wds_get_current_settings_output_unref (output);
881 operation_shutdown (FALSE);
882 return;
883 }
884
885 g_print ("[%s] Current settings retrieved:\n",
886 qmi_device_get_path_display (ctx->device));
887
888 if (qmi_message_wds_get_current_settings_output_get_ip_family (output, &ip_family, NULL))
889 g_print (" IP Family: %s\n",
890 ((ip_family == QMI_WDS_IP_FAMILY_IPV4) ? "IPv4" :
891 ((ip_family == QMI_WDS_IP_FAMILY_IPV6) ? "IPv6" :
892 "unknown")));
893
894 /* IPv4... */
895
896 if (qmi_message_wds_get_current_settings_output_get_ipv4_address (output, &addr, NULL)) {
897 in_addr_val.s_addr = GUINT32_TO_BE (addr);
898 memset (buf4, 0, sizeof (buf4));
899 inet_ntop (AF_INET, &in_addr_val, buf4, sizeof (buf4));
900 g_print (" IPv4 address: %s\n", buf4);
901 }
902
903 if (qmi_message_wds_get_current_settings_output_get_ipv4_gateway_subnet_mask (output, &addr, NULL)) {
904 in_addr_val.s_addr = GUINT32_TO_BE (addr);
905 memset (buf4, 0, sizeof (buf4));
906 inet_ntop (AF_INET, &in_addr_val, buf4, sizeof (buf4));
907 g_print (" IPv4 subnet mask: %s\n", buf4);
908 }
909
910 if (qmi_message_wds_get_current_settings_output_get_ipv4_gateway_address (output, &addr, NULL)) {
911 in_addr_val.s_addr = GUINT32_TO_BE (addr);
912 memset (buf4, 0, sizeof (buf4));
913 inet_ntop (AF_INET, &in_addr_val, buf4, sizeof (buf4));
914 g_print ("IPv4 gateway address: %s\n", buf4);
915 }
916
917 if (qmi_message_wds_get_current_settings_output_get_primary_ipv4_dns_address (output, &addr, NULL)) {
918 in_addr_val.s_addr = GUINT32_TO_BE (addr);
919 memset (buf4, 0, sizeof (buf4));
920 inet_ntop (AF_INET, &in_addr_val, buf4, sizeof (buf4));
921 g_print (" IPv4 primary DNS: %s\n", buf4);
922 }
923
924 if (qmi_message_wds_get_current_settings_output_get_secondary_ipv4_dns_address (output, &addr, NULL)) {
925 in_addr_val.s_addr = GUINT32_TO_BE (addr);
926 memset (buf4, 0, sizeof (buf4));
927 inet_ntop (AF_INET, &in_addr_val, buf4, sizeof (buf4));
928 g_print (" IPv4 secondary DNS: %s\n", buf4);
929 }
930
931 /* IPv6... */
932
933 if (qmi_message_wds_get_current_settings_output_get_ipv6_address (output, &array, &prefix, NULL)) {
934 for (i = 0; i < array->len; i++)
935 in6_addr_val.s6_addr16[i] = GUINT16_TO_BE (g_array_index (array, guint16, i));
936 memset (buf6, 0, sizeof (buf6));
937 inet_ntop (AF_INET6, &in6_addr_val, buf6, sizeof (buf6));
938 g_print (" IPv6 address: %s/%d\n", buf6, prefix);
939 }
940
941 if (qmi_message_wds_get_current_settings_output_get_ipv6_gateway_address (output, &array, &prefix, NULL)) {
942 for (i = 0; i < array->len; i++)
943 in6_addr_val.s6_addr16[i] = GUINT16_TO_BE (g_array_index (array, guint16, i));
944 memset (buf6, 0, sizeof (buf6));
945 inet_ntop (AF_INET6, &in6_addr_val, buf6, sizeof (buf6));
946 g_print ("IPv6 gateway address: %s/%d\n", buf6, prefix);
947 }
948
949 if (qmi_message_wds_get_current_settings_output_get_ipv6_primary_dns_address (output, &array, NULL)) {
950 for (i = 0; i < array->len; i++)
951 in6_addr_val.s6_addr16[i] = GUINT16_TO_BE (g_array_index (array, guint16, i));
952 memset (buf6, 0, sizeof (buf6));
953 inet_ntop (AF_INET6, &in6_addr_val, buf6, sizeof (buf6));
954 g_print (" IPv6 primary DNS: %s\n", buf6);
955 }
956
957 if (qmi_message_wds_get_current_settings_output_get_ipv6_secondary_dns_address (output, &array, NULL)) {
958 for (i = 0; i < array->len; i++)
959 in6_addr_val.s6_addr16[i] = GUINT16_TO_BE (g_array_index (array, guint16, i));
960 memset (buf6, 0, sizeof (buf6));
961 inet_ntop (AF_INET6, &in6_addr_val, buf6, sizeof (buf6));
962 g_print (" IPv6 secondary DNS: %s\n", buf6);
963 }
964
965 /* Other... */
966
967 if (qmi_message_wds_get_current_settings_output_get_mtu (output, &mtu, NULL))
968 g_print (" MTU: %u\n", mtu);
969
970 if (qmi_message_wds_get_current_settings_output_get_domain_name_list (output, &array, &error)) {
971 GString *s = NULL;
972
973 if (array) {
974 for (i = 0; i < array->len; i++) {
975 if (!s)
976 s = g_string_new ("");
977 else
978 g_string_append (s, ", ");
979 g_string_append (s, g_array_index (array, const gchar *, i));
980 }
981 }
982 if (s) {
983 g_print (" Domains: %s\n", s->str);
984 g_string_free (s, TRUE);
985 } else
986 g_print (" Domains: none\n");
987 }
988
989 qmi_message_wds_get_current_settings_output_unref (output);
990 operation_shutdown (TRUE);
991 }
992
993 #endif /* HAVE_QMI_MESSAGE_WDS_GET_CURRENT_SETTINGS */
994
995 #if defined HAVE_QMI_MESSAGE_WDS_GET_PACKET_SERVICE_STATUS
996
997 static void
998 get_packet_service_status_ready (QmiClientWds *client,
999 GAsyncResult *res)
1000 {
1001 GError *error = NULL;
1002 QmiMessageWdsGetPacketServiceStatusOutput *output;
1003 QmiWdsConnectionStatus status;
1004
1005 output = qmi_client_wds_get_packet_service_status_finish (client, res, &error);
1006 if (!output) {
1007 g_printerr ("error: operation failed: %s\n",
1008 error->message);
1009 g_error_free (error);
1010 operation_shutdown (FALSE);
1011 return;
1012 }
1013
1014 if (!qmi_message_wds_get_packet_service_status_output_get_result (output, &error)) {
1015 g_printerr ("error: couldn't get packet service status: %s\n", error->message);
1016 g_error_free (error);
1017 qmi_message_wds_get_packet_service_status_output_unref (output);
1018 operation_shutdown (FALSE);
1019 return;
1020 }
1021
1022 qmi_message_wds_get_packet_service_status_output_get_connection_status (
1023 output,
1024 &status,
1025 NULL);
1026
1027 g_print ("[%s] Connection status: '%s'\n",
1028 qmi_device_get_path_display (ctx->device),
1029 qmi_wds_connection_status_get_string (status));
1030
1031 qmi_message_wds_get_packet_service_status_output_unref (output);
1032 operation_shutdown (TRUE);
1033 }
1034
1035 #endif /* HAVE_QMI_MESSAGE_WDS_GET_PACKET_SERVICE_STATUS */
1036
1037 #if defined HAVE_QMI_MESSAGE_WDS_GET_PACKET_STATISTICS
1038
1039 static void
1040 get_packet_statistics_ready (QmiClientWds *client,
1041 GAsyncResult *res)
1042 {
1043 GError *error = NULL;
1044 QmiMessageWdsGetPacketStatisticsOutput *output;
1045 guint32 val32;
1046 guint64 val64;
1047
1048 output = qmi_client_wds_get_packet_statistics_finish (client, res, &error);
1049 if (!output) {
1050 g_printerr ("error: operation failed: %s\n",
1051 error->message);
1052 g_error_free (error);
1053 operation_shutdown (FALSE);
1054 return;
1055 }
1056
1057 if (!qmi_message_wds_get_packet_statistics_output_get_result (output, &error)) {
1058 g_printerr ("error: couldn't get packet statistics: %s\n", error->message);
1059 g_error_free (error);
1060 qmi_message_wds_get_packet_statistics_output_unref (output);
1061 operation_shutdown (FALSE);
1062 return;
1063 }
1064
1065 g_print ("[%s] Connection statistics:\n",
1066 qmi_device_get_path_display (ctx->device));
1067
1068 if (qmi_message_wds_get_packet_statistics_output_get_tx_packets_ok (output, &val32, NULL) &&
1069 val32 != 0xFFFFFFFF)
1070 g_print ("\tTX packets OK: %u\n", val32);
1071 if (qmi_message_wds_get_packet_statistics_output_get_rx_packets_ok (output, &val32, NULL) &&
1072 val32 != 0xFFFFFFFF)
1073 g_print ("\tRX packets OK: %u\n", val32);
1074 if (qmi_message_wds_get_packet_statistics_output_get_tx_packets_error (output, &val32, NULL) &&
1075 val32 != 0xFFFFFFFF)
1076 g_print ("\tTX packets error: %u\n", val32);
1077 if (qmi_message_wds_get_packet_statistics_output_get_rx_packets_error (output, &val32, NULL) &&
1078 val32 != 0xFFFFFFFF)
1079 g_print ("\tRX packets error: %u\n", val32);
1080 if (qmi_message_wds_get_packet_statistics_output_get_tx_overflows (output, &val32, NULL) &&
1081 val32 != 0xFFFFFFFF)
1082 g_print ("\tTX overflows: %u\n", val32);
1083 if (qmi_message_wds_get_packet_statistics_output_get_rx_overflows (output, &val32, NULL) &&
1084 val32 != 0xFFFFFFFF)
1085 g_print ("\tRX overflows: %u\n", val32);
1086 if (qmi_message_wds_get_packet_statistics_output_get_tx_packets_dropped (output, &val32, NULL) &&
1087 val32 != 0xFFFFFFFF)
1088 g_print ("\tTX packets dropped: %u\n", val32);
1089 if (qmi_message_wds_get_packet_statistics_output_get_rx_packets_dropped (output, &val32, NULL) &&
1090 val32 != 0xFFFFFFFF)
1091 g_print ("\tRX packets dropped: %u\n", val32);
1092
1093 if (qmi_message_wds_get_packet_statistics_output_get_tx_bytes_ok (output, &val64, NULL))
1094 g_print ("\tTX bytes OK: %" G_GUINT64_FORMAT "\n", val64);
1095 if (qmi_message_wds_get_packet_statistics_output_get_rx_bytes_ok (output, &val64, NULL))
1096 g_print ("\tRX bytes OK: %" G_GUINT64_FORMAT "\n", val64);
1097 if (qmi_message_wds_get_packet_statistics_output_get_last_call_tx_bytes_ok (output, &val64, NULL))
1098 g_print ("\tTX bytes OK (last): %" G_GUINT64_FORMAT "\n", val64);
1099 if (qmi_message_wds_get_packet_statistics_output_get_last_call_rx_bytes_ok (output, &val64, NULL))
1100 g_print ("\tRX bytes OK (last): %" G_GUINT64_FORMAT "\n", val64);
1101
1102 qmi_message_wds_get_packet_statistics_output_unref (output);
1103 operation_shutdown (TRUE);
1104 }
1105
1106 #endif /* HAVE_QMI_MESSAGE_WDS_GET_PACKET_STATISTICS */
1107
1108 #if defined HAVE_QMI_MESSAGE_WDS_GET_DATA_BEARER_TECHNOLOGY
1109
1110 static void
1111 get_data_bearer_technology_ready (QmiClientWds *client,
1112 GAsyncResult *res)
1113 {
1114 GError *error = NULL;
1115 QmiMessageWdsGetDataBearerTechnologyOutput *output;
1116 QmiWdsDataBearerTechnology current;
1117
1118 output = qmi_client_wds_get_data_bearer_technology_finish (client, res, &error);
1119 if (!output) {
1120 g_printerr ("error: operation failed: %s\n",
1121 error->message);
1122 g_error_free (error);
1123 operation_shutdown (FALSE);
1124 return;
1125 }
1126
1127 if (!qmi_message_wds_get_data_bearer_technology_output_get_result (output, &error)) {
1128 g_printerr ("error: couldn't get data bearer technology: %s\n", error->message);
1129
1130 if (g_error_matches (error,
1131 QMI_PROTOCOL_ERROR,
1132 QMI_PROTOCOL_ERROR_OUT_OF_CALL)) {
1133 QmiWdsDataBearerTechnology last = QMI_WDS_DATA_BEARER_TECHNOLOGY_UNKNOWN;
1134
1135 if (qmi_message_wds_get_data_bearer_technology_output_get_last (
1136 output,
1137 &last,
1138 NULL))
1139 g_print ("[%s] Data bearer technology (last): '%s'(%d)\n",
1140 qmi_device_get_path_display (ctx->device),
1141 qmi_wds_data_bearer_technology_get_string (last), last);
1142 }
1143
1144 g_error_free (error);
1145 qmi_message_wds_get_data_bearer_technology_output_unref (output);
1146 operation_shutdown (FALSE);
1147 return;
1148 }
1149
1150 qmi_message_wds_get_data_bearer_technology_output_get_current (
1151 output,
1152 &current,
1153 NULL);
1154 g_print ("[%s] Data bearer technology (current): '%s'\n",
1155 qmi_device_get_path_display (ctx->device),
1156 qmi_wds_data_bearer_technology_get_string (current));
1157 qmi_message_wds_get_data_bearer_technology_output_unref (output);
1158 operation_shutdown (TRUE);
1159 }
1160
1161 #endif /* HAVE_QMI_MESSAGE_WDS_GET_DATA_BEARER_TECHNOLOGY */
1162
1163 #if defined HAVE_QMI_MESSAGE_WDS_GET_CURRENT_DATA_BEARER_TECHNOLOGY
1164
1165 static void
1166 print_current_data_bearer_technology_results (const gchar *which,
1167 QmiWdsNetworkType network_type,
1168 guint32 rat_mask,
1169 guint32 so_mask)
1170 {
1171 g_autofree gchar *rat_string = NULL;
1172 g_autofree gchar *so_string = NULL;
1173
1174 if (network_type == QMI_WDS_NETWORK_TYPE_3GPP2) {
1175 rat_string = qmi_wds_rat_3gpp2_build_string_from_mask (rat_mask);
1176 if (rat_mask & QMI_WDS_RAT_3GPP2_CDMA1X)
1177 so_string = qmi_wds_so_cdma1x_build_string_from_mask (so_mask);
1178 else if (rat_mask & QMI_WDS_RAT_3GPP2_EVDO_REVA)
1179 so_string = qmi_wds_so_evdo_reva_build_string_from_mask (so_mask);
1180 } else if (network_type == QMI_WDS_NETWORK_TYPE_3GPP) {
1181 rat_string = qmi_wds_rat_3gpp_build_string_from_mask (rat_mask);
1182 }
1183
1184 g_print ("[%s] Data bearer technology (%s):\n"
1185 " Network type: '%s'\n"
1186 " Radio Access Technology: '%s'\n",
1187 qmi_device_get_path_display (ctx->device),
1188 which,
1189 qmi_wds_network_type_get_string (network_type),
1190 VALIDATE_MASK_NONE (rat_string));
1191
1192 if (network_type == QMI_WDS_NETWORK_TYPE_3GPP2)
1193 g_print (" Service Option: '%s'\n",
1194 VALIDATE_MASK_NONE (so_string));
1195 }
1196
1197 static void
1198 get_current_data_bearer_technology_ready (QmiClientWds *client,
1199 GAsyncResult *res)
1200 {
1201 GError *error = NULL;
1202 QmiMessageWdsGetCurrentDataBearerTechnologyOutput *output;
1203 QmiWdsNetworkType network_type;
1204 guint32 rat_mask;
1205 guint32 so_mask;
1206
1207 output = qmi_client_wds_get_current_data_bearer_technology_finish (client, res, &error);
1208 if (!output) {
1209 g_printerr ("error: operation failed: %s\n",
1210 error->message);
1211 g_error_free (error);
1212 operation_shutdown (FALSE);
1213 return;
1214 }
1215
1216 #undef VALIDATE_UNKNOWN
1217 #define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
1218
1219 if (!qmi_message_wds_get_current_data_bearer_technology_output_get_result (output, &error)) {
1220 g_printerr ("error: couldn't get current data bearer technology: %s\n", error->message);
1221
1222 if (qmi_message_wds_get_current_data_bearer_technology_output_get_last (
1223 output,
1224 &network_type,
1225 &rat_mask,
1226 &so_mask,
1227 NULL)) {
1228 print_current_data_bearer_technology_results (
1229 "last",
1230 network_type,
1231 rat_mask,
1232 so_mask);
1233 }
1234
1235 g_error_free (error);
1236 qmi_message_wds_get_current_data_bearer_technology_output_unref (output);
1237 operation_shutdown (FALSE);
1238 return;
1239 }
1240
1241 /* Retrieve CURRENT */
1242 if (qmi_message_wds_get_current_data_bearer_technology_output_get_current (
1243 output,
1244 &network_type,
1245 &rat_mask,
1246 &so_mask,
1247 NULL)) {
1248 print_current_data_bearer_technology_results (
1249 "current",
1250 network_type,
1251 rat_mask,
1252 so_mask);
1253 }
1254
1255 qmi_message_wds_get_current_data_bearer_technology_output_unref (output);
1256 operation_shutdown (TRUE);
1257 }
1258
1259 #endif /* HAVE_QMI_MESSAGE_WDS_GET_CURRENT_DATA_BEARER_TECHNOLOGY */
1260
1261 #if defined HAVE_QMI_MESSAGE_WDS_GO_DORMANT
1262
1263 static void
1264 go_dormant_ready (QmiClientWds *client,
1265 GAsyncResult *res)
1266 {
1267 GError *error = NULL;
1268 QmiMessageWdsGoDormantOutput *output;
1269
1270 output = qmi_client_wds_go_dormant_finish (client, res, &error);
1271 if (!output) {
1272 g_printerr ("error: operation failed: %s\n",
1273 error->message);
1274 g_error_free (error);
1275 operation_shutdown (FALSE);
1276 return;
1277 }
1278
1279 if (!qmi_message_wds_go_dormant_output_get_result (output, &error)) {
1280 g_printerr ("error: couldn't go dormant: %s\n", error->message);
1281 g_error_free (error);
1282 qmi_message_wds_go_dormant_output_unref (output);
1283 operation_shutdown (FALSE);
1284 return;
1285 }
1286
1287 qmi_message_wds_go_dormant_output_unref (output);
1288 operation_shutdown (TRUE);
1289 }
1290
1291 #endif /* HAVE_QMI_MESSAGE_WDS_GO_DORMANT */
1292
1293 #if defined HAVE_QMI_MESSAGE_WDS_GO_ACTIVE
1294
1295 static void
1296 go_active_ready (QmiClientWds *client,
1297 GAsyncResult *res)
1298 {
1299 GError *error = NULL;
1300 QmiMessageWdsGoActiveOutput *output;
1301
1302 output = qmi_client_wds_go_active_finish (client, res, &error);
1303 if (!output) {
1304 g_printerr ("error: operation failed: %s\n",
1305 error->message);
1306 g_error_free (error);
1307 operation_shutdown (FALSE);
1308 return;
1309 }
1310
1311 if (!qmi_message_wds_go_active_output_get_result (output, &error)) {
1312 g_printerr ("error: couldn't go active: %s\n", error->message);
1313 g_error_free (error);
1314 qmi_message_wds_go_active_output_unref (output);
1315 operation_shutdown (FALSE);
1316 return;
1317 }
1318
1319 qmi_message_wds_go_active_output_unref (output);
1320 operation_shutdown (TRUE);
1321 }
1322
1323 #endif /* HAVE_QMI_MESSAGE_WDS_GO_ACTIVE */
1324
1325 #if defined HAVE_QMI_MESSAGE_WDS_GET_DORMANCY_STATUS
1326
1327 static void
1328 get_dormancy_status_ready (QmiClientWds *client,
1329 GAsyncResult *res)
1330 {
1331 GError *error = NULL;
1332 QmiMessageWdsGetDormancyStatusOutput *output;
1333 QmiWdsDormancyStatus status;
1334
1335 output = qmi_client_wds_get_dormancy_status_finish (client, res, &error);
1336 if (!output) {
1337 g_printerr ("error: operation failed: %s\n",
1338 error->message);
1339 g_error_free (error);
1340 operation_shutdown (FALSE);
1341 return;
1342 }
1343
1344 if (!qmi_message_wds_get_dormancy_status_output_get_result (output, &error)) {
1345 g_printerr ("error: couldn't get dormancy status: %s\n", error->message);
1346 g_error_free (error);
1347 qmi_message_wds_get_dormancy_status_output_unref (output);
1348 operation_shutdown (FALSE);
1349 return;
1350 }
1351
1352 if (qmi_message_wds_get_dormancy_status_output_get_dormancy_status (
1353 output,
1354 &status,
1355 NULL)) {
1356 g_print ("[%s] Dormancy Status: '%s'\n",
1357 qmi_device_get_path_display (ctx->device),
1358 qmi_wds_dormancy_status_get_string (status));
1359 }
1360
1361 qmi_message_wds_get_dormancy_status_output_unref (output);
1362 operation_shutdown (TRUE);
1363 }
1364
1365 #endif /* HAVE_QMI_MESSAGE_WDS_GET_DORMANCY_STATUS */
1366
1367 #if defined HAVE_QMI_MESSAGE_WDS_CREATE_PROFILE || \
1368 defined HAVE_QMI_MESSAGE_WDS_SWI_CREATE_PROFILE_INDEXED || \
1369 defined HAVE_QMI_MESSAGE_WDS_MODIFY_PROFILE
1370
1371 typedef struct {
1372 QmiWdsProfileType profile_type;
1373 guint profile_index;
1374 guint context_number;
1375 gchar *name;
1376 QmiWdsPdpType pdp_type;
1377 gboolean pdp_type_set;
1378 QmiWdsApnTypeMask apn_type;
1379 gboolean apn_type_set;
1380 gchar *apn;
1381 gchar *username;
1382 gchar *password;
1383 QmiWdsAuthentication auth;
1384 gboolean auth_set;
1385 gboolean no_roaming;
1386 gboolean no_roaming_set;
1387 gboolean disabled;
1388 gboolean disabled_set;
1389 } CreateModifyProfileProperties;
1390
1391 static gboolean
1392 create_modify_profile_properties_handle (const gchar *key,
1393 const gchar *value,
1394 GError **error,
1395 gpointer user_data)
1396 {
1397 CreateModifyProfileProperties *props = user_data;
1398
1399 /* Allow empty values for string parameters */
1400
1401 if (g_ascii_strcasecmp (key, "name") == 0 && !props->name) {
1402 props->name = g_strdup (value);
1403 return TRUE;
1404 }
1405
1406 if (g_ascii_strcasecmp (key, "apn") == 0 && !props->apn) {
1407 props->apn = g_strdup (value);
1408 return TRUE;
1409 }
1410
1411 if (g_ascii_strcasecmp (key, "username") == 0 && !props->username) {
1412 props->username = g_strdup (value);
1413 return TRUE;
1414 }
1415
1416 if (g_ascii_strcasecmp (key, "password") == 0 && !props->password) {
1417 props->password = g_strdup (value);
1418 return TRUE;
1419 }
1420
1421 /* all other TLVs do require a value... */
1422 if (!value || !value[0]) {
1423 g_set_error (error,
1424 QMI_CORE_ERROR,
1425 QMI_CORE_ERROR_FAILED,
1426 "key '%s' required a value",
1427 key);
1428 return FALSE;
1429 }
1430
1431 if (g_ascii_strcasecmp (key, "context-num") == 0 && !props->context_number) {
1432 props->context_number = atoi (value);
1433 if (props->context_number <= 0 || props->context_number > G_MAXUINT8) {
1434 g_set_error (error,
1435 QMI_CORE_ERROR,
1436 QMI_CORE_ERROR_FAILED,
1437 "invalid or out of range context number [1,%u]: '%s'",
1438 G_MAXUINT8,
1439 value);
1440 return FALSE;
1441 }
1442 return TRUE;
1443 }
1444
1445 if (g_ascii_strcasecmp (key, "auth") == 0 && !props->auth_set) {
1446 if (!qmicli_read_authentication_from_string (value, &(props->auth))) {
1447 g_set_error (error,
1448 QMI_CORE_ERROR,
1449 QMI_CORE_ERROR_FAILED,
1450 "unknown auth protocol '%s'",
1451 value);
1452 return FALSE;
1453 }
1454 props->auth_set = TRUE;
1455 return TRUE;
1456 }
1457
1458 if (g_ascii_strcasecmp (key, "pdp-type") == 0 && !props->pdp_type_set) {
1459 if (!qmicli_read_pdp_type_from_string (value, &(props->pdp_type))) {
1460 g_set_error (error,
1461 QMI_CORE_ERROR,
1462 QMI_CORE_ERROR_FAILED,
1463 "unknown pdp type '%s'",
1464 value);
1465 return FALSE;
1466 }
1467 props->pdp_type_set = TRUE;
1468 return TRUE;
1469 }
1470
1471 if (g_ascii_strcasecmp (key, "apn-type-mask") == 0 && !props->apn_type_set) {
1472 if (!qmicli_read_wds_apn_type_mask_from_string (value, &(props->apn_type))) {
1473 g_set_error (error,
1474 QMI_CORE_ERROR,
1475 QMI_CORE_ERROR_FAILED,
1476 "unknown apn type '%s'",
1477 value);
1478 return FALSE;
1479 }
1480 props->apn_type_set = TRUE;
1481 return TRUE;
1482 }
1483
1484 if (g_ascii_strcasecmp (key, "no-roaming") == 0 && !props->no_roaming_set) {
1485 if (!qmicli_read_yes_no_from_string (value, &(props->no_roaming))) {
1486 g_set_error (error,
1487 QMI_CORE_ERROR,
1488 QMI_CORE_ERROR_FAILED,
1489 "unknown 'no-roaming' value '%s'",
1490 value);
1491 return FALSE;
1492 }
1493 props->no_roaming_set = TRUE;
1494 return TRUE;
1495 }
1496
1497 if (g_ascii_strcasecmp (key, "disabled") == 0 && !props->disabled_set) {
1498 if (!qmicli_read_yes_no_from_string (value, &(props->disabled))) {
1499 g_set_error (error,
1500 QMI_CORE_ERROR,
1501 QMI_CORE_ERROR_FAILED,
1502 "unknown 'disabled' value '%s'",
1503 value);
1504 return FALSE;
1505 }
1506 props->disabled_set = TRUE;
1507 return TRUE;
1508 }
1509
1510 g_set_error (error,
1511 QMI_CORE_ERROR,
1512 QMI_CORE_ERROR_FAILED,
1513 "unrecognized or duplicate option '%s'",
1514 key);
1515 return FALSE;
1516 }
1517
1518 #endif /* HAVE_QMI_MESSAGE_WDS_CREATE_PROFILE
1519 * HAVE_QMI_MESSAGE_WDS_SWI_CREATE_PROFILE_INDEXED
1520 * HAVE_QMI_MESSAGE_WDS_MODIFY_PROFILE */
1521
1522 #if defined HAVE_QMI_MESSAGE_WDS_CREATE_PROFILE
1523
1524 static gboolean
1525 create_profile_input_create (const gchar *str,
1526 QmiMessageWdsCreateProfileInput **input,
1527 GError **error)
1528 {
1529 GError *parse_error = NULL;
1530 CreateModifyProfileProperties props = {};
1531 gboolean success = FALSE;
1532 gchar **split;
1533
1534 g_assert (input && !*input);
1535
1536 split = g_strsplit (str, ",", 2);
1537 if (g_strv_length (split) < 1) {
1538 g_set_error (error,
1539 QMI_CORE_ERROR,
1540 QMI_CORE_ERROR_FAILED,
1541 "expected at least 1 arguments for 'wds create profile' command");
1542 goto out;
1543 }
1544
1545 g_strstrip (split[0]);
1546 if (g_str_equal (split[0], "3gpp"))
1547 props.profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
1548 else if (g_str_equal (split[0], "3gpp2"))
1549 props.profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
1550 else {
1551 g_set_error (error,
1552 QMI_CORE_ERROR,
1553 QMI_CORE_ERROR_FAILED,
1554 "invalid profile type. Expected '3gpp' or '3gpp2'.'");
1555 goto out;
1556 }
1557
1558 if (split[1]) {
1559 if (!qmicli_parse_key_value_string (split[1],
1560 &parse_error,
1561 create_modify_profile_properties_handle,
1562 &props)) {
1563 g_set_error (error,
1564 QMI_CORE_ERROR,
1565 QMI_CORE_ERROR_FAILED,
1566 "couldn't parse input string: %s",
1567 parse_error->message);
1568 g_error_free (parse_error);
1569 goto out;
1570 }
1571 }
1572
1573 /* Create input bundle */
1574 *input = qmi_message_wds_create_profile_input_new ();
1575
1576 /* Profile type is required */
1577 qmi_message_wds_create_profile_input_set_profile_type (*input, props.profile_type, NULL);
1578
1579 if (props.context_number)
1580 qmi_message_wds_create_profile_input_set_pdp_context_number (*input, props.context_number, NULL);
1581
1582 if (props.pdp_type_set)
1583 qmi_message_wds_create_profile_input_set_pdp_type (*input, props.pdp_type, NULL);
1584
1585 if (props.apn_type_set)
1586 qmi_message_wds_create_profile_input_set_apn_type_mask (*input, props.apn_type, NULL);
1587
1588 if (props.name)
1589 qmi_message_wds_create_profile_input_set_profile_name (*input, props.name, NULL);
1590
1591 if (props.apn)
1592 qmi_message_wds_create_profile_input_set_apn_name (*input, props.apn, NULL);
1593
1594 if (props.auth_set)
1595 qmi_message_wds_create_profile_input_set_authentication (*input, props.auth, NULL);
1596
1597 if (props.username)
1598 qmi_message_wds_create_profile_input_set_username (*input, props.username, NULL);
1599
1600 if (props.password)
1601 qmi_message_wds_create_profile_input_set_password (*input, props.password, NULL);
1602
1603 if (props.no_roaming_set)
1604 qmi_message_wds_create_profile_input_set_roaming_disallowed_flag (*input, props.no_roaming, NULL);
1605
1606 if (props.disabled_set)
1607 qmi_message_wds_create_profile_input_set_apn_disabled_flag (*input, props.disabled, NULL);
1608
1609 success = TRUE;
1610
1611 out:
1612 g_strfreev (split);
1613 g_free (props.name);
1614 g_free (props.apn);
1615 g_free (props.username);
1616 g_free (props.password);
1617
1618 return success;
1619 }
1620
1621 static void
1622 create_profile_ready (QmiClientWds *client,
1623 GAsyncResult *res)
1624 {
1625 QmiMessageWdsCreateProfileOutput *output;
1626 GError *error = NULL;
1627 QmiWdsProfileType profile_type;
1628 guint8 profile_index;
1629
1630 output = qmi_client_wds_create_profile_finish (client, res, &error);
1631 if (!output) {
1632 g_printerr ("error: operation failed: %s\n", error->message);
1633 g_error_free (error);
1634 operation_shutdown (FALSE);
1635 return;
1636 }
1637
1638 if (!qmi_message_wds_create_profile_output_get_result (output, &error)) {
1639 QmiWdsDsProfileError ds_profile_error;
1640
1641 if (g_error_matches (error,
1642 QMI_PROTOCOL_ERROR,
1643 QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) &&
1644 qmi_message_wds_create_profile_output_get_extended_error_code (
1645 output,
1646 &ds_profile_error,
1647 NULL)) {
1648 g_printerr ("error: couldn't create profile: ds profile error: %s\n",
1649 qmi_wds_ds_profile_error_get_string (ds_profile_error));
1650 } else {
1651 g_printerr ("error: couldn't create profile: %s\n",
1652 error->message);
1653 }
1654 g_error_free (error);
1655 qmi_message_wds_create_profile_output_unref (output);
1656 operation_shutdown (FALSE);
1657 return;
1658 }
1659
1660 g_print ("New profile created:\n");
1661 if (qmi_message_wds_create_profile_output_get_profile_identifier (output,
1662 &profile_type,
1663 &profile_index,
1664 NULL)) {
1665 g_print ("\tProfile type: '%s'\n", qmi_wds_profile_type_get_string(profile_type));
1666 g_print ("\tProfile index: '%d'\n", profile_index);
1667 }
1668 qmi_message_wds_create_profile_output_unref (output);
1669 operation_shutdown (TRUE);
1670 }
1671
1672 #endif /* HAVE_QMI_MESSAGE_WDS_CREATE_PROFILE */
1673
1674 #if defined HAVE_QMI_MESSAGE_WDS_SWI_CREATE_PROFILE_INDEXED
1675
1676 static gboolean
1677 swi_create_profile_indexed_input_create (const gchar *str,
1678 QmiMessageWdsSwiCreateProfileIndexedInput **input,
1679 GError **error)
1680 {
1681 GError *parse_error = NULL;
1682 CreateModifyProfileProperties props = {};
1683 gchar **split;
1684 gboolean success = FALSE;
1685
1686 g_assert (input && !*input);
1687
1688 /* Expect max 3 tokens: the first two give us the mandatory parameters of the command,
1689 * the 3rd one will contain the key/value pair list */
1690 split = g_strsplit (str, ",", 3);
1691 if (g_strv_length (split) < 2) {
1692 g_set_error (error,
1693 QMI_CORE_ERROR,
1694 QMI_CORE_ERROR_FAILED,
1695 "expected at least 2 arguments for 'wds swi create profile indexed' command");
1696 goto out;
1697 }
1698
1699 g_strstrip (split[0]);
1700 if (g_str_equal (split[0], "3gpp"))
1701 props.profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
1702 else if (g_str_equal (split[0], "3gpp2"))
1703 props.profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
1704 else {
1705 g_set_error (error,
1706 QMI_CORE_ERROR,
1707 QMI_CORE_ERROR_FAILED,
1708 "invalid profile type '%s'. Expected '3gpp' or '3gpp2'.'",
1709 split[0]);
1710 goto out;
1711 }
1712
1713 g_strstrip (split[1]);
1714 props.profile_index = atoi (split[1]);
1715 if (props.profile_index <= 0 || props.profile_index > G_MAXUINT8) {
1716 g_set_error (error,
1717 QMI_CORE_ERROR,
1718 QMI_CORE_ERROR_FAILED,
1719 "invalid or out of range profile index [1,%u]: '%s'\n",
1720 G_MAXUINT8,
1721 split[1]);
1722 goto out;
1723 }
1724
1725 if (split[2]) {
1726 if (!qmicli_parse_key_value_string (split[2],
1727 &parse_error,
1728 create_modify_profile_properties_handle,
1729 &props)) {
1730 g_set_error (error,
1731 QMI_CORE_ERROR,
1732 QMI_CORE_ERROR_FAILED,
1733 "couldn't parse input string: %s",
1734 parse_error->message);
1735 g_error_free (parse_error);
1736 goto out;
1737 }
1738 }
1739
1740 /* Create input bundle */
1741 *input = qmi_message_wds_swi_create_profile_indexed_input_new ();
1742
1743 /* Profile identifier is required */
1744 qmi_message_wds_swi_create_profile_indexed_input_set_profile_identifier (*input, props.profile_type, props.profile_index, NULL);
1745
1746 if (props.context_number)
1747 qmi_message_wds_swi_create_profile_indexed_input_set_pdp_context_number (*input, props.context_number, NULL);
1748
1749 if (props.pdp_type_set)
1750 qmi_message_wds_swi_create_profile_indexed_input_set_pdp_type (*input, props.pdp_type, NULL);
1751
1752 if (props.name)
1753 qmi_message_wds_swi_create_profile_indexed_input_set_profile_name (*input, props.name, NULL);
1754
1755 if (props.apn)
1756 qmi_message_wds_swi_create_profile_indexed_input_set_apn_name (*input, props.apn, NULL);
1757
1758 if (props.auth_set)
1759 qmi_message_wds_swi_create_profile_indexed_input_set_authentication (*input, props.auth, NULL);
1760
1761 if (props.username)
1762 qmi_message_wds_swi_create_profile_indexed_input_set_username (*input, props.username, NULL);
1763
1764 if (props.password)
1765 qmi_message_wds_swi_create_profile_indexed_input_set_password (*input, props.password, NULL);
1766
1767 if (props.no_roaming_set)
1768 qmi_message_wds_swi_create_profile_indexed_input_set_roaming_disallowed_flag (*input, props.no_roaming, NULL);
1769
1770 if (props.disabled_set)
1771 qmi_message_wds_swi_create_profile_indexed_input_set_apn_disabled_flag (*input, props.disabled, NULL);
1772
1773 success = TRUE;
1774
1775 out:
1776 g_strfreev (split);
1777 g_free (props.name);
1778 g_free (props.apn);
1779 g_free (props.username);
1780 g_free (props.password);
1781
1782 return success;
1783 }
1784
1785 static void
1786 swi_create_profile_indexed_ready (QmiClientWds *client,
1787 GAsyncResult *res)
1788 {
1789 QmiMessageWdsSwiCreateProfileIndexedOutput *output;
1790 GError *error = NULL;
1791 QmiWdsProfileType profile_type;
1792 guint8 profile_index;
1793
1794 output = qmi_client_wds_swi_create_profile_indexed_finish (client, res, &error);
1795 if (!output) {
1796 g_printerr ("error: operation failed: %s\n", error->message);
1797 g_error_free (error);
1798 operation_shutdown (FALSE);
1799 return;
1800 }
1801
1802 if (!qmi_message_wds_swi_create_profile_indexed_output_get_result (output, &error)) {
1803 g_printerr ("error: couldn't create indexed profile: %s\n", error->message);
1804 g_error_free (error);
1805 qmi_message_wds_swi_create_profile_indexed_output_unref (output);
1806 operation_shutdown (FALSE);
1807 return;
1808 }
1809
1810 g_print ("New profile created:\n");
1811 if (qmi_message_wds_swi_create_profile_indexed_output_get_profile_identifier (output,
1812 &profile_type,
1813 &profile_index,
1814 NULL)) {
1815 g_print ("\tProfile type: '%s'\n", qmi_wds_profile_type_get_string(profile_type));
1816 g_print ("\tProfile index: '%d'\n", profile_index);
1817 }
1818 qmi_message_wds_swi_create_profile_indexed_output_unref (output);
1819 operation_shutdown (TRUE);
1820 }
1821
1822 #endif /* HAVE_QMI_MESSAGE_WDS_SWI_CREATE_PROFILE_INDEXED */
1823
1824 #if defined HAVE_QMI_MESSAGE_WDS_MODIFY_PROFILE
1825
1826 static gboolean
1827 modify_profile_input_create (const gchar *str,
1828 QmiMessageWdsModifyProfileInput **input,
1829 GError **error)
1830 {
1831 GError *parse_error = NULL;
1832 CreateModifyProfileProperties props = {};
1833 gchar **split;
1834 gboolean success = FALSE;
1835
1836 g_assert (input && !*input);
1837
1838 /* Expect max 3 tokens: the first two give us the mandatory parameters of the command,
1839 * the 3rd one will contain the key/value pair list */
1840 split = g_strsplit (str, ",", 3);
1841 if (g_strv_length (split) < 3) {
1842 g_set_error (error,
1843 QMI_CORE_ERROR,
1844 QMI_CORE_ERROR_FAILED,
1845 "expected at least 3 arguments for 'wds modify profile' command");
1846 goto out;
1847 }
1848
1849 g_strstrip (split[0]);
1850 if (g_str_equal (split[0], "3gpp"))
1851 props.profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
1852 else if (g_str_equal (split[0], "3gpp2"))
1853 props.profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
1854 else {
1855 g_set_error (error,
1856 QMI_CORE_ERROR,
1857 QMI_CORE_ERROR_FAILED,
1858 "invalid profile type '%s'. Expected '3gpp' or '3gpp2'.'",
1859 split[0]);
1860 goto out;
1861 }
1862
1863 g_strstrip (split[1]);
1864 props.profile_index = atoi (split[1]);
1865 if (props.profile_index <= 0 || props.profile_index > G_MAXUINT8) {
1866 g_set_error (error,
1867 QMI_CORE_ERROR,
1868 QMI_CORE_ERROR_FAILED,
1869 "invalid or out of range profile index [1,%u]: '%s'\n",
1870 G_MAXUINT8,
1871 split[1]);
1872 goto out;
1873 }
1874
1875 /* advance to third token, that's where key/value pairs start */
1876 if (!qmicli_parse_key_value_string (split[2],
1877 &parse_error,
1878 create_modify_profile_properties_handle,
1879 &props)) {
1880 g_set_error (error,
1881 QMI_CORE_ERROR,
1882 QMI_CORE_ERROR_FAILED,
1883 "couldn't parse input string: %s",
1884 parse_error->message);
1885 g_error_free (parse_error);
1886 goto out;
1887 }
1888
1889 /* Create input bundle */
1890 *input = qmi_message_wds_modify_profile_input_new ();
1891
1892 /* Profile identifier is required */
1893 qmi_message_wds_modify_profile_input_set_profile_identifier (*input, props.profile_type, props.profile_index, NULL);
1894
1895 if (props.context_number)
1896 qmi_message_wds_modify_profile_input_set_pdp_context_number (*input, props.context_number, NULL);
1897
1898 if (props.pdp_type_set)
1899 qmi_message_wds_modify_profile_input_set_pdp_type (*input, props.pdp_type, NULL);
1900
1901 if (props.apn_type_set)
1902 qmi_message_wds_modify_profile_input_set_apn_type_mask (*input, props.apn_type, NULL);
1903
1904 if (props.name)
1905 qmi_message_wds_modify_profile_input_set_profile_name (*input, props.name, NULL);
1906
1907 if (props.apn)
1908 qmi_message_wds_modify_profile_input_set_apn_name (*input, props.apn, NULL);
1909
1910 if (props.auth_set)
1911 qmi_message_wds_modify_profile_input_set_authentication (*input, props.auth, NULL);
1912
1913 if (props.username)
1914 qmi_message_wds_modify_profile_input_set_username (*input, props.username, NULL);
1915
1916 if (props.password)
1917 qmi_message_wds_modify_profile_input_set_password (*input, props.password, NULL);
1918
1919 if (props.no_roaming_set)
1920 qmi_message_wds_modify_profile_input_set_roaming_disallowed_flag (*input, props.no_roaming, NULL);
1921
1922 if (props.disabled_set)
1923 qmi_message_wds_modify_profile_input_set_apn_disabled_flag (*input, props.disabled, NULL);
1924
1925 success = TRUE;
1926
1927 out:
1928 g_strfreev (split);
1929 g_free (props.name);
1930 g_free (props.apn);
1931 g_free (props.username);
1932 g_free (props.password);
1933
1934 return success;
1935 }
1936
1937 static void
1938 modify_profile_ready (QmiClientWds *client,
1939 GAsyncResult *res)
1940 {
1941 QmiMessageWdsModifyProfileOutput *output;
1942 GError *error = NULL;
1943
1944 output = qmi_client_wds_modify_profile_finish (client, res, &error);
1945 if (!output) {
1946 g_printerr ("error: operation failed: %s\n", error->message);
1947 g_error_free (error);
1948 operation_shutdown (FALSE);
1949 return;
1950 }
1951
1952 if (!qmi_message_wds_modify_profile_output_get_result (output, &error)) {
1953 QmiWdsDsProfileError ds_profile_error;
1954
1955 if (g_error_matches (error,
1956 QMI_PROTOCOL_ERROR,
1957 QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) &&
1958 qmi_message_wds_modify_profile_output_get_extended_error_code (
1959 output,
1960 &ds_profile_error,
1961 NULL)) {
1962 g_printerr ("error: couldn't modify profile: ds profile error: %s\n",
1963 qmi_wds_ds_profile_error_get_string (ds_profile_error));
1964 } else {
1965 g_printerr ("error: couldn't modify profile: %s\n",
1966 error->message);
1967 }
1968 g_error_free (error);
1969 qmi_message_wds_modify_profile_output_unref (output);
1970 operation_shutdown (FALSE);
1971 return;
1972 }
1973 qmi_message_wds_modify_profile_output_unref (output);
1974 g_print ("Profile successfully modified.\n");
1975 operation_shutdown (TRUE);
1976 }
1977
1978 #endif /* HAVE_QMI_MESSAGE_WDS_MODIFY_PROFILE */
1979
1980 #if defined HAVE_QMI_MESSAGE_WDS_DELETE_PROFILE
1981
1982 static void
1983 delete_profile_ready (QmiClientWds *client,
1984 GAsyncResult *res)
1985 {
1986 QmiMessageWdsDeleteProfileOutput *output;
1987 GError *error = NULL;
1988
1989 output = qmi_client_wds_delete_profile_finish (client, res, &error);
1990 if (!output) {
1991 g_printerr ("error: operation failed: %s\n", error->message);
1992 g_error_free (error);
1993 operation_shutdown (FALSE);
1994 return;
1995 }
1996
1997 if (!qmi_message_wds_delete_profile_output_get_result (output, &error)) {
1998 QmiWdsDsProfileError ds_profile_error;
1999
2000 if (g_error_matches (error,
2001 QMI_PROTOCOL_ERROR,
2002 QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) &&
2003 qmi_message_wds_delete_profile_output_get_extended_error_code (
2004 output,
2005 &ds_profile_error,
2006 NULL)) {
2007 g_printerr ("error: couldn't delete profile: ds profile error: %s\n",
2008 qmi_wds_ds_profile_error_get_string (ds_profile_error));
2009 } else {
2010 g_printerr ("error: couldn't delete profile: %s\n",
2011 error->message);
2012 }
2013 g_error_free (error);
2014 qmi_message_wds_delete_profile_output_unref (output);
2015 operation_shutdown (FALSE);
2016 return;
2017 }
2018 qmi_message_wds_delete_profile_output_unref (output);
2019 g_print ("Profile successfully deleted.\n");
2020 operation_shutdown (TRUE);
2021 }
2022
2023 #endif /* HAVE_QMI_MESSAGE_WDS_DELETE_PROFILE */
2024
2025 #if defined HAVE_QMI_MESSAGE_WDS_GET_PROFILE_LIST && defined HAVE_QMI_MESSAGE_WDS_GET_PROFILE_SETTINGS
2026
2027 typedef struct {
2028 guint i;
2029 GArray *profile_list;
2030 } GetProfileListContext;
2031
2032 static void get_next_profile_settings (GetProfileListContext *inner_ctx);
2033
2034 static void
2035 get_profile_settings_ready (QmiClientWds *client,
2036 GAsyncResult *res,
2037 GetProfileListContext *inner_ctx)
2038 {
2039 QmiMessageWdsGetProfileSettingsOutput *output;
2040 GError *error = NULL;
2041
2042 output = qmi_client_wds_get_profile_settings_finish (client, res, &error);
2043 if (!output) {
2044 g_printerr ("error: operation failed: %s\n", error->message);
2045 g_error_free (error);
2046 } else if (!qmi_message_wds_get_profile_settings_output_get_result (output, &error)) {
2047 QmiWdsDsProfileError ds_profile_error;
2048
2049 if (g_error_matches (error,
2050 QMI_PROTOCOL_ERROR,
2051 QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) &&
2052 qmi_message_wds_get_profile_settings_output_get_extended_error_code (
2053 output,
2054 &ds_profile_error,
2055 NULL)) {
2056 g_printerr ("error: couldn't get profile settings: ds profile error: %s\n",
2057 qmi_wds_ds_profile_error_get_string (ds_profile_error));
2058 } else {
2059 g_printerr ("error: couldn't get profile settings: %s\n",
2060 error->message);
2061 }
2062 g_error_free (error);
2063 qmi_message_wds_get_profile_settings_output_unref (output);
2064 } else {
2065 const gchar *str;
2066 guint8 context_number;
2067 QmiWdsPdpType pdp_type;
2068 QmiWdsAuthentication auth;
2069 QmiWdsApnTypeMask apn_type;
2070 gboolean flag;
2071
2072 if (qmi_message_wds_get_profile_settings_output_get_apn_name (output, &str, NULL))
2073 g_print ("\t\tAPN: '%s'\n", str);
2074 if (qmi_message_wds_get_profile_settings_output_get_apn_type_mask (output, &apn_type, NULL)) {
2075 g_autofree gchar *aux = NULL;
2076
2077 aux = qmi_wds_apn_type_mask_build_string_from_mask (apn_type);
2078 g_print ("\t\tAPN type: '%s'\n", VALIDATE_MASK_NONE (aux));
2079 }
2080 if (qmi_message_wds_get_profile_settings_output_get_pdp_type (output, &pdp_type, NULL))
2081 g_print ("\t\tPDP type: '%s'\n", qmi_wds_pdp_type_get_string (pdp_type));
2082 if (qmi_message_wds_get_profile_settings_output_get_pdp_context_number (output, &context_number, NULL))
2083 g_print ("\t\tPDP context number: '%d'\n", context_number);
2084 if (qmi_message_wds_get_profile_settings_output_get_username (output, &str, NULL))
2085 g_print ("\t\tUsername: '%s'\n", str);
2086 if (qmi_message_wds_get_profile_settings_output_get_password (output, &str, NULL))
2087 g_print ("\t\tPassword: '%s'\n", str);
2088 if (qmi_message_wds_get_profile_settings_output_get_authentication (output, &auth, NULL)) {
2089 g_autofree gchar *aux = NULL;
2090
2091 aux = qmi_wds_authentication_build_string_from_mask (auth);
2092 g_print ("\t\tAuth: '%s'\n", VALIDATE_MASK_NONE (aux));
2093 }
2094 if (qmi_message_wds_get_profile_settings_output_get_roaming_disallowed_flag (output, &flag, NULL))
2095 g_print ("\t\tNo roaming: '%s'\n", flag ? "yes" : "no");
2096 if (qmi_message_wds_get_profile_settings_output_get_apn_disabled_flag (output, &flag, NULL))
2097 g_print ("\t\tAPN disabled: '%s'\n", flag ? "yes" : "no");
2098 qmi_message_wds_get_profile_settings_output_unref (output);
2099 }
2100
2101 /* Keep on */
2102 inner_ctx->i++;
2103 get_next_profile_settings (inner_ctx);
2104 }
2105
2106 static void
2107 get_next_profile_settings (GetProfileListContext *inner_ctx)
2108 {
2109 QmiMessageWdsGetProfileListOutputProfileListProfile *profile;
2110 QmiMessageWdsGetProfileSettingsInput *input;
2111
2112 if (inner_ctx->i >= inner_ctx->profile_list->len) {
2113 /* All done */
2114 g_array_unref (inner_ctx->profile_list);
2115 g_slice_free (GetProfileListContext, inner_ctx);
2116 operation_shutdown (TRUE);
2117 return;
2118 }
2119
2120 profile = &g_array_index (inner_ctx->profile_list, QmiMessageWdsGetProfileListOutputProfileListProfile, inner_ctx->i);
2121 g_print ("\t[%u] %s - %s\n",
2122 profile->profile_index,
2123 qmi_wds_profile_type_get_string (profile->profile_type),
2124 profile->profile_name);
2125
2126 input = qmi_message_wds_get_profile_settings_input_new ();
2127 qmi_message_wds_get_profile_settings_input_set_profile_id (
2128 input,
2129 profile->profile_type,
2130 profile->profile_index,
2131 NULL);
2132 qmi_client_wds_get_profile_settings (ctx->client,
2133 input,
2134 3,
2135 NULL,
2136 (GAsyncReadyCallback)get_profile_settings_ready,
2137 inner_ctx);
2138 qmi_message_wds_get_profile_settings_input_unref (input);
2139 }
2140
2141 static void
2142 get_profile_list_ready (QmiClientWds *client,
2143 GAsyncResult *res)
2144 {
2145 GError *error = NULL;
2146 QmiMessageWdsGetProfileListOutput *output;
2147 GetProfileListContext *inner_ctx;
2148 GArray *profile_list = NULL;
2149
2150 output = qmi_client_wds_get_profile_list_finish (client, res, &error);
2151 if (!output) {
2152 g_printerr ("error: operation failed: %s\n",
2153 error->message);
2154 g_error_free (error);
2155 operation_shutdown (FALSE);
2156 return;
2157 }
2158
2159 if (!qmi_message_wds_get_profile_list_output_get_result (output, &error)) {
2160 QmiWdsDsProfileError ds_profile_error;
2161
2162 if (g_error_matches (error,
2163 QMI_PROTOCOL_ERROR,
2164 QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) &&
2165 qmi_message_wds_get_profile_list_output_get_extended_error_code (
2166 output,
2167 &ds_profile_error,
2168 NULL)) {
2169 g_printerr ("error: couldn't get profile list: ds profile error: %s\n",
2170 qmi_wds_ds_profile_error_get_string (ds_profile_error));
2171 } else {
2172 g_printerr ("error: couldn't get profile list: %s\n",
2173 error->message);
2174 }
2175
2176 g_error_free (error);
2177 qmi_message_wds_get_profile_list_output_unref (output);
2178 operation_shutdown (FALSE);
2179 return;
2180 }
2181
2182 qmi_message_wds_get_profile_list_output_get_profile_list (output, &profile_list, NULL);
2183
2184 if (!profile_list || !profile_list->len) {
2185 g_print ("Profile list empty\n");
2186 qmi_message_wds_get_profile_list_output_unref (output);
2187 operation_shutdown (TRUE);
2188 return;
2189 }
2190
2191 g_print ("Profile list retrieved:\n");
2192
2193 inner_ctx = g_slice_new (GetProfileListContext);
2194 inner_ctx->profile_list = g_array_ref (profile_list);
2195 inner_ctx->i = 0;
2196 get_next_profile_settings (inner_ctx);
2197 }
2198
2199 #endif /* HAVE_QMI_MESSAGE_WDS_GET_PROFILE_LIST
2200 * HAVE_QMI_MESSAGE_WDS_GET_PROFILE_SETTINGS */
2201
2202 #if defined HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_SETTINGS
2203
2204 static void
2205 get_default_settings_ready (QmiClientWds *client,
2206 GAsyncResult *res)
2207 {
2208 QmiMessageWdsGetDefaultSettingsOutput *output;
2209 GError *error = NULL;
2210 const gchar *str;
2211 QmiWdsPdpType pdp_type;
2212 QmiWdsAuthentication auth;
2213
2214 output = qmi_client_wds_get_default_settings_finish (client, res, &error);
2215 if (!output) {
2216 g_printerr ("error: operation failed: %s\n", error->message);
2217 g_error_free (error);
2218 operation_shutdown (FALSE);
2219 return;
2220 }
2221
2222 if (!qmi_message_wds_get_default_settings_output_get_result (output, &error)) {
2223 QmiWdsDsProfileError ds_profile_error;
2224
2225 if (g_error_matches (error,
2226 QMI_PROTOCOL_ERROR,
2227 QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) &&
2228 qmi_message_wds_get_default_settings_output_get_extended_error_code (
2229 output,
2230 &ds_profile_error,
2231 NULL)) {
2232 g_printerr ("error: couldn't get default settings: ds default error: %s\n",
2233 qmi_wds_ds_profile_error_get_string (ds_profile_error));
2234 } else {
2235 g_printerr ("error: couldn't get default settings: %s\n",
2236 error->message);
2237 }
2238 g_error_free (error);
2239 qmi_message_wds_get_default_settings_output_unref (output);
2240 operation_shutdown (FALSE);
2241 return;
2242 }
2243
2244 g_print ("Default settings retrieved:\n");
2245
2246 if (qmi_message_wds_get_default_settings_output_get_apn_name (output, &str, NULL))
2247 g_print ("\tAPN: '%s'\n", str);
2248 if (qmi_message_wds_get_default_settings_output_get_pdp_type (output, &pdp_type, NULL))
2249 g_print ("\tPDP type: '%s'\n", qmi_wds_pdp_type_get_string (pdp_type));
2250 if (qmi_message_wds_get_default_settings_output_get_username (output, &str, NULL))
2251 g_print ("\tUsername: '%s'\n", str);
2252 if (qmi_message_wds_get_default_settings_output_get_password (output, &str, NULL))
2253 g_print ("\tPassword: '%s'\n", str);
2254 if (qmi_message_wds_get_default_settings_output_get_authentication (output, &auth, NULL)) {
2255 g_autofree gchar *aux = NULL;
2256
2257 aux = qmi_wds_authentication_build_string_from_mask (auth);
2258 g_print ("\tAuth: '%s'\n", VALIDATE_MASK_NONE (aux));
2259 }
2260
2261 qmi_message_wds_get_default_settings_output_unref (output);
2262 operation_shutdown (TRUE);
2263 }
2264
2265 #endif /* HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_SETTINGS */
2266
2267 #if defined HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_PROFILE_NUMBER
2268
2269 static void
2270 get_default_profile_number_ready (QmiClientWds *client,
2271 GAsyncResult *res)
2272 {
2273 g_autoptr(QmiMessageWdsGetDefaultProfileNumberOutput) output = NULL;
2274 g_autoptr(GError) error = NULL;
2275 guint8 profile_num;
2276
2277 output = qmi_client_wds_get_default_profile_number_finish (client, res, &error);
2278 if (!output) {
2279 g_printerr ("error: operation failed: %s\n", error->message);
2280 operation_shutdown (FALSE);
2281 return;
2282 }
2283
2284 if (!qmi_message_wds_get_default_profile_number_output_get_result (output, &error)) {
2285 QmiWdsDsProfileError ds_profile_error;
2286
2287 if (g_error_matches (error,
2288 QMI_PROTOCOL_ERROR,
2289 QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) &&
2290 qmi_message_wds_get_default_profile_number_output_get_extended_error_code (
2291 output,
2292 &ds_profile_error,
2293 NULL)) {
2294 g_printerr ("error: couldn't get default profile number: ds profile error: %s\n",
2295 qmi_wds_ds_profile_error_get_string (ds_profile_error));
2296 } else {
2297 g_printerr ("error: couldn't get default profile number: %s\n",
2298 error->message);
2299 }
2300 operation_shutdown (FALSE);
2301 return;
2302 }
2303
2304 g_print ("Default profile number retrieved:\n");
2305 if (qmi_message_wds_get_default_profile_number_output_get_index (output, &profile_num, NULL))
2306 g_print ("\tDefault profile number: '%d'\n", profile_num);
2307 operation_shutdown (TRUE);
2308 }
2309
2310 #endif /* HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_PROFILE_NUMBER */
2311
2312 #if defined HAVE_QMI_MESSAGE_WDS_SET_DEFAULT_PROFILE_NUMBER
2313
2314 static void
2315 set_default_profile_number_ready (QmiClientWds *client,
2316 GAsyncResult *res)
2317 {
2318 g_autoptr(QmiMessageWdsSetDefaultProfileNumberOutput) output = NULL;
2319 g_autoptr(GError) error = NULL;
2320
2321 output = qmi_client_wds_set_default_profile_number_finish (client, res, &error);
2322 if (!output) {
2323 g_printerr ("error: operation failed: %s\n", error->message);
2324 operation_shutdown (FALSE);
2325 return;
2326 }
2327
2328 if (!qmi_message_wds_set_default_profile_number_output_get_result (output, &error)) {
2329 QmiWdsDsProfileError ds_profile_error;
2330
2331 if (g_error_matches (error,
2332 QMI_PROTOCOL_ERROR,
2333 QMI_PROTOCOL_ERROR_EXTENDED_INTERNAL) &&
2334 qmi_message_wds_set_default_profile_number_output_get_extended_error_code (
2335 output,
2336 &ds_profile_error,
2337 NULL)) {
2338 g_printerr ("error: couldn't set default settings: ds profile error: %s\n",
2339 qmi_wds_ds_profile_error_get_string (ds_profile_error));
2340 } else {
2341 g_printerr ("error: couldn't set default settings: %s\n",
2342 error->message);
2343 }
2344 operation_shutdown (FALSE);
2345 return;
2346 }
2347
2348 g_print ("Default profile number updated\n");
2349 operation_shutdown (TRUE);
2350 }
2351
2352 static QmiMessageWdsSetDefaultProfileNumberInput *
2353 set_default_profile_number_input_create (const gchar *str)
2354 {
2355 g_autoptr(QmiMessageWdsSetDefaultProfileNumberInput) input = NULL;
2356 g_autoptr(GError) error = NULL;
2357 g_auto(GStrv) split = NULL;
2358 QmiWdsProfileType profile_type;
2359 guint profile_num;
2360
2361 split = g_strsplit (str, ",", -1);
2362 input = qmi_message_wds_set_default_profile_number_input_new ();
2363
2364 if (g_strv_length (split) != 2) {
2365 g_printerr ("error: expected 2 options in default profile number settings\n");
2366 return NULL;
2367 }
2368
2369 g_strstrip (split[0]);
2370 if (g_str_equal (split[0], "3gpp"))
2371 profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
2372 else if (g_str_equal (split[0], "3gpp2"))
2373 profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
2374 else {
2375 g_printerr ("error: invalid profile type '%s'. Expected '3gpp' or '3gpp2'.'\n", split[0]);
2376 return NULL;
2377 }
2378
2379 g_strstrip (split[1]);
2380 profile_num = atoi (split[1]);
2381 if (profile_num <= 0 || profile_num > G_MAXUINT8) {
2382 g_printerr ("error: invalid or out of range profile number [1,%u]: '%s'\n",
2383 G_MAXUINT8,
2384 split[1]);
2385 return NULL;
2386 }
2387
2388 if (!qmi_message_wds_set_default_profile_number_input_set_profile_identifier (
2389 input,
2390 profile_type,
2391 QMI_WDS_PROFILE_FAMILY_TETHERED,
2392 (guint8)profile_num,
2393 &error)) {
2394 g_printerr ("error: couldn't create input bundle: '%s'\n", error->message);
2395 return NULL;
2396 }
2397
2398 return g_steal_pointer (&input);
2399 }
2400
2401 #endif /* HAVE_QMI_MESSAGE_WDS_SET_DEFAULT_PROFILE_NUMBER */
2402
2403 #if defined HAVE_QMI_MESSAGE_WDS_GET_AUTOCONNECT_SETTINGS
2404
2405 static void
2406 get_autoconnect_settings_ready (QmiClientWds *client,
2407 GAsyncResult *res)
2408 {
2409 QmiMessageWdsGetAutoconnectSettingsOutput *output;
2410 GError *error = NULL;
2411 QmiWdsAutoconnectSetting status;
2412 QmiWdsAutoconnectSettingRoaming roaming;
2413
2414 output = qmi_client_wds_get_autoconnect_settings_finish (client, res, &error);
2415 if (!output) {
2416 g_printerr ("error: operation failed: %s\n", error->message);
2417 g_error_free (error);
2418 operation_shutdown (FALSE);
2419 return;
2420 }
2421
2422 if (!qmi_message_wds_get_autoconnect_settings_output_get_result (output, &error)) {
2423 g_printerr ("error: couldn't get autoconnect settings: %s\n",
2424 error->message);
2425 g_error_free (error);
2426 qmi_message_wds_get_autoconnect_settings_output_unref (output);
2427 operation_shutdown (FALSE);
2428 return;
2429 }
2430
2431 g_print ("Autoconnect settings retrieved:\n");
2432
2433 qmi_message_wds_get_autoconnect_settings_output_get_status (output, &status, NULL);
2434 g_print ("\tStatus: '%s'\n", qmi_wds_autoconnect_setting_get_string (status));
2435
2436 if (qmi_message_wds_get_autoconnect_settings_output_get_roaming (output, &roaming, NULL))
2437 g_print ("\tRoaming: '%s'\n", qmi_wds_autoconnect_setting_roaming_get_string (roaming));
2438
2439 qmi_message_wds_get_autoconnect_settings_output_unref (output);
2440 operation_shutdown (TRUE);
2441 }
2442
2443 #endif /* HAVE_QMI_MESSAGE_WDS_GET_AUTOCONNECT_SETTINGS */
2444
2445 #if defined HAVE_QMI_MESSAGE_WDS_SET_AUTOCONNECT_SETTINGS
2446
2447 static QmiMessageWdsSetAutoconnectSettingsInput *
2448 set_autoconnect_settings_input_create (const gchar *str)
2449 {
2450 QmiMessageWdsSetAutoconnectSettingsInput *input = NULL;
2451 gchar **split;
2452 QmiWdsAutoconnectSetting status;
2453 QmiWdsAutoconnectSettingRoaming roaming;
2454 GError *error = NULL;
2455
2456 split = g_strsplit (str, ",", -1);
2457 input = qmi_message_wds_set_autoconnect_settings_input_new ();
2458
2459 if (g_strv_length (split) != 2 && g_strv_length (split) != 1) {
2460 g_printerr ("error: expected 1 or 2 options in autoconnect settings\n");
2461 goto error_out;
2462 }
2463
2464 g_strstrip (split[0]);
2465 if (!qmicli_read_wds_autoconnect_setting_from_string (split[0], &status)) {
2466 g_printerr ("error: failed to parse autoconnect setting\n");
2467 goto error_out;
2468 }
2469 if (!qmi_message_wds_set_autoconnect_settings_input_set_status (input, status, &error)) {
2470 g_printerr ("error: couldn't create input data bundle: '%s'\n",
2471 error->message);
2472 goto error_out;
2473 }
2474
2475 if (g_strv_length (split) == 2) {
2476 g_strstrip (split[1]);
2477 if (!qmicli_read_wds_autoconnect_setting_roaming_from_string (g_str_equal (split[1], "roaming-allowed") ? "allowed" : split[1], &roaming)) {
2478 g_printerr ("error: failed to parse autoconnect roaming setting\n");
2479 goto error_out;
2480 }
2481 if (!qmi_message_wds_set_autoconnect_settings_input_set_roaming (input, roaming, &error)) {
2482 g_printerr ("error: couldn't create input data bundle: '%s'\n",
2483 error->message);
2484 goto error_out;
2485 }
2486 }
2487
2488 g_strfreev (split);
2489 return input;
2490
2491 error_out:
2492 if (error)
2493 g_error_free (error);
2494 g_strfreev (split);
2495 qmi_message_wds_set_autoconnect_settings_input_unref (input);
2496 return NULL;
2497 }
2498
2499 static void
2500 set_autoconnect_settings_ready (QmiClientWds *client,
2501 GAsyncResult *res)
2502 {
2503 QmiMessageWdsSetAutoconnectSettingsOutput *output;
2504 GError *error = NULL;
2505
2506 output = qmi_client_wds_set_autoconnect_settings_finish (client, res, &error);
2507 if (!output) {
2508 g_printerr ("error: operation failed: %s\n", error->message);
2509 g_error_free (error);
2510 operation_shutdown (FALSE);
2511 return;
2512 }
2513
2514 if (!qmi_message_wds_set_autoconnect_settings_output_get_result (output, &error)) {
2515 g_printerr ("error: couldn't set autoconnect settings: %s\n",
2516 error->message);
2517 g_error_free (error);
2518 qmi_message_wds_set_autoconnect_settings_output_unref (output);
2519 operation_shutdown (FALSE);
2520 return;
2521 }
2522
2523 g_print ("Autoconnect settings updated\n");
2524 qmi_message_wds_set_autoconnect_settings_output_unref (output);
2525 operation_shutdown (TRUE);
2526 }
2527
2528 #endif /* HAVE_QMI_MESSAGE_WDS_SET_AUTOCONNECT_SETTINGS */
2529
2530 #if defined HAVE_QMI_MESSAGE_WDS_GET_SUPPORTED_MESSAGES
2531
2532 static void
2533 get_supported_messages_ready (QmiClientWds *client,
2534 GAsyncResult *res)
2535 {
2536 QmiMessageWdsGetSupportedMessagesOutput *output;
2537 GError *error = NULL;
2538 GArray *bytearray = NULL;
2539 gchar *str;
2540
2541 output = qmi_client_wds_get_supported_messages_finish (client, res, &error);
2542 if (!output) {
2543 g_printerr ("error: operation failed: %s\n", error->message);
2544 g_error_free (error);
2545 operation_shutdown (FALSE);
2546 return;
2547 }
2548
2549 if (!qmi_message_wds_get_supported_messages_output_get_result (output, &error)) {
2550 g_printerr ("error: couldn't get supported WDS messages: %s\n", error->message);
2551 g_error_free (error);
2552 qmi_message_wds_get_supported_messages_output_unref (output);
2553 operation_shutdown (FALSE);
2554 return;
2555 }
2556
2557 g_print ("[%s] Successfully got supported WDS messages:\n",
2558 qmi_device_get_path_display (ctx->device));
2559
2560 qmi_message_wds_get_supported_messages_output_get_list (output, &bytearray, NULL);
2561 str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL,
2562 bytearray ? bytearray->len : 0);
2563 g_print ("%s", str);
2564 g_free (str);
2565
2566 qmi_message_wds_get_supported_messages_output_unref (output);
2567 operation_shutdown (TRUE);
2568 }
2569
2570 #endif /* HAVE_QMI_MESSAGE_WDS_GET_SUPPORTED_MESSAGES */
2571
2572 #if defined HAVE_QMI_MESSAGE_WDS_RESET
2573
2574 static void
2575 reset_ready (QmiClientWds *client,
2576 GAsyncResult *res)
2577 {
2578 QmiMessageWdsResetOutput *output;
2579 GError *error = NULL;
2580
2581 output = qmi_client_wds_reset_finish (client, res, &error);
2582 if (!output) {
2583 g_printerr ("error: operation failed: %s\n", error->message);
2584 g_error_free (error);
2585 operation_shutdown (FALSE);
2586 return;
2587 }
2588
2589 if (!qmi_message_wds_reset_output_get_result (output, &error)) {
2590 g_printerr ("error: couldn't reset the WDS service: %s\n", error->message);
2591 g_error_free (error);
2592 qmi_message_wds_reset_output_unref (output);
2593 operation_shutdown (FALSE);
2594 return;
2595 }
2596
2597 g_print ("[%s] Successfully performed WDS service reset\n",
2598 qmi_device_get_path_display (ctx->device));
2599
2600 qmi_message_wds_reset_output_unref (output);
2601 operation_shutdown (TRUE);
2602 }
2603
2604 #endif /* HAVE_QMI_MESSAGE_WDS_RESET */
2605
2606 static gboolean
2607 noop_cb (gpointer unused)
2608 {
2609 operation_shutdown (TRUE);
2610 return FALSE;
2611 }
2612
2613 #if defined HAVE_QMI_MESSAGE_WDS_BIND_DATA_PORT
2614
2615 static QmiMessageWdsBindDataPortInput *
2616 bind_data_port_input_create (const gchar *str)
2617 {
2618 g_autoptr(QmiMessageWdsBindDataPortInput) input = NULL;
2619 g_autoptr(GError) error = NULL;
2620 QmiSioPort sio_port;
2621
2622 sio_port = strtoul(str, NULL, 0);
2623 if (!sio_port && !qmicli_read_sio_port_from_string (str, &sio_port))
2624 return NULL;
2625
2626 input = qmi_message_wds_bind_data_port_input_new ();
2627 if (!qmi_message_wds_bind_data_port_input_set_data_port (input, sio_port, &error)) {
2628 g_printerr ("error: couldn't set data port: '%s'\n", error->message);
2629 return NULL;
2630 }
2631
2632 return g_steal_pointer (&input);
2633 }
2634
2635 static void
2636 bind_data_port_ready (QmiClientWds *client,
2637 GAsyncResult *res)
2638 {
2639 g_autoptr(QmiMessageWdsBindDataPortOutput) output = NULL;
2640 g_autoptr(GError) error = NULL;
2641
2642 output = qmi_client_wds_bind_data_port_finish (client, res, &error);
2643 if (!output) {
2644 g_printerr ("error: operation failed: %s\n", error->message);
2645 operation_shutdown (FALSE);
2646 return;
2647 }
2648
2649 if (!qmi_message_wds_bind_data_port_output_get_result (output, &error)) {
2650 g_printerr ("error: couldn't bind data port: %s\n", error->message);
2651 operation_shutdown (FALSE);
2652 return;
2653 }
2654
2655 operation_shutdown (TRUE);
2656 }
2657
2658 #endif /* HAVE_QMI_MESSAGE_WDS_BIND_DATA_PORT */
2659
2660 #if defined HAVE_QMI_MESSAGE_WDS_BIND_MUX_DATA_PORT
2661
2662 typedef struct {
2663 guint8 mux_id;
2664 QmiDataEndpointType ep_type;
2665 gint ep_iface_number;
2666 QmiWdsClientType client_type;
2667 } BindMuxDataPortProperties;
2668
2669 static gboolean
2670 bind_mux_data_port_properties_handle (const gchar *key,
2671 const gchar *value,
2672 GError **error,
2673 gpointer user_data)
2674 {
2675 BindMuxDataPortProperties *props = user_data;
2676
2677 if (!value || !value[0]) {
2678 g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED,
2679 "key '%s' requires a value", key);
2680 return FALSE;
2681 }
2682
2683 if (g_ascii_strcasecmp (key, "mux-id") == 0) {
2684 guint aux;
2685
2686 /* QMI_WDS_MUX_ID_UNDEFINED is G_MAXUINT8 (0xff) */
2687 if (!qmicli_read_uint_from_string (value, &aux) || (aux >= G_MAXUINT8)) {
2688 g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED,
2689 "failed reading key 'mux-id' value in range [0,254]: '%s'", value);
2690 return FALSE;
2691 }
2692 props->mux_id = (guint8) aux;
2693 return TRUE;
2694 }
2695
2696 if (g_ascii_strcasecmp (key, "ep-type") == 0) {
2697 if (!qmicli_read_data_endpoint_type_from_string (value, &(props->ep_type))) {
2698 g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED,
2699 "failed reading key 'ep-type' value: '%s'", value);
2700 return FALSE;
2701 }
2702 return TRUE;
2703 }
2704
2705 if (g_ascii_strcasecmp (key, "ep-iface-number") == 0) {
2706 guint aux;
2707
2708 if (!qmicli_read_uint_from_string (value, &aux)) {
2709 g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED,
2710 "failed reading key 'ep-iface-number' value: '%s'", value);
2711 return FALSE;
2712 }
2713
2714 props->ep_iface_number = (gint) aux;
2715 return TRUE;
2716 }
2717
2718 g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED,
2719 "unrecognized key: '%s'", key);
2720 return FALSE;
2721 }
2722
2723 static QmiMessageWdsBindMuxDataPortInput *
2724 bind_mux_data_port_input_create (const gchar *str)
2725 {
2726 QmiMessageWdsBindMuxDataPortInput *input = NULL;
2727 GError *error = NULL;
2728 BindMuxDataPortProperties props = {
2729 .mux_id = QMI_WDS_MUX_ID_UNDEFINED,
2730 .ep_type = QMI_DATA_ENDPOINT_TYPE_HSUSB,
2731 .ep_iface_number = QMI_WDS_ENDPOINT_INTERFACE_NUMBER_UNDEFINED,
2732 .client_type = QMI_WDS_CLIENT_TYPE_TETHERED,
2733 };
2734
2735 if (!str[0])
2736 return NULL;
2737
2738 if (strchr (str, '=')) {
2739 if (!qmicli_parse_key_value_string (str,
2740 &error,
2741 bind_mux_data_port_properties_handle,
2742 &props)) {
2743 g_printerr ("error: could not parse input string '%s'\n", error->message);
2744 g_error_free (error);
2745 return NULL;
2746 }
2747 } else {
2748 g_printerr ("error: malformed input string, key=value format expected.\n");
2749 goto error_out;
2750 }
2751
2752
2753 if ((props.mux_id == QMI_WDS_MUX_ID_UNDEFINED) ||
2754 (props.ep_iface_number == QMI_WDS_ENDPOINT_INTERFACE_NUMBER_UNDEFINED)) {
2755 g_printerr ("error: Mux ID and Endpoint Iface Number are both needed\n");
2756 return NULL;
2757 }
2758
2759 input = qmi_message_wds_bind_mux_data_port_input_new ();
2760
2761 if (!qmi_message_wds_bind_mux_data_port_input_set_endpoint_info (input, props.ep_type, props.ep_iface_number, &error)) {
2762 g_printerr ("error: couldn't set endpoint info: '%s'\n", error->message);
2763 goto error_out;
2764 }
2765
2766 if (!qmi_message_wds_bind_mux_data_port_input_set_mux_id (input, props.mux_id, &error)) {
2767 g_printerr ("error: couldn't set mux ID %d: '%s'\n", props.mux_id, error->message);
2768 goto error_out;
2769 }
2770
2771 if (!qmi_message_wds_bind_mux_data_port_input_set_client_type (input, props.client_type , &error)) {
2772 g_printerr ("error: couldn't set client type: '%s'\n", error->message);
2773 goto error_out;
2774 }
2775
2776 return input;
2777
2778 error_out:
2779 if (error)
2780 g_error_free (error);
2781 qmi_message_wds_bind_mux_data_port_input_unref (input);
2782 return NULL;
2783 }
2784
2785 static void
2786 bind_mux_data_port_ready (QmiClientWds *client,
2787 GAsyncResult *res) {
2788 QmiMessageWdsBindMuxDataPortOutput *output;
2789 GError *error = NULL;
2790
2791 output = qmi_client_wds_bind_mux_data_port_finish (client, res, &error);
2792 if (!output) {
2793 g_printerr ("error: operation failed: %s\n", error->message);
2794 g_error_free (error);
2795 operation_shutdown (FALSE);
2796 return;
2797 }
2798
2799 if (!qmi_message_wds_bind_mux_data_port_output_get_result (output, &error)) {
2800 g_printerr ("error: couldn't bind mux data port: %s\n", error->message);
2801 g_error_free (error);
2802 qmi_message_wds_bind_mux_data_port_output_unref (output);
2803 operation_shutdown (FALSE);
2804 return;
2805 }
2806
2807 qmi_message_wds_bind_mux_data_port_output_unref (output);
2808 operation_shutdown (TRUE);
2809 }
2810
2811 #endif /* HAVE_QMI_MESSAGE_WDS_BIND_MUX_DATA_PORT */
2812
2813 #if defined HAVE_QMI_MESSAGE_WDS_SET_IP_FAMILY
2814
2815 static void
2816 set_ip_family_ready (QmiClientWds *client,
2817 GAsyncResult *res)
2818 {
2819 QmiMessageWdsSetIpFamilyOutput *output;
2820 GError *error = NULL;
2821
2822 output = qmi_client_wds_set_ip_family_finish (client, res, &error);
2823 if (!output) {
2824 g_printerr ("error: operation failed: %s\n", error->message);
2825 g_error_free (error);
2826 operation_shutdown (FALSE);
2827 return;
2828 }
2829
2830 if (!qmi_message_wds_set_ip_family_output_get_result (output, &error)) {
2831 g_printerr ("error: couldn't set IP family: %s\n", error->message);
2832 g_error_free (error);
2833 qmi_message_wds_set_ip_family_output_unref (output);
2834 operation_shutdown (FALSE);
2835 return;
2836 }
2837
2838 qmi_message_wds_set_ip_family_output_unref (output);
2839 operation_shutdown (TRUE);
2840 }
2841
2842 #endif /* HAVE_QMI_MESSAGE_WDS_SET_IP_FAMILY */
2843
2844 #if defined HAVE_QMI_MESSAGE_WDS_GET_CHANNEL_RATES
2845
2846 static void
2847 get_channel_rates_ready (QmiClientWds *client,
2848 GAsyncResult *res)
2849 {
2850 QmiMessageWdsGetChannelRatesOutput *output;
2851 guint32 txrate = 0, rxrate = 0, maxtxrate = 0, maxrxrate = 0;
2852 GError *error = NULL;
2853
2854 output = qmi_client_wds_get_channel_rates_finish (client, res, &error);
2855 if (!output) {
2856 g_printerr ("error: operation failed: %s\n", error->message);
2857 g_error_free (error);
2858 operation_shutdown (FALSE);
2859 return;
2860 }
2861
2862 if (!qmi_message_wds_get_channel_rates_output_get_result (output, &error)) {
2863 g_printerr ("error: couldn't get channel rates: %s\n",
2864 error->message);
2865 g_error_free (error);
2866 qmi_message_wds_get_channel_rates_output_unref (output);
2867 operation_shutdown (FALSE);
2868 return;
2869 }
2870
2871 g_print ("Channel data rates:\n");
2872
2873 qmi_message_wds_get_channel_rates_output_get_channel_rates (output,
2874 &txrate,
2875 &rxrate,
2876 &maxtxrate,
2877 &maxrxrate,
2878 NULL);
2879
2880 /* Current TX/RX rates may not be available if device is disconnected */
2881
2882 g_print ("\tCurrent TX rate: ");
2883 if (txrate != QMI_WDS_RATE_UNAVAILABLE)
2884 g_print ("%ubps\n", txrate);
2885 else
2886 g_print ("n/a\n");
2887
2888 g_print ("\tCurrent RX rate: ");
2889 if (rxrate != QMI_WDS_RATE_UNAVAILABLE)
2890 g_print ("%ubps\n", rxrate);
2891 else
2892 g_print ("n/a\n");
2893
2894 g_print ("\tMax TX rate: %ubps\n"
2895 "\tMax RX rate: %ubps\n",
2896 maxtxrate,
2897 maxrxrate);
2898
2899 qmi_message_wds_get_channel_rates_output_unref (output);
2900 operation_shutdown (TRUE);
2901 }
2902
2903 #endif /* HAVE_QMI_MESSAGE_WDS_GET_CHANNEL_RATES */
2904
2905 #if defined HAVE_QMI_MESSAGE_WDS_GET_LTE_ATTACH_PARAMETERS
2906
2907 static void
2908 get_lte_attach_parameters_ready (QmiClientWds *client,
2909 GAsyncResult *res)
2910 {
2911 g_autoptr(QmiMessageWdsGetLteAttachParametersOutput) output = NULL;
2912 g_autoptr(GError) error = NULL;
2913 const gchar *apn;
2914 gboolean ota_attach_performed;
2915 QmiWdsIpSupportType ip_support_type;
2916
2917 output = qmi_client_wds_get_lte_attach_parameters_finish (client, res, &error);
2918 if (!output) {
2919 g_printerr ("error: operation failed: %s\n", error->message);
2920 operation_shutdown (FALSE);
2921 return;
2922 }
2923
2924 if (!qmi_message_wds_get_lte_attach_parameters_output_get_result (output, &error)) {
2925 g_printerr ("error: couldn't get LTE attach parameters: %s\n", error->message);
2926 operation_shutdown (FALSE);
2927 return;
2928 }
2929
2930 g_print ("LTE attach parameters successfully retrieved:\n");
2931 if (qmi_message_wds_get_lte_attach_parameters_output_get_apn (output, &apn, NULL))
2932 g_print ("\tAPN: %s\n", apn);
2933 if (qmi_message_wds_get_lte_attach_parameters_output_get_ip_support_type (output, &ip_support_type, NULL))
2934 g_print ("\tIP support type: %s\n", qmi_wds_ip_support_type_get_string (ip_support_type));
2935 if (qmi_message_wds_get_lte_attach_parameters_output_get_ota_attach_performed (output, &ota_attach_performed, NULL))
2936 g_print ("\tOTA attach performed: %s\n", ota_attach_performed ? "yes" : "no");
2937
2938 operation_shutdown (TRUE);
2939 }
2940
2941 #endif /* HAVE_QMI_MESSAGE_WDS_GET_LTE_ATTACH_PARAMETERS */
2942
2943 #if defined HAVE_QMI_MESSAGE_WDS_GET_MAX_LTE_ATTACH_PDN_NUMBER
2944
2945 static void
2946 get_max_lte_attach_pdn_number_ready (QmiClientWds *client,
2947 GAsyncResult *res)
2948 {
2949 g_autoptr(QmiMessageWdsGetMaxLteAttachPdnNumberOutput) output = NULL;
2950 g_autoptr(GError) error = NULL;
2951 guint8 maxnum = 0;
2952
2953 output = qmi_client_wds_get_max_lte_attach_pdn_number_finish (client, res, &error);
2954 if (!output) {
2955 g_printerr ("error: operation failed: %s\n", error->message);
2956 operation_shutdown (FALSE);
2957 return;
2958 }
2959
2960 if (!qmi_message_wds_get_max_lte_attach_pdn_number_output_get_result (output, &error)) {
2961 g_printerr ("error: couldn't get maximum number of attach PDN: %s\n", error->message);
2962 operation_shutdown (FALSE);
2963 return;
2964 }
2965
2966 qmi_message_wds_get_max_lte_attach_pdn_number_output_get_info (output, &maxnum, NULL);
2967 g_print ("Maximum number of LTE attach PDN: %u\n", maxnum);
2968 operation_shutdown (TRUE);
2969 }
2970
2971 #endif /* HAVE_QMI_MESSAGE_WDS_GET_MAX_LTE_ATTACH_PDN_NUMBER */
2972
2973 #if defined HAVE_QMI_MESSAGE_WDS_GET_LTE_ATTACH_PDN_LIST
2974
2975 static void
2976 get_lte_attach_pdn_list_ready (QmiClientWds *client,
2977 GAsyncResult *res)
2978 {
2979 g_autoptr(QmiMessageWdsGetLteAttachPdnListOutput) output = NULL;
2980 g_autoptr(GError) error = NULL;
2981 GArray *current_list = NULL;
2982 GArray *pending_list = NULL;
2983 guint i;
2984
2985 output = qmi_client_wds_get_lte_attach_pdn_list_finish (client, res, &error);
2986 if (!output) {
2987 g_printerr ("error: operation failed: %s\n", error->message);
2988 operation_shutdown (FALSE);
2989 return;
2990 }
2991
2992 if (!qmi_message_wds_get_lte_attach_pdn_list_output_get_result (output, &error)) {
2993 g_printerr ("error: couldn't get the list of LTE attach PDN: %s\n", error->message);
2994 operation_shutdown (FALSE);
2995 return;
2996 }
2997
2998 g_print ("Attach PDN list retrieved:\n");
2999
3000 qmi_message_wds_get_lte_attach_pdn_list_output_get_current_list (output, &current_list, NULL);
3001 if (!current_list || !current_list->len) {
3002 g_print ("\tCurrent list: n/a\n");
3003 } else {
3004 g_print ("\tCurrent list: '");
3005 for (i = 0; i < current_list->len; i++)
3006 g_print ("%s%u", i > 0 ? ", " : "", g_array_index (current_list, guint16, i));
3007 g_print ("'\n");
3008 }
3009
3010 qmi_message_wds_get_lte_attach_pdn_list_output_get_pending_list (output, &pending_list, NULL);
3011 if (!pending_list || !pending_list->len) {
3012 g_print ("\tPending list: n/a\n");
3013 } else {
3014 g_print ("\tPending list: '");
3015 for (i = 0; i < pending_list->len; i++)
3016 g_print ("%s%u", i > 0 ? ", " : "", g_array_index (pending_list, guint16, i));
3017 g_print ("'\n");
3018 }
3019
3020 operation_shutdown (TRUE);
3021 }
3022
3023 #endif /* HAVE_QMI_MESSAGE_WDS_GET_LTE_ATTACH_PDN_LIST */
3024
3025 #if defined HAVE_QMI_MESSAGE_WDS_SET_LTE_ATTACH_PDN_LIST
3026
3027 static QmiMessageWdsSetLteAttachPdnListInput *
3028 set_lte_attach_pdn_list_input_create (const gchar *str)
3029 {
3030 g_autoptr(QmiMessageWdsSetLteAttachPdnListInput) input = NULL;
3031 g_autoptr(GError) error = NULL;
3032 g_auto(GStrv) split = NULL;
3033 g_autoptr(GArray) pdn_list = NULL;
3034 guint i;
3035
3036 pdn_list = g_array_new (FALSE, FALSE, sizeof (guint16));
3037
3038 split = g_strsplit (str, ",", -1);
3039
3040 for (i = 0; i < g_strv_length (split); i++) {
3041 guint val = 0;
3042 guint16 profile_index;
3043 gboolean success;
3044
3045 g_strstrip (split[i]);
3046 success = qmicli_read_uint_from_string (split[i], &val);
3047 if (!success || val == 0 || val > G_MAXUINT16) {
3048 g_printerr ("error: invalid or out of range profile number [1,%u]: '%s'\n", G_MAXUINT16, split[i]);
3049 operation_shutdown (FALSE);
3050 return NULL;
3051 }
3052 profile_index = (guint16) val;
3053 g_array_append_val (pdn_list, profile_index);
3054 }
3055
3056 input = qmi_message_wds_set_lte_attach_pdn_list_input_new ();
3057 if (!qmi_message_wds_set_lte_attach_pdn_list_input_set_list (input, pdn_list, &error)) {
3058 g_printerr ("error: couldn't set attach PDN list: '%s'\n", error->message);
3059 return NULL;
3060 }
3061 if (!qmi_message_wds_set_lte_attach_pdn_list_input_set_action (input, QMI_WDS_ATTACH_PDN_LIST_ACTION_DETACH_OR_PDN_DISCONNECT, &error)) {
3062 g_printerr ("error: couldn't set attach PDN list action: '%s'\n", error->message);
3063 return NULL;
3064 }
3065
3066 return g_steal_pointer (&input);
3067 }
3068
3069 static void
3070 set_lte_attach_pdn_list_ready (QmiClientWds *client,
3071 GAsyncResult *res)
3072 {
3073 g_autoptr(QmiMessageWdsSetLteAttachPdnListOutput) output = NULL;
3074 g_autoptr(GError) error = NULL;
3075
3076 output = qmi_client_wds_set_lte_attach_pdn_list_finish (client, res, &error);
3077 if (!output) {
3078 g_printerr ("error: operation failed: %s\n", error->message);
3079 operation_shutdown (FALSE);
3080 return;
3081 }
3082
3083 if (!qmi_message_wds_set_lte_attach_pdn_list_output_get_result (output, &error)) {
3084 g_printerr ("error: couldn't set attach PDN list: %s\n", error->message);
3085 operation_shutdown (FALSE);
3086 return;
3087 }
3088
3089 g_print ("Attach PDN list update successfully requested\n");
3090 operation_shutdown (TRUE);
3091 }
3092
3093 #endif /* HAVE_QMI_MESSAGE_WDS_SET_LTE_ATTACH_PDN_LIST */
3094
3095 void
3096 qmicli_wds_run (QmiDevice *device,
3097 QmiClientWds *client,
3098 GCancellable *cancellable)
3099 {
3100 /* Initialize context */
3101 ctx = g_slice_new (Context);
3102 ctx->device = g_object_ref (device);
3103 ctx->client = g_object_ref (client);
3104 ctx->cancellable = g_object_ref (cancellable);
3105 ctx->network_started_id = 0;
3106 ctx->packet_status_timeout_id = 0;
3107
3108 #if defined HAVE_QMI_MESSAGE_WDS_START_NETWORK
3109 if (start_network_str) {
3110 QmiMessageWdsStartNetworkInput *input = NULL;
3111 GError *error = NULL;
3112
3113 if (!start_network_input_create (start_network_str, &input, &error)) {
3114 g_printerr ("error: %s\n", error->message);
3115 g_error_free (error);
3116 return;
3117 }
3118
3119 g_debug ("Asynchronously starting network...");
3120 qmi_client_wds_start_network (ctx->client,
3121 input,
3122 180,
3123 ctx->cancellable,
3124 (GAsyncReadyCallback)start_network_ready,
3125 NULL);
3126 if (input)
3127 qmi_message_wds_start_network_input_unref (input);
3128 return;
3129 }
3130 #endif /* HAVE_QMI_MESSAGE_WDS_START_NETWORK */
3131
3132 #if defined HAVE_QMI_MESSAGE_WDS_STOP_NETWORK
3133 if (stop_network_str) {
3134 gulong packet_data_handle;
3135 gboolean disable_autoconnect;
3136
3137 if (g_str_equal (stop_network_str, "disable-autoconnect")) {
3138 packet_data_handle = 0xFFFFFFFF;
3139 disable_autoconnect = TRUE;
3140 } else {
3141 disable_autoconnect = FALSE;
3142 if (g_str_has_prefix (stop_network_str, "0x"))
3143 packet_data_handle = strtoul (stop_network_str, NULL, 16);
3144 else
3145 packet_data_handle = strtoul (stop_network_str, NULL, 10);
3146 if (!packet_data_handle || packet_data_handle > G_MAXUINT32) {
3147 g_printerr ("error: invalid packet data handle given '%s'\n",
3148 stop_network_str);
3149 operation_shutdown (FALSE);
3150 return;
3151 }
3152 }
3153
3154 g_debug ("Asynchronously stopping network (%lu)...", packet_data_handle);
3155 internal_stop_network (ctx->cancellable, (guint32)packet_data_handle, disable_autoconnect);
3156 return;
3157 }
3158 #endif /* HAVE_QMI_MESSAGE_WDS_STOP_NETWORK */
3159
3160 #if defined HAVE_QMI_MESSAGE_WDS_BIND_DATA_PORT
3161 if (bind_data_port_str) {
3162 g_autoptr(QmiMessageWdsBindDataPortInput) input = NULL;
3163
3164 g_debug ("Binding data port...");
3165 input = bind_data_port_input_create (bind_data_port_str);
3166 if (!input) {
3167 operation_shutdown (FALSE);
3168 return;
3169 }
3170 qmi_client_wds_bind_data_port (client,
3171 input,
3172 10,
3173 ctx->cancellable,
3174 (GAsyncReadyCallback) bind_data_port_ready,
3175 NULL);
3176 return;
3177 }
3178 #endif /* HAVE_QMI_MESSAGE_WDS_BIND_MUX_DATA_PORT */
3179
3180 #if defined HAVE_QMI_MESSAGE_WDS_BIND_MUX_DATA_PORT
3181 if (bind_mux_str) {
3182 QmiMessageWdsBindMuxDataPortInput *input;
3183
3184 g_debug ("Binding mux data port..");
3185 input = bind_mux_data_port_input_create (bind_mux_str);
3186 qmi_client_wds_bind_mux_data_port (client,
3187 input,
3188 10,
3189 ctx->cancellable,
3190 (GAsyncReadyCallback) bind_mux_data_port_ready,
3191 NULL);
3192 qmi_message_wds_bind_mux_data_port_input_unref (input);
3193 return;
3194 }
3195 #endif /* HAVE_QMI_MESSAGE_WDS_BIND_MUX_DATA_PORT */
3196
3197 #if defined HAVE_QMI_MESSAGE_WDS_SET_IP_FAMILY
3198 if (set_ip_family_str) {
3199 QmiMessageWdsSetIpFamilyInput *input;
3200 QmiWdsIpFamily preference;
3201
3202 switch (atoi (set_ip_family_str)) {
3203 case 4:
3204 preference = QMI_WDS_IP_FAMILY_IPV4;
3205 break;
3206 case 6:
3207 preference = QMI_WDS_IP_FAMILY_IPV6;
3208 break;
3209 default:
3210 g_printerr ("error: unknown IP type '%s' (not 4 or 6)\n",
3211 set_ip_family_str);
3212 operation_shutdown (FALSE);
3213 return;
3214 }
3215
3216 input = qmi_message_wds_set_ip_family_input_new ();
3217 qmi_message_wds_set_ip_family_input_set_preference (input, preference, NULL);
3218
3219 g_debug ("Asynchronously set IP family...");
3220 qmi_client_wds_set_ip_family (client,
3221 input,
3222 10,
3223 ctx->cancellable,
3224 (GAsyncReadyCallback) set_ip_family_ready,
3225 NULL);
3226 qmi_message_wds_set_ip_family_input_unref (input);
3227 return;
3228 }
3229 #endif
3230
3231 #if defined HAVE_QMI_MESSAGE_WDS_GET_CURRENT_SETTINGS
3232 if (get_current_settings_flag) {
3233 QmiMessageWdsGetCurrentSettingsInput *input;
3234
3235 input = qmi_message_wds_get_current_settings_input_new ();
3236 qmi_message_wds_get_current_settings_input_set_requested_settings (
3237 input,
3238 (QMI_WDS_REQUESTED_SETTINGS_DNS_ADDRESS |
3239 QMI_WDS_REQUESTED_SETTINGS_GRANTED_QOS |
3240 QMI_WDS_REQUESTED_SETTINGS_IP_ADDRESS |
3241 QMI_WDS_REQUESTED_SETTINGS_GATEWAY_INFO |
3242 QMI_WDS_REQUESTED_SETTINGS_MTU |
3243 QMI_WDS_REQUESTED_SETTINGS_DOMAIN_NAME_LIST |
3244 QMI_WDS_REQUESTED_SETTINGS_IP_FAMILY),
3245 NULL);
3246
3247 g_debug ("Asynchronously getting current settings...");
3248 qmi_client_wds_get_current_settings (client,
3249 input,
3250 10,
3251 ctx->cancellable,
3252 (GAsyncReadyCallback)get_current_settings_ready,
3253 NULL);
3254 qmi_message_wds_get_current_settings_input_unref (input);
3255 return;
3256 }
3257 #endif
3258
3259 #if defined HAVE_QMI_MESSAGE_WDS_GET_PACKET_SERVICE_STATUS
3260 if (get_packet_service_status_flag) {
3261 g_debug ("Asynchronously getting packet service status...");
3262 qmi_client_wds_get_packet_service_status (ctx->client,
3263 NULL,
3264 10,
3265 ctx->cancellable,
3266 (GAsyncReadyCallback)get_packet_service_status_ready,
3267 NULL);
3268 return;
3269 }
3270 #endif
3271
3272 #if defined HAVE_QMI_MESSAGE_WDS_GET_PACKET_STATISTICS
3273 if (get_packet_statistics_flag) {
3274 QmiMessageWdsGetPacketStatisticsInput *input;
3275
3276 input = qmi_message_wds_get_packet_statistics_input_new ();
3277 qmi_message_wds_get_packet_statistics_input_set_mask (
3278 input,
3279 (QMI_WDS_PACKET_STATISTICS_MASK_FLAG_TX_PACKETS_OK |
3280 QMI_WDS_PACKET_STATISTICS_MASK_FLAG_RX_PACKETS_OK |
3281 QMI_WDS_PACKET_STATISTICS_MASK_FLAG_TX_PACKETS_ERROR |
3282 QMI_WDS_PACKET_STATISTICS_MASK_FLAG_RX_PACKETS_ERROR |
3283 QMI_WDS_PACKET_STATISTICS_MASK_FLAG_TX_OVERFLOWS |
3284 QMI_WDS_PACKET_STATISTICS_MASK_FLAG_RX_OVERFLOWS |
3285 QMI_WDS_PACKET_STATISTICS_MASK_FLAG_TX_BYTES_OK |
3286 QMI_WDS_PACKET_STATISTICS_MASK_FLAG_RX_BYTES_OK |
3287 QMI_WDS_PACKET_STATISTICS_MASK_FLAG_TX_PACKETS_DROPPED |
3288 QMI_WDS_PACKET_STATISTICS_MASK_FLAG_RX_PACKETS_DROPPED),
3289 NULL);
3290
3291 g_debug ("Asynchronously getting packet statistics...");
3292 qmi_client_wds_get_packet_statistics (ctx->client,
3293 input,
3294 10,
3295 ctx->cancellable,
3296 (GAsyncReadyCallback)get_packet_statistics_ready,
3297 NULL);
3298 qmi_message_wds_get_packet_statistics_input_unref (input);
3299 return;
3300 }
3301 #endif
3302
3303 #if defined HAVE_QMI_MESSAGE_WDS_GET_DATA_BEARER_TECHNOLOGY
3304 if (get_data_bearer_technology_flag) {
3305 g_debug ("Asynchronously getting data bearer technology...");
3306 qmi_client_wds_get_data_bearer_technology (ctx->client,
3307 NULL,
3308 10,
3309 ctx->cancellable,
3310 (GAsyncReadyCallback)get_data_bearer_technology_ready,
3311 NULL);
3312 return;
3313 }
3314 #endif
3315
3316 #if defined HAVE_QMI_MESSAGE_WDS_GET_CURRENT_DATA_BEARER_TECHNOLOGY
3317 if (get_current_data_bearer_technology_flag) {
3318 g_debug ("Asynchronously getting current data bearer technology...");
3319 qmi_client_wds_get_current_data_bearer_technology (ctx->client,
3320 NULL,
3321 10,
3322 ctx->cancellable,
3323 (GAsyncReadyCallback)get_current_data_bearer_technology_ready,
3324 NULL);
3325 return;
3326 }
3327 #endif
3328
3329 #if defined HAVE_QMI_MESSAGE_WDS_GO_DORMANT
3330 if (go_dormant_flag) {
3331 g_debug ("Asynchronously going dormant...");
3332 qmi_client_wds_go_dormant (ctx->client,
3333 NULL,
3334 10,
3335 ctx->cancellable,
3336 (GAsyncReadyCallback)go_dormant_ready,
3337 NULL);
3338 return;
3339 }
3340 #endif
3341
3342 #if defined HAVE_QMI_MESSAGE_WDS_GO_ACTIVE
3343 if (go_active_flag) {
3344 g_debug ("Asynchronously going active...");
3345 qmi_client_wds_go_active (ctx->client,
3346 NULL,
3347 10,
3348 ctx->cancellable,
3349 (GAsyncReadyCallback)go_active_ready,
3350 NULL);
3351 return;
3352 }
3353 #endif
3354
3355 #if defined HAVE_QMI_MESSAGE_WDS_GET_DORMANCY_STATUS
3356 if (get_dormancy_status_flag) {
3357 g_debug ("Asynchronously getting dormancy status...");
3358 qmi_client_wds_get_dormancy_status (ctx->client,
3359 NULL,
3360 10,
3361 ctx->cancellable,
3362 (GAsyncReadyCallback)get_dormancy_status_ready,
3363 NULL);
3364 return;
3365 }
3366 #endif
3367
3368 #if defined HAVE_QMI_MESSAGE_WDS_CREATE_PROFILE
3369 if (create_profile_str) {
3370 QmiMessageWdsCreateProfileInput *input = NULL;
3371 GError *error = NULL;
3372
3373 if (!create_profile_input_create (create_profile_str, &input, &error)) {
3374 g_printerr ("error: %s\n", error->message);
3375 g_error_free (error);
3376 operation_shutdown (FALSE);
3377 return;
3378 }
3379
3380 g_debug ("Asynchronously creating new profile...");
3381 qmi_client_wds_create_profile (ctx->client,
3382 input,
3383 10,
3384 ctx->cancellable,
3385 (GAsyncReadyCallback)create_profile_ready,
3386 NULL);
3387 qmi_message_wds_create_profile_input_unref (input);
3388 return;
3389 }
3390 #endif
3391
3392 #if defined HAVE_QMI_MESSAGE_WDS_SWI_CREATE_PROFILE_INDEXED
3393 if (swi_create_profile_indexed_str) {
3394 QmiMessageWdsSwiCreateProfileIndexedInput *input = NULL;
3395 GError *error = NULL;
3396
3397 if (!swi_create_profile_indexed_input_create (swi_create_profile_indexed_str, &input, &error)) {
3398 g_printerr ("error: %s\n", error->message);
3399 g_error_free (error);
3400 operation_shutdown (FALSE);
3401 return;
3402 }
3403
3404 g_debug ("Asynchronously creating new indexed profile...");
3405 qmi_client_wds_swi_create_profile_indexed (ctx->client,
3406 input,
3407 10,
3408 ctx->cancellable,
3409 (GAsyncReadyCallback)swi_create_profile_indexed_ready,
3410 NULL);
3411 qmi_message_wds_swi_create_profile_indexed_input_unref (input);
3412 return;
3413 }
3414 #endif
3415
3416 #if defined HAVE_QMI_MESSAGE_WDS_MODIFY_PROFILE
3417 if (modify_profile_str) {
3418 QmiMessageWdsModifyProfileInput *input = NULL;
3419 GError *error = NULL;
3420
3421 if (!modify_profile_input_create (modify_profile_str, &input, &error)) {
3422 g_printerr ("error: %s\n", error->message);
3423 g_error_free (error);
3424 operation_shutdown (FALSE);
3425 return;
3426 }
3427
3428 g_debug ("Asynchronously modifying profile...");
3429 qmi_client_wds_modify_profile (ctx->client,
3430 input,
3431 10,
3432 ctx->cancellable,
3433 (GAsyncReadyCallback)modify_profile_ready,
3434 NULL);
3435 qmi_message_wds_modify_profile_input_unref (input);
3436 return;
3437 }
3438 #endif
3439
3440 #if defined HAVE_QMI_MESSAGE_WDS_DELETE_PROFILE
3441 if (delete_profile_str) {
3442 QmiMessageWdsDeleteProfileInput *input;
3443 gchar **split;
3444 QmiWdsProfileType profile_type;
3445 guint profile_index;
3446
3447 split = g_strsplit (delete_profile_str, ",", -1);
3448
3449 if (g_strv_length (split) != 2) {
3450 g_printerr ("error: expected 2 arguments for delete profile command\n");
3451 operation_shutdown (FALSE);
3452 return;
3453 }
3454
3455 g_strstrip (split[0]);
3456 if (g_str_equal (split[0], "3gpp"))
3457 profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
3458 else if (g_str_equal (split[0], "3gpp2"))
3459 profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
3460 else {
3461 g_printerr ("error: invalid profile type '%s'. Expected '3gpp' or '3gpp2'.'\n",
3462 split[0]);
3463 operation_shutdown (FALSE);
3464 return;
3465 }
3466
3467 g_strstrip (split[1]);
3468 profile_index = atoi (split[1]);
3469 if (profile_index <= 0 || profile_index > G_MAXUINT8) {
3470 g_printerr ("error: invalid or out of range profile number [1,%u]: '%s'\n",
3471 G_MAXUINT8,
3472 split[1]);
3473 operation_shutdown (FALSE);
3474 return;
3475 }
3476
3477 input = qmi_message_wds_delete_profile_input_new ();
3478
3479 qmi_message_wds_delete_profile_input_set_profile_identifier (input, profile_type, (guint8)profile_index, NULL);
3480
3481 g_strfreev (split);
3482
3483 g_debug ("Asynchronously deleting new profile...");
3484 qmi_client_wds_delete_profile (ctx->client,
3485 input,
3486 10,
3487 ctx->cancellable,
3488 (GAsyncReadyCallback)delete_profile_ready,
3489 NULL);
3490 qmi_message_wds_delete_profile_input_unref (input);
3491 return;
3492 }
3493 #endif
3494
3495 #if defined HAVE_QMI_MESSAGE_WDS_GET_PROFILE_LIST && defined HAVE_QMI_MESSAGE_WDS_GET_PROFILE_SETTINGS
3496 if (get_profile_list_str) {
3497 QmiMessageWdsGetProfileListInput *input;
3498 QmiWdsProfileType profile_type;
3499
3500 if (g_str_equal (get_profile_list_str, "3gpp"))
3501 profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
3502 else if (g_str_equal (get_profile_list_str, "3gpp2"))
3503 profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
3504 else {
3505 g_printerr ("error: invalid profile type '%s'. Expected '3gpp' or '3gpp2'.'\n",
3506 get_profile_list_str);
3507 operation_shutdown (FALSE);
3508 return;
3509 }
3510
3511 input = qmi_message_wds_get_profile_list_input_new ();
3512 qmi_message_wds_get_profile_list_input_set_profile_type (input, profile_type, NULL);
3513
3514 g_debug ("Asynchronously get profile list...");
3515 qmi_client_wds_get_profile_list (ctx->client,
3516 input,
3517 10,
3518 ctx->cancellable,
3519 (GAsyncReadyCallback)get_profile_list_ready,
3520 NULL);
3521 qmi_message_wds_get_profile_list_input_unref (input);
3522 return;
3523 }
3524 #endif
3525
3526 #if defined HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_PROFILE_NUMBER
3527 if (get_default_profile_number_str || get_default_profile_num_str) {
3528 g_autoptr(QmiMessageWdsGetDefaultProfileNumberInput) input = NULL;
3529 QmiWdsProfileType profile_type;
3530 const gchar *str;
3531
3532 str = get_default_profile_number_str ? get_default_profile_number_str : get_default_profile_num_str;
3533 if (g_str_equal (str, "3gpp"))
3534 profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
3535 else if (g_str_equal (str, "3gpp2"))
3536 profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
3537 else {
3538 g_printerr ("error: invalid profile type '%s'. Expected '3gpp' or '3gpp2'.'\n", str);
3539 operation_shutdown (FALSE);
3540 return;
3541 }
3542
3543 input = qmi_message_wds_get_default_profile_number_input_new ();
3544 /* always use profile family 'tethered', we don't really know what it means */
3545 qmi_message_wds_get_default_profile_number_input_set_profile_type (input,
3546 profile_type,
3547 QMI_WDS_PROFILE_FAMILY_TETHERED,
3548 NULL);
3549
3550 g_debug ("Asynchronously getting default profile number...");
3551 qmi_client_wds_get_default_profile_number (ctx->client,
3552 input,
3553 10,
3554 ctx->cancellable,
3555 (GAsyncReadyCallback)get_default_profile_number_ready,
3556 NULL);
3557 return;
3558 }
3559 #endif
3560
3561 #if defined HAVE_QMI_MESSAGE_WDS_SET_DEFAULT_PROFILE_NUMBER
3562 if (set_default_profile_number_str || set_default_profile_num_str) {
3563 g_autoptr(QmiMessageWdsSetDefaultProfileNumberInput) input = NULL;
3564
3565 input = set_default_profile_number_input_create (set_default_profile_number_str ? set_default_profile_number_str : set_default_profile_num_str);
3566 if (!input) {
3567 operation_shutdown (FALSE);
3568 return;
3569 }
3570
3571 g_debug ("Asynchronously setting default profile number...");
3572 qmi_client_wds_set_default_profile_number (ctx->client,
3573 input,
3574 10,
3575 ctx->cancellable,
3576 (GAsyncReadyCallback)set_default_profile_number_ready,
3577 NULL);
3578 return;
3579 }
3580 #endif
3581
3582 #if defined HAVE_QMI_MESSAGE_WDS_GET_DEFAULT_SETTINGS
3583 if (get_default_settings_str) {
3584 QmiMessageWdsGetDefaultSettingsInput *input;
3585 QmiWdsProfileType profile_type;
3586
3587 if (g_str_equal (get_default_settings_str, "3gpp"))
3588 profile_type = QMI_WDS_PROFILE_TYPE_3GPP;
3589 else if (g_str_equal (get_default_settings_str, "3gpp2"))
3590 profile_type = QMI_WDS_PROFILE_TYPE_3GPP2;
3591 else {
3592 g_printerr ("error: invalid default type '%s'. Expected '3gpp' or '3gpp2'.'\n",
3593 get_default_settings_str);
3594 operation_shutdown (FALSE);
3595 return;
3596 }
3597
3598 input = qmi_message_wds_get_default_settings_input_new ();
3599 qmi_message_wds_get_default_settings_input_set_profile_type (input, profile_type, NULL);
3600
3601 g_debug ("Asynchronously get default settings...");
3602 qmi_client_wds_get_default_settings (ctx->client,
3603 input,
3604 10,
3605 ctx->cancellable,
3606 (GAsyncReadyCallback)get_default_settings_ready,
3607 NULL);
3608 qmi_message_wds_get_default_settings_input_unref (input);
3609 return;
3610 }
3611 #endif
3612
3613 #if defined HAVE_QMI_MESSAGE_WDS_GET_AUTOCONNECT_SETTINGS
3614 if (get_autoconnect_settings_flag) {
3615 g_debug ("Asynchronously getting autoconnect settings...");
3616 qmi_client_wds_get_autoconnect_settings (ctx->client,
3617 NULL,
3618 10,
3619 ctx->cancellable,
3620 (GAsyncReadyCallback)get_autoconnect_settings_ready,
3621 NULL);
3622 return;
3623 }
3624 #endif
3625
3626 #if defined HAVE_QMI_MESSAGE_WDS_SET_AUTOCONNECT_SETTINGS
3627 if (set_autoconnect_settings_str) {
3628 QmiMessageWdsSetAutoconnectSettingsInput *input;
3629
3630 input = set_autoconnect_settings_input_create (set_autoconnect_settings_str);
3631 if (!input) {
3632 operation_shutdown (FALSE);
3633 return;
3634 }
3635
3636 g_debug ("Asynchronously set autoconnect settings...");
3637 qmi_client_wds_set_autoconnect_settings (ctx->client,
3638 input,
3639 10,
3640 ctx->cancellable,
3641 (GAsyncReadyCallback)set_autoconnect_settings_ready,
3642 NULL);
3643 qmi_message_wds_set_autoconnect_settings_input_unref (input);
3644 return;
3645 }
3646 #endif
3647
3648 #if defined HAVE_QMI_MESSAGE_WDS_GET_SUPPORTED_MESSAGES
3649 if (get_supported_messages_flag) {
3650 g_debug ("Asynchronously getting supported WDS messages...");
3651 qmi_client_wds_get_supported_messages (ctx->client,
3652 NULL,
3653 10,
3654 ctx->cancellable,
3655 (GAsyncReadyCallback)get_supported_messages_ready,
3656 NULL);
3657 return;
3658 }
3659 #endif
3660
3661 #if defined HAVE_QMI_MESSAGE_WDS_RESET
3662 if (reset_flag) {
3663 g_debug ("Asynchronously resetting WDS service...");
3664 qmi_client_wds_reset (ctx->client,
3665 NULL,
3666 10,
3667 ctx->cancellable,
3668 (GAsyncReadyCallback)reset_ready,
3669 NULL);
3670 return;
3671 }
3672 #endif
3673
3674 #if defined HAVE_QMI_MESSAGE_WDS_GET_CHANNEL_RATES
3675 if (get_channel_rates_flag) {
3676 g_debug ("Asynchronously getting channel data rates...");
3677 qmi_client_wds_get_channel_rates (client,
3678 NULL,
3679 10,
3680 ctx->cancellable,
3681 (GAsyncReadyCallback)get_channel_rates_ready,
3682 NULL);
3683 return;
3684 }
3685 #endif
3686
3687 #if defined HAVE_QMI_MESSAGE_WDS_GET_LTE_ATTACH_PARAMETERS
3688 if (get_lte_attach_parameters_flag) {
3689 g_debug ("Asynchronously getting LTE attach parameters...");
3690 qmi_client_wds_get_lte_attach_parameters (client,
3691 NULL,
3692 10,
3693 ctx->cancellable,
3694 (GAsyncReadyCallback)get_lte_attach_parameters_ready,
3695 NULL);
3696 return;
3697 }
3698 #endif
3699
3700 #if defined HAVE_QMI_MESSAGE_WDS_GET_MAX_LTE_ATTACH_PDN_NUMBER
3701 if (get_max_lte_attach_pdn_number_flag) {
3702 g_debug ("Asynchronously getting max LTE attach PDN number...");
3703 qmi_client_wds_get_max_lte_attach_pdn_number (client,
3704 NULL,
3705 10,
3706 ctx->cancellable,
3707 (GAsyncReadyCallback)get_max_lte_attach_pdn_number_ready,
3708 NULL);
3709 return;
3710 }
3711 #endif
3712
3713 #if defined HAVE_QMI_MESSAGE_WDS_GET_LTE_ATTACH_PDN_LIST
3714 if (get_lte_attach_pdn_list_flag) {
3715 g_debug ("Asynchronously getting LTE Attach PDN list...");
3716 qmi_client_wds_get_lte_attach_pdn_list (client,
3717 NULL,
3718 10,
3719 ctx->cancellable,
3720 (GAsyncReadyCallback)get_lte_attach_pdn_list_ready,
3721 NULL);
3722 return;
3723 }
3724 #endif
3725
3726 #if defined HAVE_QMI_MESSAGE_WDS_SET_LTE_ATTACH_PDN_LIST
3727 if (set_lte_attach_pdn_list_str) {
3728 g_autoptr(QmiMessageWdsSetLteAttachPdnListInput) input = NULL;
3729
3730 input = set_lte_attach_pdn_list_input_create (set_lte_attach_pdn_list_str);
3731 g_debug ("Asynchronously setting LTE Attach PDN list...");
3732 qmi_client_wds_set_lte_attach_pdn_list (client,
3733 input,
3734 10,
3735 ctx->cancellable,
3736 (GAsyncReadyCallback) set_lte_attach_pdn_list_ready,
3737 NULL);
3738 return;
3739 }
3740 #endif
3741
3742 /* Just client allocate/release? */
3743 if (noop_flag) {
3744 g_idle_add (noop_cb, NULL);
3745 return;
3746 }
3747
3748 g_warn_if_reached ();
3749 }
3750
3751 #endif /* HAVE_QMI_SERVICE_WDS */