Debian Codegraph @

src/qmicli/qmicli-nas.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) 2012-2017 Aleksander Morgado <[email protected]>
19 * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc.
20 */
21
22 #include "config.h"
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <locale.h>
27 #include <string.h>
28
29 #include <glib.h>
30 #include <gio/gio.h>
31
32 #include <libqmi-glib.h>
33
34 #include "qmicli.h"
35 #include "qmicli-helpers.h"
36
37 #if defined HAVE_QMI_SERVICE_NAS
38
39 #undef VALIDATE_MASK_NONE
40 #define VALIDATE_MASK_NONE(str) (str ? str : "none")
41
42 /* Context */
43 typedef struct {
44 QmiDevice *device;
45 QmiClientNas *client;
46 GCancellable *cancellable;
47
48 /* For Incremental Network Scan indication */
49 guint network_scan_indication_id;
50 } Context;
51 static Context *ctx;
52
53 /* Options */
54 static gboolean get_signal_strength_flag;
55 static gboolean get_signal_info_flag;
56 static gchar *get_tx_rx_info_str;
57 static gboolean get_home_network_flag;
58 static gboolean get_serving_system_flag;
59 static gboolean get_system_info_flag;
60 static gboolean get_technology_preference_flag;
61 static gboolean get_preferred_networks_flag;
62 static gchar *set_preferred_networks_str;
63 static gboolean get_system_selection_preference_flag;
64 static gchar *set_system_selection_preference_str;
65 static gchar *get_plmn_name_str;
66 #if defined HAVE_QMI_MESSAGE_NAS_NETWORK_SCAN
67 static gchar *network_scan_str;
68 #endif
69 static gboolean network_scan_flag;
70 #if defined HAVE_QMI_MESSAGE_NAS_INCREMENTAL_NETWORK_SCAN
71 static gchar *incremental_network_scan_str;
72 #endif
73 static gboolean incremental_network_scan_flag;
74 static gboolean get_cell_location_info_flag;
75 static gboolean force_network_search_flag;
76 static gboolean get_operator_name_flag;
77 static gboolean get_lte_cphy_ca_info_flag;
78 static gboolean get_rf_band_info_flag;
79 static gboolean get_network_time_flag;
80 static gboolean get_drx_flag;
81 static gboolean get_endc_config_flag;
82 static gboolean get_supported_messages_flag;
83 static gboolean swi_get_status_flag;
84 static gboolean reset_flag;
85 static gboolean noop_flag;
86
87 #if defined HAVE_QMI_MESSAGE_NAS_NETWORK_SCAN
88 static gboolean
89 parse_network_scan (const gchar *option_name,
90 const gchar *value,
91 gpointer data,
92 GError **error)
93 {
94 network_scan_flag = TRUE;
95 if (value && value[0])
96 network_scan_str = g_strdup (value);
97 return TRUE;
98 }
99 #endif
100
101 #if defined HAVE_QMI_MESSAGE_NAS_INCREMENTAL_NETWORK_SCAN
102 static gboolean
103 parse_incremental_network_scan (const gchar *option_name,
104 const gchar *value,
105 gpointer data,
106 GError **error)
107 {
108 incremental_network_scan_flag = TRUE;
109 if (value && value[0])
110 incremental_network_scan_str = g_strdup (value);
111 return TRUE;
112 }
113 #endif
114
115 static GOptionEntry entries[] = {
116 #if defined HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_STRENGTH
117 { "nas-get-signal-strength", 0, 0, G_OPTION_ARG_NONE, &get_signal_strength_flag,
118 "Get signal strength",
119 NULL
120 },
121 #endif
122 #if defined HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_INFO
123 { "nas-get-signal-info", 0, 0, G_OPTION_ARG_NONE, &get_signal_info_flag,
124 "Get signal info",
125 NULL
126 },
127 #endif
128 #if defined HAVE_QMI_MESSAGE_NAS_GET_TX_RX_INFO
129 { "nas-get-tx-rx-info", 0, 0, G_OPTION_ARG_STRING, &get_tx_rx_info_str,
130 "Get TX/RX info",
131 "[(Radio Interface)]",
132 },
133 #endif
134 #if defined HAVE_QMI_MESSAGE_NAS_GET_HOME_NETWORK
135 { "nas-get-home-network", 0, 0, G_OPTION_ARG_NONE, &get_home_network_flag,
136 "Get home network",
137 NULL
138 },
139 #endif
140 #if defined HAVE_QMI_MESSAGE_NAS_GET_SERVING_SYSTEM
141 { "nas-get-serving-system", 0, 0, G_OPTION_ARG_NONE, &get_serving_system_flag,
142 "Get serving system",
143 NULL
144 },
145 #endif
146 #if defined HAVE_QMI_MESSAGE_NAS_GET_SYSTEM_INFO
147 { "nas-get-system-info", 0, 0, G_OPTION_ARG_NONE, &get_system_info_flag,
148 "Get system info",
149 NULL
150 },
151 #endif
152 #if defined HAVE_QMI_MESSAGE_NAS_GET_TECHNOLOGY_PREFERENCE
153 { "nas-get-technology-preference", 0, 0, G_OPTION_ARG_NONE, &get_technology_preference_flag,
154 "Get technology preference",
155 NULL
156 },
157 #endif
158 #if defined HAVE_QMI_MESSAGE_NAS_GET_PREFERRED_NETWORKS
159 { "nas-get-preferred-networks", 0, 0, G_OPTION_ARG_NONE, &get_preferred_networks_flag,
160 "Get preferred networks",
161 NULL
162 },
163 #endif
164 #if defined HAVE_QMI_MESSAGE_NAS_SET_PREFERRED_NETWORKS
165 { "nas-set-preferred-networks", 0, 0, G_OPTION_ARG_STRING, &set_preferred_networks_str,
166 "Set preferred networks list",
167 "[[MCCMNC,access_tech],...]"
168 },
169 #endif
170 #if defined HAVE_QMI_MESSAGE_NAS_GET_SYSTEM_SELECTION_PREFERENCE
171 { "nas-get-system-selection-preference", 0, 0, G_OPTION_ARG_NONE, &get_system_selection_preference_flag,
172 "Get system selection preference",
173 NULL
174 },
175 #endif
176 #if defined HAVE_QMI_MESSAGE_NAS_SET_SYSTEM_SELECTION_PREFERENCE
177 { "nas-set-system-selection-preference", 0, 0, G_OPTION_ARG_STRING, &set_system_selection_preference_str,
178 "Set system selection preference",
179 "[cdma-1x|cdma-1xevdo|gsm|umts|lte|td-scdma][,[automatic|manual=MCCMNC]]"
180 },
181 #endif
182 #if defined HAVE_QMI_MESSAGE_NAS_NETWORK_SCAN
183 { "nas-network-scan", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, parse_network_scan,
184 "Scan all networks (no argument) or scan one specific network type",
185 "[gsm|umts|lte|td-scdma|5gnr]",
186 },
187 #endif
188 #if defined HAVE_QMI_MESSAGE_NAS_INCREMENTAL_NETWORK_SCAN
189 { "nas-incremental-network-scan", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, parse_incremental_network_scan,
190 "Incrementally scan all networks (no argument) or scan one specific network type",
191 "[gsm|umts|lte|td-scdma|5gnr]",
192 },
193 #endif
194 #if defined HAVE_QMI_MESSAGE_NAS_GET_CELL_LOCATION_INFO
195 { "nas-get-cell-location-info", 0, 0, G_OPTION_ARG_NONE, &get_cell_location_info_flag,
196 "Get Cell Location Info",
197 NULL
198 },
199 #endif
200 #if defined HAVE_QMI_MESSAGE_NAS_FORCE_NETWORK_SEARCH
201 { "nas-force-network-search", 0, 0, G_OPTION_ARG_NONE, &force_network_search_flag,
202 "Force network search",
203 NULL
204 },
205 #endif
206 #if defined HAVE_QMI_MESSAGE_NAS_GET_OPERATOR_NAME
207 { "nas-get-operator-name", 0, 0, G_OPTION_ARG_NONE, &get_operator_name_flag,
208 "Get operator name data",
209 NULL
210 },
211 #endif
212 #if defined HAVE_QMI_MESSAGE_NAS_GET_PLMN_NAME
213 { "nas-get-plmn-name", 0, 0, G_OPTION_ARG_STRING, &get_plmn_name_str,
214 "Get plmn name data",
215 "[mccmnc]"
216 },
217 #endif
218 #if defined HAVE_QMI_MESSAGE_NAS_GET_LTE_CPHY_CA_INFO
219 { "nas-get-lte-cphy-ca-info", 0, 0, G_OPTION_ARG_NONE, &get_lte_cphy_ca_info_flag,
220 "Get LTE Cphy CA Info",
221 NULL
222 },
223 #endif
224 #if defined HAVE_QMI_MESSAGE_NAS_GET_RF_BAND_INFORMATION
225 { "nas-get-rf-band-info", 0, 0, G_OPTION_ARG_NONE, &get_rf_band_info_flag,
226 "Get RF Band Info",
227 NULL
228 },
229 #endif
230 #if defined HAVE_QMI_MESSAGE_NAS_GET_NETWORK_TIME
231 { "nas-get-network-time", 0, 0, G_OPTION_ARG_NONE, &get_network_time_flag,
232 "Get Network Time",
233 NULL
234 },
235 #endif
236 #if defined HAVE_QMI_MESSAGE_NAS_GET_DRX
237 { "nas-get-drx", 0, 0, G_OPTION_ARG_NONE, &get_drx_flag,
238 "Get DRX",
239 NULL
240 },
241 #endif
242 #if defined HAVE_QMI_MESSAGE_NAS_GET_ENDC_CONFIG
243 { "nas-get-endc-config", 0, 0, G_OPTION_ARG_NONE, &get_endc_config_flag,
244 "Get EN-DC Config",
245 NULL
246 },
247 #endif
248 #if defined HAVE_QMI_MESSAGE_NAS_GET_SUPPORTED_MESSAGES
249 { "nas-get-supported-messages", 0, 0, G_OPTION_ARG_NONE, &get_supported_messages_flag,
250 "Get supported messages",
251 NULL
252 },
253 #endif
254 #if defined HAVE_QMI_MESSAGE_NAS_SWI_GET_STATUS
255 { "nas-swi-get-status", 0, 0, G_OPTION_ARG_NONE, &swi_get_status_flag,
256 "Get status ((Sierra Wireless specific)",
257 NULL
258 },
259 #endif
260 #if defined HAVE_QMI_MESSAGE_NAS_RESET
261 { "nas-reset", 0, 0, G_OPTION_ARG_NONE, &reset_flag,
262 "Reset the service state",
263 NULL
264 },
265 #endif
266 { "nas-noop", 0, 0, G_OPTION_ARG_NONE, &noop_flag,
267 "Just allocate or release a NAS client. Use with `--client-no-release-cid' and/or `--client-cid'",
268 NULL
269 },
270 { NULL, 0, 0, 0, NULL, NULL, NULL }
271 };
272
273 GOptionGroup *
274 qmicli_nas_get_option_group (void)
275 {
276 GOptionGroup *group;
277
278 group = g_option_group_new ("nas",
279 "NAS options:",
280 "Show Network Access Service options",
281 NULL,
282 NULL);
283 g_option_group_add_entries (group, entries);
284
285 return group;
286 }
287
288 gboolean
289 qmicli_nas_options_enabled (void)
290 {
291 static guint n_actions = 0;
292 static gboolean checked = FALSE;
293
294 if (checked)
295 return !!n_actions;
296
297 n_actions = (get_signal_strength_flag +
298 get_signal_info_flag +
299 !!get_tx_rx_info_str +
300 get_home_network_flag +
301 get_serving_system_flag +
302 get_system_info_flag +
303 get_technology_preference_flag +
304 get_preferred_networks_flag +
305 !!set_preferred_networks_str +
306 get_system_selection_preference_flag +
307 !!set_system_selection_preference_str +
308 !!get_plmn_name_str +
309 network_scan_flag +
310 incremental_network_scan_flag +
311 get_cell_location_info_flag +
312 force_network_search_flag +
313 get_operator_name_flag +
314 get_lte_cphy_ca_info_flag +
315 get_rf_band_info_flag +
316 get_network_time_flag +
317 get_drx_flag +
318 get_endc_config_flag +
319 get_supported_messages_flag +
320 swi_get_status_flag +
321 reset_flag +
322 noop_flag);
323
324 if (n_actions > 1) {
325 g_printerr ("error: too many NAS actions requested\n");
326 exit (EXIT_FAILURE);
327 }
328
329 /* Actions that require receiving QMI indication messages must specify that
330 * indications are expected. */
331 if (incremental_network_scan_flag)
332 qmicli_expect_indications ();
333
334 checked = TRUE;
335 return !!n_actions;
336 }
337
338 static void
339 context_free (Context *context)
340 {
341 if (!context)
342 return;
343
344 if (context->network_scan_indication_id)
345 g_signal_handler_disconnect (context->client,
346 context->network_scan_indication_id);
347
348 if (context->cancellable)
349 g_object_unref (context->cancellable);
350 if (context->device)
351 g_object_unref (context->device);
352 if (context->client)
353 g_object_unref (context->client);
354 g_slice_free (Context, context);
355 }
356
357 static void
358 operation_shutdown (gboolean operation_status)
359 {
360 /* Cleanup context and finish async operation */
361 context_free (ctx);
362 qmicli_async_operation_done (operation_status, FALSE);
363 }
364
365 #if defined HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_INFO || \
366 defined HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_STRENGTH
367
368 static gboolean
369 get_db_from_sinr_level (QmiNasEvdoSinrLevel level,
370 gdouble *out)
371 {
372 g_assert (out != NULL);
373
374 switch (level) {
375 case QMI_NAS_EVDO_SINR_LEVEL_0:
376 *out = -9.0;
377 return TRUE;
378 case QMI_NAS_EVDO_SINR_LEVEL_1:
379 *out = -6.0;
380 return TRUE;
381 case QMI_NAS_EVDO_SINR_LEVEL_2:
382 *out = -4.5;
383 return TRUE;
384 case QMI_NAS_EVDO_SINR_LEVEL_3:
385 *out = -3.0;
386 return TRUE;
387 case QMI_NAS_EVDO_SINR_LEVEL_4:
388 *out = -2.0;
389 return TRUE;
390 case QMI_NAS_EVDO_SINR_LEVEL_5:
391 *out = 1.0;
392 return TRUE;
393 case QMI_NAS_EVDO_SINR_LEVEL_6:
394 *out = 3.0;
395 return TRUE;
396 case QMI_NAS_EVDO_SINR_LEVEL_7:
397 *out = 6.0;
398 return TRUE;
399 case QMI_NAS_EVDO_SINR_LEVEL_8:
400 *out = 9.0;
401 return TRUE;
402 default:
403 g_warning ("Invalid SINR level '%u'", level);
404 return FALSE;
405 }
406 }
407
408 #endif /* HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_INFO
409 * HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_STRENGTH */
410
411 #if defined HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_INFO
412
413 static void
414 get_signal_info_ready (QmiClientNas *client,
415 GAsyncResult *res)
416 {
417 QmiMessageNasGetSignalInfoOutput *output;
418 GError *error = NULL;
419 gint8 rssi;
420 gint16 ecio;
421 QmiNasEvdoSinrLevel sinr_level;
422 gint32 io;
423 gint8 rsrq;
424 gint16 rsrp;
425 gint16 snr;
426 gint8 rscp;
427 gint16 wcdma_rscp;
428 gint16 rsrq_5g;
429 gint32 rssi_tdma;
430 gint32 rscp_tdma;
431 gint32 ecio_tdma;
432 gint32 sinr_tdma;
433
434 output = qmi_client_nas_get_signal_info_finish (client, res, &error);
435 if (!output) {
436 g_printerr ("error: operation failed: %s\n", error->message);
437 g_error_free (error);
438 operation_shutdown (FALSE);
439 return;
440 }
441
442 if (!qmi_message_nas_get_signal_info_output_get_result (output, &error)) {
443 g_printerr ("error: couldn't get signal info: %s\n", error->message);
444 g_error_free (error);
445 qmi_message_nas_get_signal_info_output_unref (output);
446 operation_shutdown (FALSE);
447 return;
448 }
449
450 g_print ("[%s] Successfully got signal info\n",
451 qmi_device_get_path_display (ctx->device));
452
453 /* CDMA... */
454 if (qmi_message_nas_get_signal_info_output_get_cdma_signal_strength (output,
455 &rssi,
456 &ecio,
457 NULL)) {
458 g_print ("CDMA:\n"
459 "\tRSSI: '%d dBm'\n"
460 "\tECIO: '%.1lf dBm'\n",
461 rssi,
462 (-0.5)*((gdouble)ecio));
463 }
464
465 /* HDR... */
466 if (qmi_message_nas_get_signal_info_output_get_hdr_signal_strength (output,
467 &rssi,
468 &ecio,
469 &sinr_level,
470 &io,
471 NULL)) {
472 gdouble db_sinr = 0.0;
473
474 g_print ("HDR:\n"
475 "\tRSSI: '%d dBm'\n"
476 "\tECIO: '%.1lf dBm'\n"
477 "\tIO: '%d dBm'\n",
478 rssi,
479 (-0.5)*((gdouble)ecio),
480 io);
481
482 if (get_db_from_sinr_level (sinr_level, &db_sinr))
483 g_print ("\tSINR (%u): '%.1lf dB'\n", sinr_level, db_sinr);
484 else
485 g_print ("\tSINR (%u): N/A'\n", sinr_level);
486 }
487
488 /* GSM */
489 if (qmi_message_nas_get_signal_info_output_get_gsm_signal_strength (output,
490 &rssi,
491 NULL)) {
492 g_print ("GSM:\n"
493 "\tRSSI: '%d dBm'\n",
494 rssi);
495 }
496
497 /* WCDMA... */
498 if (qmi_message_nas_get_signal_info_output_get_wcdma_signal_strength (output,
499 &rssi,
500 &ecio,
501 NULL)) {
502 g_print ("WCDMA:\n"
503 "\tRSSI: '%d dBm'\n"
504 "\tECIO: '%.1lf dBm'\n",
505 rssi,
506 (-0.5)*((gdouble)ecio));
507 }
508
509 /* WCDMA Signal Code Power... */
510 if (qmi_message_nas_get_signal_info_output_get_wcdma_rscp (output,
511 &wcdma_rscp,
512 NULL)) {
513 g_print ("\tRSCP: '%d dBm'\n",
514 (-1)*wcdma_rscp);
515 }
516
517 /* LTE... */
518 if (qmi_message_nas_get_signal_info_output_get_lte_signal_strength (output,
519 &rssi,
520 &rsrq,
521 &rsrp,
522 &snr,
523 NULL)) {
524 g_print ("LTE:\n"
525 "\tRSSI: '%d dBm'\n"
526 "\tRSRQ: '%d dB'\n"
527 "\tRSRP: '%d dBm'\n"
528 "\tSNR: '%.1lf dB'\n",
529 rssi,
530 rsrq,
531 rsrp,
532 (0.1) * ((gdouble)snr));
533 }
534
535 /* TDMA */
536 if (qmi_message_nas_get_signal_info_output_get_tdma_signal_strength (output,
537 &rscp,
538 NULL)) {
539 g_print ("TDMA:\n"
540 "\tRSCP: '%d dBm'\n",
541 rscp);
542 }
543
544 /* TDMA extended */
545 if (qmi_message_nas_get_signal_info_output_get_tdma_signal_strength_extended (output,
546 &rssi_tdma,
547 &rscp_tdma,
548 &ecio_tdma,
549 &sinr_tdma,
550 NULL)) {
551 g_print ("\tRSSI: '%d dB'\n"
552 "\tRSCP: '%d dBm'\n"
553 "\tECIO: '%d dBm'\n"
554 "\tSINR: '%d dB'\n",
555 rssi_tdma,
556 rscp_tdma,
557 ecio_tdma,
558 sinr_tdma);
559 }
560
561 /* 5G, values of -32768 in EN-DC mode indicate the modem is not connected... */
562 if (qmi_message_nas_get_signal_info_output_get_5g_signal_strength (output,
563 &rsrp,
564 &snr,
565 NULL)) {
566 g_print ("5G:\n");
567 if (rsrp == (gint16)(0x8000))
568 g_print ("\tRSRP: 'n/a'\n");
569 else
570 g_print ("\tRSRP: '%d dBm'\n", rsrp);
571 if (snr == (gint16)(0x8000))
572 g_print ("\tSNR: 'n/a'\n");
573 else
574 g_print ("\tSNR: '%.1lf dB'\n", (0.1) * ((gdouble)snr));
575 }
576
577 /* 5G extended... */
578 if (qmi_message_nas_get_signal_info_output_get_5g_signal_strength_extended (output,
579 &rsrq_5g,
580 NULL)) {
581 if (rsrq_5g == (gint16)(0x8000))
582 g_print ("\tRSRQ: 'n/a'\n");
583 else
584 g_print ("\tRSRQ: '%d dB'\n",
585 rsrq_5g);
586 }
587
588 qmi_message_nas_get_signal_info_output_unref (output);
589 operation_shutdown (TRUE);
590 }
591
592 #endif /* HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_INFO */
593
594 #if defined HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_STRENGTH
595
596 static QmiMessageNasGetSignalStrengthInput *
597 get_signal_strength_input_create (void)
598 {
599 GError *error = NULL;
600 QmiMessageNasGetSignalStrengthInput *input;
601 QmiNasSignalStrengthRequest mask;
602
603 mask = (QMI_NAS_SIGNAL_STRENGTH_REQUEST_RSSI |
604 QMI_NAS_SIGNAL_STRENGTH_REQUEST_ECIO |
605 QMI_NAS_SIGNAL_STRENGTH_REQUEST_IO |
606 QMI_NAS_SIGNAL_STRENGTH_REQUEST_SINR |
607 QMI_NAS_SIGNAL_STRENGTH_REQUEST_RSRQ |
608 QMI_NAS_SIGNAL_STRENGTH_REQUEST_LTE_SNR |
609 QMI_NAS_SIGNAL_STRENGTH_REQUEST_LTE_RSRP);
610
611 input = qmi_message_nas_get_signal_strength_input_new ();
612 if (!qmi_message_nas_get_signal_strength_input_set_request_mask (
613 input,
614 mask,
615 &error)) {
616 g_printerr ("error: couldn't create input data bundle: '%s'\n",
617 error->message);
618 g_error_free (error);
619 qmi_message_nas_get_signal_strength_input_unref (input);
620 input = NULL;
621 }
622
623 return input;
624 }
625
626 static void
627 get_signal_strength_ready (QmiClientNas *client,
628 GAsyncResult *res)
629 {
630 QmiMessageNasGetSignalStrengthOutput *output;
631 GError *error = NULL;
632 GArray *array;
633 QmiNasRadioInterface radio_interface;
634 gint8 strength;
635 gint32 io;
636 QmiNasEvdoSinrLevel sinr_level;
637 gint8 rsrq;
638 gint16 rsrp;
639 gint16 snr;
640
641 output = qmi_client_nas_get_signal_strength_finish (client, res, &error);
642 if (!output) {
643 g_printerr ("error: operation failed: %s\n", error->message);
644 g_error_free (error);
645 operation_shutdown (FALSE);
646 return;
647 }
648
649 if (!qmi_message_nas_get_signal_strength_output_get_result (output, &error)) {
650 g_printerr ("error: couldn't get signal strength: %s\n", error->message);
651 g_error_free (error);
652 qmi_message_nas_get_signal_strength_output_unref (output);
653 operation_shutdown (FALSE);
654 return;
655 }
656
657 qmi_message_nas_get_signal_strength_output_get_signal_strength (output,
658 &strength,
659 &radio_interface,
660 NULL);
661
662 g_print ("[%s] Successfully got signal strength\n"
663 "Current:\n"
664 "\tNetwork '%s': '%d dBm'\n",
665 qmi_device_get_path_display (ctx->device),
666 qmi_nas_radio_interface_get_string (radio_interface),
667 strength);
668
669 /* Other signal strengths in other networks... */
670 if (qmi_message_nas_get_signal_strength_output_get_strength_list (output, &array, NULL)) {
671 guint i;
672
673 g_print ("Other:\n");
674 for (i = 0; i < array->len; i++) {
675 QmiMessageNasGetSignalStrengthOutputStrengthListElement *element;
676
677 element = &g_array_index (array, QmiMessageNasGetSignalStrengthOutputStrengthListElement, i);
678 g_print ("\tNetwork '%s': '%d dBm'\n",
679 qmi_nas_radio_interface_get_string (element->radio_interface),
680 element->strength);
681 }
682 }
683
684 /* RSSI... */
685 if (qmi_message_nas_get_signal_strength_output_get_rssi_list (output, &array, NULL)) {
686 guint i;
687
688 g_print ("RSSI:\n");
689 for (i = 0; i < array->len; i++) {
690 QmiMessageNasGetSignalStrengthOutputRssiListElement *element;
691
692 element = &g_array_index (array, QmiMessageNasGetSignalStrengthOutputRssiListElement, i);
693 g_print ("\tNetwork '%s': '%d dBm'\n",
694 qmi_nas_radio_interface_get_string (element->radio_interface),
695 (-1) * element->rssi);
696 }
697 }
698
699 /* ECIO... */
700 if (qmi_message_nas_get_signal_strength_output_get_ecio_list (output, &array, NULL)) {
701 guint i;
702
703 g_print ("ECIO:\n");
704 for (i = 0; i < array->len; i++) {
705 QmiMessageNasGetSignalStrengthOutputEcioListElement *element;
706
707 element = &g_array_index (array, QmiMessageNasGetSignalStrengthOutputEcioListElement, i);
708 g_print ("\tNetwork '%s': '%.1lf dBm'\n",
709 qmi_nas_radio_interface_get_string (element->radio_interface),
710 (-0.5) * ((gdouble)element->ecio));
711 }
712 }
713
714 /* IO... */
715 if (qmi_message_nas_get_signal_strength_output_get_io (output, &io, NULL)) {
716 g_print ("IO: '%d dBm'\n", io);
717 }
718
719 /* SINR level */
720 if (qmi_message_nas_get_signal_strength_output_get_sinr (output, &sinr_level, NULL)) {
721 gdouble db_sinr = 0.0;
722
723 if (get_db_from_sinr_level (sinr_level, &db_sinr))
724 g_print ("SINR (%u): '%.1lf dB'\n", sinr_level, db_sinr);
725 else
726 g_print ("SINR (%u): N/A'\n", sinr_level);
727 }
728
729 /* RSRQ */
730 if (qmi_message_nas_get_signal_strength_output_get_rsrq (output, &rsrq, &radio_interface, NULL)) {
731 g_print ("RSRQ:\n"
732 "\tNetwork '%s': '%d dB'\n",
733 qmi_nas_radio_interface_get_string (radio_interface),
734 rsrq);
735 }
736
737 /* LTE SNR */
738 if (qmi_message_nas_get_signal_strength_output_get_lte_snr (output, &snr, NULL)) {
739 g_print ("SNR:\n"
740 "\tNetwork '%s': '%.1lf dB'\n",
741 qmi_nas_radio_interface_get_string (QMI_NAS_RADIO_INTERFACE_LTE),
742 (0.1) * ((gdouble)snr));
743 }
744
745 /* LTE RSRP */
746 if (qmi_message_nas_get_signal_strength_output_get_lte_rsrp (output, &rsrp, NULL)) {
747 g_print ("RSRP:\n"
748 "\tNetwork '%s': '%d dBm'\n",
749 qmi_nas_radio_interface_get_string (QMI_NAS_RADIO_INTERFACE_LTE),
750 rsrp);
751 }
752
753 /* Just skip others for now */
754
755 qmi_message_nas_get_signal_strength_output_unref (output);
756 operation_shutdown (TRUE);
757 }
758
759 #endif /* HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_STRENGTH */
760
761 #if defined HAVE_QMI_MESSAGE_NAS_GET_TX_RX_INFO
762
763 static void
764 get_tx_rx_info_ready (QmiClientNas *client,
765 GAsyncResult *res,
766 gpointer user_data)
767 {
768 QmiNasRadioInterface interface;
769 QmiMessageNasGetTxRxInfoOutput *output;
770 GError *error = NULL;
771 gboolean is_radio_tuned;
772 gboolean is_in_traffic;
773 gint32 power;
774 gint32 ecio;
775 gint32 rscp;
776 gint32 rsrp;
777 guint32 phase;
778
779 interface = GPOINTER_TO_UINT (user_data);
780
781 output = qmi_client_nas_get_tx_rx_info_finish (client, res, &error);
782 if (!output) {
783 g_printerr ("error: operation failed: %s\n", error->message);
784 g_error_free (error);
785 operation_shutdown (FALSE);
786 return;
787 }
788
789 if (!qmi_message_nas_get_tx_rx_info_output_get_result (output, &error)) {
790 g_printerr ("error: couldn't get TX/RX info: %s\n", error->message);
791 g_error_free (error);
792 qmi_message_nas_get_tx_rx_info_output_unref (output);
793 operation_shutdown (FALSE);
794 return;
795 }
796
797 g_print ("[%s] Successfully got TX/RX info\n",
798 qmi_device_get_path_display (ctx->device));
799
800 /* RX Channel 0 */
801 if (qmi_message_nas_get_tx_rx_info_output_get_rx_chain_0_info (
802 output,
803 &is_radio_tuned,
804 &power,
805 &ecio,
806 &rscp,
807 &rsrp,
808 &phase,
809 NULL)) {
810 g_print ("RX Chain 0:\n"
811 "\tRadio tuned: '%s'\n"
812 "\tPower: '%.1lf dBm'\n",
813 is_radio_tuned ? "yes" : "no",
814 (0.1) * ((gdouble)power));
815 if (interface == QMI_NAS_RADIO_INTERFACE_CDMA_1X ||
816 interface == QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO ||
817 interface == QMI_NAS_RADIO_INTERFACE_GSM ||
818 interface == QMI_NAS_RADIO_INTERFACE_UMTS ||
819 interface == QMI_NAS_RADIO_INTERFACE_LTE ||
820 interface == QMI_NAS_RADIO_INTERFACE_5GNR)
821 g_print ("\tECIO: '%.1lf dB'\n", (0.1) * ((gdouble)ecio));
822
823 if (interface == QMI_NAS_RADIO_INTERFACE_UMTS)
824 g_print ("\tRSCP: '%.1lf dBm'\n", (0.1) * ((gdouble)rscp));
825
826 if (interface == QMI_NAS_RADIO_INTERFACE_LTE ||
827 interface == QMI_NAS_RADIO_INTERFACE_5GNR)
828 g_print ("\tRSRP: '%.1lf dBm'\n", (0.1) * ((gdouble)rsrp));
829
830 if (interface == QMI_NAS_RADIO_INTERFACE_LTE ||
831 interface == QMI_NAS_RADIO_INTERFACE_5GNR) {
832 if (phase == 0xFFFFFFFF)
833 g_print ("\tPhase: 'unknown'\n");
834 else
835 g_print ("\tPhase: '%.2lf degrees'\n", (0.01) * ((gdouble)phase));
836 }
837 }
838
839 /* RX Channel 1 */
840 if (qmi_message_nas_get_tx_rx_info_output_get_rx_chain_1_info (
841 output,
842 &is_radio_tuned,
843 &power,
844 &ecio,
845 &rscp,
846 &rsrp,
847 &phase,
848 NULL)) {
849 g_print ("RX Chain 1:\n"
850 "\tRadio tuned: '%s'\n"
851 "\tPower: '%.1lf dBm'\n",
852 is_radio_tuned ? "yes" : "no",
853 (0.1) * ((gdouble)power));
854 if (interface == QMI_NAS_RADIO_INTERFACE_CDMA_1X ||
855 interface == QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO ||
856 interface == QMI_NAS_RADIO_INTERFACE_GSM ||
857 interface == QMI_NAS_RADIO_INTERFACE_UMTS ||
858 interface == QMI_NAS_RADIO_INTERFACE_LTE ||
859 interface == QMI_NAS_RADIO_INTERFACE_5GNR)
860 g_print ("\tECIO: '%.1lf dB'\n", (0.1) * ((gdouble)ecio));
861
862 if (interface == QMI_NAS_RADIO_INTERFACE_UMTS)
863 g_print ("\tRSCP: '%.1lf dBm'\n", (0.1) * ((gdouble)rscp));
864
865 if (interface == QMI_NAS_RADIO_INTERFACE_LTE ||
866 interface == QMI_NAS_RADIO_INTERFACE_5GNR)
867 g_print ("\tRSRP: '%.1lf dBm'\n", (0.1) * ((gdouble)rsrp));
868
869 if (interface == QMI_NAS_RADIO_INTERFACE_LTE ||
870 interface == QMI_NAS_RADIO_INTERFACE_5GNR) {
871 if (phase == 0xFFFFFFFF)
872 g_print ("\tPhase: 'unknown'\n");
873 else
874 g_print ("\tPhase: '%.2lf degrees'\n", (0.01) * ((gdouble)phase));
875 }
876 }
877
878 /* RX Channel 2 */
879 if (qmi_message_nas_get_tx_rx_info_output_get_rx_chain_2_info (
880 output,
881 &is_radio_tuned,
882 &power,
883 &ecio,
884 &rscp,
885 &rsrp,
886 &phase,
887 NULL)) {
888 g_print ("RX Chain 2:\n"
889 "\tRadio tuned: '%s'\n"
890 "\tPower: '%.1lf dBm'\n",
891 is_radio_tuned ? "yes" : "no",
892 (0.1) * ((gdouble)power));
893 if (interface == QMI_NAS_RADIO_INTERFACE_CDMA_1X ||
894 interface == QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO ||
895 interface == QMI_NAS_RADIO_INTERFACE_GSM ||
896 interface == QMI_NAS_RADIO_INTERFACE_UMTS ||
897 interface == QMI_NAS_RADIO_INTERFACE_LTE ||
898 interface == QMI_NAS_RADIO_INTERFACE_5GNR)
899 g_print ("\tECIO: '%.1lf dB'\n", (0.1) * ((gdouble)ecio));
900
901 if (interface == QMI_NAS_RADIO_INTERFACE_UMTS)
902 g_print ("\tRSCP: '%.1lf dBm'\n", (0.1) * ((gdouble)rscp));
903
904 if (interface == QMI_NAS_RADIO_INTERFACE_LTE ||
905 interface == QMI_NAS_RADIO_INTERFACE_5GNR)
906 g_print ("\tRSRP: '%.1lf dBm'\n", (0.1) * ((gdouble)rsrp));
907
908 if (interface == QMI_NAS_RADIO_INTERFACE_LTE ||
909 interface == QMI_NAS_RADIO_INTERFACE_5GNR) {
910 if (phase == 0xFFFFFFFF)
911 g_print ("\tPhase: 'unknown'\n");
912 else
913 g_print ("\tPhase: '%.2lf degrees'\n", (0.01) * ((gdouble)phase));
914 }
915 }
916
917 /* RX Channel 3 */
918 if (qmi_message_nas_get_tx_rx_info_output_get_rx_chain_3_info (
919 output,
920 &is_radio_tuned,
921 &power,
922 &ecio,
923 &rscp,
924 &rsrp,
925 &phase,
926 NULL)) {
927 g_print ("RX Chain 3:\n"
928 "\tRadio tuned: '%s'\n"
929 "\tPower: '%.1lf dBm'\n",
930 is_radio_tuned ? "yes" : "no",
931 (0.1) * ((gdouble)power));
932 if (interface == QMI_NAS_RADIO_INTERFACE_CDMA_1X ||
933 interface == QMI_NAS_RADIO_INTERFACE_CDMA_1XEVDO ||
934 interface == QMI_NAS_RADIO_INTERFACE_GSM ||
935 interface == QMI_NAS_RADIO_INTERFACE_UMTS ||
936 interface == QMI_NAS_RADIO_INTERFACE_LTE ||
937 interface == QMI_NAS_RADIO_INTERFACE_5GNR)
938 g_print ("\tECIO: '%.1lf dB'\n", (0.1) * ((gdouble)ecio));
939
940 if (interface == QMI_NAS_RADIO_INTERFACE_UMTS)
941 g_print ("\tRSCP: '%.1lf dBm'\n", (0.1) * ((gdouble)rscp));
942
943 if (interface == QMI_NAS_RADIO_INTERFACE_LTE ||
944 interface == QMI_NAS_RADIO_INTERFACE_5GNR)
945 g_print ("\tRSRP: '%.1lf dBm'\n", (0.1) * ((gdouble)rsrp));
946
947 if (interface == QMI_NAS_RADIO_INTERFACE_LTE ||
948 interface == QMI_NAS_RADIO_INTERFACE_5GNR) {
949 if (phase == 0xFFFFFFFF)
950 g_print ("\tPhase: 'unknown'\n");
951 else
952 g_print ("\tPhase: '%.2lf degrees'\n", (0.01) * ((gdouble)phase));
953 }
954 }
955
956 /* TX Channel */
957 if (qmi_message_nas_get_tx_rx_info_output_get_tx_info (
958 output,
959 &is_in_traffic,
960 &power,
961 NULL)) {
962 g_print ("TX:\n");
963 if (is_in_traffic)
964 g_print ("\tIn traffic: 'yes'\n"
965 "\tPower: '%.1lf dBm'\n",
966 (0.1) * ((gdouble)power));
967 else
968 g_print ("\tIn traffic: 'no'\n");
969 }
970
971 qmi_message_nas_get_tx_rx_info_output_unref (output);
972 operation_shutdown (TRUE);
973 }
974
975 static QmiMessageNasGetTxRxInfoInput *
976 get_tx_rx_info_input_create (const gchar *str,
977 QmiNasRadioInterface *interface)
978 {
979 QmiMessageNasGetTxRxInfoInput *input = NULL;
980
981 g_assert (interface != NULL);
982
983 if (qmicli_read_nas_radio_interface_from_string (str, interface)) {
984 GError *error = NULL;
985
986 input = qmi_message_nas_get_tx_rx_info_input_new ();
987 if (!qmi_message_nas_get_tx_rx_info_input_set_radio_interface (
988 input,
989 *interface,
990 &error)) {
991 g_printerr ("error: couldn't create input data bundle: '%s'\n",
992 error->message);
993 g_error_free (error);
994 qmi_message_nas_get_tx_rx_info_input_unref (input);
995 input = NULL;
996 }
997 }
998
999 return input;
1000 }
1001
1002 #endif /* HAVE_QMI_MESSAGE_NAS_GET_TX_RX_INFO */
1003
1004 #if defined HAVE_QMI_MESSAGE_NAS_GET_HOME_NETWORK
1005
1006 static void
1007 get_home_network_ready (QmiClientNas *client,
1008 GAsyncResult *res)
1009 {
1010 QmiMessageNasGetHomeNetworkOutput *output;
1011 GError *error = NULL;
1012
1013 output = qmi_client_nas_get_home_network_finish (client, res, &error);
1014 if (!output) {
1015 g_printerr ("error: operation failed: %s\n", error->message);
1016 g_error_free (error);
1017 operation_shutdown (FALSE);
1018 return;
1019 }
1020
1021 if (!qmi_message_nas_get_home_network_output_get_result (output, &error)) {
1022 g_printerr ("error: couldn't get home network: %s\n", error->message);
1023 g_error_free (error);
1024 qmi_message_nas_get_home_network_output_unref (output);
1025 operation_shutdown (FALSE);
1026 return;
1027 }
1028
1029 g_print ("[%s] Successfully got home network:\n",
1030 qmi_device_get_path_display (ctx->device));
1031
1032 {
1033 guint16 mcc;
1034 guint16 mnc;
1035 const gchar *description;
1036
1037 qmi_message_nas_get_home_network_output_get_home_network (
1038 output,
1039 &mcc,
1040 &mnc,
1041 &description,
1042 NULL);
1043
1044 g_print ("\tHome network:\n"
1045 "\t\tMCC: '%" G_GUINT16_FORMAT"'\n"
1046 "\t\tMNC: '%" G_GUINT16_FORMAT"'\n"
1047 "\t\tDescription: '%s'\n",
1048 mcc,
1049 mnc,
1050 description);
1051 }
1052
1053 {
1054 QmiNasNetworkNameSource network_name_source;
1055 if (qmi_message_nas_get_home_network_output_get_network_name_source (
1056 output,
1057 &network_name_source,
1058 NULL)) {
1059 g_print ("\tNetwork name source: %s\n",
1060 qmi_nas_network_name_source_get_string (network_name_source));
1061 }
1062 }
1063
1064 {
1065 guint16 sid;
1066 guint16 nid;
1067
1068 if (qmi_message_nas_get_home_network_output_get_home_system_id (
1069 output,
1070 &sid,
1071 &nid,
1072 NULL)) {
1073 g_print ("\t\tSID: '%" G_GUINT16_FORMAT"'\n"
1074 "\t\tNID: '%" G_GUINT16_FORMAT"'\n",
1075 sid,
1076 nid);
1077 }
1078 }
1079
1080 {
1081 guint16 mcc;
1082 guint16 mnc;
1083 QmiNasNetworkDescriptionEncoding description_encoding;
1084 GArray *description_array;
1085
1086 if (qmi_message_nas_get_home_network_output_get_home_network_3gpp2_ext (
1087 output,
1088 &mcc,
1089 &mnc,
1090 NULL, /* display_description */
1091 &description_encoding,
1092 &description_array,
1093 NULL)) {
1094 g_autofree gchar *description = NULL;
1095
1096 description = qmi_nas_read_string_from_network_description_encoded_array (description_encoding, description_array);
1097 g_print ("\t3GPP2 Home network (extended):\n"
1098 "\t\tMCC: '%" G_GUINT16_FORMAT"'\n"
1099 "\t\tMNC: '%" G_GUINT16_FORMAT"'\n"
1100 "\t\tDescription: '%s'\n",
1101 mcc,
1102 mnc,
1103 description ?: "");
1104 }
1105 }
1106
1107 qmi_message_nas_get_home_network_output_unref (output);
1108 operation_shutdown (TRUE);
1109 }
1110
1111 #endif /* HAVE_QMI_MESSAGE_NAS_GET_HOME_NETWORK */
1112
1113 #if defined HAVE_QMI_MESSAGE_NAS_GET_PREFERRED_NETWORKS
1114
1115 static void
1116 print_preferred_networks (GArray *preferred_networks_array,
1117 GArray *pcs_digit_array,
1118 const gchar *detail)
1119 {
1120 if (preferred_networks_array) {
1121 guint i;
1122
1123 g_print ("%s%sPreferred PLMN list:\n", detail ? detail : "", detail ? " " : "");
1124 if (preferred_networks_array->len == 0)
1125 g_print ("\t<empty>\n");
1126 for (i = 0; i < preferred_networks_array->len; i++) {
1127 QmiMessageNasGetPreferredNetworksOutputPreferredNetworksElement *element;
1128 g_autofree gchar *access_tech_string = NULL;
1129
1130 /* Rely on the fact that QmiMessageNasGetPreferredNetworksOutputPreferredNetworksElement
1131 * is the same layout as QmiMessageNasGetPreferredNetworksOutputStaticPreferredNetworksElement.
1132 */
1133 element = &g_array_index (preferred_networks_array, QmiMessageNasGetPreferredNetworksOutputPreferredNetworksElement, i);
1134 access_tech_string = qmi_nas_plmn_access_technology_identifier_build_string_from_mask (element->radio_access_technology);
1135 g_print ("[%u]:\n"
1136 "\tMCC: '%" G_GUINT16_FORMAT "'\n"
1137 "\tMNC: '%" G_GUINT16_FORMAT "'\n"
1138 "\tAccess Technology: '%s'\n",
1139 i,
1140 element->mcc,
1141 element->mnc,
1142 VALIDATE_MASK_NONE (access_tech_string));
1143 }
1144 }
1145
1146 if (pcs_digit_array) {
1147 guint i;
1148
1149 g_print ("%s%sPCS digit status:\n", detail ? detail : "", detail ? " " : "");
1150 if (pcs_digit_array->len == 0)
1151 g_print ("\t<empty>\n");
1152 for (i = 0; i < pcs_digit_array->len; i++) {
1153 QmiMessageNasGetPreferredNetworksOutputMncPcsDigitIncludeStatusElement *element;
1154
1155 element = &g_array_index (pcs_digit_array, QmiMessageNasGetPreferredNetworksOutputMncPcsDigitIncludeStatusElement, i);
1156 g_print ("[%u]:\n"
1157 "\tMCC: '%" G_GUINT16_FORMAT "'\n"
1158 "\tMNC: '%" G_GUINT16_FORMAT "'\n"
1159 "\tMCC with PCS digit: '%s'\n",
1160 i,
1161 element->mcc,
1162 element->mnc,
1163 element->includes_pcs_digit ? "yes" : "no");
1164 }
1165 }
1166 }
1167
1168 static void
1169 get_preferred_networks_ready (QmiClientNas *client,
1170 GAsyncResult *res)
1171 {
1172 QmiMessageNasGetPreferredNetworksOutput *output;
1173 GError *error = NULL;
1174 GArray *preferred_networks_array;
1175 GArray *pcs_digit_array;
1176
1177 output = qmi_client_nas_get_preferred_networks_finish (client, res, &error);
1178 if (!output) {
1179 g_printerr ("error: operation failed: %s\n", error->message);
1180 g_error_free (error);
1181 operation_shutdown (FALSE);
1182 return;
1183 }
1184
1185 if (!qmi_message_nas_get_preferred_networks_output_get_result (output, &error)) {
1186 g_printerr ("error: couldn't get preferred networks: %s\n", error->message);
1187 g_error_free (error);
1188 qmi_message_nas_get_preferred_networks_output_unref (output);
1189 operation_shutdown (FALSE);
1190 return;
1191 }
1192
1193 g_print ("[%s] Successfully got preferred networks:\n",
1194 qmi_device_get_path_display (ctx->device));
1195
1196 /* User-defined networks */
1197 preferred_networks_array = NULL;
1198 qmi_message_nas_get_preferred_networks_output_get_preferred_networks (output, &preferred_networks_array, NULL);
1199 pcs_digit_array = NULL;
1200 qmi_message_nas_get_preferred_networks_output_get_mnc_pcs_digit_include_status (output, &pcs_digit_array, NULL);
1201 print_preferred_networks (preferred_networks_array, pcs_digit_array, NULL);
1202
1203 /* Operator-defined networks */
1204 preferred_networks_array = NULL;
1205 qmi_message_nas_get_preferred_networks_output_get_static_preferred_networks (output, &preferred_networks_array, NULL);
1206 pcs_digit_array = NULL;
1207 qmi_message_nas_get_preferred_networks_output_get_static_mnc_pcs_digit_include_status (output, &pcs_digit_array, NULL);
1208 print_preferred_networks (preferred_networks_array, pcs_digit_array, "Static");
1209
1210 qmi_message_nas_get_preferred_networks_output_unref (output);
1211 operation_shutdown (TRUE);
1212 }
1213
1214 #endif /* HAVE_QMI_MESSAGE_NAS_GET_PREFERRED_NETWORKS */
1215
1216 #if defined HAVE_QMI_MESSAGE_NAS_SET_PREFERRED_NETWORKS
1217
1218 static QmiMessageNasSetPreferredNetworksInput *
1219 set_preferred_networks_input_create (const gchar *str)
1220 {
1221 QmiMessageNasSetPreferredNetworksInput *input = NULL;
1222 GError *error = NULL;
1223 gchar **parts = NULL;
1224 gint i;
1225 gint num_parts;
1226 const gchar *part;
1227 guint16 mcc = 0;
1228 guint16 mnc = 0;
1229 gboolean pcs_digit = FALSE;
1230 QmiNasPlmnAccessTechnologyIdentifier access_tech = QMI_NAS_PLMN_ACCESS_TECHNOLOGY_IDENTIFIER_UNSPECIFIED;
1231 GArray *preferred_nets_array;
1232 GArray *pcs_digit_array;
1233 QmiMessageNasSetPreferredNetworksInputPreferredNetworksElement preferred_nets_element;
1234 QmiMessageNasSetPreferredNetworksInputMncPcsDigitIncludeStatusElement pcs_digit_element;
1235
1236 preferred_nets_array = g_array_new (FALSE, FALSE, sizeof (QmiMessageNasSetPreferredNetworksInputPreferredNetworksElement));
1237 pcs_digit_array = g_array_new (FALSE, FALSE, sizeof (QmiMessageNasSetPreferredNetworksInputMncPcsDigitIncludeStatusElement));
1238
1239 parts = g_strsplit (str, ",", -1);
1240 num_parts = g_strv_length (parts);
1241 for (i = 0; i < num_parts; i += 2) {
1242 part = parts[i];
1243 /* Parse MCCMNC, if it's found, also read the access technology in numeric format */
1244 if (qmicli_read_parse_3gpp_mcc_mnc (part, &mcc, &mnc, &pcs_digit)) {
1245 access_tech = QMI_NAS_PLMN_ACCESS_TECHNOLOGY_IDENTIFIER_UNSPECIFIED;
1246 if (i + 1 < num_parts) {
1247 const gchar *access_tech_str = parts[i + 1];
1248
1249 if (!qmicli_read_nas_plmn_access_technology_identifier_from_string (access_tech_str, &access_tech))
1250 goto out;
1251
1252 memset (&preferred_nets_element, 0, sizeof (preferred_nets_element));
1253 preferred_nets_element.mcc = mcc;
1254 preferred_nets_element.mnc = mnc;
1255 preferred_nets_element.radio_access_technology = access_tech;
1256 g_array_append_val (preferred_nets_array, preferred_nets_element);
1257 memset (&pcs_digit_element, 0, sizeof (pcs_digit_element));
1258 pcs_digit_element.mcc = mcc;
1259 pcs_digit_element.mnc = mnc;
1260 pcs_digit_element.includes_pcs_digit = pcs_digit;
1261 g_array_append_val (pcs_digit_array, pcs_digit_element);
1262 } else {
1263 g_printerr ("error: access technology missing for MCCMNC: '%s'\n", part);
1264 goto out;
1265 }
1266 } else
1267 goto out;
1268 }
1269
1270 input = qmi_message_nas_set_preferred_networks_input_new ();
1271
1272 if (!qmi_message_nas_set_preferred_networks_input_set_preferred_networks (input, preferred_nets_array, &error))
1273 goto out;
1274
1275 if (!qmi_message_nas_set_preferred_networks_input_set_mnc_pcs_digit_include_status (input, pcs_digit_array, &error))
1276 goto out;
1277
1278 /* Always set the clear previous flag, leaving any previously configured networks is not desired */
1279 if (!qmi_message_nas_set_preferred_networks_input_set_clear_previous_preferred_networks (input, TRUE, &error))
1280 goto out;
1281
1282 out:
1283 g_strfreev (parts);
1284
1285 if (preferred_nets_array)
1286 g_array_unref (preferred_nets_array);
1287 if (pcs_digit_array)
1288 g_array_unref (pcs_digit_array);
1289
1290 if (error) {
1291 g_printerr ("error: couldn't create preferred networks input data bundle: '%s'\n", error->message);
1292 g_error_free (error);
1293 qmi_message_nas_set_preferred_networks_input_unref (input);
1294 return NULL;
1295 }
1296
1297 return input;
1298 }
1299
1300 static void
1301 set_preferred_networks_ready (QmiClientNas *client,
1302 GAsyncResult *res)
1303 {
1304 QmiMessageNasSetPreferredNetworksOutput *output = NULL;
1305 GError *error = NULL;
1306
1307 output = qmi_client_nas_set_preferred_networks_finish (client, res, &error);
1308 if (!output) {
1309 g_printerr ("error: operation failed: %s\n", error->message);
1310 g_error_free (error);
1311 operation_shutdown (FALSE);
1312 return;
1313 }
1314
1315 if (!qmi_message_nas_set_preferred_networks_output_get_result (output, &error)) {
1316 g_printerr ("error: couldn't set preferred networks: %s\n", error->message);
1317 g_error_free (error);
1318 qmi_message_nas_set_preferred_networks_output_unref (output);
1319 operation_shutdown (FALSE);
1320 return;
1321 }
1322
1323 g_print ("[%s] Preferred networks set successfully.\n",
1324 qmi_device_get_path_display (ctx->device));
1325
1326 qmi_message_nas_set_preferred_networks_output_unref (output);
1327 operation_shutdown (TRUE);
1328 }
1329
1330 #endif /* HAVE_QMI_MESSAGE_NAS_SET_PREFERRED_NETWORKS */
1331
1332 #if defined HAVE_QMI_MESSAGE_NAS_GET_SERVING_SYSTEM
1333
1334 static void
1335 get_serving_system_ready (QmiClientNas *client,
1336 GAsyncResult *res)
1337 {
1338 QmiMessageNasGetServingSystemOutput *output;
1339 GError *error = NULL;
1340
1341 output = qmi_client_nas_get_serving_system_finish (client, res, &error);
1342 if (!output) {
1343 g_printerr ("error: operation failed: %s\n", error->message);
1344 g_error_free (error);
1345 operation_shutdown (FALSE);
1346 return;
1347 }
1348
1349 if (!qmi_message_nas_get_serving_system_output_get_result (output, &error)) {
1350 g_printerr ("error: couldn't get serving system: %s\n", error->message);
1351 g_error_free (error);
1352 qmi_message_nas_get_serving_system_output_unref (output);
1353 operation_shutdown (FALSE);
1354 return;
1355 }
1356
1357 g_print ("[%s] Successfully got serving system:\n",
1358 qmi_device_get_path_display (ctx->device));
1359
1360 {
1361 QmiNasRegistrationState registration_state;
1362 QmiNasAttachState cs_attach_state;
1363 QmiNasAttachState ps_attach_state;
1364 QmiNasNetworkType selected_network;
1365 GArray *radio_interfaces;
1366 guint i;
1367
1368 qmi_message_nas_get_serving_system_output_get_serving_system (
1369 output,
1370 &registration_state,
1371 &cs_attach_state,
1372 &ps_attach_state,
1373 &selected_network,
1374 &radio_interfaces,
1375 NULL);
1376
1377 g_print ("\tRegistration state: '%s'\n"
1378 "\tCS: '%s'\n"
1379 "\tPS: '%s'\n"
1380 "\tSelected network: '%s'\n"
1381 "\tRadio interfaces: '%u'\n",
1382 qmi_nas_registration_state_get_string (registration_state),
1383 qmi_nas_attach_state_get_string (cs_attach_state),
1384 qmi_nas_attach_state_get_string (ps_attach_state),
1385 qmi_nas_network_type_get_string (selected_network),
1386 radio_interfaces->len);
1387
1388 for (i = 0; i < radio_interfaces->len; i++) {
1389 QmiNasRadioInterface iface;
1390
1391 iface = g_array_index (radio_interfaces, QmiNasRadioInterface, i);
1392 g_print ("\t\t[%u]: '%s'\n", i, qmi_nas_radio_interface_get_string (iface));
1393 }
1394 }
1395
1396 {
1397 QmiNasRoamingIndicatorStatus roaming;
1398
1399 if (qmi_message_nas_get_serving_system_output_get_roaming_indicator (
1400 output,
1401 &roaming,
1402 NULL)) {
1403 g_print ("\tRoaming status: '%s'\n",
1404 qmi_nas_roaming_indicator_status_get_string (roaming));
1405 }
1406 }
1407
1408 {
1409 GArray *data_service_capability;
1410
1411 if (qmi_message_nas_get_serving_system_output_get_data_service_capability (
1412 output,
1413 &data_service_capability,
1414 NULL)) {
1415 guint i;
1416
1417 g_print ("\tData service capabilities: '%u'\n",
1418 data_service_capability->len);
1419
1420 for (i = 0; i < data_service_capability->len; i++) {
1421 QmiNasDataCapability cap;
1422
1423 cap = g_array_index (data_service_capability, QmiNasDataCapability, i);
1424 g_print ("\t\t[%u]: '%s'\n", i, qmi_nas_data_capability_get_string (cap));
1425 }
1426 }
1427 }
1428
1429 {
1430 guint16 current_plmn_mcc;
1431 guint16 current_plmn_mnc;
1432 const gchar *current_plmn_description;
1433
1434 if (qmi_message_nas_get_serving_system_output_get_current_plmn (
1435 output,
1436 &current_plmn_mcc,
1437 &current_plmn_mnc,
1438 &current_plmn_description,
1439 NULL)) {
1440 g_print ("\tCurrent PLMN:\n"
1441 "\t\tMCC: '%" G_GUINT16_FORMAT"'\n"
1442 "\t\tMNC: '%" G_GUINT16_FORMAT"'\n"
1443 "\t\tDescription: '%s'\n",
1444 current_plmn_mcc,
1445 current_plmn_mnc,
1446 current_plmn_description);
1447 }
1448 }
1449
1450 {
1451 QmiNasNetworkNameSource network_name_source;
1452 if (qmi_message_nas_get_serving_system_output_get_network_name_source (
1453 output,
1454 &network_name_source,
1455 NULL)) {
1456 g_print ("\tNetwork name source: %s\n",
1457 qmi_nas_network_name_source_get_string (network_name_source));
1458 }
1459 }
1460
1461 {
1462 guint16 sid;
1463 guint16 nid;
1464
1465 if (qmi_message_nas_get_serving_system_output_get_cdma_system_id (
1466 output,
1467 &sid,
1468 &nid,
1469 NULL)) {
1470 g_print ("\tCDMA System ID:\n"
1471 "\t\tSID: '%" G_GUINT16_FORMAT"'\n"
1472 "\t\tNID: '%" G_GUINT16_FORMAT"'\n",
1473 sid, nid);
1474 }
1475 }
1476
1477 {
1478 guint16 id;
1479 gint32 latitude;
1480 gint32 longitude;
1481
1482 if (qmi_message_nas_get_serving_system_output_get_cdma_base_station_info (
1483 output,
1484 &id,
1485 &latitude,
1486 &longitude,
1487 NULL)) {
1488 gdouble latitude_degrees;
1489 gdouble longitude_degrees;
1490
1491 /* TODO: give degrees, minutes, seconds */
1492 latitude_degrees = ((gdouble)latitude * 0.25)/3600.0;
1493 longitude_degrees = ((gdouble)longitude * 0.25)/3600.0;
1494
1495 g_print ("\tCDMA Base station info:\n"
1496 "\t\tBase station ID: '%" G_GUINT16_FORMAT"'\n"
1497 "\t\tLatitude: '%lf'º\n"
1498 "\t\tLongitude: '%lf'º\n",
1499 id, latitude_degrees, longitude_degrees);
1500 }
1501 }
1502
1503 {
1504 GArray *roaming_indicators;
1505
1506 if (qmi_message_nas_get_serving_system_output_get_roaming_indicator_list (
1507 output,
1508 &roaming_indicators,
1509 NULL)) {
1510 guint i;
1511
1512 g_print ("\tRoaming indicators: '%u'\n",
1513 roaming_indicators->len);
1514
1515 for (i = 0; i < roaming_indicators->len; i++) {
1516 QmiMessageNasGetServingSystemOutputRoamingIndicatorListElement *element;
1517
1518 element = &g_array_index (roaming_indicators, QmiMessageNasGetServingSystemOutputRoamingIndicatorListElement, i);
1519 g_print ("\t\t[%u]: '%s' (%s)\n",
1520 i,
1521 qmi_nas_roaming_indicator_status_get_string (element->roaming_indicator),
1522 qmi_nas_radio_interface_get_string (element->radio_interface));
1523 }
1524 }
1525 }
1526
1527 {
1528 QmiNasRoamingIndicatorStatus roaming;
1529
1530 if (qmi_message_nas_get_serving_system_output_get_default_roaming_indicator (
1531 output,
1532 &roaming,
1533 NULL)) {
1534 g_print ("\tDefault roaming status: '%s'\n",
1535 qmi_nas_roaming_indicator_status_get_string (roaming));
1536 }
1537 }
1538
1539 {
1540 guint8 leap_seconds;
1541 gint8 local_time_offset;
1542 gboolean daylight_saving_time;
1543
1544 if (qmi_message_nas_get_serving_system_output_get_time_zone_3gpp2 (
1545 output,
1546 &leap_seconds,
1547 &local_time_offset,
1548 &daylight_saving_time,
1549 NULL)) {
1550 g_print ("\t3GPP2 time zone:\n"
1551 "\t\tLeap seconds: '%u' seconds\n"
1552 "\t\tLocal time offset: '%d' minutes\n"
1553 "\t\tDaylight saving time: '%s'\n",
1554 leap_seconds,
1555 (gint)local_time_offset * 30,
1556 daylight_saving_time ? "yes" : "no");
1557 }
1558 }
1559
1560 {
1561 guint8 cdma_p_rev;
1562
1563 if (qmi_message_nas_get_serving_system_output_get_cdma_p_rev (
1564 output,
1565 &cdma_p_rev,
1566 NULL)) {
1567 g_print ("\tCDMA P_Rev: '%u'\n", cdma_p_rev);
1568 }
1569 }
1570
1571 {
1572 gint8 time_zone;
1573
1574 if (qmi_message_nas_get_serving_system_output_get_time_zone_3gpp (
1575 output,
1576 &time_zone,
1577 NULL)) {
1578 g_print ("\t3GPP time zone offset: '%d' minutes\n",
1579 (gint)time_zone * 15);
1580 }
1581 }
1582
1583 {
1584 guint8 adjustment;
1585
1586 if (qmi_message_nas_get_serving_system_output_get_daylight_saving_time_adjustment_3gpp (
1587 output,
1588 &adjustment,
1589 NULL)) {
1590 g_print ("\t3GPP daylight saving time adjustment: '%u' hours\n",
1591 adjustment);
1592 }
1593 }
1594
1595 {
1596 guint16 lac;
1597
1598 if (qmi_message_nas_get_serving_system_output_get_lac_3gpp (
1599 output,
1600 &lac,
1601 NULL)) {
1602 g_print ("\t3GPP location area code: '%" G_GUINT16_FORMAT"'\n", lac);
1603 }
1604 }
1605
1606 {
1607 guint32 cid;
1608
1609 if (qmi_message_nas_get_serving_system_output_get_cid_3gpp (
1610 output,
1611 &cid,
1612 NULL)) {
1613 g_print ("\t3GPP cell ID: '%u'\n", cid);
1614 }
1615 }
1616
1617 {
1618 gboolean concurrent;
1619
1620 if (qmi_message_nas_get_serving_system_output_get_concurrent_service_info_3gpp2 (
1621 output,
1622 &concurrent,
1623 NULL)) {
1624 g_print ("\t3GPP2 concurrent service info: '%s'\n",
1625 concurrent ? "available" : "not available");
1626 }
1627 }
1628
1629 {
1630 gboolean prl;
1631
1632 if (qmi_message_nas_get_serving_system_output_get_prl_indicator_3gpp2 (
1633 output,
1634 &prl,
1635 NULL)) {
1636 g_print ("\t3GPP2 PRL indicator: '%s'\n",
1637 prl ? "system in PRL" : "system not in PRL");
1638 }
1639 }
1640
1641 {
1642 gboolean supported;
1643
1644 if (qmi_message_nas_get_serving_system_output_get_dtm_support (
1645 output,
1646 &supported,
1647 NULL)) {
1648 g_print ("\tDual transfer mode: '%s'\n",
1649 supported ? "supported" : "not supported");
1650 }
1651 }
1652
1653 {
1654 QmiNasServiceStatus status;
1655 QmiNasNetworkServiceDomain capability;
1656 QmiNasServiceStatus hdr_status;
1657 gboolean hdr_hybrid;
1658 gboolean forbidden;
1659
1660 if (qmi_message_nas_get_serving_system_output_get_detailed_service_status (
1661 output,
1662 &status,
1663 &capability,
1664 &hdr_status,
1665 &hdr_hybrid,
1666 &forbidden,
1667 NULL)) {
1668 g_print ("\tDetailed status:\n"
1669 "\t\tStatus: '%s'\n"
1670 "\t\tCapability: '%s'\n"
1671 "\t\tHDR Status: '%s'\n"
1672 "\t\tHDR Hybrid: '%s'\n"
1673 "\t\tForbidden: '%s'\n",
1674 qmi_nas_service_status_get_string (status),
1675 qmi_nas_network_service_domain_get_string (capability),
1676 qmi_nas_service_status_get_string (hdr_status),
1677 hdr_hybrid ? "yes" : "no",
1678 forbidden ? "yes" : "no");
1679 }
1680 }
1681
1682 {
1683 guint16 mcc;
1684 guint8 imsi_11_12;
1685
1686 if (qmi_message_nas_get_serving_system_output_get_cdma_system_info (
1687 output,
1688 &mcc,
1689 &imsi_11_12,
1690 NULL)) {
1691 g_print ("\tCDMA system info:\n"
1692 "\t\tMCC: '%" G_GUINT16_FORMAT"'\n"
1693 "\t\tIMSI_11_12: '%u'\n",
1694 mcc,
1695 imsi_11_12);
1696 }
1697 }
1698
1699 {
1700 QmiNasHdrPersonality personality;
1701
1702 if (qmi_message_nas_get_serving_system_output_get_hdr_personality (
1703 output,
1704 &personality,
1705 NULL)) {
1706 g_print ("\tHDR personality: '%s'\n",
1707 qmi_nas_hdr_personality_get_string (personality));
1708 }
1709 }
1710
1711 {
1712 guint16 tac;
1713
1714 if (qmi_message_nas_get_serving_system_output_get_lte_tac (
1715 output,
1716 &tac,
1717 NULL)) {
1718 g_print ("\tLTE tracking area code: '%" G_GUINT16_FORMAT"'\n", tac);
1719 }
1720 }
1721
1722 {
1723 QmiNasCallBarringStatus cs_status;
1724 QmiNasCallBarringStatus ps_status;
1725
1726 if (qmi_message_nas_get_serving_system_output_get_call_barring_status (
1727 output,
1728 &cs_status,
1729 &ps_status,
1730 NULL)) {
1731 g_print ("\tCall barring status:\n"
1732 "\t\tCircuit switched: '%s'\n"
1733 "\t\tPacket switched: '%s'\n",
1734 qmi_nas_call_barring_status_get_string (cs_status),
1735 qmi_nas_call_barring_status_get_string (ps_status));
1736 }
1737 }
1738
1739 {
1740 guint16 code;
1741
1742 if (qmi_message_nas_get_serving_system_output_get_umts_primary_scrambling_code (
1743 output,
1744 &code,
1745 NULL)) {
1746 g_print ("\tUMTS primary scrambling code: '%" G_GUINT16_FORMAT"'\n", code);
1747 }
1748 }
1749
1750 {
1751 guint16 mcc;
1752 guint16 mnc;
1753 gboolean has_pcs_digit;
1754
1755 if (qmi_message_nas_get_serving_system_output_get_mnc_pcs_digit_include_status (
1756 output,
1757 &mcc,
1758 &mnc,
1759 &has_pcs_digit,
1760 NULL)) {
1761 g_print ("\tFull operator code info:\n"
1762 "\t\tMCC: '%" G_GUINT16_FORMAT"'\n"
1763 "\t\tMNC: '%" G_GUINT16_FORMAT"'\n"
1764 "\t\tMNC with PCS digit: '%s'\n",
1765 mcc,
1766 mnc,
1767 has_pcs_digit ? "yes" : "no");
1768 }
1769 }
1770
1771 qmi_message_nas_get_serving_system_output_unref (output);
1772 operation_shutdown (TRUE);
1773 }
1774
1775 #endif /* HAVE_QMI_MESSAGE_NAS_GET_SERVING_SYSTEM */
1776
1777 #if defined HAVE_QMI_MESSAGE_NAS_GET_SYSTEM_INFO
1778
1779 static void
1780 get_system_info_ready (QmiClientNas *client,
1781 GAsyncResult *res)
1782 {
1783 QmiMessageNasGetSystemInfoOutput *output;
1784 GError *error = NULL;
1785
1786 output = qmi_client_nas_get_system_info_finish (client, res, &error);
1787 if (!output) {
1788 g_printerr ("error: operation failed: %s\n", error->message);
1789 g_error_free (error);
1790 operation_shutdown (FALSE);
1791 return;
1792 }
1793
1794 if (!qmi_message_nas_get_system_info_output_get_result (output, &error)) {
1795 g_printerr ("error: couldn't get system info: %s\n", error->message);
1796 g_error_free (error);
1797 qmi_message_nas_get_system_info_output_unref (output);
1798 operation_shutdown (FALSE);
1799 return;
1800 }
1801
1802 g_print ("[%s] Successfully got system info:\n",
1803 qmi_device_get_path_display (ctx->device));
1804
1805 /* CDMA 1x */
1806 {
1807 QmiNasServiceStatus service_status;
1808 gboolean preferred_data_path;
1809 gboolean domain_valid;
1810 QmiNasNetworkServiceDomain domain;
1811 gboolean service_capability_valid;
1812 QmiNasNetworkServiceDomain service_capability;
1813 gboolean roaming_status_valid;
1814 QmiNasRoamingStatus roaming_status;
1815 gboolean forbidden_valid;
1816 gboolean forbidden;
1817 gboolean prl_match_valid;
1818 gboolean prl_match;
1819 gboolean p_rev_valid;
1820 guint8 p_rev;
1821 gboolean base_station_p_rev_valid;
1822 guint8 base_station_p_rev;
1823 gboolean concurrent_service_support_valid;
1824 gboolean concurrent_service_support;
1825 gboolean cdma_system_id_valid;
1826 guint16 sid;
1827 guint16 nid;
1828 gboolean base_station_info_valid;
1829 guint16 base_station_id;
1830 gint32 base_station_latitude;
1831 gint32 base_station_longitude;
1832 gboolean packet_zone_valid;
1833 guint16 packet_zone;
1834 gboolean network_id_valid;
1835 const gchar *mcc;
1836 const gchar *mnc;
1837 guint16 geo_system_index;
1838 guint16 registration_period;
1839
1840 if (qmi_message_nas_get_system_info_output_get_cdma_service_status (
1841 output,
1842 &service_status,
1843 &preferred_data_path,
1844 NULL)) {
1845 g_print ("\tCDMA 1x service:\n"
1846 "\t\tStatus: '%s'\n"
1847 "\t\tPreferred data path: '%s'\n",
1848 qmi_nas_service_status_get_string (service_status),
1849 preferred_data_path ? "yes" : "no");
1850
1851 if (qmi_message_nas_get_system_info_output_get_cdma_system_info (
1852 output,
1853 &domain_valid, &domain,
1854 &service_capability_valid, &service_capability,
1855 &roaming_status_valid, &roaming_status,
1856 &forbidden_valid, &forbidden,
1857 &prl_match_valid, &prl_match,
1858 &p_rev_valid, &p_rev,
1859 &base_station_p_rev_valid, &base_station_p_rev,
1860 &concurrent_service_support_valid, &concurrent_service_support,
1861 &cdma_system_id_valid, &sid, &nid,
1862 &base_station_info_valid, &base_station_id, &base_station_longitude, &base_station_latitude,
1863 &packet_zone_valid, &packet_zone,
1864 &network_id_valid, &mcc, &mnc,
1865 NULL)) {
1866 if (domain_valid)
1867 g_print ("\t\tDomain: '%s'\n", qmi_nas_network_service_domain_get_string (domain));
1868 if (service_capability_valid)
1869 g_print ("\t\tService capability: '%s'\n", qmi_nas_network_service_domain_get_string (service_capability));
1870 if (roaming_status_valid)
1871 g_print ("\t\tRoaming status: '%s'\n", qmi_nas_roaming_status_get_string (roaming_status));
1872 if (forbidden_valid)
1873 g_print ("\t\tForbidden: '%s'\n", forbidden ? "yes" : "no");
1874 if (prl_match_valid)
1875 g_print ("\t\tPRL match: '%s'\n", prl_match ? "yes" : "no");
1876 if (p_rev_valid)
1877 g_print ("\t\tP-Rev: '%u'\n", p_rev);
1878 if (base_station_p_rev_valid)
1879 g_print ("\t\tBase station P-Rev: '%u'\n", base_station_p_rev);
1880 if (concurrent_service_support_valid)
1881 g_print ("\t\tConcurrent service support: '%s'\n", concurrent_service_support ? "yes" : "no");
1882 if (cdma_system_id_valid) {
1883 g_print ("\t\tSID: '%" G_GUINT16_FORMAT"'\n", sid);
1884 g_print ("\t\tNID: '%" G_GUINT16_FORMAT"'\n", nid);
1885 }
1886 if (base_station_info_valid) {
1887 gdouble latitude_degrees;
1888 gdouble longitude_degrees;
1889
1890 /* TODO: give degrees, minutes, seconds */
1891 latitude_degrees = ((gdouble)base_station_latitude * 0.25)/3600.0;
1892 longitude_degrees = ((gdouble)base_station_longitude * 0.25)/3600.0;
1893 g_print ("\t\tBase station ID: '%" G_GUINT16_FORMAT"'\n", base_station_id);
1894 g_print ("\t\tBase station latitude: '%lf'º\n", latitude_degrees);
1895 g_print ("\t\tBase station longitude: '%lf'º\n", longitude_degrees);
1896 }
1897 if (packet_zone_valid)
1898 g_print ("\t\tPacket zone: '%" G_GUINT16_FORMAT "'\n", packet_zone);
1899 if (network_id_valid) {
1900 g_print ("\t\tMCC: '%s'\n", mcc);
1901 if ((guchar)mnc[2] == 0xFF)
1902 g_print ("\t\tMNC: '%.2s'\n", mnc);
1903 else
1904 g_print ("\t\tMNC: '%.3s'\n", mnc);
1905 }
1906 }
1907
1908 if (qmi_message_nas_get_system_info_output_get_additional_cdma_system_info (
1909 output,
1910 &geo_system_index,
1911 &registration_period,
1912 NULL)) {
1913 if (geo_system_index != 0xFFFF)
1914 g_print ("\t\tGeo system index: '%" G_GUINT16_FORMAT "'\n", geo_system_index);
1915 if (registration_period != 0xFFFF)
1916 g_print ("\t\tRegistration period: '%" G_GUINT16_FORMAT "'\n", registration_period);
1917 }
1918 }
1919 }
1920
1921 /* CDMA 1xEV-DO */
1922 {
1923 QmiNasServiceStatus service_status;
1924 gboolean preferred_data_path;
1925 gboolean domain_valid;
1926 QmiNasNetworkServiceDomain domain;
1927 gboolean service_capability_valid;
1928 QmiNasNetworkServiceDomain service_capability;
1929 gboolean roaming_status_valid;
1930 QmiNasRoamingStatus roaming_status;
1931 gboolean forbidden_valid;
1932 gboolean forbidden;
1933 gboolean prl_match_valid;
1934 gboolean prl_match;
1935 gboolean personality_valid;
1936 QmiNasHdrPersonality personality;
1937 gboolean protocol_revision_valid;
1938 QmiNasHdrProtocolRevision protocol_revision;
1939 gboolean is_856_system_id_valid;
1940 const gchar *is_856_system_id;
1941 guint16 geo_system_index;
1942
1943 if (qmi_message_nas_get_system_info_output_get_hdr_service_status (
1944 output,
1945 &service_status,
1946 &preferred_data_path,
1947 NULL)) {
1948 g_print ("\tCDMA 1xEV-DO (HDR) service:\n"
1949 "\t\tStatus: '%s'\n"
1950 "\t\tPreferred data path: '%s'\n",
1951 qmi_nas_service_status_get_string (service_status),
1952 preferred_data_path ? "yes" : "no");
1953
1954 if (qmi_message_nas_get_system_info_output_get_hdr_system_info (
1955 output,
1956 &domain_valid, &domain,
1957 &service_capability_valid, &service_capability,
1958 &roaming_status_valid, &roaming_status,
1959 &forbidden_valid, &forbidden,
1960 &prl_match_valid, &prl_match,
1961 &personality_valid, &personality,
1962 &protocol_revision_valid, &protocol_revision,
1963 &is_856_system_id_valid, &is_856_system_id,
1964 NULL)) {
1965 if (domain_valid)
1966 g_print ("\t\tDomain: '%s'\n", qmi_nas_network_service_domain_get_string (domain));
1967 if (service_capability_valid)
1968 g_print ("\t\tService capability: '%s'\n", qmi_nas_network_service_domain_get_string (service_capability));
1969 if (roaming_status_valid)
1970 g_print ("\t\tRoaming status: '%s'\n", qmi_nas_roaming_status_get_string (roaming_status));
1971 if (forbidden_valid)
1972 g_print ("\t\tForbidden: '%s'\n", forbidden ? "yes" : "no");
1973 if (prl_match_valid)
1974 g_print ("\t\tPRL match: '%s'\n", prl_match ? "yes" : "no");
1975 if (personality_valid)
1976 g_print ("\t\tPersonality: '%s'\n", qmi_nas_hdr_personality_get_string (personality));
1977 if (protocol_revision_valid)
1978 g_print ("\t\tProtocol revision: '%s'\n", qmi_nas_hdr_protocol_revision_get_string (protocol_revision));
1979 if (is_856_system_id_valid)
1980 g_print ("\t\tIS-856 system ID: '%s'\n", is_856_system_id);
1981 }
1982
1983 if (qmi_message_nas_get_system_info_output_get_additional_hdr_system_info (
1984 output,
1985 &geo_system_index,
1986 NULL)) {
1987 if (geo_system_index != 0xFFFF)
1988 g_print ("\t\tGeo system index: '%" G_GUINT16_FORMAT "'\n", geo_system_index);
1989 }
1990 }
1991 }
1992
1993 /* GSM */
1994 {
1995 QmiNasServiceStatus service_status;
1996 QmiNasServiceStatus true_service_status;
1997 gboolean preferred_data_path;
1998 gboolean domain_valid;
1999 QmiNasNetworkServiceDomain domain;
2000 gboolean service_capability_valid;
2001 QmiNasNetworkServiceDomain service_capability;
2002 gboolean roaming_status_valid;
2003 QmiNasRoamingStatus roaming_status;
2004 gboolean forbidden_valid;
2005 gboolean forbidden;
2006 gboolean lac_valid;
2007 guint16 lac;
2008 gboolean cid_valid;
2009 guint32 cid;
2010 gboolean registration_reject_info_valid;
2011 QmiNasNetworkServiceDomain registration_reject_domain;
2012 QmiNasRejectCause registration_reject_cause;
2013 gboolean network_id_valid;
2014 const gchar *mcc;
2015 const gchar *mnc;
2016 gboolean egprs_support_valid;
2017 gboolean egprs_support;
2018 gboolean dtm_support_valid;
2019 gboolean dtm_support;
2020 guint16 geo_system_index;
2021 QmiNasCellBroadcastCapability cell_broadcast_support;
2022 QmiNasCallBarringStatus call_barring_status_cs;
2023 QmiNasCallBarringStatus call_barring_status_ps;
2024 QmiNasNetworkServiceDomain cipher_domain;
2025
2026 if (qmi_message_nas_get_system_info_output_get_gsm_service_status (
2027 output,
2028 &service_status,
2029 &true_service_status,
2030 &preferred_data_path,
2031 NULL)) {
2032 g_print ("\tGSM service:\n"
2033 "\t\tStatus: '%s'\n"
2034 "\t\tTrue Status: '%s'\n"
2035 "\t\tPreferred data path: '%s'\n",
2036 qmi_nas_service_status_get_string (service_status),
2037 qmi_nas_service_status_get_string (true_service_status),
2038 preferred_data_path ? "yes" : "no");
2039
2040 if (qmi_message_nas_get_system_info_output_get_gsm_system_info_v2 (
2041 output,
2042 &domain_valid, &domain,
2043 &service_capability_valid, &service_capability,
2044 &roaming_status_valid, &roaming_status,
2045 &forbidden_valid, &forbidden,
2046 &lac_valid, &lac,
2047 &cid_valid, &cid,
2048 &registration_reject_info_valid, &registration_reject_domain, &registration_reject_cause,
2049 &network_id_valid, &mcc, &mnc,
2050 &egprs_support_valid, &egprs_support,
2051 &dtm_support_valid, &dtm_support,
2052 NULL)) {
2053 if (domain_valid)
2054 g_print ("\t\tDomain: '%s'\n", qmi_nas_network_service_domain_get_string (domain));
2055 if (service_capability_valid)
2056 g_print ("\t\tService capability: '%s'\n", qmi_nas_network_service_domain_get_string (service_capability));
2057 if (roaming_status_valid)
2058 g_print ("\t\tRoaming status: '%s'\n", qmi_nas_roaming_status_get_string (roaming_status));
2059 if (forbidden_valid)
2060 g_print ("\t\tForbidden: '%s'\n", forbidden ? "yes" : "no");
2061 if (lac_valid)
2062 g_print ("\t\tLocation Area Code: '%" G_GUINT16_FORMAT"'\n", lac);
2063 if (cid_valid)
2064 g_print ("\t\tCell ID: '%u'\n", cid);
2065 if (registration_reject_info_valid)
2066 g_print ("\t\tRegistration reject: '%s' (%s)\n",
2067 qmi_nas_network_service_domain_get_string (registration_reject_domain),
2068 qmi_nas_reject_cause_get_string (registration_reject_cause));
2069 if (network_id_valid) {
2070 g_print ("\t\tMCC: '%s'\n", mcc);
2071 if ((guchar)mnc[2] == 0xFF)
2072 g_print ("\t\tMNC: '%.2s'\n", mnc);
2073 else
2074 g_print ("\t\tMNC: '%.3s'\n", mnc);
2075 }
2076 if (egprs_support_valid)
2077 g_print ("\t\tE-GPRS supported: '%s'\n", egprs_support ? "yes" : "no");
2078 if (dtm_support_valid)
2079 g_print ("\t\tDual Transfer Mode supported: '%s'\n", dtm_support ? "yes" : "no");
2080 }
2081
2082 if (qmi_message_nas_get_system_info_output_get_additional_gsm_system_info (
2083 output,
2084 &geo_system_index,
2085 &cell_broadcast_support,
2086 NULL)) {
2087 if (geo_system_index != 0xFFFF)
2088 g_print ("\t\tGeo system index: '%" G_GUINT16_FORMAT "'\n", geo_system_index);
2089 g_print ("\t\tCell broadcast support: '%s'\n", qmi_nas_cell_broadcast_capability_get_string (cell_broadcast_support));
2090 }
2091
2092 if (qmi_message_nas_get_system_info_output_get_gsm_call_barring_status (
2093 output,
2094 &call_barring_status_cs,
2095 &call_barring_status_ps,
2096 NULL)) {
2097 g_print ("\t\tCall barring status (CS): '%s'\n", qmi_nas_call_barring_status_get_string (call_barring_status_cs));
2098 g_print ("\t\tCall barring status (PS): '%s'\n", qmi_nas_call_barring_status_get_string (call_barring_status_ps));
2099 }
2100
2101 if (qmi_message_nas_get_system_info_output_get_gsm_cipher_domain (
2102 output,
2103 &cipher_domain,
2104 NULL)) {
2105 g_print ("\t\tCipher Domain: '%s'\n", qmi_nas_network_service_domain_get_string (cipher_domain));
2106 }
2107 }
2108 }
2109
2110 /* WCDMA */
2111 {
2112 QmiNasServiceStatus service_status;
2113 QmiNasServiceStatus true_service_status;
2114 gboolean preferred_data_path;
2115 gboolean domain_valid;
2116 QmiNasNetworkServiceDomain domain;
2117 gboolean service_capability_valid;
2118 QmiNasNetworkServiceDomain service_capability;
2119 gboolean roaming_status_valid;
2120 QmiNasRoamingStatus roaming_status;
2121 gboolean forbidden_valid;
2122 gboolean forbidden;
2123 gboolean lac_valid;
2124 guint16 lac;
2125 gboolean cid_valid;
2126 guint32 cid;
2127 gboolean registration_reject_info_valid;
2128 QmiNasNetworkServiceDomain registration_reject_domain;
2129 QmiNasRejectCause registration_reject_cause;
2130 gboolean network_id_valid;
2131 const gchar *mcc;
2132 const gchar *mnc;
2133 gboolean hs_call_status_valid;
2134 QmiNasWcdmaHsService hs_call_status;
2135 gboolean hs_service_valid;
2136 QmiNasWcdmaHsService hs_service;
2137 gboolean primary_scrambling_code_valid;
2138 guint16 primary_scrambling_code;
2139 guint16 geo_system_index;
2140 QmiNasCellBroadcastCapability cell_broadcast_support;
2141 QmiNasCallBarringStatus call_barring_status_cs;
2142 QmiNasCallBarringStatus call_barring_status_ps;
2143 QmiNasNetworkServiceDomain cipher_domain;
2144
2145 if (qmi_message_nas_get_system_info_output_get_wcdma_service_status (
2146 output,
2147 &service_status,
2148 &true_service_status,
2149 &preferred_data_path,
2150 NULL)) {
2151 g_print ("\tWCDMA service:\n"
2152 "\t\tStatus: '%s'\n"
2153 "\t\tTrue Status: '%s'\n"
2154 "\t\tPreferred data path: '%s'\n",
2155 qmi_nas_service_status_get_string (service_status),
2156 qmi_nas_service_status_get_string (true_service_status),
2157 preferred_data_path ? "yes" : "no");
2158
2159 if (qmi_message_nas_get_system_info_output_get_wcdma_system_info_v2 (
2160 output,
2161 &domain_valid, &domain,
2162 &service_capability_valid, &service_capability,
2163 &roaming_status_valid, &roaming_status,
2164 &forbidden_valid, &forbidden,
2165 &lac_valid, &lac,
2166 &cid_valid, &cid,
2167 &registration_reject_info_valid, &registration_reject_domain, &registration_reject_cause,
2168 &network_id_valid, &mcc, &mnc,
2169 &hs_call_status_valid, &hs_call_status,
2170 &hs_service_valid, &hs_service,
2171 &primary_scrambling_code_valid, &primary_scrambling_code,
2172 NULL)) {
2173 if (domain_valid)
2174 g_print ("\t\tDomain: '%s'\n", qmi_nas_network_service_domain_get_string (domain));
2175 if (service_capability_valid)
2176 g_print ("\t\tService capability: '%s'\n", qmi_nas_network_service_domain_get_string (service_capability));
2177 if (roaming_status_valid)
2178 g_print ("\t\tRoaming status: '%s'\n", qmi_nas_roaming_status_get_string (roaming_status));
2179 if (forbidden_valid)
2180 g_print ("\t\tForbidden: '%s'\n", forbidden ? "yes" : "no");
2181 if (lac_valid)
2182 g_print ("\t\tLocation Area Code: '%" G_GUINT16_FORMAT"'\n", lac);
2183 if (cid_valid)
2184 g_print ("\t\tCell ID: '%u'\n", cid);
2185 if (registration_reject_info_valid)
2186 g_print ("\t\tRegistration reject: '%s' (%s)\n",
2187 qmi_nas_network_service_domain_get_string (registration_reject_domain),
2188 qmi_nas_reject_cause_get_string (registration_reject_cause));
2189 if (network_id_valid) {
2190 g_print ("\t\tMCC: '%s'\n", mcc);
2191 if ((guchar)mnc[2] == 0xFF)
2192 g_print ("\t\tMNC: '%.2s'\n", mnc);
2193 else
2194 g_print ("\t\tMNC: '%.3s'\n", mnc);
2195 }
2196 if (hs_call_status_valid)
2197 g_print ("\t\tHS call status: '%s'\n", qmi_nas_wcdma_hs_service_get_string (hs_call_status));
2198 if (hs_service_valid)
2199 g_print ("\t\tHS service: '%s'\n", qmi_nas_wcdma_hs_service_get_string (hs_service));
2200 if (primary_scrambling_code_valid)
2201 g_print ("\t\tPrimary scrambling code: '%" G_GUINT16_FORMAT"'\n", primary_scrambling_code);
2202 }
2203
2204 if (qmi_message_nas_get_system_info_output_get_additional_wcdma_system_info (
2205 output,
2206 &geo_system_index,
2207 &cell_broadcast_support,
2208 NULL)) {
2209 if (geo_system_index != 0xFFFF)
2210 g_print ("\t\tGeo system index: '%" G_GUINT16_FORMAT "'\n", geo_system_index);
2211 g_print ("\t\tCell broadcast support: '%s'\n", qmi_nas_cell_broadcast_capability_get_string (cell_broadcast_support));
2212 }
2213
2214 if (qmi_message_nas_get_system_info_output_get_wcdma_call_barring_status (
2215 output,
2216 &call_barring_status_cs,
2217 &call_barring_status_ps,
2218 NULL)) {
2219 g_print ("\t\tCall barring status (CS): '%s'\n", qmi_nas_call_barring_status_get_string (call_barring_status_cs));
2220 g_print ("\t\tCall barring status (PS): '%s'\n", qmi_nas_call_barring_status_get_string (call_barring_status_ps));
2221 }
2222
2223 if (qmi_message_nas_get_system_info_output_get_wcdma_cipher_domain (
2224 output,
2225 &cipher_domain,
2226 NULL)) {
2227 g_print ("\t\tCipher Domain: '%s'\n", qmi_nas_network_service_domain_get_string (cipher_domain));
2228 }
2229 }
2230 }
2231
2232 /* LTE */
2233 {
2234 QmiNasServiceStatus service_status;
2235 QmiNasServiceStatus true_service_status;
2236 gboolean preferred_data_path;
2237 gboolean domain_valid;
2238 QmiNasNetworkServiceDomain domain;
2239 gboolean service_capability_valid;
2240 QmiNasNetworkServiceDomain service_capability;
2241 gboolean roaming_status_valid;
2242 QmiNasRoamingStatus roaming_status;
2243 gboolean forbidden_valid;
2244 gboolean forbidden;
2245 gboolean lac_valid;
2246 guint16 lac;
2247 gboolean cid_valid;
2248 guint32 cid;
2249 gboolean registration_reject_info_valid;
2250 QmiNasNetworkServiceDomain registration_reject_domain;
2251 QmiNasRejectCause registration_reject_cause;
2252 gboolean network_id_valid;
2253 const gchar *mcc;
2254 const gchar *mnc;
2255 gboolean tac_valid;
2256 guint16 tac;
2257 guint16 geo_system_index;
2258 gboolean voice_support;
2259 gboolean ims_voice_support;
2260 gboolean embms_coverage_info_support;
2261 guint16 embms_coverage_info_trace_id;
2262 QmiNasNetworkSelectionRegistrationRestriction registration_restriction;
2263 QmiNasLteCellAccessStatus cell_access_status;
2264 QmiNasLteRegistrationDomain registration_domain;
2265 gboolean endc_available;
2266 gboolean restrict_dcnr;
2267
2268 if (qmi_message_nas_get_system_info_output_get_lte_service_status (
2269 output,
2270 &service_status,
2271 &true_service_status,
2272 &preferred_data_path,
2273 NULL)) {
2274 g_print ("\tLTE service:\n"
2275 "\t\tStatus: '%s'\n"
2276 "\t\tTrue Status: '%s'\n"
2277 "\t\tPreferred data path: '%s'\n",
2278 qmi_nas_service_status_get_string (service_status),
2279 qmi_nas_service_status_get_string (true_service_status),
2280 preferred_data_path ? "yes" : "no");
2281
2282 if (qmi_message_nas_get_system_info_output_get_lte_system_info_v2 (
2283 output,
2284 &domain_valid, &domain,
2285 &service_capability_valid, &service_capability,
2286 &roaming_status_valid, &roaming_status,
2287 &forbidden_valid, &forbidden,
2288 &lac_valid, &lac,
2289 &cid_valid, &cid,
2290 &registration_reject_info_valid,&registration_reject_domain,&registration_reject_cause,
2291 &network_id_valid, &mcc, &mnc,
2292 &tac_valid, &tac,
2293 NULL)) {
2294 if (domain_valid)
2295 g_print ("\t\tDomain: '%s'\n", qmi_nas_network_service_domain_get_string (domain));
2296 if (service_capability_valid)
2297 g_print ("\t\tService capability: '%s'\n", qmi_nas_network_service_domain_get_string (service_capability));
2298 if (roaming_status_valid)
2299 g_print ("\t\tRoaming status: '%s'\n", qmi_nas_roaming_status_get_string (roaming_status));
2300 if (forbidden_valid)
2301 g_print ("\t\tForbidden: '%s'\n", forbidden ? "yes" : "no");
2302 if (lac_valid)
2303 g_print ("\t\tLocation Area Code: '%" G_GUINT16_FORMAT"'\n", lac);
2304 if (cid_valid)
2305 g_print ("\t\tCell ID: '%u'\n", cid);
2306 if (registration_reject_info_valid)
2307 g_print ("\t\tRegistration reject: '%s' (%s)\n",
2308 qmi_nas_network_service_domain_get_string (registration_reject_domain),
2309 qmi_nas_reject_cause_get_string (registration_reject_cause));
2310 if (network_id_valid) {
2311 g_print ("\t\tMCC: '%s'\n", mcc);
2312 if ((guchar)mnc[2] == 0xFF)
2313 g_print ("\t\tMNC: '%.2s'\n", mnc);
2314 else
2315 g_print ("\t\tMNC: '%.3s'\n", mnc);
2316 }
2317 if (tac_valid)
2318 g_print ("\t\tTracking Area Code: '%" G_GUINT16_FORMAT"'\n", tac);
2319 }
2320
2321 if (qmi_message_nas_get_system_info_output_get_additional_lte_system_info (
2322 output,
2323 &geo_system_index,
2324 NULL)) {
2325 if (geo_system_index != 0xFFFF)
2326 g_print ("\t\tGeo system index: '%" G_GUINT16_FORMAT "'\n", geo_system_index);
2327 }
2328
2329 if (qmi_message_nas_get_system_info_output_get_lte_voice_support (
2330 output,
2331 &voice_support,
2332 NULL)) {
2333 g_print ("\t\tVoice support: '%s'\n", voice_support ? "yes" : "no");
2334 }
2335
2336 if (qmi_message_nas_get_system_info_output_get_ims_voice_support (
2337 output,
2338 &ims_voice_support,
2339 NULL)) {
2340 g_print ("\t\tIMS voice support: '%s'\n", ims_voice_support ? "yes" : "no");
2341 }
2342
2343 if (qmi_message_nas_get_system_info_output_get_lte_embms_coverage_info_support (
2344 output,
2345 &embms_coverage_info_support,
2346 NULL)) {
2347 g_print ("\t\teMBMS coverage info support: '%s'\n", embms_coverage_info_support ? "yes" : "no");
2348 }
2349
2350 if (qmi_message_nas_get_system_info_output_get_lte_embms_coverage_info_trace_id (
2351 output,
2352 &embms_coverage_info_trace_id,
2353 NULL)) {
2354 g_print ("\t\teMBMS coverage info trace ID: '%" G_GUINT16_FORMAT "'\n", embms_coverage_info_trace_id);
2355 }
2356
2357 if (qmi_message_nas_get_system_info_output_get_lte_cell_access_status (
2358 output,
2359 &cell_access_status,
2360 NULL)) {
2361 g_print ("\t\tCell access: '%s'\n", qmi_nas_lte_cell_access_status_get_string (cell_access_status));
2362 }
2363
2364 if (qmi_message_nas_get_system_info_output_get_network_selection_registration_restriction (
2365 output,
2366 &registration_restriction,
2367 NULL)) {
2368 g_print ("\t\tRegistration restriction: '%s'\n", qmi_nas_network_selection_registration_restriction_get_string (registration_restriction));
2369 }
2370
2371 if (qmi_message_nas_get_system_info_output_get_lte_registration_domain (
2372 output,
2373 &registration_domain,
2374 NULL)) {
2375 g_print ("\t\tRegistration domain: '%s'\n", qmi_nas_lte_registration_domain_get_string (registration_domain));
2376 }
2377
2378 if (qmi_message_nas_get_system_info_output_get_eutra_with_nr5g_availability (
2379 output,
2380 &endc_available,
2381 NULL)) {
2382 g_print ("\t\t5G NSA Available: '%s'\n", endc_available ? "yes" : "no");
2383 }
2384
2385 if (qmi_message_nas_get_system_info_output_get_dcnr_restriction_info (
2386 output,
2387 &restrict_dcnr,
2388 NULL)) {
2389 g_print ("\t\tDCNR Restriction: '%s'\n", restrict_dcnr ? "yes" : "no");
2390 }
2391 }
2392 }
2393
2394 /* TD-SCDMA */
2395 {
2396 QmiNasServiceStatus service_status;
2397 QmiNasServiceStatus true_service_status;
2398 gboolean preferred_data_path;
2399 gboolean domain_valid;
2400 QmiNasNetworkServiceDomain domain;
2401 gboolean service_capability_valid;
2402 QmiNasNetworkServiceDomain service_capability;
2403 gboolean roaming_status_valid;
2404 QmiNasRoamingStatus roaming_status;
2405 gboolean forbidden_valid;
2406 gboolean forbidden;
2407 gboolean lac_valid;
2408 guint16 lac;
2409 gboolean cid_valid;
2410 guint32 cid;
2411 gboolean registration_reject_info_valid;
2412 QmiNasNetworkServiceDomain registration_reject_domain;
2413 QmiNasRejectCause registration_reject_cause;
2414 gboolean network_id_valid;
2415 const gchar *mcc;
2416 const gchar *mnc;
2417 gboolean hs_call_status_valid;
2418 QmiNasWcdmaHsService hs_call_status;
2419 gboolean hs_service_valid;
2420 QmiNasWcdmaHsService hs_service;
2421 gboolean cell_parameter_id_valid;
2422 guint16 cell_parameter_id;
2423 gboolean cell_broadcast_support_valid;
2424 QmiNasCellBroadcastCapability cell_broadcast_support;
2425 gboolean call_barring_status_cs_valid;
2426 QmiNasCallBarringStatus call_barring_status_cs;
2427 gboolean call_barring_status_ps_valid;
2428 QmiNasCallBarringStatus call_barring_status_ps;
2429 gboolean cipher_domain_valid;
2430 QmiNasNetworkServiceDomain cipher_domain;
2431
2432 if (qmi_message_nas_get_system_info_output_get_td_scdma_service_status (
2433 output,
2434 &service_status,
2435 &true_service_status,
2436 &preferred_data_path,
2437 NULL)) {
2438 g_print ("\tTD-SCDMA service:\n"
2439 "\t\tStatus: '%s'\n"
2440 "\t\tTrue Status: '%s'\n"
2441 "\t\tPreferred data path: '%s'\n",
2442 qmi_nas_service_status_get_string (service_status),
2443 qmi_nas_service_status_get_string (true_service_status),
2444 preferred_data_path ? "yes" : "no");
2445
2446 if (qmi_message_nas_get_system_info_output_get_td_scdma_system_info_v2 (
2447 output,
2448 &domain_valid, &domain,
2449 &service_capability_valid, &service_capability,
2450 &roaming_status_valid, &roaming_status,
2451 &forbidden_valid, &forbidden,
2452 &lac_valid, &lac,
2453 &cid_valid, &cid,
2454 &registration_reject_info_valid, &registration_reject_domain, &registration_reject_cause,
2455 &network_id_valid, &mcc, &mnc,
2456 &hs_call_status_valid, &hs_call_status,
2457 &hs_service_valid, &hs_service,
2458 &cell_parameter_id_valid, &cell_parameter_id,
2459 &cell_broadcast_support_valid, &cell_broadcast_support,
2460 &call_barring_status_cs_valid, &call_barring_status_cs,
2461 &call_barring_status_ps_valid, &call_barring_status_ps,
2462 &cipher_domain_valid, &cipher_domain,
2463 NULL)) {
2464 if (domain_valid)
2465 g_print ("\t\tDomain: '%s'\n", qmi_nas_network_service_domain_get_string (domain));
2466 if (service_capability_valid)
2467 g_print ("\t\tService capability: '%s'\n", qmi_nas_network_service_domain_get_string (service_capability));
2468 if (roaming_status_valid)
2469 g_print ("\t\tRoaming status: '%s'\n", qmi_nas_roaming_status_get_string (roaming_status));
2470 if (forbidden_valid)
2471 g_print ("\t\tForbidden: '%s'\n", forbidden ? "yes" : "no");
2472 if (lac_valid)
2473 g_print ("\t\tLocation Area Code: '%" G_GUINT16_FORMAT"'\n", lac);
2474 if (cid_valid)
2475 g_print ("\t\tCell ID: '%u'\n", cid);
2476 if (registration_reject_info_valid)
2477 g_print ("\t\tRegistration reject: '%s' (%s)\n",
2478 qmi_nas_network_service_domain_get_string (registration_reject_domain),
2479 qmi_nas_reject_cause_get_string (registration_reject_cause));
2480 if (network_id_valid) {
2481 g_print ("\t\tMCC: '%s'\n", mcc);
2482 if ((guchar)mnc[2] == 0xFF)
2483 g_print ("\t\tMNC: '%.2s'\n", mnc);
2484 else
2485 g_print ("\t\tMNC: '%.3s'\n", mnc);
2486 }
2487 if (hs_call_status_valid)
2488 g_print ("\t\tHS call status: '%s'\n", qmi_nas_wcdma_hs_service_get_string (hs_call_status));
2489 if (hs_service_valid)
2490 g_print ("\t\tHS service: '%s'\n", qmi_nas_wcdma_hs_service_get_string (hs_service));
2491 if (cell_parameter_id_valid)
2492 g_print ("\t\tCell parameter ID: '%" G_GUINT16_FORMAT"'\n", cell_parameter_id);
2493 if (cell_broadcast_support_valid)
2494 g_print ("\t\tCell broadcast support: '%s'\n", qmi_nas_cell_broadcast_capability_get_string (cell_broadcast_support));
2495 if (call_barring_status_cs_valid)
2496 g_print ("\t\tCall barring status (CS): '%s'\n", qmi_nas_call_barring_status_get_string (call_barring_status_cs));
2497 if (call_barring_status_ps_valid)
2498 g_print ("\t\tCall barring status (PS): '%s'\n", qmi_nas_call_barring_status_get_string (call_barring_status_ps));
2499 if (cipher_domain_valid)
2500 g_print ("\t\tCipher Domain: '%s'\n", qmi_nas_network_service_domain_get_string (cipher_domain));
2501 }
2502 }
2503 }
2504
2505 /* 5G SA */
2506 {
2507 QmiNasServiceStatus service_status;
2508 QmiNasServiceStatus true_service_status;
2509 gboolean preferred_data_path;
2510 gboolean domain_valid;
2511 QmiNasNetworkServiceDomain domain;
2512 gboolean service_capability_valid;
2513 QmiNasNetworkServiceDomain service_capability;
2514 gboolean roaming_status_valid;
2515 QmiNasRoamingStatus roaming_status;
2516 gboolean forbidden_valid;
2517 gboolean forbidden;
2518 gboolean lac_valid;
2519 guint16 lac;
2520 gboolean cid_valid;
2521 guint32 cid;
2522 gboolean registration_reject_info_valid;
2523 QmiNasNetworkServiceDomain registration_reject_domain;
2524 guint8 registration_reject_cause;
2525 gboolean network_id_valid;
2526 const gchar *mcc;
2527 const gchar *mnc;
2528 gboolean tac_valid;
2529 guint16 tac;
2530
2531 if (qmi_message_nas_get_system_info_output_get_nr5g_service_status_info (
2532 output,
2533 &service_status,
2534 &true_service_status,
2535 &preferred_data_path,
2536 NULL)) {
2537 g_print ("\t5G SA service:\n"
2538 "\t\tStatus: '%s'\n"
2539 "\t\tTrue Status: '%s'\n"
2540 "\t\tPreferred data path: '%s'\n",
2541 qmi_nas_service_status_get_string (service_status),
2542 qmi_nas_service_status_get_string (true_service_status),
2543 preferred_data_path ? "yes" : "no");
2544
2545 if (qmi_message_nas_get_system_info_output_get_nr5g_system_info (
2546 output,
2547 &domain_valid, &domain,
2548 &service_capability_valid, &service_capability,
2549 &roaming_status_valid, &roaming_status,
2550 &forbidden_valid, &forbidden,
2551 &lac_valid, &lac,
2552 &cid_valid, &cid,
2553 &registration_reject_info_valid,&registration_reject_domain,&registration_reject_cause,
2554 &network_id_valid, &mcc, &mnc,
2555 &tac_valid, &tac,
2556 NULL)) {
2557 if (domain_valid)
2558 g_print ("\t\tDomain: '%s'\n", qmi_nas_network_service_domain_get_string (domain));
2559 if (service_capability_valid)
2560 g_print ("\t\tService capability: '%s'\n", qmi_nas_network_service_domain_get_string (service_capability));
2561 if (roaming_status_valid)
2562 g_print ("\t\tRoaming status: '%s'\n", qmi_nas_roaming_status_get_string (roaming_status));
2563 if (forbidden_valid)
2564 g_print ("\t\tForbidden: '%s'\n", forbidden ? "yes" : "no");
2565 if (lac_valid)
2566 g_print ("\t\tLocation Area Code: '%" G_GUINT16_FORMAT"'\n", lac);
2567 if (cid_valid)
2568 g_print ("\t\tCell ID: '%u'\n", cid);
2569 if (registration_reject_info_valid)
2570 g_print ("\t\tRegistration reject: '%s' (%u)\n",
2571 qmi_nas_network_service_domain_get_string (registration_reject_domain),
2572 registration_reject_cause);
2573 if (network_id_valid) {
2574 g_print ("\t\tMCC: '%s'\n", mcc);
2575 if ((guchar)mnc[2] == 0xFF)
2576 g_print ("\t\tMNC: '%.2s'\n", mnc);
2577 else
2578 g_print ("\t\tMNC: '%.3s'\n", mnc);
2579 }
2580 if (tac_valid)
2581 g_print ("\t\tTracking Area Code: '%" G_GUINT16_FORMAT"'\n", tac);
2582 }
2583 }
2584 }
2585
2586 {
2587 GArray *nr5g_tracking_area_code;
2588
2589 if (qmi_message_nas_get_system_info_output_get_nr5g_tracking_area_code (
2590 output,
2591 &nr5g_tracking_area_code,
2592 NULL)) {
2593 guint32 tac;
2594
2595 g_assert (nr5g_tracking_area_code->len == 3);
2596 tac = ((((g_array_index (nr5g_tracking_area_code, guint8, 0) << 8) |
2597 g_array_index (nr5g_tracking_area_code, guint8, 1)) << 8) |
2598 g_array_index (nr5g_tracking_area_code, guint8, 2));
2599
2600 g_print ("\t5GNR Tracking Area Code: '%" G_GUINT32_FORMAT "'\n",
2601 tac);
2602 }
2603 }
2604
2605 /* Common */
2606 {
2607 QmiNasSimRejectState sim_reject_info;
2608
2609 if (qmi_message_nas_get_system_info_output_get_sim_reject_info (
2610 output,
2611 &sim_reject_info,
2612 NULL)) {
2613 g_print ("\tSIM reject info: '%s'\n", qmi_nas_sim_reject_state_get_string (sim_reject_info));
2614 }
2615 }
2616
2617 qmi_message_nas_get_system_info_output_unref (output);
2618 operation_shutdown (TRUE);
2619 }
2620
2621 #endif /* HAVE_QMI_MESSAGE_NAS_GET_SYSTEM_INFO */
2622
2623 #if defined HAVE_QMI_MESSAGE_NAS_GET_TECHNOLOGY_PREFERENCE
2624
2625 static void
2626 get_technology_preference_ready (QmiClientNas *client,
2627 GAsyncResult *res)
2628 {
2629 QmiMessageNasGetTechnologyPreferenceOutput *output;
2630 GError *error = NULL;
2631 QmiNasRadioTechnologyPreference preference;
2632 QmiNasPreferenceDuration duration;
2633 g_autofree gchar *preference_string = NULL;
2634 g_autofree gchar *persistent_preference_string = NULL;
2635
2636 output = qmi_client_nas_get_technology_preference_finish (client, res, &error);
2637 if (!output) {
2638 g_printerr ("error: operation failed: %s\n", error->message);
2639 g_error_free (error);
2640 operation_shutdown (FALSE);
2641 return;
2642 }
2643
2644 if (!qmi_message_nas_get_technology_preference_output_get_result (output, &error)) {
2645 g_printerr ("error: couldn't get technology preference: %s\n", error->message);
2646 g_error_free (error);
2647 qmi_message_nas_get_technology_preference_output_unref (output);
2648 operation_shutdown (FALSE);
2649 return;
2650 }
2651
2652 qmi_message_nas_get_technology_preference_output_get_active (
2653 output,
2654 &preference,
2655 &duration,
2656 NULL);
2657
2658 preference_string = qmi_nas_radio_technology_preference_build_string_from_mask (preference);
2659 g_print ("[%s] Successfully got technology preference\n"
2660 "\tActive: '%s', duration: '%s'\n",
2661 qmi_device_get_path_display (ctx->device),
2662 VALIDATE_MASK_NONE (preference_string),
2663 qmi_nas_preference_duration_get_string (duration));
2664
2665 if (qmi_message_nas_get_technology_preference_output_get_persistent (
2666 output,
2667 &preference,
2668 NULL)) {
2669 persistent_preference_string = qmi_nas_radio_technology_preference_build_string_from_mask (preference);
2670 g_print ("\tPersistent: '%s'\n", VALIDATE_MASK_NONE (persistent_preference_string));
2671 }
2672
2673 qmi_message_nas_get_technology_preference_output_unref (output);
2674 operation_shutdown (TRUE);
2675 }
2676
2677 #endif /* HAVE_QMI_MESSAGE_NAS_GET_TECHNOLOGY_PREFERENCE */
2678
2679 #if defined HAVE_QMI_MESSAGE_NAS_GET_SYSTEM_SELECTION_PREFERENCE
2680
2681 static void
2682 get_system_selection_preference_ready (QmiClientNas *client,
2683 GAsyncResult *res)
2684 {
2685 QmiMessageNasGetSystemSelectionPreferenceOutput *output;
2686 GError *error = NULL;
2687 gboolean emergency_mode;
2688 QmiNasRatModePreference mode_preference;
2689 QmiNasRatModePreference disabled_modes;
2690 QmiNasBandPreference band_preference;
2691 QmiNasLteBandPreference lte_band_preference;
2692 QmiNasTdScdmaBandPreference td_scdma_band_preference;
2693 QmiNasCdmaPrlPreference cdma_prl_preference;
2694 QmiNasRoamingPreference roaming_preference;
2695 QmiNasNetworkSelectionPreference network_selection_preference;
2696 QmiNasServiceDomainPreference service_domain_preference;
2697 QmiNasUsagePreference usage_preference;
2698 QmiNasGsmWcdmaAcquisitionOrderPreference gsm_wcdma_acquisition_order_preference;
2699 QmiNasNetworkSelectionRegistrationRestriction registration_restriction;
2700 QmiNasVoiceDomainPreference voice_domain_preference;
2701 guint16 mcc;
2702 guint16 mnc;
2703 guint64 extended_lte_band_preference[4];
2704 guint64 nr5g_sa_band_preference[8];
2705 guint64 nr5g_nsa_band_preference[8];
2706 gboolean has_pcs_digit;
2707 GArray *acquisition_order_preference;
2708
2709 output = qmi_client_nas_get_system_selection_preference_finish (client, res, &error);
2710 if (!output) {
2711 g_printerr ("error: operation failed: %s\n", error->message);
2712 g_error_free (error);
2713 operation_shutdown (FALSE);
2714 return;
2715 }
2716
2717 if (!qmi_message_nas_get_system_selection_preference_output_get_result (output, &error)) {
2718 g_printerr ("error: couldn't get system_selection preference: %s\n", error->message);
2719 g_error_free (error);
2720 qmi_message_nas_get_system_selection_preference_output_unref (output);
2721 operation_shutdown (FALSE);
2722 return;
2723 }
2724
2725 g_print ("[%s] Successfully got system selection preference\n",
2726 qmi_device_get_path_display (ctx->device));
2727
2728 if (qmi_message_nas_get_system_selection_preference_output_get_emergency_mode (
2729 output,
2730 &emergency_mode,
2731 NULL)) {
2732 g_print ("\tEmergency mode: '%s'\n",
2733 emergency_mode ? "yes" : "no");
2734 }
2735
2736 if (qmi_message_nas_get_system_selection_preference_output_get_mode_preference (
2737 output,
2738 &mode_preference,
2739 NULL)) {
2740 g_autofree gchar *str = NULL;
2741
2742 str = qmi_nas_rat_mode_preference_build_string_from_mask (mode_preference);
2743 g_print ("\tMode preference: '%s'\n", VALIDATE_MASK_NONE (str));
2744 }
2745
2746 if (qmi_message_nas_get_system_selection_preference_output_get_disabled_modes (
2747 output,
2748 &disabled_modes,
2749 NULL)) {
2750 g_autofree gchar *str = NULL;
2751
2752 str = qmi_nas_rat_mode_preference_build_string_from_mask (disabled_modes);
2753 g_print ("\tDisabled modes: '%s'\n", VALIDATE_MASK_NONE (str));
2754 }
2755
2756
2757 if (qmi_message_nas_get_system_selection_preference_output_get_band_preference (
2758 output,
2759 &band_preference,
2760 NULL)) {
2761 g_autofree gchar *str = NULL;
2762
2763 str = qmi_nas_band_preference_build_string_from_mask (band_preference);
2764 g_print ("\tBand preference: '%s'\n", VALIDATE_MASK_NONE (str));
2765 }
2766
2767 if (qmi_message_nas_get_system_selection_preference_output_get_lte_band_preference (
2768 output,
2769 &lte_band_preference,
2770 NULL)) {
2771 g_autofree gchar *str = NULL;
2772
2773 str = qmi_nas_lte_band_preference_build_string_from_mask (lte_band_preference);
2774 g_print ("\tLTE band preference: '%s'\n", VALIDATE_MASK_NONE (str));
2775 }
2776
2777 if (qmi_message_nas_get_system_selection_preference_output_get_extended_lte_band_preference (
2778 output,
2779 &extended_lte_band_preference[0],
2780 &extended_lte_band_preference[1],
2781 &extended_lte_band_preference[2],
2782 &extended_lte_band_preference[3],
2783 NULL)) {
2784 guint i;
2785 gboolean first = TRUE;
2786
2787 g_print ("\tLTE band preference (extended): '");
2788 for (i = 0; i < G_N_ELEMENTS (extended_lte_band_preference); i++) {
2789 guint j;
2790
2791 for (j = 0; j < 64; j++) {
2792 guint band;
2793
2794 if (!(extended_lte_band_preference[i] & (((guint64) 1) << j)))
2795 continue;
2796 band = 1 + j + (i * 64);
2797 if (first) {
2798 g_print ("%u", band);
2799 first = FALSE;
2800 } else
2801 g_print (", %u", band);
2802 }
2803 }
2804 g_print ("'\n");
2805 }
2806
2807 if (qmi_message_nas_get_system_selection_preference_output_get_nr5g_sa_band_preference (
2808 output,
2809 &nr5g_sa_band_preference[0],
2810 &nr5g_sa_band_preference[1],
2811 &nr5g_sa_band_preference[2],
2812 &nr5g_sa_band_preference[3],
2813 &nr5g_sa_band_preference[4],
2814 &nr5g_sa_band_preference[5],
2815 &nr5g_sa_band_preference[6],
2816 &nr5g_sa_band_preference[7],
2817 NULL)) {
2818 guint i;
2819 gboolean first = TRUE;
2820
2821 g_print ("\tNR5G SA band preference: '");
2822 for (i = 0; i < G_N_ELEMENTS (nr5g_sa_band_preference); i++) {
2823 guint j;
2824
2825 for (j = 0; j < 64; j++) {
2826 guint band;
2827
2828 if (!(nr5g_sa_band_preference[i] & (((guint64) 1) << j)))
2829 continue;
2830 band = 1 + j + (i * 64);
2831 if (first) {
2832 g_print ("%u", band);
2833 first = FALSE;
2834 } else
2835 g_print (", %u", band);
2836 }
2837 }
2838 g_print ("'\n");
2839 }
2840
2841 if (qmi_message_nas_get_system_selection_preference_output_get_nr5g_nsa_band_preference (
2842 output,
2843 &nr5g_nsa_band_preference[0],
2844 &nr5g_nsa_band_preference[1],
2845 &nr5g_nsa_band_preference[2],
2846 &nr5g_nsa_band_preference[3],
2847 &nr5g_nsa_band_preference[4],
2848 &nr5g_nsa_band_preference[5],
2849 &nr5g_nsa_band_preference[6],
2850 &nr5g_nsa_band_preference[7],
2851 NULL)) {
2852 guint i;
2853 gboolean first = TRUE;
2854
2855 g_print ("\tNR5G NSA band preference: '");
2856 for (i = 0; i < G_N_ELEMENTS (nr5g_nsa_band_preference); i++) {
2857 guint j;
2858
2859 for (j = 0; j < 64; j++) {
2860 guint band;
2861
2862 if (!(nr5g_nsa_band_preference[i] & (((guint64) 1) << j)))
2863 continue;
2864 band = 1 + j + (i * 64);
2865 if (first) {
2866 g_print ("%u", band);
2867 first = FALSE;
2868 } else
2869 g_print (", %u", band);
2870 }
2871 }
2872 g_print ("'\n");
2873 }
2874
2875 if (qmi_message_nas_get_system_selection_preference_output_get_td_scdma_band_preference (
2876 output,
2877 &td_scdma_band_preference,
2878 NULL)) {
2879 g_autofree gchar *str = NULL;
2880
2881 str = qmi_nas_td_scdma_band_preference_build_string_from_mask (td_scdma_band_preference);
2882 g_print ("\tTD-SCDMA band preference: '%s'\n", VALIDATE_MASK_NONE (str));
2883 }
2884
2885 if (qmi_message_nas_get_system_selection_preference_output_get_cdma_prl_preference (
2886 output,
2887 &cdma_prl_preference,
2888 NULL)) {
2889 g_print ("\tCDMA PRL preference: '%s'\n",
2890 qmi_nas_cdma_prl_preference_get_string (cdma_prl_preference));
2891 }
2892
2893 if (qmi_message_nas_get_system_selection_preference_output_get_roaming_preference (
2894 output,
2895 &roaming_preference,
2896 NULL)) {
2897 g_print ("\tRoaming preference: '%s'\n",
2898 qmi_nas_roaming_preference_get_string (roaming_preference));
2899 }
2900
2901 if (qmi_message_nas_get_system_selection_preference_output_get_network_selection_preference (
2902 output,
2903 &network_selection_preference,
2904 NULL)) {
2905 g_print ("\tNetwork selection preference: '%s'\n",
2906 qmi_nas_network_selection_preference_get_string (network_selection_preference));
2907 }
2908
2909
2910 if (qmi_message_nas_get_system_selection_preference_output_get_service_domain_preference (
2911 output,
2912 &service_domain_preference,
2913 NULL)) {
2914 g_print ("\tService domain preference: '%s'\n",
2915 qmi_nas_service_domain_preference_get_string (service_domain_preference));
2916 }
2917
2918 if (qmi_message_nas_get_system_selection_preference_output_get_gsm_wcdma_acquisition_order_preference (
2919 output,
2920 &gsm_wcdma_acquisition_order_preference,
2921 NULL)) {
2922 g_print ("\tGSM/WCDMA acquisition order preference: '%s'\n",
2923 qmi_nas_gsm_wcdma_acquisition_order_preference_get_string (gsm_wcdma_acquisition_order_preference));
2924 }
2925
2926 if (qmi_message_nas_get_system_selection_preference_output_get_usage_preference (
2927 output,
2928 &usage_preference,
2929 NULL)) {
2930 g_print ("\tUsage preference: '%s'\n",
2931 qmi_nas_usage_preference_get_string (usage_preference));
2932 }
2933
2934 if (qmi_message_nas_get_system_selection_preference_output_get_voice_domain_preference (
2935 output,
2936 &voice_domain_preference,
2937 NULL)) {
2938 g_print ("\tVoice domain preference: '%s'\n",
2939 qmi_nas_voice_domain_preference_get_string (voice_domain_preference));
2940 }
2941
2942
2943 if (qmi_message_nas_get_system_selection_preference_output_get_network_selection_registration_restriction (
2944 output,
2945 &registration_restriction,
2946 NULL)) {
2947 g_print ("\tRegistration restriction: '%s'\n", qmi_nas_network_selection_registration_restriction_get_string (registration_restriction));
2948 }
2949
2950 if (qmi_message_nas_get_system_selection_preference_output_get_manual_network_selection (
2951 output,
2952 &mcc,
2953 &mnc,
2954 &has_pcs_digit,
2955 NULL)) {
2956 g_print ("\tManual network selection:\n"
2957 "\t\tMCC: '%" G_GUINT16_FORMAT"'\n"
2958 "\t\tMNC: '%" G_GUINT16_FORMAT"'\n"
2959 "\t\tMCC with PCS digit: '%s'\n",
2960 mcc,
2961 mnc,
2962 has_pcs_digit ? "yes" : "no");
2963 }
2964
2965 if (qmi_message_nas_get_system_selection_preference_output_get_acquisition_order_preference (
2966 output,
2967 &acquisition_order_preference,
2968 NULL)) {
2969 guint i;
2970
2971 g_print ("\tAcquisition order preference: '");
2972 for (i = 0; i < acquisition_order_preference->len; i++) {
2973 QmiNasRadioInterface radio_interface;
2974
2975 radio_interface = g_array_index (acquisition_order_preference, QmiNasRadioInterface, i);
2976 g_print ("%s%s",
2977 i > 0 ? ", " : "",
2978 qmi_nas_radio_interface_get_string (radio_interface));
2979 }
2980 g_print ("'\n");
2981 }
2982
2983 qmi_message_nas_get_system_selection_preference_output_unref (output);
2984 operation_shutdown (TRUE);
2985 }
2986
2987 #endif /* HAVE_QMI_MESSAGE_NAS_GET_SYSTEM_SELECTION_PREFERENCE */
2988
2989 #if defined HAVE_QMI_MESSAGE_NAS_SET_SYSTEM_SELECTION_PREFERENCE
2990
2991 static QmiMessageNasSetSystemSelectionPreferenceInput *
2992 set_system_selection_preference_input_create (const gchar *str)
2993 {
2994 QmiMessageNasSetSystemSelectionPreferenceInput *input = NULL;
2995 GError *error = NULL;
2996 gchar *rat_pref_str = NULL;
2997 gchar *net_pref_str = NULL;
2998 QmiNasRatModePreference rat_mode_preference = 0;
2999 GArray *acquisition_order = NULL;
3000 QmiNasNetworkSelectionPreference net_preference = 0;
3001 guint16 mcc = 0;
3002 guint16 mnc = 0;
3003
3004 if (strchr (str, ',')) {
3005 gchar **parts;
3006
3007 /* Both RAT mode preference and network selection preference were given */
3008 parts = g_strsplit_set (str, ",", -1);
3009 if (g_strv_length (parts) != 2) {
3010 g_printerr ("error: failed to parse selection pref: '%s'\n", str);
3011 g_strfreev (parts);
3012 return NULL;
3013 }
3014 rat_pref_str = g_strdup (parts[0]);
3015 net_pref_str = g_strdup (parts[1]);
3016 g_strfreev (parts);
3017 } else if (g_str_has_prefix (str, "automatic") || g_str_has_prefix (str, "manual")) {
3018 /* Only network selection preference was given */
3019 net_pref_str = g_strdup (str);
3020 } else {
3021 /* Only RAT mode preference was given */
3022 rat_pref_str = g_strdup (str);
3023 }
3024
3025 if (net_pref_str && !qmicli_read_ssp_net_options_from_string (net_pref_str, &net_preference, &mcc, &mnc)) {
3026 g_printerr ("error: failed to parse network preference options: '%s'\n", net_pref_str);
3027 goto out;
3028 }
3029
3030 if (rat_pref_str && !qmicli_read_ssp_rat_options_from_string (rat_pref_str, &rat_mode_preference, &acquisition_order)) {
3031 g_printerr ("error: failed to parse system selection preference options: '%s'\n", rat_pref_str);
3032 goto out;
3033 }
3034
3035 /* from now on, if an error happens, the GError must be set */
3036 input = qmi_message_nas_set_system_selection_preference_input_new ();
3037
3038 if (!qmi_message_nas_set_system_selection_preference_input_set_change_duration (input, QMI_NAS_CHANGE_DURATION_PERMANENT, &error))
3039 goto out;
3040
3041 if (rat_mode_preference && !qmi_message_nas_set_system_selection_preference_input_set_mode_preference (input, rat_mode_preference, &error))
3042 goto out;
3043
3044 if ((rat_mode_preference & (QMI_NAS_RAT_MODE_PREFERENCE_GSM | QMI_NAS_RAT_MODE_PREFERENCE_UMTS | QMI_NAS_RAT_MODE_PREFERENCE_LTE)) &&
3045 (!qmi_message_nas_set_system_selection_preference_input_set_gsm_wcdma_acquisition_order_preference (
3046 input,
3047 QMI_NAS_GSM_WCDMA_ACQUISITION_ORDER_PREFERENCE_AUTOMATIC,
3048 &error)))
3049 goto out;
3050
3051 if (acquisition_order && !qmi_message_nas_set_system_selection_preference_input_set_acquisition_order_preference (input, acquisition_order, &error))
3052 goto out;
3053
3054 if (net_pref_str && !qmi_message_nas_set_system_selection_preference_input_set_network_selection_preference (input, net_preference, mcc, mnc, &error))
3055 goto out;
3056
3057 out:
3058 g_free (rat_pref_str);
3059 g_free (net_pref_str);
3060
3061 if (acquisition_order)
3062 g_array_unref (acquisition_order);
3063
3064 if (error) {
3065 g_printerr ("error: couldn't create input data bundle: '%s'\n", error->message);
3066 g_error_free (error);
3067 qmi_message_nas_set_system_selection_preference_input_unref (input);
3068 return NULL;
3069 }
3070
3071 return input;
3072 }
3073
3074 static void
3075 set_system_selection_preference_ready (QmiClientNas *client,
3076 GAsyncResult *res)
3077 {
3078 QmiMessageNasSetSystemSelectionPreferenceOutput *output = NULL;
3079 GError *error = NULL;
3080
3081 output = qmi_client_nas_set_system_selection_preference_finish (client, res, &error);
3082 if (!output) {
3083 g_printerr ("error: operation failed: %s\n", error->message);
3084 g_error_free (error);
3085 operation_shutdown (FALSE);
3086 return;
3087 }
3088
3089 if (!qmi_message_nas_set_system_selection_preference_output_get_result (output, &error)) {
3090 g_printerr ("error: couldn't set operating mode: %s\n", error->message);
3091 g_error_free (error);
3092 qmi_message_nas_set_system_selection_preference_output_unref (output);
3093 operation_shutdown (FALSE);
3094 return;
3095 }
3096
3097 g_print ("[%s] System selection preference set successfully; replug your device.\n",
3098 qmi_device_get_path_display (ctx->device));
3099
3100 qmi_message_nas_set_system_selection_preference_output_unref (output);
3101 operation_shutdown (TRUE);
3102 }
3103
3104 #endif /* HAVE_QMI_MESSAGE_NAS_SET_SYSTEM_SELECTION_PREFERENCE */
3105
3106 #if defined HAVE_QMI_MESSAGE_NAS_NETWORK_SCAN
3107
3108 static QmiMessageNasNetworkScanInput *
3109 network_scan_input_create (const gchar *str)
3110 {
3111 g_autoptr(QmiMessageNasNetworkScanInput) input = NULL;
3112 g_autoptr(GError) error = NULL;
3113 QmiNasNetworkScanType scan_type = 0;
3114
3115 input = qmi_message_nas_network_scan_input_new ();
3116
3117 if (!qmicli_read_nas_network_scan_type_from_string (str, &scan_type)) {
3118 g_printerr ("error: could not parse input string '%s': %s\n",
3119 str, error->message);
3120 return NULL;
3121 }
3122
3123 if (!qmi_message_nas_network_scan_input_set_network_type (
3124 input,
3125 scan_type,
3126 &error)) {
3127 g_printerr ("error: could not set network scan type '%s': %s\n",
3128 str, error->message);
3129 return NULL;
3130 }
3131
3132 return g_steal_pointer (&input);
3133 }
3134
3135 static void
3136 network_scan_ready (QmiClientNas *client,
3137 GAsyncResult *res)
3138 {
3139 QmiMessageNasNetworkScanOutput *output;
3140 QmiNasNetworkScanResult network_scan_result;
3141 GError *error = NULL;
3142 GArray *array;
3143
3144 output = qmi_client_nas_network_scan_finish (client, res, &error);
3145 if (!output) {
3146 g_printerr ("error: operation failed: %s\n", error->message);
3147 g_error_free (error);
3148 operation_shutdown (FALSE);
3149 return;
3150 }
3151
3152 if (!qmi_message_nas_network_scan_output_get_result (output, &error)) {
3153 g_printerr ("error: couldn't scan networks: %s\n", error->message);
3154 g_error_free (error);
3155 qmi_message_nas_network_scan_output_unref (output);
3156 operation_shutdown (FALSE);
3157 return;
3158 }
3159
3160 g_print ("[%s] Successfully scanned networks\n",
3161 qmi_device_get_path_display (ctx->device));
3162
3163 array = NULL;
3164 if (qmi_message_nas_network_scan_output_get_network_information (output, &array, NULL)) {
3165 guint i;
3166
3167 for (i = 0; i < array->len; i++) {
3168 QmiMessageNasNetworkScanOutputNetworkInformationElement *element;
3169 g_autofree gchar *status_str = NULL;
3170
3171 element = &g_array_index (array, QmiMessageNasNetworkScanOutputNetworkInformationElement, i);
3172 status_str = qmi_nas_network_status_build_string_from_mask (element->network_status);
3173 g_print ("Network [%u]:\n"
3174 "\tMCC: '%" G_GUINT16_FORMAT"'\n"
3175 "\tMNC: '%" G_GUINT16_FORMAT"'\n"
3176 "\tStatus: '%s'\n"
3177 "\tDescription: '%s'\n",
3178 i,
3179 element->mcc,
3180 element->mnc,
3181 VALIDATE_MASK_NONE (status_str),
3182 element->description);
3183 }
3184 }
3185
3186 array = NULL;
3187 if (qmi_message_nas_network_scan_output_get_radio_access_technology (output, &array, NULL)) {
3188 guint i;
3189
3190 for (i = 0; i < array->len; i++) {
3191 QmiMessageNasNetworkScanOutputRadioAccessTechnologyElement *element;
3192
3193 element = &g_array_index (array, QmiMessageNasNetworkScanOutputRadioAccessTechnologyElement, i);
3194 g_print ("Network [%u]:\n"
3195 "\tMCC: '%" G_GUINT16_FORMAT"'\n"
3196 "\tMNC: '%" G_GUINT16_FORMAT"'\n"
3197 "\tRAT: '%s'\n",
3198 i,
3199 element->mcc,
3200 element->mnc,
3201 qmi_nas_radio_interface_get_string (element->radio_interface));
3202 }
3203 }
3204
3205 array = NULL;
3206 if (qmi_message_nas_network_scan_output_get_mnc_pcs_digit_include_status (output, &array, NULL)) {
3207 guint i;
3208
3209 for (i = 0; i < array->len; i++) {
3210 QmiMessageNasNetworkScanOutputMncPcsDigitIncludeStatusElement *element;
3211
3212 element = &g_array_index (array, QmiMessageNasNetworkScanOutputMncPcsDigitIncludeStatusElement, i);
3213 g_print ("Network [%u]:\n"
3214 "\tMCC: '%" G_GUINT16_FORMAT"'\n"
3215 "\tMNC: '%" G_GUINT16_FORMAT"'\n"
3216 "\tMCC with PCS digit: '%s'\n",
3217 i,
3218 element->mcc,
3219 element->mnc,
3220 element->includes_pcs_digit ? "yes" : "no");
3221 }
3222 }
3223
3224 if (qmi_message_nas_network_scan_output_get_network_scan_result (output,
3225 &network_scan_result,
3226 NULL)) {
3227 g_print ("Network scan result: %s\n",
3228 qmi_nas_network_scan_result_get_string (network_scan_result));
3229 }
3230
3231 qmi_message_nas_network_scan_output_unref (output);
3232 operation_shutdown (TRUE);
3233 }
3234
3235 #endif /* HAVE_QMI_MESSAGE_NAS_NETWORK_SCAN */
3236
3237 #if defined HAVE_QMI_MESSAGE_NAS_INCREMENTAL_NETWORK_SCAN
3238
3239 static QmiMessageNasIncrementalNetworkScanInput *
3240 incremental_network_scan_input_create (const gchar *str)
3241 {
3242 g_autoptr(QmiMessageNasIncrementalNetworkScanInput) input = NULL;
3243 g_autoptr(GError) error = NULL;
3244 QmiNasNetworkScanType scan_type = 0;
3245
3246 input = qmi_message_nas_incremental_network_scan_input_new ();
3247
3248 if (!qmicli_read_nas_network_scan_type_from_string (str, &scan_type)) {
3249 g_printerr ("error: could not parse input string '%s': %s\n",
3250 str, error->message);
3251 return NULL;
3252 }
3253
3254 if (!qmi_message_nas_incremental_network_scan_input_set_network_type (
3255 input,
3256 scan_type,
3257 &error)) {
3258 g_printerr ("error: could not set network scan type '%s': %s\n",
3259 str, error->message);
3260 return NULL;
3261 }
3262
3263 return g_steal_pointer (&input);
3264 }
3265
3266 static void
3267 network_scan_cancelled (GCancellable *cancellable)
3268 {
3269 operation_shutdown (TRUE);
3270 }
3271
3272 static gboolean
3273 network_scan_timeout (gpointer user_data)
3274 {
3275 g_print ("\nIncremental network scan timed out\n");
3276 operation_shutdown (TRUE);
3277 return TRUE;
3278 }
3279
3280 static void
3281 incremental_network_scan_received (QmiClientNas *client,
3282 QmiIndicationNasIncrementalNetworkScanOutput *output)
3283 {
3284 g_autoptr(GError) error = NULL;
3285 QmiNasIncrementalNetworkScanStatus status = 0;
3286 GArray *array = NULL;
3287
3288 g_print ("[%s] Received incremental network scan indication:\n",
3289 qmi_device_get_path_display (ctx->device));
3290
3291 if (!qmi_indication_nas_incremental_network_scan_output_get_status (
3292 output, &status, &error)) {
3293 g_printerr ("error: could not parse incremental network scan status: %s\n", error->message);
3294 operation_shutdown (FALSE);
3295 return;
3296 }
3297
3298 if (qmi_indication_nas_incremental_network_scan_output_get_network_information (output, &array, NULL)) {
3299 guint i;
3300
3301 for (i = 0; i < array->len; i++) {
3302 QmiIndicationNasIncrementalNetworkScanOutputNetworkInformationElement *element;
3303 g_autofree gchar *status_str = NULL;
3304
3305 element = &g_array_index (array, QmiIndicationNasIncrementalNetworkScanOutputNetworkInformationElement, i);
3306 status_str = qmi_nas_network_status_build_string_from_mask (element->network_status);
3307 g_print ("Network [%u]:\n"
3308 "\tMCC: '%" G_GUINT16_FORMAT"'\n"
3309 "\tMNC: '%" G_GUINT16_FORMAT"'\n"
3310 "\tMCC with PCS digit: '%s'\n"
3311 "\tStatus: '%s'\n"
3312 "\tRAT: '%s'\n"
3313 "\tDescription: '%s'\n",
3314 i,
3315 element->mcc,
3316 element->mnc,
3317 element->includes_pcs_digit ? "yes" : "no",
3318 VALIDATE_MASK_NONE (status_str),
3319 qmi_nas_radio_interface_get_string (element->radio_interface),
3320 element->description);
3321 }
3322 }
3323
3324 switch (status) {
3325 case QMI_NAS_INCREMENTAL_NETWORK_SCAN_STATUS_PARTIAL:
3326 /* Continue waiting for more results */
3327 return;
3328 case QMI_NAS_INCREMENTAL_NETWORK_SCAN_STATUS_COMPLETE:
3329 g_print ("\nIncremental network scan complete\n");
3330 break;
3331 case QMI_NAS_INCREMENTAL_NETWORK_SCAN_STATUS_ABORTED:
3332 g_print ("\nIncremental network scan aborted\n");
3333 break;
3334 default:
3335 g_print ("\nUnknown incremental network scan status %d\n", status);
3336 break;
3337 }
3338
3339 operation_shutdown (TRUE);
3340 }
3341
3342 static void
3343 incremental_network_scan_ready (QmiClientNas *client,
3344 GAsyncResult *res)
3345 {
3346 g_autoptr(QmiMessageNasIncrementalNetworkScanOutput) output = NULL;
3347 g_autoptr(GError) error = NULL;
3348
3349 output = qmi_client_nas_incremental_network_scan_finish (client, res, &error);
3350 if (!output) {
3351 g_printerr ("error: operation failed: %s\n", error->message);
3352 operation_shutdown (FALSE);
3353 return;
3354 }
3355
3356 if (!qmi_message_nas_incremental_network_scan_output_get_result (output, &error)) {
3357 g_printerr ("error: couldn't scan networks: %s\n", error->message);
3358 operation_shutdown (FALSE);
3359 return;
3360 }
3361
3362 g_print ("Registered incremental network scan events...\n");
3363
3364 ctx->network_scan_indication_id =
3365 g_signal_connect (ctx->client,
3366 "incremental-network-scan",
3367 G_CALLBACK (incremental_network_scan_received),
3368 NULL);
3369
3370 /* User can use Ctrl+C to cancel the scan at any time */
3371 g_cancellable_connect (ctx->cancellable,
3372 G_CALLBACK (network_scan_cancelled),
3373 NULL,
3374 NULL);
3375
3376 g_timeout_add_seconds (300, network_scan_timeout, NULL);
3377 }
3378
3379 #endif /* HAVE_QMI_MESSAGE_NAS_INCREMENTAL_NETWORK_SCAN */
3380
3381 #if defined HAVE_QMI_MESSAGE_NAS_GET_CELL_LOCATION_INFO
3382
3383 static gchar *
3384 str_from_bcd_plmn (GArray *bcd)
3385 {
3386 static const gchar bcd_chars[] = "0123456789*#abc\0\0";
3387 gchar *str;
3388 guint i;
3389 guint j;
3390
3391 if (!bcd || !bcd->len)
3392 return NULL;
3393
3394 str = g_malloc (1 + (bcd->len * 2));
3395 for (i = 0, j = 0 ; i < bcd->len; i++) {
3396 str[j] = bcd_chars[g_array_index (bcd, guint8, i) & 0xF];
3397 if (str[j])
3398 j++;
3399 str[j] = bcd_chars[(g_array_index (bcd, guint8, i) >> 4) & 0xF];
3400 if (str[j])
3401 j++;
3402 }
3403 str[j] = '\0';
3404
3405 return str;
3406 }
3407
3408 static void
3409 get_cell_location_info_ready (QmiClientNas *client,
3410 GAsyncResult *res)
3411 {
3412 QmiMessageNasGetCellLocationInfoOutput *output;
3413 GError *error = NULL;
3414 GArray *array;
3415 GArray *array2;
3416
3417 GArray *operator;
3418
3419 guint32 cell_id;
3420 guint16 lac;
3421 guint16 absolute_rf_channel_number;
3422 guint8 base_station_identity_code;
3423 guint32 timing_advance;
3424 guint16 rx_level;
3425
3426 guint16 cell_id_16;
3427 guint16 primary_scrambling_code;
3428 gint16 rscp;
3429 gint16 ecio;
3430
3431 guint16 system_id;
3432 guint16 network_id;
3433 guint16 base_station_id;
3434 guint16 reference_pn;
3435 guint32 latitude;
3436 guint32 longitude;
3437
3438 gboolean ue_in_idle;
3439 guint16 tracking_area_code;
3440 guint32 global_cell_id;
3441 guint16 serving_cell_id;
3442 guint8 cell_reselection_priority;
3443 guint8 s_non_intra_search_threshold;
3444 guint8 serving_cell_low_threshold;
3445 guint8 s_intra_search_threshold;
3446
3447 QmiNasWcdmaRrcState rrc_state;
3448
3449 guint32 lte_timing_advance;
3450
3451 guint32 nr5g_arfcn;
3452
3453 GArray *nr5g_cell_information_plmn;
3454 GArray *nr5g_cell_information_tac;
3455 guint64 nr5g_cell_information_global_cell_id;
3456 guint16 nr5g_cell_information_physical_cell_id;
3457 gint16 nr5g_cell_information_rsrp;
3458 gint16 nr5g_cell_information_rsrq;
3459 gint16 nr5g_cell_information_snr;
3460
3461 output = qmi_client_nas_get_cell_location_info_finish (client, res, &error);
3462 if (!output) {
3463 g_printerr ("error: operation failed: %s\n", error->message);
3464 g_error_free (error);
3465 operation_shutdown (FALSE);
3466 return;
3467 }
3468
3469 if (!qmi_message_nas_get_cell_location_info_output_get_result (output, &error)) {
3470 g_printerr ("error: couldn't get cell location info: %s\n", error->message);
3471 g_error_free (error);
3472 qmi_message_nas_get_cell_location_info_output_unref (output);
3473 operation_shutdown (FALSE);
3474 return;
3475 }
3476
3477 g_print ("[%s] Successfully got cell location info\n",
3478 qmi_device_get_path_display (ctx->device));
3479
3480 array = NULL;
3481 if (qmi_message_nas_get_cell_location_info_output_get_geran_info_v2 (
3482 output,
3483 &cell_id,
3484 &operator,
3485 &lac,
3486 &absolute_rf_channel_number,
3487 &base_station_identity_code,
3488 &timing_advance,
3489 &rx_level,
3490 &array, NULL)) {
3491 guint i;
3492
3493 g_print ("GERAN Info\n");
3494 if (cell_id == 0xFFFFFFFF)
3495 g_print ("\tCell ID: 'unavailable'\n"
3496 "\tPLMN: 'unavailable'\n"
3497 "\tLocation Area Code: 'unavailable'\n");
3498 else {
3499 gchar *plmn;
3500
3501 plmn = str_from_bcd_plmn (operator);
3502 g_print ("\tCell ID: '%" G_GUINT32_FORMAT"'\n"
3503 "\tPLMN: '%s'\n"
3504 "\tLocation Area Code: '%" G_GUINT16_FORMAT"'\n",
3505 cell_id,
3506 plmn,
3507 lac);
3508 g_free (plmn);
3509 }
3510 g_print ("\tGERAN Absolute RF Channel Number: '%" G_GUINT16_FORMAT"'\n"
3511 "\tBase Station Identity Code: '%u'\n",
3512 absolute_rf_channel_number,
3513 base_station_identity_code);
3514 if (timing_advance == 0xFFFFFFFF)
3515 g_print ("\tTiming Advance: 'unavailable'\n");
3516 else
3517 g_print ("\tTiming Advance: '%" G_GUINT32_FORMAT"' bit periods ('%lf' us)\n",
3518 timing_advance,
3519 (gdouble)timing_advance * 48.0 / 13.0);
3520 if (rx_level == 0)
3521 g_print ("\tRX Level: -110 dBm > level ('%" G_GUINT16_FORMAT"')\n", rx_level);
3522 else if (rx_level == 63)
3523 g_print ("\tRX Level: level > -48 dBm ('%" G_GUINT16_FORMAT"')\n", rx_level);
3524 else if (rx_level > 0 && rx_level < 63)
3525 g_print ("\tRX Level: %d dBm > level > %d dBm ('%" G_GUINT16_FORMAT"')\n",
3526 (gint32) rx_level - 111,
3527 (gint32) rx_level - 110,
3528 rx_level);
3529 else
3530 g_print ("\tRX Level: invalid ('%" G_GUINT16_FORMAT"')\n", rx_level);
3531
3532
3533 for (i = 0; i < array->len; i++) {
3534 QmiMessageNasGetCellLocationInfoOutputGeranInfoV2CellElement *element;
3535
3536 element = &g_array_index (array, QmiMessageNasGetCellLocationInfoOutputGeranInfoV2CellElement, i);
3537
3538 g_print ("\tCell [%u]:\n", i);
3539 if (element->cell_id == 0xFFFFFFFF)
3540 g_print ("\t\tCell ID: 'unavailable'\n"
3541 "\t\tPLMN: 'unavailable'\n"
3542 "\t\tLocation Area Code: 'unavailable'\n");
3543 else {
3544 gchar *plmn;
3545
3546 plmn = str_from_bcd_plmn (element->plmn);
3547 g_print ("\t\tCell ID: '%" G_GUINT32_FORMAT"'\n"
3548 "\t\tPLMN: '%s'\n"
3549 "\t\tLocation Area Code: '%" G_GUINT16_FORMAT"'\n",
3550 element->cell_id,
3551 plmn,
3552 element->lac);
3553 g_free (plmn);
3554 }
3555 g_print ("\t\tGERAN Absolute RF Channel Number: '%" G_GUINT16_FORMAT"'\n"
3556 "\t\tBase Station Identity Code: '%u'\n",
3557 element->geran_absolute_rf_channel_number,
3558 element->base_station_identity_code);
3559 if (element->rx_level == 0)
3560 g_print ("\t\tRX Level: -110 dBm > level ('%" G_GUINT16_FORMAT"')\n", element->rx_level);
3561 else if (element->rx_level == 63)
3562 g_print ("\t\tRX Level: level > -48 dBm ('%" G_GUINT16_FORMAT"')\n", element->rx_level);
3563 else if (element->rx_level > 0 && element->rx_level < 63)
3564 g_print ("\t\tRX Level: %d dBm > level > %d dBm ('%" G_GUINT16_FORMAT"')\n",
3565 (gint32) element->rx_level - 111,
3566 (gint32) element->rx_level - 110,
3567 element->rx_level);
3568 else
3569 g_print ("\tRX Level: invalid ('%" G_GUINT16_FORMAT"')\n", element->rx_level);
3570 }
3571 }
3572
3573 array = NULL;
3574 array2 = NULL;
3575 if (qmi_message_nas_get_cell_location_info_output_get_umts_info_v2 (
3576 output,
3577 &cell_id_16,
3578 &operator,
3579 &lac,
3580 &absolute_rf_channel_number,
3581 &primary_scrambling_code,
3582 &rscp,
3583 &ecio,
3584 &array, &array2, NULL)) {
3585 guint i;
3586 gchar *plmn;
3587
3588 g_print ("UMTS Info\n");
3589 if (cell_id_16 == 0xFFFF)
3590 g_print ("\tCell ID: 'unavailable'\n");
3591 else
3592 g_print ("\tCell ID: '%" G_GUINT16_FORMAT"'\n", cell_id_16);
3593 plmn = str_from_bcd_plmn (operator);
3594 g_print ("\tPLMN: '%s'\n"
3595 "\tLocation Area Code: '%" G_GUINT16_FORMAT"'\n"
3596 "\tUTRA Absolute RF Channel Number: '%" G_GUINT16_FORMAT"'\n"
3597 "\tPrimary Scrambling Code: '%" G_GUINT16_FORMAT"'\n"
3598 "\tRSCP: '%" G_GINT16_FORMAT"' dBm\n"
3599 "\tECIO: '%" G_GINT16_FORMAT"' dBm\n",
3600 plmn,
3601 lac,
3602 absolute_rf_channel_number,
3603 primary_scrambling_code,
3604 rscp,
3605 ecio);
3606 g_free (plmn);
3607
3608 for (i = 0; i < array->len; i++) {
3609 QmiMessageNasGetCellLocationInfoOutputUmtsInfoV2CellElement *element;
3610
3611 element = &g_array_index (array, QmiMessageNasGetCellLocationInfoOutputUmtsInfoV2CellElement, i);
3612 g_print ("\tCell [%u]:\n"
3613 "\t\tUTRA Absolute RF Channel Number: '%" G_GUINT16_FORMAT"'\n"
3614 "\t\tPrimary Scrambling Code: '%" G_GUINT16_FORMAT"'\n"
3615 "\t\tRSCP: '%" G_GINT16_FORMAT"' dBm\n"
3616 "\t\tECIO: '%" G_GINT16_FORMAT"' dBm\n",
3617 i,
3618 element->utra_absolute_rf_channel_number,
3619 element->primary_scrambling_code,
3620 element->rscp,
3621 element->ecio);
3622 }
3623
3624 for (i = 0; i < array2->len; i++) {
3625 QmiMessageNasGetCellLocationInfoOutputUmtsInfoV2NeighboringGeranElement *element;
3626
3627 element = &g_array_index (array2, QmiMessageNasGetCellLocationInfoOutputUmtsInfoV2NeighboringGeranElement, i);
3628 g_print ("\tNeighboring GERAN Cell [%u]:\n"
3629 "\t\tGERAN Absolute RF Channel Number: '%" G_GUINT16_FORMAT"'\n",
3630 i,
3631 element->geran_absolute_rf_channel_number);
3632 if (element->network_color_code == 0xFF)
3633 g_print ("\t\tNetwork Color Code: 'unavailable'\n");
3634 else
3635 g_print ("\t\tNetwork Color Code: '%u'\n", element->network_color_code);
3636 if (element->base_station_color_code == 0xFF)
3637 g_print ("\t\tBase Station Color Code: 'unavailable'\n");
3638 else
3639 g_print ("\t\tBase Station Color Code: '%u'\n", element->base_station_color_code);
3640 g_print ("\t\tRSSI: '%" G_GUINT16_FORMAT"'\n",
3641 element->rssi);
3642 }
3643 }
3644
3645 if (qmi_message_nas_get_cell_location_info_output_get_cdma_info (
3646 output,
3647 &system_id,
3648 &network_id,
3649 &base_station_id,
3650 &reference_pn,
3651 &latitude,
3652 &longitude,
3653 NULL)) {
3654 gdouble latitude_degrees;
3655 gdouble longitude_degrees;
3656
3657 /* TODO: give degrees, minutes, seconds */
3658 latitude_degrees = ((gdouble)latitude * 0.25)/3600.0;
3659 longitude_degrees = ((gdouble)longitude * 0.25)/3600.0;
3660 g_print ("CDMA Info\n"
3661 "\tSystem ID: '%" G_GUINT16_FORMAT"'\n"
3662 "\tNetwork ID: '%" G_GUINT16_FORMAT"'\n"
3663 "\tBase Station ID: '%" G_GUINT16_FORMAT"'\n"
3664 "\tReference PN: '%" G_GUINT16_FORMAT"'\n"
3665 "\tLatitude: '%lf'º\n"
3666 "\tLongitude: '%lfº'\n",
3667 system_id,
3668 network_id,
3669 base_station_id,
3670 reference_pn,
3671 latitude_degrees,
3672 longitude_degrees);
3673 }
3674
3675 array = NULL;
3676 if (qmi_message_nas_get_cell_location_info_output_get_intrafrequency_lte_info_v2 (
3677 output,
3678 &ue_in_idle,
3679 &operator,
3680 &tracking_area_code,
3681 &global_cell_id,
3682 &absolute_rf_channel_number,
3683 &serving_cell_id,
3684 &cell_reselection_priority,
3685 &s_non_intra_search_threshold,
3686 &serving_cell_low_threshold,
3687 &s_intra_search_threshold,
3688 &array, NULL)) {
3689 guint i;
3690 gchar *plmn;
3691
3692 plmn = str_from_bcd_plmn (operator);
3693 g_print ("Intrafrequency LTE Info\n"
3694 "\tUE In Idle: '%s'\n"
3695 "\tPLMN: '%s'\n"
3696 "\tTracking Area Code: '%" G_GUINT16_FORMAT"'\n"
3697 "\tGlobal Cell ID: '%" G_GUINT32_FORMAT"'\n"
3698 "\tEUTRA Absolute RF Channel Number: '%" G_GUINT16_FORMAT"' (%s)\n"
3699 "\tServing Cell ID: '%" G_GUINT16_FORMAT"'\n",
3700 ue_in_idle ? "yes" : "no",
3701 plmn,
3702 tracking_area_code,
3703 global_cell_id,
3704 absolute_rf_channel_number, qmicli_earfcn_to_eutra_band_string (absolute_rf_channel_number),
3705 serving_cell_id);
3706 g_free (plmn);
3707 if (ue_in_idle)
3708 g_print ("\tCell Reselection Priority: '%u'\n"
3709 "\tS Non Intra Search Threshold: '%u'\n"
3710 "\tServing Cell Low Threshold: '%u'\n"
3711 "\tS Intra Search Threshold: '%u'\n",
3712 cell_reselection_priority,
3713 s_non_intra_search_threshold,
3714 serving_cell_low_threshold,
3715 s_intra_search_threshold);
3716
3717 for (i = 0; i < array->len; i++) {
3718 QmiMessageNasGetCellLocationInfoOutputIntrafrequencyLteInfoV2CellElement *element;
3719
3720 element = &g_array_index (array, QmiMessageNasGetCellLocationInfoOutputIntrafrequencyLteInfoV2CellElement, i);
3721 g_print ("\tCell [%u]:\n"
3722 "\t\tPhysical Cell ID: '%" G_GUINT16_FORMAT"'\n"
3723 "\t\tRSRQ: '%.1lf' dB\n"
3724 "\t\tRSRP: '%.1lf' dBm\n"
3725 "\t\tRSSI: '%.1lf' dBm\n",
3726 i,
3727 element->physical_cell_id,
3728 (gdouble) element->rsrq * 0.1,
3729 (gdouble) element->rsrp * 0.1,
3730 (gdouble) element->rssi * 0.1);
3731 if (ue_in_idle)
3732 g_print ("\t\tCell Selection RX Level: '%" G_GINT16_FORMAT"'\n",
3733 element->cell_selection_rx_level);
3734 }
3735 }
3736
3737 array = NULL;
3738 if (qmi_message_nas_get_cell_location_info_output_get_interfrequency_lte_info (
3739 output,
3740 &ue_in_idle,
3741 &array, NULL)) {
3742 guint i;
3743
3744 g_print ("Interfrequency LTE Info\n"
3745 "\tUE In Idle: '%s'\n", ue_in_idle ? "yes" : "no");
3746
3747 for (i = 0; i < array->len; i++) {
3748 QmiMessageNasGetCellLocationInfoOutputInterfrequencyLteInfoFrequencyElement *element;
3749 GArray *cell_array;
3750 guint j;
3751
3752 element = &g_array_index (array, QmiMessageNasGetCellLocationInfoOutputInterfrequencyLteInfoFrequencyElement, i);
3753 g_print ("\tFrequency [%u]:\n"
3754 "\t\tEUTRA Absolute RF Channel Number: '%" G_GUINT16_FORMAT"' (%s)\n"
3755 "\t\tSelection RX Level Low Threshold: '%u'\n"
3756 "\t\tCell Selection RX Level High Threshold: '%u'\n",
3757 i,
3758 element->eutra_absolute_rf_channel_number, qmicli_earfcn_to_eutra_band_string (element->eutra_absolute_rf_channel_number),
3759 element->cell_selection_rx_level_low_threshold,
3760 element->cell_selection_rx_level_high_threshold);
3761 if (ue_in_idle)
3762 g_print ("\t\tCell Reselection Priority: '%u'\n",
3763 element->cell_reselection_priority);
3764
3765 cell_array = element->cell;
3766
3767 for (j = 0; j < cell_array->len; j++) {
3768 QmiMessageNasGetCellLocationInfoOutputInterfrequencyLteInfoFrequencyElementCellElement *cell;
3769
3770 cell = &g_array_index (cell_array, QmiMessageNasGetCellLocationInfoOutputInterfrequencyLteInfoFrequencyElementCellElement, j);
3771 g_print ("\t\tCell [%u]:\n"
3772 "\t\t\tPhysical Cell ID: '%" G_GUINT16_FORMAT"'\n"
3773 "\t\t\tRSRQ: '%.1lf' dB\n"
3774 "\t\t\tRSRP: '%.1lf' dBm\n"
3775 "\t\t\tRSSI: '%.1lf' dBm\n"
3776 "\t\t\tCell Selection RX Level: '%" G_GINT16_FORMAT"'\n",
3777 j,
3778 cell->physical_cell_id,
3779 (gdouble) cell->rsrq * 0.1,
3780 (gdouble) cell->rsrp * 0.1,
3781 (gdouble) cell->rssi * 0.1,
3782 cell->cell_selection_rx_level);
3783 }
3784 }
3785 }
3786
3787 array = NULL;
3788 if (qmi_message_nas_get_cell_location_info_output_get_lte_info_neighboring_gsm (
3789 output,
3790 &ue_in_idle,
3791 &array, NULL)) {
3792 guint i;
3793
3794 g_print ("LTE Info Neighboring GSM\n"
3795 "\tUE In Idle: '%s'\n", ue_in_idle ? "yes" : "no");
3796
3797 for (i = 0; i < array->len; i++) {
3798 QmiMessageNasGetCellLocationInfoOutputLteInfoNeighboringGsmFrequencyElement *element;
3799 GArray *cell_array;
3800 guint j;
3801
3802 element = &g_array_index (array, QmiMessageNasGetCellLocationInfoOutputLteInfoNeighboringGsmFrequencyElement, i);
3803
3804 g_print ("\tFrequency [%u]:\n", i);
3805 if (ue_in_idle)
3806 g_print ("\t\tCell Reselection Priority: '%u'\n"
3807 "\t\tCell Reselection High Threshold: '%u'\n"
3808 "\t\tCell Reselection Low Threshold: '%u'\n"
3809 "\t\tNCC Permitted: '0x%2X'\n",
3810 element->cell_reselection_priority,
3811 element->cell_reselection_high_threshold,
3812 element->cell_reselection_low_threshold,
3813 element->ncc_permitted);
3814
3815 cell_array = element->cell;
3816
3817 for (j = 0; j < cell_array->len; j++) {
3818 QmiMessageNasGetCellLocationInfoOutputLteInfoNeighboringGsmFrequencyElementCellElement *cell;
3819
3820 cell = &g_array_index (cell_array, QmiMessageNasGetCellLocationInfoOutputLteInfoNeighboringGsmFrequencyElementCellElement, j);
3821 g_print ("\t\tCell [%u]:\n"
3822 "\t\t\tGERAN Absolute RF Channel Number: '%" G_GUINT16_FORMAT"'\n"
3823 "\t\t\tBand Is 1900: '%s'\n",
3824 j,
3825 cell->geran_absolute_rf_channel_number,
3826 cell->band_is_1900 ? "yes" : "no");
3827 if (cell->cell_id_valid)
3828 g_print ("\t\t\tBase Station Identity Code: '%u'\n",
3829 cell->base_station_identity_code);
3830 else
3831 g_print ("\t\t\tBase Station Identity Code: 'unknown'\n");
3832 g_print ("\t\t\tRSSI: '%.1lf' dB\n"
3833 "\t\t\tCell Selection RX Level: '%" G_GINT16_FORMAT"'\n",
3834 (gdouble) cell->rssi * 0.1,
3835 cell->cell_selection_rx_level);
3836 }
3837 }
3838 }
3839
3840 array = NULL;
3841 if (qmi_message_nas_get_cell_location_info_output_get_lte_info_neighboring_wcdma (
3842 output,
3843 &ue_in_idle,
3844 &array, NULL)) {
3845 guint i;
3846
3847 g_print ("LTE Info Neighboring WCDMA\n"
3848 "\tUE In Idle: '%s'\n", ue_in_idle ? "yes" : "no");
3849
3850 for (i = 0; i < array->len; i++) {
3851 QmiMessageNasGetCellLocationInfoOutputLteInfoNeighboringWcdmaFrequencyElement *element;
3852 GArray *cell_array;
3853 guint j;
3854
3855 element = &g_array_index (array, QmiMessageNasGetCellLocationInfoOutputLteInfoNeighboringWcdmaFrequencyElement, i);
3856
3857 g_print ("\tFrequency [%u]:\n"
3858 "\t\tUTRA Absolute RF Channel Number: '%" G_GUINT16_FORMAT"'\n",
3859 i,
3860 element->utra_absolute_rf_channel_number);
3861 if (ue_in_idle)
3862 g_print ("\t\tCell Reselection Priority: '%u'\n"
3863 "\t\tCell Reselection High Threshold: '%" G_GINT16_FORMAT"'\n"
3864 "\t\tCell Reselection Low Threshold: '%" G_GINT16_FORMAT"'\n",
3865 element->cell_reselection_priority,
3866 element->cell_reselection_high_threshold,
3867 element->cell_reselection_low_threshold);
3868
3869 cell_array = element->cell;
3870
3871 for (j = 0; j < cell_array->len; j++) {
3872 QmiMessageNasGetCellLocationInfoOutputLteInfoNeighboringWcdmaFrequencyElementCellElement *cell;
3873
3874 cell = &g_array_index (cell_array, QmiMessageNasGetCellLocationInfoOutputLteInfoNeighboringWcdmaFrequencyElementCellElement, j);
3875 g_print ("\t\tCell [%u]:\n"
3876 "\t\t\tPrimary Scrambling Code: '%" G_GUINT16_FORMAT"'\n"
3877 "\t\t\tCPICH RSCP: '%.1lf' dBm\n"
3878 "\t\t\tCPICH EcNo: '%.1lf' dB\n",
3879 j,
3880 cell->primary_scrambling_code,
3881 (gdouble) cell->cpich_rscp * 0.1,
3882 (gdouble) cell->cpich_ecno * 0.1);
3883 if (ue_in_idle)
3884 g_print ("\t\t\tCell Selection RX Level: '%" G_GUINT16_FORMAT"'\n",
3885 cell->cell_selection_rx_level);
3886 }
3887 }
3888 }
3889
3890 if (qmi_message_nas_get_cell_location_info_output_get_umts_cell_id (
3891 output,
3892 &cell_id,
3893 NULL)) {
3894 g_print ("UMTS Cell ID: '%" G_GUINT32_FORMAT"'\n", cell_id);
3895 }
3896
3897 array = NULL;
3898 if (qmi_message_nas_get_cell_location_info_output_get_umts_info_neighboring_lte (
3899 output,
3900 &rrc_state,
3901 &array, NULL)) {
3902 guint i;
3903
3904 g_print ("UMTS Info Neighboring LTE\n"
3905 "\tRRC State: '%s'\n", qmi_nas_wcdma_rrc_state_get_string (rrc_state));
3906
3907 for (i = 0; i < array->len; i++) {
3908 QmiMessageNasGetCellLocationInfoOutputUmtsInfoNeighboringLteFrequencyElement *element;
3909
3910 element = &g_array_index (array, QmiMessageNasGetCellLocationInfoOutputUmtsInfoNeighboringLteFrequencyElement, i);
3911
3912 g_print ("\tFrequency [%u]:\n"
3913 "\t\tEUTRA Absolute RF Channel Number: '%" G_GUINT16_FORMAT"' (%s)\n"
3914 "\t\tPhysical Cell ID: '%" G_GUINT16_FORMAT "'\n"
3915 "\t\tRSRP: '%lf' dBm\n"
3916 "\t\tRSRQ: '%lf' dB\n",
3917 i,
3918 element->eutra_absolute_rf_channel_number, qmicli_earfcn_to_eutra_band_string (element->eutra_absolute_rf_channel_number),
3919 element->physical_cell_id,
3920 (gdouble)element->rsrp,
3921 (gdouble)element->rsrq);
3922 if (rrc_state != QMI_NAS_WCDMA_RRC_STATE_CELL_FACH &&
3923 rrc_state != QMI_NAS_WCDMA_RRC_STATE_CELL_DCH)
3924 g_print ("\t\tCell Selection RX Level: '%" G_GINT16_FORMAT"'\n",
3925 element->cell_selection_rx_level);
3926 g_print ("\t\tIs TDD?: '%s'\n",
3927 element->is_tdd ? "yes" : "no");
3928 }
3929 }
3930
3931 if (qmi_message_nas_get_cell_location_info_output_get_lte_info_timing_advance (
3932 output,
3933 &lte_timing_advance,
3934 NULL)) {
3935 if (lte_timing_advance == 0xFFFFFFFF)
3936 g_print ("LTE Timing Advance: 'unavailable'\n");
3937 else
3938 g_print ("LTE Timing Advance: '%" G_GUINT32_FORMAT"' us\n", lte_timing_advance);
3939 }
3940
3941 if (qmi_message_nas_get_cell_location_info_output_get_nr5g_arfcn (
3942 output,
3943 &nr5g_arfcn,
3944 NULL)) {
3945 g_print ("5GNR ARFCN: '%" G_GUINT32_FORMAT"'\n", nr5g_arfcn);
3946 }
3947
3948 if (qmi_message_nas_get_cell_location_info_output_get_nr5g_cell_information (
3949 output,
3950 &nr5g_cell_information_plmn,
3951 &nr5g_cell_information_tac,
3952 &nr5g_cell_information_global_cell_id,
3953 &nr5g_cell_information_physical_cell_id,
3954 &nr5g_cell_information_rsrq,
3955 &nr5g_cell_information_rsrp,
3956 &nr5g_cell_information_snr,
3957 NULL)) {
3958 g_autofree gchar *plmn = NULL;
3959 guint32 tac;
3960
3961 plmn = str_from_bcd_plmn (nr5g_cell_information_plmn);
3962
3963 g_assert (nr5g_cell_information_tac->len == 3);
3964 tac = ((((g_array_index (nr5g_cell_information_tac, guint8, 0) << 8) |
3965 g_array_index (nr5g_cell_information_tac, guint8, 1)) << 8) |
3966 g_array_index (nr5g_cell_information_tac, guint8, 2));
3967
3968 g_print ("5GNR cell information\n"
3969 "\tPLMN: '%s'\n"
3970 "\tTracking Area Code: '%" G_GUINT32_FORMAT "'\n"
3971 "\tGlobal Cell ID: '%" G_GUINT64_FORMAT "'\n"
3972 "\tPhysical Cell ID: '%" G_GUINT16_FORMAT "'\n"
3973 "\tRSRQ: '%.1lf dB'\n"
3974 "\tRSRP: '%.1lf dBm'\n"
3975 "\tSNR: '%.1lf dB'\n",
3976 plmn,
3977 tac,
3978 nr5g_cell_information_global_cell_id,
3979 nr5g_cell_information_physical_cell_id,
3980 (0.1) * ((gdouble)nr5g_cell_information_rsrq),
3981 (0.1) * ((gdouble)nr5g_cell_information_rsrp),
3982 (0.1) * ((gdouble)nr5g_cell_information_snr));
3983 }
3984
3985 qmi_message_nas_get_cell_location_info_output_unref (output);
3986 operation_shutdown (TRUE);
3987 }
3988
3989 #endif /* HAVE_QMI_MESSAGE_NAS_GET_CELL_LOCATION_INFO */
3990
3991 #if defined HAVE_QMI_MESSAGE_NAS_FORCE_NETWORK_SEARCH
3992
3993 static void
3994 force_network_search_ready (QmiClientNas *client,
3995 GAsyncResult *res)
3996 {
3997 QmiMessageNasForceNetworkSearchOutput *output;
3998 GError *error = NULL;
3999
4000 output = qmi_client_nas_force_network_search_finish (client, res, &error);
4001 if (!output) {
4002 g_printerr ("error: operation failed: %s\n", error->message);
4003 g_error_free (error);
4004 operation_shutdown (FALSE);
4005 return;
4006 }
4007
4008 if (!qmi_message_nas_force_network_search_output_get_result (output, &error)) {
4009 g_printerr ("error: couldn't force network search: %s\n", error->message);
4010 g_error_free (error);
4011 qmi_message_nas_force_network_search_output_unref (output);
4012 operation_shutdown (FALSE);
4013 return;
4014 }
4015
4016 g_print ("[%s] Successfully forced network search\n",
4017 qmi_device_get_path_display (ctx->device));
4018 qmi_message_nas_force_network_search_output_unref (output);
4019 operation_shutdown (TRUE);
4020 }
4021
4022 #endif /* HAVE_QMI_MESSAGE_NAS_FORCE_NETWORK_SEARCH */
4023
4024 #if defined HAVE_QMI_MESSAGE_NAS_GET_OPERATOR_NAME
4025
4026 static void
4027 get_operator_name_ready (QmiClientNas *client,
4028 GAsyncResult *res)
4029 {
4030 QmiMessageNasGetOperatorNameOutput *output;
4031 GError *error = NULL;
4032 QmiNasNetworkNameDisplayCondition spn_display_condition;
4033 const gchar *spn;
4034 const gchar *operator_name;
4035 GArray *array;
4036 QmiNasPlmnEncodingScheme nitz_information_name_encoding;
4037 QmiNasPlmnNameCountryInitials nitz_information_short_country_initials;
4038 QmiNasPlmnNameSpareBits nitz_information_long_name_spare_bits;
4039 QmiNasPlmnNameSpareBits nitz_information_short_name_spare_bits;
4040 GArray *nitz_information_long_name;
4041 GArray *nitz_information_short_name;
4042
4043 output = qmi_client_nas_get_operator_name_finish (client, res, &error);
4044 if (!output) {
4045 g_printerr ("error: operation failed: %s\n", error->message);
4046 g_error_free (error);
4047 operation_shutdown (FALSE);
4048 return;
4049 }
4050
4051 if (!qmi_message_nas_get_operator_name_output_get_result (output, &error)) {
4052 g_printerr ("error: couldn't get operator name data: %s\n", error->message);
4053 g_error_free (error);
4054 qmi_message_nas_get_operator_name_output_unref (output);
4055 operation_shutdown (FALSE);
4056 return;
4057 }
4058
4059 g_print ("[%s] Successfully got operator name data\n",
4060 qmi_device_get_path_display (ctx->device));
4061
4062 if (qmi_message_nas_get_operator_name_output_get_service_provider_name (
4063 output,
4064 &spn_display_condition,
4065 &spn,
4066 NULL)) {
4067 g_autofree gchar *dc_string = NULL;
4068
4069 dc_string = qmi_nas_network_name_display_condition_build_string_from_mask (spn_display_condition);
4070 g_print ("Service Provider Name\n");
4071 g_print ("\tDisplay Condition: '%s'\n"
4072 "\tName : '%s'\n",
4073 VALIDATE_MASK_NONE (dc_string),
4074 spn);
4075 }
4076
4077 if (qmi_message_nas_get_operator_name_output_get_operator_string_name (
4078 output,
4079 &operator_name,
4080 NULL)) {
4081 g_print ("Operator Name: '%s'\n",
4082 operator_name);
4083 }
4084
4085 if (qmi_message_nas_get_operator_name_output_get_operator_plmn_list (output, &array, NULL)) {
4086 guint i;
4087
4088 g_print ("PLMN List:\n");
4089 for (i = 0; i < array->len; i++) {
4090 QmiMessageNasGetOperatorNameOutputOperatorPlmnListElement *element;
4091 gchar *mnc;
4092
4093 element = &g_array_index (array, QmiMessageNasGetOperatorNameOutputOperatorPlmnListElement, i);
4094 mnc = g_strdup (element->mnc);
4095 if (strlen (mnc) >= 3 && (mnc[2] == 'F' || mnc[2] == 'f'))
4096 mnc[2] = '\0';
4097 g_print ("\tMCC/MNC: '%s-%s'%s LAC Range: %u->%u\tPNN Record: %u\n",
4098 element->mcc,
4099 mnc,
4100 mnc[2] == '\0' ? " " : "",
4101 element->lac1,
4102 element->lac2,
4103 element->plmn_name_record_identifier);
4104 g_free(mnc);
4105 }
4106 }
4107
4108 if (qmi_message_nas_get_operator_name_output_get_operator_plmn_name (output, &array, NULL)) {
4109 guint i;
4110
4111 g_print ("PLMN Names:\n");
4112 for (i = 0; i < array->len; i++) {
4113 QmiMessageNasGetOperatorNameOutputOperatorPlmnNameElement *element;
4114 gchar *long_name;
4115 gchar *short_name;
4116
4117 element = &g_array_index (array, QmiMessageNasGetOperatorNameOutputOperatorPlmnNameElement, i);
4118 long_name = qmi_nas_read_string_from_plmn_encoded_array (element->name_encoding, element->long_name);
4119 short_name = qmi_nas_read_string_from_plmn_encoded_array (element->name_encoding, element->short_name);
4120 g_print ("\t%d: '%s'%s%s%s\t\tCountry: '%s'\n",
4121 i,
4122 long_name ?: "",
4123 short_name ? " ('" : "",
4124 short_name ?: "",
4125 short_name ? "')" : "",
4126 qmi_nas_plmn_name_country_initials_get_string (element->short_country_initials));
4127 g_free (long_name);
4128 g_free (short_name);
4129 }
4130 }
4131
4132 if (qmi_message_nas_get_operator_name_output_get_nitz_information (
4133 output,
4134 &nitz_information_name_encoding,
4135 &nitz_information_short_country_initials,
4136 &nitz_information_long_name_spare_bits,
4137 &nitz_information_short_name_spare_bits,
4138 &nitz_information_long_name,
4139 &nitz_information_short_name,
4140 NULL)) {
4141 g_autofree gchar *long_name = NULL;
4142 g_autofree gchar *short_name = NULL;
4143
4144 long_name = qmi_nas_read_string_from_plmn_encoded_array (nitz_information_name_encoding, nitz_information_long_name);
4145 short_name = qmi_nas_read_string_from_plmn_encoded_array (nitz_information_name_encoding, nitz_information_short_name);
4146 g_print ("NITZ information:\n"
4147 "\tLong Name: '%s'\n"
4148 "\tShort Name: '%s'\n"
4149 "\tCountry: '%s'\n",
4150 long_name ?: "",
4151 short_name ?: "",
4152 qmi_nas_plmn_name_country_initials_get_string (nitz_information_short_country_initials));
4153 }
4154
4155 qmi_message_nas_get_operator_name_output_unref (output);
4156 operation_shutdown (TRUE);
4157 }
4158
4159 #endif /* HAVE_QMI_MESSAGE_NAS_GET_OPERATOR_NAME */
4160
4161 #if defined HAVE_QMI_MESSAGE_NAS_GET_PLMN_NAME
4162
4163 static QmiMessageNasGetPlmnNameInput *
4164 set_plmn_name_input_plmn_create (const gchar *str)
4165 {
4166 g_autoptr(GError) error = NULL;
4167 g_autoptr(QmiMessageNasGetPlmnNameInput) input = NULL;
4168 guint16 mcc = 0;
4169 guint16 mnc = 0;
4170
4171 if (!qmicli_read_parse_3gpp_mcc_mnc (str, &mcc, &mnc, NULL)) {
4172 g_printerr ("error: invalid net selection MCC/MNC: '%s'\n", str);
4173 return NULL;
4174 }
4175
4176 input = qmi_message_nas_get_plmn_name_input_new ();
4177 if (!qmi_message_nas_get_plmn_name_input_set_plmn (
4178 input,
4179 mcc,
4180 mnc,
4181 &error)) {
4182 g_printerr ("error: couldn't set MCC/MNC: '%s'\n",
4183 error->message);
4184 g_clear_pointer(&input, qmi_message_nas_get_plmn_name_input_unref);
4185 }
4186
4187 return g_steal_pointer (&input);
4188 }
4189
4190 static void
4191 get_plmn_name_ready (QmiClientNas *client,
4192 GAsyncResult *res)
4193 {
4194 g_autoptr(QmiMessageNasGetPlmnNameOutput) output = NULL;
4195 g_autoptr(GError) error = NULL;
4196 GArray *array;
4197 QmiNasNetworkDescriptionEncoding plmn_name_service_provider_name_encoding;
4198 GArray *plmn_name_service_provider_name;
4199 QmiNasNetworkDescriptionEncoding plmn_name_short_name_encoding;
4200 QmiNasPlmnNameCountryInitials plmn_name_short_name_country_initials;
4201 QmiNasPlmnNameSpareBits plmn_name_short_name_spare_bits;
4202 GArray *plmn_name_short_name;
4203 QmiNasNetworkDescriptionEncoding plmn_name_long_name_encoding;
4204 QmiNasPlmnNameCountryInitials plmn_name_long_name_country_initials;
4205 QmiNasPlmnNameSpareBits plmn_name_long_name_spare_bits;
4206 GArray *plmn_name_long_name;
4207
4208 output = qmi_client_nas_get_plmn_name_finish (client, res, &error);
4209 if (!output) {
4210 g_printerr ("error: operation failed: %s\n", error->message);
4211 operation_shutdown (FALSE);
4212 return;
4213 }
4214
4215 if (!qmi_message_nas_get_plmn_name_output_get_result (output, &error)) {
4216 g_printerr ("error: couldn't get operator name data: %s\n", error->message);
4217 operation_shutdown (FALSE);
4218 return;
4219 }
4220
4221 g_print ("[%s] Successfully got plmn name data\n",
4222 qmi_device_get_path_display (ctx->device));
4223
4224 if (qmi_message_nas_get_plmn_name_output_get_3gpp_eons_plmn_name (
4225 output,
4226 &plmn_name_service_provider_name_encoding,
4227 &plmn_name_service_provider_name,
4228 &plmn_name_short_name_encoding,
4229 &plmn_name_short_name_country_initials,
4230 &plmn_name_short_name_spare_bits,
4231 &plmn_name_short_name,
4232 &plmn_name_long_name_encoding,
4233 &plmn_name_long_name_country_initials,
4234 &plmn_name_long_name_spare_bits,
4235 &plmn_name_long_name,
4236 NULL)) {
4237 g_autofree gchar *long_name = NULL;
4238 g_autofree gchar *short_name = NULL;
4239 g_autofree gchar *service_name = NULL;
4240 long_name = qmi_nas_read_string_from_network_description_encoded_array (plmn_name_long_name_encoding, plmn_name_long_name);
4241 short_name = qmi_nas_read_string_from_network_description_encoded_array (plmn_name_short_name_encoding, plmn_name_short_name);
4242 service_name = qmi_nas_read_string_from_network_description_encoded_array (plmn_name_service_provider_name_encoding, plmn_name_service_provider_name);
4243 g_print ("3GPP EONS PLMN Name:\n"
4244 "\tLong Name: '%s'\n"
4245 "\tShort Name: '%s'\n"
4246 "\tService Name: '%s'\n"
4247 "\tCountry: '%s'\n",
4248 long_name ?: "",
4249 short_name ?: "",
4250 service_name ?: "",
4251 qmi_nas_plmn_name_country_initials_get_string (plmn_name_short_name_country_initials));
4252 }
4253
4254 if (qmi_message_nas_get_plmn_name_output_get_plmn_name_with_language_id (output, &array, NULL)) {
4255 guint i;
4256
4257 g_print ("3GPP EONS PLMN Name with Language ID:\n");
4258 for (i = 0; i < array->len; i++) {
4259 QmiMessageNasGetPlmnNameOutputPlmnNameWithLanguageIdElement *element;
4260 g_autofree gchar *long_name;
4261 g_autofree gchar *short_name;
4262
4263 element = &g_array_index (array, QmiMessageNasGetPlmnNameOutputPlmnNameWithLanguageIdElement, i);
4264 long_name = qmi_nas_read_string_from_plmn_encoded_array (QMI_NAS_PLMN_ENCODING_SCHEME_UCS2LE, element->long_name);
4265 short_name = qmi_nas_read_string_from_plmn_encoded_array (QMI_NAS_PLMN_ENCODING_SCHEME_UCS2LE, element->short_name);
4266 g_print ("\t%d: '%s'%s%s%s\t\tCountry: '%s'\n",
4267 i,
4268 long_name ?: "",
4269 short_name ? " ('" : "",
4270 short_name ?: "",
4271 short_name ? "')" : "",
4272 qmi_nas_plmn_language_id_get_string (element->language_id));
4273 }
4274 }
4275
4276 operation_shutdown (TRUE);
4277 }
4278
4279 #endif /* HAVE_QMI_MESSAGE_NAS_GET_PLMN_NAME */
4280
4281 #if defined HAVE_QMI_MESSAGE_NAS_GET_LTE_CPHY_CA_INFO
4282
4283 static void
4284 get_lte_cphy_ca_info_ready (QmiClientNas *client,
4285 GAsyncResult *res)
4286 {
4287 QmiMessageNasGetLteCphyCaInfoOutput *output;
4288 GError *error = NULL;
4289 guint16 pci;
4290 guint16 channel;
4291 QmiNasDLBandwidth dl_bandwidth;
4292 QmiNasActiveBand band;
4293 QmiNasScellState state;
4294 guint8 scell_index;
4295 GArray *array;
4296
4297 output = qmi_client_nas_get_lte_cphy_ca_info_finish (client, res, &error);
4298 if (!output) {
4299 g_printerr ("error: operation failed: %s\n", error->message);
4300 g_error_free (error);
4301 operation_shutdown (FALSE);
4302 return;
4303 }
4304
4305 if (!qmi_message_nas_get_lte_cphy_ca_info_output_get_result (output, &error)) {
4306 g_printerr ("error: couldn't get carrier aggregation info: %s\n", error->message);
4307 g_error_free (error);
4308 qmi_message_nas_get_lte_cphy_ca_info_output_unref (output);
4309 operation_shutdown (FALSE);
4310 return;
4311 }
4312
4313 g_print ("[%s] Successfully got carrier aggregation info\n",
4314 qmi_device_get_path_display (ctx->device));
4315
4316 if (qmi_message_nas_get_lte_cphy_ca_info_output_get_dl_bandwidth (
4317 output,
4318 &dl_bandwidth,
4319 NULL)) {
4320 g_print ("DL Bandwidth: '%s'\n",
4321 qmi_nas_dl_bandwidth_get_string (dl_bandwidth));
4322 }
4323
4324 if (qmi_message_nas_get_lte_cphy_ca_info_output_get_phy_ca_agg_pcell_info (
4325 output,
4326 &pci,
4327 &channel,
4328 &dl_bandwidth,
4329 &band,
4330 NULL)) {
4331 g_print ("Primary Cell Info\n");
4332 g_print ("\tPhysical Cell ID: '%" G_GUINT16_FORMAT"'\n"
4333 "\tRX Channel: '%" G_GUINT16_FORMAT"'\n"
4334 "\tDL Bandwidth: '%s'\n"
4335 "\tLTE Band: '%s'\n",
4336 pci, channel,
4337 qmi_nas_dl_bandwidth_get_string (dl_bandwidth),
4338 qmi_nas_active_band_get_string (band));
4339 }
4340
4341 if (qmi_message_nas_get_lte_cphy_ca_info_output_get_phy_ca_agg_secondary_cells (
4342 output, &array, NULL)) {
4343 guint i;
4344
4345 if (!array->len)
4346 g_print ("No Secondary Cells\n");
4347 for (i = 0; i < array->len; i++) {
4348 QmiMessageNasGetLteCphyCaInfoOutputPhyCaAggSecondaryCellsSsc *e;
4349 e = &g_array_index (array, QmiMessageNasGetLteCphyCaInfoOutputPhyCaAggSecondaryCellsSsc, i);
4350 g_print ("Secondary Cell %u Info\n"
4351 "\tPhysical Cell ID: '%" G_GUINT16_FORMAT"'\n"
4352 "\tRX Channel: '%" G_GUINT16_FORMAT"'\n"
4353 "\tDL Bandwidth: '%s'\n"
4354 "\tLTE Band: '%s'\n"
4355 "\tState: '%s'\n"
4356 "\tCell index: '%u'\n",
4357 i + 1, e->physical_cell_id, e->rx_channel,
4358 qmi_nas_dl_bandwidth_get_string (e->dl_bandwidth),
4359 qmi_nas_active_band_get_string (e->lte_band),
4360 qmi_nas_scell_state_get_string (e->state),
4361 e->cell_index);
4362 }
4363
4364 } else {
4365 if (qmi_message_nas_get_lte_cphy_ca_info_output_get_phy_ca_agg_scell_info (
4366 output,
4367 &pci,
4368 &channel,
4369 &dl_bandwidth,
4370 &band,
4371 &state,
4372 NULL)) {
4373 g_print ("Secondary Cell Info\n");
4374 g_print ("\tPhysical Cell ID: '%" G_GUINT16_FORMAT"'\n"
4375 "\tRX Channel: '%" G_GUINT16_FORMAT"'\n"
4376 "\tDL Bandwidth: '%s'\n"
4377 "\tLTE Band: '%s'\n"
4378 "\tState: '%s'\n",
4379 pci, channel,
4380 qmi_nas_dl_bandwidth_get_string (dl_bandwidth),
4381 qmi_nas_active_band_get_string (band),
4382 qmi_nas_scell_state_get_string (state));
4383 }
4384
4385 if (qmi_message_nas_get_lte_cphy_ca_info_output_get_scell_index (
4386 output,
4387 &scell_index,
4388 NULL)) {
4389 g_print ("Secondary Cell index: '%u'\n", scell_index);
4390 }
4391 }
4392
4393 qmi_message_nas_get_lte_cphy_ca_info_output_unref (output);
4394 operation_shutdown (TRUE);
4395 }
4396
4397 #endif /* HAVE_QMI_MESSAGE_NAS_GET_LTE_CPHY_CA_INFO */
4398
4399 #if defined HAVE_QMI_MESSAGE_NAS_GET_RF_BAND_INFORMATION
4400
4401 static void
4402 get_rf_band_info_ready (QmiClientNas *client,
4403 GAsyncResult *res)
4404 {
4405 QmiMessageNasGetRfBandInformationOutput *output;
4406 GError *error = NULL;
4407 GArray *band_array = NULL;
4408 GArray *extended_band_array = NULL;
4409 GArray *bandwidth_array = NULL;
4410 guint i;
4411
4412 output = qmi_client_nas_get_rf_band_information_finish (client, res, &error);
4413 if (!output) {
4414 g_printerr ("error: operation failed: %s\n", error->message);
4415 g_error_free (error);
4416 operation_shutdown (FALSE);
4417 return;
4418 }
4419
4420 if (!qmi_message_nas_get_rf_band_information_output_get_result (output, &error)) {
4421 g_printerr ("error: couldn't get rf band info: %s\n", error->message);
4422 g_error_free (error);
4423 qmi_message_nas_get_rf_band_information_output_unref (output);
4424 operation_shutdown (FALSE);
4425 return;
4426 }
4427
4428 g_print ("[%s] Successfully got RF band info\n",
4429 qmi_device_get_path_display (ctx->device));
4430
4431 if (!qmi_message_nas_get_rf_band_information_output_get_list (
4432 output,
4433 &band_array,
4434 &error)) {
4435 g_printerr ("error: couldn't get rf band list: %s\n", error->message);
4436 g_error_free (error);
4437 qmi_message_nas_get_rf_band_information_output_unref (output);
4438 operation_shutdown (FALSE);
4439 return;
4440 }
4441
4442 g_print ("Band Information:\n");
4443 for (i = 0; band_array && i < band_array->len; i++) {
4444 QmiMessageNasGetRfBandInformationOutputListElement *info;
4445
4446 info = &g_array_index (band_array, QmiMessageNasGetRfBandInformationOutputListElement, i);
4447 g_print ("\tRadio Interface: '%s'\n"
4448 "\tActive Band Class: '%s'\n"
4449 "\tActive Channel: '%" G_GUINT16_FORMAT"'\n",
4450 qmi_nas_radio_interface_get_string (info->radio_interface),
4451 qmi_nas_active_band_get_string (info->active_band_class),
4452 info->active_channel);
4453 }
4454
4455 if (qmi_message_nas_get_rf_band_information_output_get_extended_list (
4456 output,
4457 &extended_band_array,
4458 NULL)) {
4459 g_print ("Band Information (Extended):\n");
4460 for (i = 0; extended_band_array && i < extended_band_array->len; i++) {
4461 QmiMessageNasGetRfBandInformationOutputExtendedListElement *info;
4462
4463 info = &g_array_index (extended_band_array, QmiMessageNasGetRfBandInformationOutputExtendedListElement, i);
4464 g_print ("\tRadio Interface: '%s'\n"
4465 "\tActive Band Class: '%s'\n"
4466 "\tActive Channel: '%" G_GUINT32_FORMAT"'\n",
4467 qmi_nas_radio_interface_get_string (info->radio_interface),
4468 qmi_nas_active_band_get_string (info->active_band_class),
4469 info->active_channel);
4470 }
4471 }
4472
4473 if (qmi_message_nas_get_rf_band_information_output_get_bandwidth_list (
4474 output,
4475 &bandwidth_array,
4476 NULL)) {
4477 g_print ("Bandwidth:\n");
4478 for (i = 0; bandwidth_array && i < bandwidth_array->len; i++) {
4479 QmiMessageNasGetRfBandInformationOutputBandwidthListElement *info;
4480 info = &g_array_index (bandwidth_array, QmiMessageNasGetRfBandInformationOutputBandwidthListElement, i);
4481 g_print ("\tRadio Interface: '%s'\n"
4482 "\tBandwidth: '%s'\n",
4483 qmi_nas_radio_interface_get_string (info->radio_interface),
4484 qmi_nas_dl_bandwidth_get_string (info->bandwidth));
4485 }
4486 }
4487
4488 qmi_message_nas_get_rf_band_information_output_unref (output);
4489 operation_shutdown (TRUE);
4490 }
4491
4492 #endif /* HAVE_QMI_MESSAGE_NAS_GET_RF_BAND_INFORMATION */
4493
4494 #if defined HAVE_QMI_MESSAGE_NAS_GET_NETWORK_TIME
4495
4496 typedef struct {
4497 guint16 year;
4498 guint8 month;
4499 guint8 day;
4500 guint8 hour;
4501 guint8 minute;
4502 guint8 second;
4503 QmiNasDayOfWeek day_of_week;
4504 gint8 tz_offset;
4505 QmiNasDaylightSavingsAdjustment ds_adj;
4506 QmiNasRadioInterface radio_if;
4507 } NASNetworkTime;
4508
4509 static void
4510 print_time (const char *prefix, const NASNetworkTime *nt)
4511 {
4512 g_print ("%s Date: '%u-%02u-%02u'\n",
4513 prefix, nt->year, nt->month, nt->day);
4514 g_print ("%s Time: '%02u:%02u:%02u'\n",
4515 prefix, nt->hour, nt->minute, nt->second);
4516 g_print ("%s Day-of-Week: '%s'\n",
4517 prefix, qmi_nas_day_of_week_get_string (nt->day_of_week));
4518 g_print ("%s Timezone Offset: '%d' minutes\n",
4519 prefix, nt->tz_offset * 15);
4520 g_print ("%s Daylight Saving Time Adjustment: '%u' hours\n",
4521 prefix, nt->ds_adj);
4522 g_print ("%s Radio Interface: '%s'\n",
4523 prefix, qmi_nas_radio_interface_get_string (nt->radio_if));
4524 }
4525
4526 static void
4527 get_network_time_ready (QmiClientNas *client,
4528 GAsyncResult *res)
4529 {
4530 g_autoptr(QmiMessageNasGetNetworkTimeOutput) output = NULL;
4531 g_autoptr(GError) error = NULL;
4532 NASNetworkTime nt = { 0 };
4533
4534 output = qmi_client_nas_get_network_time_finish (client, res, &error);
4535 if (!output) {
4536 g_printerr ("error: operation failed: %s\n", error->message);
4537 operation_shutdown (FALSE);
4538 return;
4539 }
4540
4541 if (!qmi_message_nas_get_network_time_output_get_result (output, &error)) {
4542 g_printerr ("error: couldn't get network time: %s\n", error->message);
4543 operation_shutdown (FALSE);
4544 return;
4545 }
4546
4547 g_print ("[%s] Successfully got network time:\n",
4548 qmi_device_get_path_display (ctx->device));
4549
4550 if (qmi_message_nas_get_network_time_output_get_3gpp2_time (output,
4551 &nt.year,
4552 &nt.month,
4553 &nt.day,
4554 &nt.hour,
4555 &nt.minute,
4556 &nt.second,
4557 &nt.day_of_week,
4558 &nt.tz_offset,
4559 &nt.ds_adj,
4560 &nt.radio_if,
4561 NULL)) {
4562 print_time ("\t3GPP2", &nt);
4563 }
4564
4565 memset (&nt, 0, sizeof (nt));
4566 if (qmi_message_nas_get_network_time_output_get_3gpp_time (output,
4567 &nt.year,
4568 &nt.month,
4569 &nt.day,
4570 &nt.hour,
4571 &nt.minute,
4572 &nt.second,
4573 &nt.day_of_week,
4574 &nt.tz_offset,
4575 &nt.ds_adj,
4576 &nt.radio_if,
4577 NULL)) {
4578 print_time ("\t3GPP", &nt);
4579 }
4580
4581 operation_shutdown (TRUE);
4582 }
4583
4584 #endif /* HAVE_QMI_MESSAGE_NAS_GET_NETWORK_TIME */
4585
4586 #if defined HAVE_QMI_MESSAGE_NAS_GET_DRX
4587
4588 static void
4589 get_drx_ready (QmiClientNas *client,
4590 GAsyncResult *res)
4591 {
4592 g_autoptr(QmiMessageNasGetDrxOutput) output = NULL;
4593 g_autoptr(GError) error = NULL;
4594 QmiNasDrx drx = QMI_NAS_DRX_UNKNOWN;
4595
4596 output = qmi_client_nas_get_drx_finish (client, res, &error);
4597 if (!output) {
4598 g_printerr ("error: operation failed: %s\n", error->message);
4599 operation_shutdown (FALSE);
4600 return;
4601 }
4602
4603 if (!qmi_message_nas_get_drx_output_get_result (output, &error)) {
4604 g_printerr ("error: couldn't get DRX: %s\n", error->message);
4605 operation_shutdown (FALSE);
4606 return;
4607 }
4608
4609 if (!qmi_message_nas_get_drx_output_get_info (output, &drx, NULL)) {
4610 g_printerr ("error: DRX info not provided\n");
4611 operation_shutdown (FALSE);
4612 return;
4613 }
4614
4615 g_print ("[%s] Successfully got DRX: %s\n",
4616 qmi_device_get_path_display (ctx->device),
4617 qmi_nas_drx_get_string (drx));
4618 operation_shutdown (TRUE);
4619 }
4620
4621 #endif /* HAVE_QMI_MESSAGE_NAS_GET_DRX */
4622
4623 #if defined HAVE_QMI_MESSAGE_NAS_GET_ENDC_CONFIG
4624
4625 static void
4626 get_endc_config_ready (QmiClientNas *client,
4627 GAsyncResult *res)
4628 {
4629 g_autoptr(QmiMessageNasGetEndcConfigOutput) output = NULL;
4630 g_autoptr(GError) error = NULL;
4631 gboolean enabled = FALSE;
4632 gboolean scg_release = FALSE;
4633
4634 output = qmi_client_nas_get_endc_config_finish (client, res, &error);
4635 if (!output) {
4636 g_printerr ("error: operation failed: %s\n", error->message);
4637 operation_shutdown (FALSE);
4638 return;
4639 }
4640
4641 if (!qmi_message_nas_get_endc_config_output_get_result (output, &error)) {
4642 g_printerr ("error: couldn't get EN-DC config: %s\n", error->message);
4643 operation_shutdown (FALSE);
4644 return;
4645 }
4646
4647 if (!qmi_message_nas_get_endc_config_output_get_enabled (output, &enabled, NULL)) {
4648 g_printerr ("error: EN-DC config not provided\n");
4649 operation_shutdown (FALSE);
4650 return;
4651 }
4652
4653 if (!qmi_message_nas_get_endc_config_output_get_immediate_scg_release (output, &scg_release, NULL)) {
4654 g_printerr ("error: EN-DC SCG release info not provided\n");
4655 operation_shutdown (FALSE);
4656 return;
4657 }
4658
4659 g_print ("[%s] Successfully got EN-DC Config:\n"
4660 "\tEnabled: %s\n"
4661 "\tImmediate SCG Release: %s\n",
4662 qmi_device_get_path_display (ctx->device),
4663 enabled ? "true" : "false",
4664 scg_release ? "true" : "false");
4665 operation_shutdown (TRUE);
4666 }
4667
4668 #endif /* HAVE_QMI_MESSAGE_NAS_GET_ENDC_CONFIG */
4669
4670 #if defined HAVE_QMI_MESSAGE_NAS_GET_SUPPORTED_MESSAGES
4671
4672 static void
4673 get_supported_messages_ready (QmiClientNas *client,
4674 GAsyncResult *res)
4675 {
4676 QmiMessageNasGetSupportedMessagesOutput *output;
4677 GError *error = NULL;
4678 GArray *bytearray = NULL;
4679 gchar *str;
4680
4681 output = qmi_client_nas_get_supported_messages_finish (client, res, &error);
4682 if (!output) {
4683 g_printerr ("error: operation failed: %s\n", error->message);
4684 g_error_free (error);
4685 operation_shutdown (FALSE);
4686 return;
4687 }
4688
4689 if (!qmi_message_nas_get_supported_messages_output_get_result (output, &error)) {
4690 g_printerr ("error: couldn't get supported NAS messages: %s\n", error->message);
4691 g_error_free (error);
4692 qmi_message_nas_get_supported_messages_output_unref (output);
4693 operation_shutdown (FALSE);
4694 return;
4695 }
4696
4697 g_print ("[%s] Successfully got supported NAS messages:\n",
4698 qmi_device_get_path_display (ctx->device));
4699
4700 qmi_message_nas_get_supported_messages_output_get_list (output, &bytearray, NULL);
4701 str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL,
4702 bytearray ? bytearray->len : 0);
4703 g_print ("%s", str);
4704 g_free (str);
4705
4706 qmi_message_nas_get_supported_messages_output_unref (output);
4707 operation_shutdown (TRUE);
4708 }
4709
4710 #endif /* HAVE_QMI_MESSAGE_NAS_GET_SUPPORTED_MESSAGES */
4711
4712 #if defined HAVE_QMI_MESSAGE_NAS_SWI_GET_STATUS
4713
4714 static void
4715 swi_get_status_ready (QmiClientNas *client,
4716 GAsyncResult *res)
4717 {
4718 QmiMessageNasSwiGetStatusOutput *output;
4719 GError *error = NULL;
4720
4721 gint8 temperature;
4722 QmiNasSwiModemMode modem_mode;
4723 QmiNasSwiSystemMode system_mode;
4724 QmiNasSwiImsRegState ims_reg_state;
4725 QmiNasSwiPsState ps_state;
4726
4727 QmiNasActiveBand band;
4728 QmiNasDLBandwidth bandwidth;
4729 guint16 rx_channel;
4730 guint16 tx_channel;
4731 QmiNasSwiEmmState emm_state;
4732 guint8 emm_sub_state;
4733 QmiNasSwiEmmConnectionState emm_conn_state;
4734
4735 output = qmi_client_nas_swi_get_status_finish (client, res, &error);
4736 if (!output) {
4737 g_printerr ("error: operation failed: %s\n", error->message);
4738 g_error_free (error);
4739 operation_shutdown (FALSE);
4740 return;
4741 }
4742
4743 if (!qmi_message_nas_swi_get_status_output_get_result (output, &error)) {
4744 g_printerr ("error: couldn't get status: %s\n", error->message);
4745 g_error_free (error);
4746 qmi_message_nas_swi_get_status_output_unref (output);
4747 operation_shutdown (FALSE);
4748 return;
4749 }
4750
4751 g_print ("[%s] Successfully got status:\n",
4752 qmi_device_get_path_display (ctx->device));
4753
4754 if (qmi_message_nas_swi_get_status_output_get_common_info_v2 (
4755 output,
4756 &temperature,
4757 &modem_mode,
4758 &system_mode,
4759 &ims_reg_state,
4760 &ps_state,
4761 NULL)) {
4762 g_print ("Common Info:\n"
4763 "\tTemperature: '%d'\n"
4764 "\tModem mode: '%s'\n"
4765 "\tSystem mode: '%s'\n"
4766 "\tIMS registration state: '%s'\n"
4767 "\tPacket service state: '%s'\n",
4768 temperature,
4769 qmi_nas_swi_modem_mode_get_string (modem_mode),
4770 qmi_nas_swi_system_mode_get_string (system_mode),
4771 qmi_nas_swi_ims_reg_state_get_string (ims_reg_state),
4772 qmi_nas_swi_ps_state_get_string (ps_state));
4773 }
4774
4775 if (qmi_message_nas_swi_get_status_output_get_lte_info (
4776 output,
4777 &band,
4778 &bandwidth,
4779 &rx_channel,
4780 &tx_channel,
4781 &emm_state,
4782 &emm_sub_state,
4783 &emm_conn_state,
4784 NULL)) {
4785 g_print ("LTE info:\n"
4786 "\tBand: '%s'\n"
4787 "\tBandwidth: '%s'\n"
4788 "\tRX channel: '%" G_GUINT16_FORMAT"'\n"
4789 "\tTX channel: '%" G_GUINT16_FORMAT"'\n"
4790 "\tEMM state: '%s'\n"
4791 "\tEMM sub state: '%u'\n"
4792 "\tEMM connection state: '%s'\n",
4793 qmi_nas_active_band_get_string (band),
4794 qmi_nas_dl_bandwidth_get_string (bandwidth),
4795 rx_channel,
4796 tx_channel,
4797 qmi_nas_swi_emm_state_get_string (emm_state),
4798 emm_sub_state,
4799 qmi_nas_swi_emm_connection_state_get_string (emm_conn_state));
4800 }
4801
4802 qmi_message_nas_swi_get_status_output_unref (output);
4803 operation_shutdown (TRUE);
4804 }
4805
4806 #endif /* HAVE_QMI_MESSAGE_NAS_SWI_GET_STATUS */
4807
4808 #if defined HAVE_QMI_MESSAGE_NAS_RESET
4809
4810 static void
4811 reset_ready (QmiClientNas *client,
4812 GAsyncResult *res)
4813 {
4814 QmiMessageNasResetOutput *output;
4815 GError *error = NULL;
4816
4817 output = qmi_client_nas_reset_finish (client, res, &error);
4818 if (!output) {
4819 g_printerr ("error: operation failed: %s\n", error->message);
4820 g_error_free (error);
4821 operation_shutdown (FALSE);
4822 return;
4823 }
4824
4825 if (!qmi_message_nas_reset_output_get_result (output, &error)) {
4826 g_printerr ("error: couldn't reset the NAS service: %s\n", error->message);
4827 g_error_free (error);
4828 qmi_message_nas_reset_output_unref (output);
4829 operation_shutdown (FALSE);
4830 return;
4831 }
4832
4833 g_print ("[%s] Successfully performed NAS service reset\n",
4834 qmi_device_get_path_display (ctx->device));
4835
4836 qmi_message_nas_reset_output_unref (output);
4837 operation_shutdown (TRUE);
4838 }
4839
4840 #endif /* HAVE_QMI_MESSAGE_NAS_RESET */
4841
4842 static gboolean
4843 noop_cb (gpointer unused)
4844 {
4845 operation_shutdown (TRUE);
4846 return FALSE;
4847 }
4848
4849 void
4850 qmicli_nas_run (QmiDevice *device,
4851 QmiClientNas *client,
4852 GCancellable *cancellable)
4853 {
4854 /* Initialize context */
4855 ctx = g_slice_new0 (Context);
4856 ctx->device = g_object_ref (device);
4857 ctx->client = g_object_ref (client);
4858 ctx->cancellable = g_object_ref (cancellable);
4859
4860 #if defined HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_STRENGTH
4861 if (get_signal_strength_flag) {
4862 QmiMessageNasGetSignalStrengthInput *input;
4863
4864 input = get_signal_strength_input_create ();
4865
4866 g_debug ("Asynchronously getting signal strength...");
4867 qmi_client_nas_get_signal_strength (ctx->client,
4868 input,
4869 10,
4870 ctx->cancellable,
4871 (GAsyncReadyCallback)get_signal_strength_ready,
4872 NULL);
4873 qmi_message_nas_get_signal_strength_input_unref (input);
4874 return;
4875 }
4876 #endif
4877
4878 #if defined HAVE_QMI_MESSAGE_NAS_GET_SIGNAL_INFO
4879 if (get_signal_info_flag) {
4880 g_debug ("Asynchronously getting signal info...");
4881 qmi_client_nas_get_signal_info (ctx->client,
4882 NULL,
4883 10,
4884 ctx->cancellable,
4885 (GAsyncReadyCallback)get_signal_info_ready,
4886 NULL);
4887 return;
4888 }
4889 #endif
4890
4891 #if defined HAVE_QMI_MESSAGE_NAS_GET_TX_RX_INFO
4892 if (get_tx_rx_info_str) {
4893 QmiMessageNasGetTxRxInfoInput *input;
4894 QmiNasRadioInterface interface;
4895
4896 input = get_tx_rx_info_input_create (get_tx_rx_info_str,
4897 &interface);
4898 if (!input) {
4899 operation_shutdown (FALSE);
4900 return;
4901 }
4902
4903 g_debug ("Asynchronously getting TX/RX info...");
4904 qmi_client_nas_get_tx_rx_info (ctx->client,
4905 input,
4906 10,
4907 ctx->cancellable,
4908 (GAsyncReadyCallback)get_tx_rx_info_ready,
4909 GUINT_TO_POINTER (interface));
4910 qmi_message_nas_get_tx_rx_info_input_unref (input);
4911 return;
4912 }
4913 #endif
4914
4915 #if defined HAVE_QMI_MESSAGE_NAS_GET_HOME_NETWORK
4916 if (get_home_network_flag) {
4917 g_debug ("Asynchronously getting home network...");
4918 qmi_client_nas_get_home_network (ctx->client,
4919 NULL,
4920 10,
4921 ctx->cancellable,
4922 (GAsyncReadyCallback)get_home_network_ready,
4923 NULL);
4924 return;
4925 }
4926 #endif
4927
4928 #if defined HAVE_QMI_MESSAGE_NAS_GET_PREFERRED_NETWORKS
4929 if (get_preferred_networks_flag) {
4930 g_debug ("Asynchronously getting preferred networks...");
4931 qmi_client_nas_get_preferred_networks (ctx->client,
4932 NULL,
4933 10,
4934 ctx->cancellable,
4935 (GAsyncReadyCallback)get_preferred_networks_ready,
4936 NULL);
4937 return;
4938 }
4939 #endif
4940
4941 #if defined HAVE_QMI_MESSAGE_NAS_SET_PREFERRED_NETWORKS
4942 if (set_preferred_networks_str) {
4943 QmiMessageNasSetPreferredNetworksInput *input;
4944 g_debug ("Asynchronously setting preferred networks...");
4945
4946 input = set_preferred_networks_input_create (set_preferred_networks_str);
4947 if (!input) {
4948 operation_shutdown (FALSE);
4949 return;
4950 }
4951
4952 qmi_client_nas_set_preferred_networks (ctx->client,
4953 input,
4954 10,
4955 ctx->cancellable,
4956 (GAsyncReadyCallback)set_preferred_networks_ready,
4957 NULL);
4958 qmi_message_nas_set_preferred_networks_input_ref (input);
4959 return;
4960 }
4961 #endif
4962
4963 #if defined HAVE_QMI_MESSAGE_NAS_GET_SERVING_SYSTEM
4964 if (get_serving_system_flag) {
4965 g_debug ("Asynchronously getting serving system...");
4966 qmi_client_nas_get_serving_system (ctx->client,
4967 NULL,
4968 10,
4969 ctx->cancellable,
4970 (GAsyncReadyCallback)get_serving_system_ready,
4971 NULL);
4972 return;
4973 }
4974 #endif
4975
4976 #if defined HAVE_QMI_MESSAGE_NAS_GET_SYSTEM_INFO
4977 if (get_system_info_flag) {
4978 g_debug ("Asynchronously getting system info...");
4979 qmi_client_nas_get_system_info (ctx->client,
4980 NULL,
4981 10,
4982 ctx->cancellable,
4983 (GAsyncReadyCallback)get_system_info_ready,
4984 NULL);
4985 return;
4986 }
4987 #endif
4988
4989 #if defined HAVE_QMI_MESSAGE_NAS_GET_TECHNOLOGY_PREFERENCE
4990 if (get_technology_preference_flag) {
4991 g_debug ("Asynchronously getting technology preference...");
4992 qmi_client_nas_get_technology_preference (ctx->client,
4993 NULL,
4994 10,
4995 ctx->cancellable,
4996 (GAsyncReadyCallback)get_technology_preference_ready,
4997 NULL);
4998 return;
4999 }
5000 #endif
5001
5002 #if defined HAVE_QMI_MESSAGE_NAS_GET_SYSTEM_SELECTION_PREFERENCE
5003 if (get_system_selection_preference_flag) {
5004 g_debug ("Asynchronously getting system selection preference...");
5005 qmi_client_nas_get_system_selection_preference (ctx->client,
5006 NULL,
5007 10,
5008 ctx->cancellable,
5009 (GAsyncReadyCallback)get_system_selection_preference_ready,
5010 NULL);
5011 return;
5012 }
5013 #endif
5014
5015 #if defined HAVE_QMI_MESSAGE_NAS_SET_SYSTEM_SELECTION_PREFERENCE
5016 if (set_system_selection_preference_str) {
5017 QmiMessageNasSetSystemSelectionPreferenceInput *input;
5018 g_debug ("Asynchronously setting system selection preference...");
5019
5020 input = set_system_selection_preference_input_create (set_system_selection_preference_str);
5021 if (!input) {
5022 operation_shutdown (FALSE);
5023 return;
5024 }
5025
5026 qmi_client_nas_set_system_selection_preference (ctx->client,
5027 input,
5028 10,
5029 ctx->cancellable,
5030 (GAsyncReadyCallback)set_system_selection_preference_ready,
5031 NULL);
5032 qmi_message_nas_set_system_selection_preference_input_unref (input);
5033 return;
5034 }
5035 #endif
5036
5037 #if defined HAVE_QMI_MESSAGE_NAS_NETWORK_SCAN
5038 if (network_scan_flag) {
5039 g_autoptr(QmiMessageNasNetworkScanInput) input = NULL;
5040
5041 if (network_scan_str) {
5042 input = network_scan_input_create (network_scan_str);
5043 if (!input) {
5044 operation_shutdown (FALSE);
5045 return;
5046 }
5047 }
5048
5049 g_debug ("Asynchronously scanning networks...");
5050 qmi_client_nas_network_scan (ctx->client,
5051 input,
5052 300, /* this operation takes a lot of time! */
5053 ctx->cancellable,
5054 (GAsyncReadyCallback)network_scan_ready,
5055 NULL);
5056 return;
5057 }
5058 #endif
5059
5060 #if defined HAVE_QMI_MESSAGE_NAS_INCREMENTAL_NETWORK_SCAN
5061 if (incremental_network_scan_flag) {
5062 g_autoptr(QmiMessageNasIncrementalNetworkScanInput) input = NULL;
5063
5064 if (incremental_network_scan_str) {
5065 input = incremental_network_scan_input_create (incremental_network_scan_str);
5066 if (!input) {
5067 operation_shutdown (FALSE);
5068 return;
5069 }
5070 }
5071
5072 g_debug ("Incrementally scanning networks...");
5073 qmi_client_nas_incremental_network_scan (ctx->client,
5074 input,
5075 10,
5076 ctx->cancellable,
5077 (GAsyncReadyCallback)incremental_network_scan_ready,
5078 NULL);
5079 return;
5080 }
5081 #endif
5082
5083 #if defined HAVE_QMI_MESSAGE_NAS_GET_CELL_LOCATION_INFO
5084 if (get_cell_location_info_flag) {
5085 g_debug ("Asynchronously getting cell location info ...");
5086 qmi_client_nas_get_cell_location_info (ctx->client,
5087 NULL,
5088 10,
5089 ctx->cancellable,
5090 (GAsyncReadyCallback)get_cell_location_info_ready,
5091 NULL);
5092 return;
5093 }
5094 #endif
5095
5096 #if defined HAVE_QMI_MESSAGE_NAS_FORCE_NETWORK_SEARCH
5097 if (force_network_search_flag) {
5098 g_debug ("Forcing network search...");
5099 qmi_client_nas_force_network_search (ctx->client,
5100 NULL,
5101 10,
5102 ctx->cancellable,
5103 (GAsyncReadyCallback)force_network_search_ready,
5104 NULL);
5105 return;
5106 }
5107 #endif
5108
5109 #if defined HAVE_QMI_MESSAGE_NAS_GET_OPERATOR_NAME
5110 if (get_operator_name_flag) {
5111 g_debug ("Asynchronously getting operator name data...");
5112 qmi_client_nas_get_operator_name (ctx->client,
5113 NULL,
5114 10,
5115 ctx->cancellable,
5116 (GAsyncReadyCallback)get_operator_name_ready,
5117 NULL);
5118 return;
5119 }
5120 #endif
5121
5122 #if defined HAVE_QMI_MESSAGE_NAS_GET_PLMN_NAME
5123 if (get_plmn_name_str) {
5124
5125 g_autoptr(QmiMessageNasGetPlmnNameInput) input = NULL;
5126 input = set_plmn_name_input_plmn_create(get_plmn_name_str);
5127
5128 g_debug ("Asynchronously getting plmn name data...");
5129 qmi_client_nas_get_plmn_name (ctx->client,
5130 input,
5131 10,
5132 ctx->cancellable,
5133 (GAsyncReadyCallback)get_plmn_name_ready,
5134 NULL);
5135 return;
5136 }
5137 #endif
5138
5139 #if defined HAVE_QMI_MESSAGE_NAS_GET_LTE_CPHY_CA_INFO
5140 if (get_lte_cphy_ca_info_flag) {
5141 g_debug ("Asynchronously getting carrier aggregation info ...");
5142 qmi_client_nas_get_lte_cphy_ca_info (ctx->client,
5143 NULL,
5144 10,
5145 ctx->cancellable,
5146 (GAsyncReadyCallback)get_lte_cphy_ca_info_ready,
5147 NULL);
5148 return;
5149 }
5150 #endif
5151
5152 #if defined HAVE_QMI_MESSAGE_NAS_GET_RF_BAND_INFORMATION
5153 if (get_rf_band_info_flag) {
5154 g_debug ("Asynchronously getting RF band info ...");
5155 qmi_client_nas_get_rf_band_information (ctx->client,
5156 NULL,
5157 10,
5158 ctx->cancellable,
5159 (GAsyncReadyCallback)get_rf_band_info_ready,
5160 NULL);
5161 return;
5162 }
5163 #endif
5164
5165 #if defined HAVE_QMI_MESSAGE_NAS_GET_NETWORK_TIME
5166 if (get_network_time_flag) {
5167 g_debug ("Asynchronously getting network time ...");
5168 qmi_client_nas_get_network_time (ctx->client,
5169 NULL,
5170 10,
5171 ctx->cancellable,
5172 (GAsyncReadyCallback)get_network_time_ready,
5173 NULL);
5174 return;
5175 }
5176 #endif
5177
5178 #if defined HAVE_QMI_MESSAGE_NAS_GET_DRX
5179 if (get_drx_flag) {
5180 g_debug ("Asynchronously getting DRX ...");
5181 qmi_client_nas_get_drx (ctx->client,
5182 NULL,
5183 10,
5184 ctx->cancellable,
5185 (GAsyncReadyCallback)get_drx_ready,
5186 NULL);
5187 return;
5188 }
5189 #endif
5190
5191 #if defined HAVE_QMI_MESSAGE_NAS_GET_ENDC_CONFIG
5192 if (get_endc_config_flag) {
5193 g_debug ("Asynchronously getting EN-DC Config ...");
5194 qmi_client_nas_get_endc_config (ctx->client,
5195 NULL,
5196 10,
5197 ctx->cancellable,
5198 (GAsyncReadyCallback)get_endc_config_ready,
5199 NULL);
5200 return;
5201 }
5202 #endif
5203
5204 #if defined HAVE_QMI_MESSAGE_NAS_GET_SUPPORTED_MESSAGES
5205 if (get_supported_messages_flag) {
5206 g_debug ("Asynchronously getting supported NAS messages...");
5207 qmi_client_nas_get_supported_messages (ctx->client,
5208 NULL,
5209 10,
5210 ctx->cancellable,
5211 (GAsyncReadyCallback)get_supported_messages_ready,
5212 NULL);
5213 return;
5214 }
5215 #endif
5216
5217 #if defined HAVE_QMI_MESSAGE_NAS_SWI_GET_STATUS
5218 if (swi_get_status_flag) {
5219 g_debug ("Asynchronously getting status (Sierra Wireless specific)...");
5220 qmi_client_nas_swi_get_status (ctx->client,
5221 NULL,
5222 10,
5223 ctx->cancellable,
5224 (GAsyncReadyCallback)swi_get_status_ready,
5225 NULL);
5226 return;
5227 }
5228 #endif
5229
5230 #if defined HAVE_QMI_MESSAGE_NAS_RESET
5231 if (reset_flag) {
5232 g_debug ("Asynchronously resetting NAS service...");
5233 qmi_client_nas_reset (ctx->client,
5234 NULL,
5235 10,
5236 ctx->cancellable,
5237 (GAsyncReadyCallback)reset_ready,
5238 NULL);
5239 return;
5240 }
5241 #endif
5242
5243 /* Just client allocate/release? */
5244 if (noop_flag) {
5245 g_idle_add (noop_cb, NULL);
5246 return;
5247 }
5248
5249 g_warn_if_reached ();
5250 }
5251
5252 #endif /* HAVE_QMI_SERVICE_NAS */