Debian Codegraph @

src/mbimcli/mbimcli-ms-basic-connect-extensions.c

raw
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /*
4 * mbimcli -- Command line interface to control MBIM devices
5 *
6 * Copyright (C) 2018 Google LLC
7 * Copyright (C) 2018 Aleksander Morgado <[email protected]>
8 */
9
10 #include "config.h"
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <locale.h>
15 #include <string.h>
16 #include <errno.h>
17
18 #include <glib.h>
19 #include <gio/gio.h>
20
21 #include <libmbim-glib.h>
22
23 #include "mbim-common.h"
24 #include "mbimcli.h"
25 #include "mbimcli-helpers.h"
26
27 /* Context */
28 typedef struct {
29 MbimDevice *device;
30 GCancellable *cancellable;
31 } Context;
32 static Context *ctx;
33
34 /* Options */
35 static gchar *query_pco_str;
36 static gboolean query_lte_attach_configuration_flag;
37 static gchar *set_lte_attach_configuration_str;
38 static gboolean query_lte_attach_status_flag; /* support for the deprecated name */
39 static gboolean query_lte_attach_info_flag;
40 static gboolean query_sys_caps_flag;
41 static gboolean query_device_caps_flag;
42 static gchar *query_slot_info_status_str;
43 static gboolean query_device_slot_mappings_flag;
44 static gchar *set_device_slot_mappings_str;
45 static gboolean query_location_info_status_flag;
46 static gboolean query_provisioned_contexts_flag;
47 static gchar *set_provisioned_contexts_str;
48 static gboolean query_base_stations_flag;
49 static gchar *query_version_str;
50 static gboolean query_registration_parameters_flag;
51 static gchar *set_registration_parameters_str;
52 static gboolean query_modem_configuration_flag;
53 static gboolean query_wake_reason_flag;
54 static gboolean device_reset_flag;
55
56 static gboolean query_pco_arg_parse (const gchar *option_name,
57 const gchar *value,
58 gpointer user_data,
59 GError **error);
60
61 static GOptionEntry entries[] = {
62 { "ms-query-pco", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, G_CALLBACK (query_pco_arg_parse),
63 "Query PCO value (SessionID is optional, defaults to 0)",
64 "[SessionID]"
65 },
66 { "ms-query-lte-attach-configuration", 0, 0, G_OPTION_ARG_NONE, &query_lte_attach_configuration_flag,
67 "Query LTE attach configuration",
68 NULL
69 },
70 { "ms-set-lte-attach-configuration", 0, 0, G_OPTION_ARG_STRING, &set_lte_attach_configuration_str,
71 "Set LTE attach configurations (groups separated by '/' if more than one, with allowed-keys: ip-type, roaming-control, source, access-string, username, password, compression, auth)",
72 "[(default|restore-factory)[,\"key=value,...\"[/\"key=value,...\"[/\"key=value,...\"]]]"
73 },
74 { "ms-query-lte-attach-status", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &query_lte_attach_status_flag,
75 NULL,
76 NULL
77 },
78 { "ms-query-lte-attach-info", 0, 0, G_OPTION_ARG_NONE, &query_lte_attach_info_flag,
79 "Query LTE attach status information",
80 NULL
81 },
82 { "ms-query-sys-caps", 0, 0, G_OPTION_ARG_NONE, &query_sys_caps_flag,
83 "Query system capabilities",
84 NULL
85 },
86 { "ms-query-device-caps", 0,0, G_OPTION_ARG_NONE, &query_device_caps_flag,
87 "Query device capabilities",
88 NULL
89 },
90 { "ms-query-slot-info-status", 0, 0, G_OPTION_ARG_STRING, &query_slot_info_status_str,
91 "Query slot information status",
92 "[SlotIndex]"
93 },
94 { "ms-set-device-slot-mappings", 0, 0, G_OPTION_ARG_STRING, &set_device_slot_mappings_str,
95 "Set device slot mappings for each executor",
96 "[(SlotIndex)[,(SlotIndex)[,...]]]"
97
98 },
99 { "ms-query-device-slot-mappings", 0, 0, G_OPTION_ARG_NONE, &query_device_slot_mappings_flag,
100 "Query device slot mappings",
101 NULL
102 },
103 { "ms-query-location-info-status", 0, 0, G_OPTION_ARG_NONE, &query_location_info_status_flag,
104 "Query location info status",
105 NULL
106 },
107 { "ms-set-provisioned-contexts", 0, 0, G_OPTION_ARG_STRING, &set_provisioned_contexts_str,
108 "Set provisioned contexts (allowed keys: operation, context-type, ip-type, state, roaming-control, media-type, source, auth, compression, username, password, access-string)",
109 "[\"key=value,...\"]"
110 },
111 { "ms-query-provisioned-contexts", 0, 0, G_OPTION_ARG_NONE, &query_provisioned_contexts_flag,
112 "Query provisioned contexts",
113 NULL
114 },
115 { "ms-query-base-stations-info", 0, 0, G_OPTION_ARG_NONE, &query_base_stations_flag,
116 "Query base stations info",
117 NULL
118 },
119 { "ms-device-reset", 0, 0, G_OPTION_ARG_NONE, &device_reset_flag,
120 "Reset device",
121 NULL
122 },
123 { "ms-query-version", 0, 0,G_OPTION_ARG_STRING , &query_version_str,
124 "Exchange supported version information. Since MBIMEx v2.0.",
125 "[(MBIM version),(MBIM extended version)]"
126 },
127 { "ms-query-registration-parameters", 0, 0, G_OPTION_ARG_NONE, &query_registration_parameters_flag,
128 "Query registration parameters. Since MBIMEx v3.0.",
129 NULL
130 },
131 { "ms-set-registration-parameters", 0, 0,G_OPTION_ARG_STRING , &set_registration_parameters_str,
132 "Set registration parameters (required keys: mico-mode, drx-cycle, ladn-info, default-pdu-activation-hint, re-register-if-needed). Since MBIMEx v3.0.",
133 "[\"key=value,...\"]"
134 },
135 { "ms-query-modem-configuration", 0, 0, G_OPTION_ARG_NONE, &query_modem_configuration_flag,
136 "Query modem configuration. Since MBIMEx v3.0.",
137 NULL
138 },
139 { "ms-query-wake-reason", 0, 0, G_OPTION_ARG_NONE, &query_wake_reason_flag,
140 "Query wake reason. Since MBIMEx v3.0.",
141 NULL
142 },
143 { NULL, 0, 0, 0, NULL, NULL, NULL }
144 };
145
146 static gboolean
147 query_pco_arg_parse (const gchar *option_name,
148 const gchar *value,
149 gpointer user_data,
150 GError **error)
151 {
152 query_pco_str = g_strdup (value ? value : "0");
153 return TRUE;
154 }
155
156 GOptionGroup *
157 mbimcli_ms_basic_connect_extensions_get_option_group (void)
158 {
159 GOptionGroup *group;
160
161 group = g_option_group_new ("ms-basic-connect-extensions",
162 "Microsoft Basic Connect Extensions options:",
163 "Show Microsoft Basic Connect Extensions Service options",
164 NULL,
165 NULL);
166 g_option_group_add_entries (group, entries);
167
168 return group;
169 }
170
171 static gboolean
172 session_id_parse (const gchar *str,
173 guint32 *session_id,
174 GError **error)
175 {
176 gchar *endptr = NULL;
177 gint64 n;
178
179 g_assert (str != NULL);
180 g_assert (session_id != NULL);
181
182 if (!str[0]) {
183 *session_id = 0;
184 return TRUE;
185 }
186
187 errno = 0;
188 n = g_ascii_strtoll (str, &endptr, 10);
189 if (errno || n < 0 || n > 255 || ((size_t)(endptr - str) < strlen (str))) {
190 g_set_error (error,
191 MBIM_CORE_ERROR,
192 MBIM_CORE_ERROR_FAILED,
193 "couldn't parse session ID '%s' (must be 0 - 255)",
194 str);
195 return FALSE;
196 }
197 *session_id = (guint32) n;
198
199 return TRUE;
200 }
201
202 gboolean
203 mbimcli_ms_basic_connect_extensions_options_enabled (void)
204 {
205 static guint n_actions = 0;
206 static gboolean checked = FALSE;
207
208 if (checked)
209 return !!n_actions;
210
211 n_actions = (!!query_pco_str +
212 query_lte_attach_configuration_flag +
213 !!set_lte_attach_configuration_str +
214 (query_lte_attach_status_flag || query_lte_attach_info_flag) +
215 query_sys_caps_flag +
216 query_device_caps_flag +
217 !!query_slot_info_status_str +
218 !!set_device_slot_mappings_str +
219 query_device_slot_mappings_flag +
220 query_location_info_status_flag +
221 query_provisioned_contexts_flag +
222 !!set_provisioned_contexts_str +
223 query_base_stations_flag +
224 !!query_version_str +
225 device_reset_flag +
226 query_registration_parameters_flag +
227 !!set_registration_parameters_str +
228 query_modem_configuration_flag +
229 query_wake_reason_flag);
230
231 if (n_actions > 1) {
232 g_printerr ("error: too many Microsoft Basic Connect Extensions Service actions requested\n");
233 exit (EXIT_FAILURE);
234 }
235
236 checked = TRUE;
237 return !!n_actions;
238 }
239
240 static void
241 context_free (Context *context)
242 {
243 if (!context)
244 return;
245
246 if (context->cancellable)
247 g_object_unref (context->cancellable);
248 if (context->device)
249 g_object_unref (context->device);
250 g_slice_free (Context, context);
251 }
252
253 static void
254 shutdown (gboolean operation_status)
255 {
256 /* Cleanup context and finish async operation */
257 context_free (ctx);
258 mbimcli_async_operation_done (operation_status);
259 }
260
261 static void
262 query_pco_ready (MbimDevice *device,
263 GAsyncResult *res)
264 {
265 g_autoptr(MbimMessage) response = NULL;
266 g_autoptr(GError) error = NULL;
267 g_autoptr(MbimPcoValue) pco_value = NULL;
268 g_autofree gchar *pco_data = NULL;
269
270 response = mbim_device_command_finish (device, res, &error);
271 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
272 g_printerr ("error: operation failed: %s\n", error->message);
273 shutdown (FALSE);
274 return;
275 }
276
277 g_print ("[%s] Successfully queried PCO\n", mbim_device_get_path_display (device));
278
279 if (!mbim_message_ms_basic_connect_extensions_pco_response_parse (
280 response,
281 &pco_value,
282 &error)) {
283 g_printerr ("error: couldn't parse response message: %s\n", error->message);
284 shutdown (FALSE);
285 return;
286 }
287
288 pco_data = mbim_common_str_hex (pco_value->pco_data_buffer, pco_value->pco_data_size, ' ');
289 g_print ("[%s] PCO:\n"
290 "\t Session ID: '%u'\n"
291 "\tPCO data type: '%s'\n"
292 "\tPCO data size: '%u'\n"
293 "\t PCO data: '%s'\n",
294 mbim_device_get_path_display (device),
295 pco_value->session_id,
296 VALIDATE_UNKNOWN (mbim_pco_type_get_string (pco_value->pco_data_type)),
297 pco_value->pco_data_size,
298 pco_data);
299
300 shutdown (TRUE);
301 }
302
303 static void
304 lte_attach_configuration_ready (MbimDevice *device,
305 GAsyncResult *res)
306 {
307 g_autoptr(MbimMessage) response = NULL;
308 g_autoptr(GError) error = NULL;
309 g_autoptr(MbimLteAttachConfigurationArray) configurations = NULL;
310 guint32 configuration_count = 0;
311 guint i;
312
313 response = mbim_device_command_finish (device, res, &error);
314 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
315 g_printerr ("error: operation failed: %s\n", error->message);
316 shutdown (FALSE);
317 return;
318 }
319
320 g_print ("[%s] LTE attach configuration available\n",
321 mbim_device_get_path_display (device));
322
323 if (!mbim_message_ms_basic_connect_extensions_lte_attach_configuration_response_parse (
324 response,
325 &configuration_count,
326 &configurations,
327 &error)) {
328 g_printerr ("error: couldn't parse response message: %s\n", error->message);
329 shutdown (FALSE);
330 return;
331 }
332
333 for (i = 0; i < configuration_count; i++) {
334 g_print ("Configuration %u:\n", i);
335 g_print (" IP type: '%s'\n", VALIDATE_UNKNOWN (mbim_context_ip_type_get_string (configurations[i]->ip_type)));
336 g_print (" Roaming: '%s'\n", VALIDATE_UNKNOWN (mbim_lte_attach_context_roaming_control_get_string (configurations[i]->roaming)));
337 g_print (" Source: '%s'\n", VALIDATE_UNKNOWN (mbim_context_source_get_string (configurations[i]->source)));
338 g_print (" Access string: '%s'\n", VALIDATE_EMPTY (configurations[i]->access_string));
339 g_print (" Username: '%s'\n", VALIDATE_EMPTY (configurations[i]->user_name));
340 g_print (" Password: '%s'\n", VALIDATE_EMPTY (configurations[i]->password));
341 g_print (" Compression: '%s'\n", VALIDATE_UNKNOWN (mbim_compression_get_string (configurations[i]->compression)));
342 g_print (" Auth protocol: '%s'\n", VALIDATE_UNKNOWN (mbim_auth_protocol_get_string (configurations[i]->auth_protocol)));
343 }
344
345 shutdown (TRUE);
346 }
347
348 static gboolean
349 set_lte_attach_configuration_foreach_cb (const gchar *key,
350 const gchar *value,
351 GError **error,
352 MbimLteAttachConfiguration *configuration)
353 {
354 if (g_ascii_strcasecmp (key, "ip-type") == 0) {
355 if (!mbimcli_read_context_ip_type_from_string (value, &configuration->ip_type, error)) {
356 return FALSE;
357 }
358 } else if (g_ascii_strcasecmp (key, "roaming-control") == 0) {
359 if (!mbimcli_read_lte_attach_context_roaming_control_from_string (value, &configuration->roaming, error)) {
360 return FALSE;
361 }
362 } else if (g_ascii_strcasecmp (key, "source") == 0) {
363 if (!mbimcli_read_context_source_from_string (value, &configuration->source, error)) {
364 return FALSE;
365 }
366 } else if (g_ascii_strcasecmp (key, "auth") == 0) {
367 if (!mbimcli_read_auth_protocol_from_string (value, &configuration->auth_protocol, error)) {
368 return FALSE;
369 }
370 } else if (g_ascii_strcasecmp (key, "compression") == 0) {
371 if (!mbimcli_read_compression_from_string (value, &configuration->compression, error)) {
372 return FALSE;
373 }
374 } else if (g_ascii_strcasecmp (key, "username") == 0) {
375 g_free (configuration->user_name);
376 configuration->user_name = g_strdup (value);
377 } else if (g_ascii_strcasecmp (key, "password") == 0) {
378 g_free (configuration->password);
379 configuration->password = g_strdup (value);
380 } else if (g_ascii_strcasecmp (key, "access-string") == 0) {
381 g_free (configuration->access_string);
382 configuration->access_string = g_strdup (value);
383 } else {
384 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
385 "unrecognized option '%s'", key);
386 return FALSE;
387 }
388
389 return TRUE;
390 }
391
392 static gboolean
393 set_lte_attach_configuration_input_parse (const gchar *str,
394 MbimLteAttachContextOperation *out_operation,
395 guint32 *out_configuration_count,
396 MbimLteAttachConfigurationArray **out_configurations,
397 GError **error)
398 {
399 g_auto(GStrv) outer_split = NULL;
400 g_auto(GStrv) inner_split = NULL;
401 g_autoptr(MbimLteAttachConfigurationArray) configurations = NULL;
402 guint32 configuration_count;
403 guint i;
404
405 /* The first element in the string must be the operation. Split in two items,
406 * the second one will contain all the list of configuration groups. */
407 outer_split = g_strsplit (str, ",", 2);
408
409 if (!outer_split || !outer_split[0]) {
410 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
411 "no operation specified");
412 return FALSE;
413 }
414
415 g_strstrip (outer_split[0]);
416 if (!mbimcli_read_lte_attach_context_operation_from_string (outer_split[0], out_operation, error))
417 return FALSE;
418
419 *out_configuration_count = 0;
420 *out_configurations = NULL;
421
422 /* This is allowed when restoring defaults */
423 if (!outer_split[1])
424 return TRUE;
425
426 inner_split = g_strsplit_set (outer_split[1], "/", -1);
427 g_assert (inner_split);
428
429 /* This array is compatible with mbim_lte_attach_configuration_array_free() */
430 configuration_count = g_strv_length (inner_split);
431 configurations = g_new0 (MbimLteAttachConfiguration *, configuration_count + 1);
432 for (i = 0; i < configuration_count; i++) {
433 configurations[i] = g_new0 (MbimLteAttachConfiguration, 1);
434 if (!mbimcli_parse_key_value_string (inner_split[i],
435 error,
436 (MbimParseKeyValueForeachFn)set_lte_attach_configuration_foreach_cb,
437 configurations[i])) {
438 return FALSE;
439 }
440 }
441
442 *out_configuration_count = configuration_count;
443 *out_configurations = g_steal_pointer (&configurations);
444 return TRUE;
445 }
446
447 static void
448 query_lte_attach_info_ready (MbimDevice *device,
449 GAsyncResult *res)
450 {
451 g_autoptr(MbimMessage) response = NULL;
452 g_autoptr(GError) error = NULL;
453 guint32 lte_attach_state;
454 guint32 ip_type;
455 g_autofree gchar *access_string = NULL;
456 g_autofree gchar *user_name = NULL;
457 g_autofree gchar *password = NULL;
458 guint32 compression;
459 guint32 auth_protocol;
460 MbimNwError nw_error = 0;
461
462 response = mbim_device_command_finish (device, res, &error);
463 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
464 g_printerr ("error: operation failed: %s\n", error->message);
465 shutdown (FALSE);
466 return;
467 }
468
469
470 /* MBIMEx 3.0 support */
471 if (mbim_device_check_ms_mbimex_version (device, 3, 0)) {
472 if (!mbim_message_ms_basic_connect_extensions_v3_lte_attach_info_response_parse (
473 response,
474 &lte_attach_state,
475 &nw_error,
476 &ip_type,
477 &access_string,
478 &user_name,
479 &password,
480 &compression,
481 &auth_protocol,
482 &error)) {
483 g_printerr ("error: couldn't parse response message: %s\n", error->message);
484 shutdown (FALSE);
485 return;
486 }
487 g_print ("[%s] Successfully received v3.0 LTE attach info\n",
488 mbim_device_get_path_display (device));
489 }
490 /* MBIM 1.0 support */
491 else {
492 if (!mbim_message_ms_basic_connect_extensions_lte_attach_info_response_parse (
493 response,
494 &lte_attach_state,
495 &ip_type,
496 &access_string,
497 &user_name,
498 &password,
499 &compression,
500 &auth_protocol,
501 &error)) {
502 g_printerr ("error: couldn't parse response message: %s\n", error->message);
503 shutdown (FALSE);
504 return;
505 }
506 g_print ("[%s] Successfully received v1.0 LTE attach info\n",
507 mbim_device_get_path_display (device));
508 }
509
510 g_print (" Attach state: '%s'\n", VALIDATE_UNKNOWN (mbim_lte_attach_state_get_string (lte_attach_state)));
511 g_print (" IP type: '%s'\n", VALIDATE_UNKNOWN (mbim_context_ip_type_get_string (ip_type)));
512 g_print (" Access string: '%s'\n", VALIDATE_EMPTY (access_string));
513 g_print (" Username: '%s'\n", VALIDATE_EMPTY (user_name));
514 g_print (" Password: '%s'\n", VALIDATE_EMPTY (password));
515 g_print (" Compression: '%s'\n", VALIDATE_UNKNOWN (mbim_compression_get_string (compression)));
516 g_print (" Auth protocol: '%s'\n", VALIDATE_UNKNOWN (mbim_auth_protocol_get_string (auth_protocol)));
517 if (mbim_device_check_ms_mbimex_version (device, 3, 0)) {
518 if (nw_error == 0)
519 g_print (" Network error: 'none'\n");
520 else if (nw_error == 0xFFFFFFFF)
521 g_print (" Network error: 'unknown'\n");
522 else {
523 const gchar *nw_error_str;
524
525 nw_error_str = mbim_nw_error_get_string (nw_error);
526 if (nw_error_str)
527 g_print (" Network error: '%s'\n", nw_error_str);
528 else
529 g_print (" Network error: 'unknown' (0x%08x)\n", nw_error);
530 }
531 }
532
533 shutdown (TRUE);
534 }
535
536 static void
537 query_sys_caps_ready (MbimDevice *device,
538 GAsyncResult *res)
539 {
540 g_autoptr(MbimMessage) response = NULL;
541 g_autoptr(GError) error = NULL;
542 guint32 number_executors;
543 guint32 number_slots;
544 guint32 concurrency;
545 guint64 modem_id;
546
547 response = mbim_device_command_finish (device, res, &error);
548 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
549 g_printerr ("error: operation failed: %s\n", error->message);
550 shutdown (FALSE);
551 return;
552 }
553
554 g_print ("[%s] Successfully queried sys caps\n",
555 mbim_device_get_path_display (device));
556
557 if (!mbim_message_ms_basic_connect_extensions_sys_caps_response_parse (
558 response,
559 &number_executors,
560 &number_slots,
561 &concurrency,
562 &modem_id,
563 &error)) {
564 g_printerr ("error: couldn't parse response messages: %s\n", error->message);
565 shutdown (FALSE);
566 return;
567 }
568
569 g_print ("[%s] System capabilities retrieved:\n"
570 "\t Number of executors: '%u'\n"
571 "\t Number of slots: '%u'\n"
572 "\t Concurrency: '%u'\n"
573 "\t Modem ID: '%" G_GUINT64_FORMAT "'\n",
574 mbim_device_get_path_display (device),
575 number_executors,
576 number_slots,
577 concurrency,
578 modem_id);
579
580 shutdown (TRUE);
581 }
582
583 static void
584 query_device_caps_ready (MbimDevice *device,
585 GAsyncResult *res)
586 {
587 g_autoptr(MbimMessage) response = NULL;
588 g_autoptr(GError) error = NULL;
589 MbimDeviceType device_type = MBIM_DEVICE_TYPE_UNKNOWN;
590 const gchar *device_type_str = NULL;
591 MbimVoiceClass voice_class = MBIM_VOICE_CLASS_UNKNOWN;
592 const gchar *voice_class_str = NULL;
593 MbimCellularClass cellular_class = MBIM_CELLULAR_CLASS_NONE;
594 g_autofree gchar *cellular_class_str = NULL;
595 MbimSimClass sim_class = MBIM_SIM_CLASS_NONE;
596 g_autofree gchar *sim_class_str = NULL;
597 MbimDataClass data_class = MBIM_DATA_CLASS_NONE;
598 MbimDataClassV3 data_class_v3 = MBIM_DATA_CLASS_V3_NONE;
599 g_autofree gchar *data_class_str = NULL;
600 MbimDataSubclass data_subclass = MBIM_DATA_SUBCLASS_NONE;
601 MbimSmsCaps sms_caps = MBIM_SMS_CAPS_NONE;
602 g_autofree gchar *sms_caps_str = NULL;
603 MbimCtrlCaps ctrl_caps = MBIM_CTRL_CAPS_NONE;
604 g_autofree gchar *ctrl_caps_str = NULL;
605 guint32 max_sessions = 0;
606 guint32 wcdma_band_class = 0;
607 guint32 lte_band_class_array_size = 0;
608 g_autofree guint16 *lte_band_class_array = NULL;
609 guint32 nr_band_class_array_size = 0;
610 g_autofree guint16 *nr_band_class_array = NULL;
611 g_autofree gchar *custom_data_class = NULL;
612 g_autofree gchar *device_id = NULL;
613 g_autofree gchar *firmware_info = NULL;
614 g_autofree gchar *hardware_info = NULL;
615 guint32 executor_index = 0;
616
617 response = mbim_device_command_finish(device, res, &error);
618 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
619 g_printerr ("error: operation failed: %s\n", error->message);
620 shutdown (FALSE);
621 return;
622 }
623
624 if (mbim_device_check_ms_mbimex_version (device, 3, 0)) {
625 if (!mbim_message_ms_basic_connect_extensions_v3_device_caps_response_parse (
626 response,
627 &device_type,
628 &cellular_class,
629 &voice_class,
630 &sim_class,
631 &data_class_v3,
632 &sms_caps,
633 &ctrl_caps,
634 &data_subclass,
635 &max_sessions,
636 &executor_index,
637 &wcdma_band_class,
638 &lte_band_class_array_size,
639 &lte_band_class_array,
640 &nr_band_class_array_size,
641 &nr_band_class_array,
642 &custom_data_class,
643 &device_id,
644 &firmware_info,
645 &hardware_info,
646 &error)) {
647 g_printerr ("error: couldn't parse response message: %s\n", error->message);
648 shutdown (FALSE);
649 return;
650 }
651 g_debug ("Successfully parsed response as MBIMEx 3.0 Device Caps");
652 } else {
653 if (!mbim_message_ms_basic_connect_extensions_device_caps_response_parse (
654 response,
655 &device_type,
656 &cellular_class,
657 &voice_class,
658 &sim_class,
659 &data_class,
660 &sms_caps,
661 &ctrl_caps,
662 &max_sessions,
663 &custom_data_class,
664 &device_id,
665 &firmware_info,
666 &hardware_info,
667 &executor_index,
668 &error)) {
669 g_printerr ("error: couldn't parse response message: %s\n", error->message);
670 shutdown (FALSE);
671 return;
672 }
673 g_debug ("Successfully parsed response as MBIMEx 1.0 Device Caps");
674 }
675
676 if (mbim_device_check_ms_mbimex_version (device, 3, 0))
677 data_class_str = mbim_data_class_v3_build_string_from_mask (data_class_v3);
678 else
679 data_class_str = mbim_data_class_build_string_from_mask (data_class);
680
681 device_type_str = mbim_device_type_get_string (device_type);
682 cellular_class_str = mbim_cellular_class_build_string_from_mask (cellular_class);
683 voice_class_str = mbim_voice_class_get_string (voice_class);
684 sim_class_str = mbim_sim_class_build_string_from_mask (sim_class);
685 sms_caps_str = mbim_sms_caps_build_string_from_mask (sms_caps);
686 ctrl_caps_str = mbim_ctrl_caps_build_string_from_mask (ctrl_caps);
687
688 g_print ("[%s] Device capabilities retrieved:\n"
689 "\t Device type: '%s'\n"
690 "\t Cellular class: '%s'\n"
691 "\t Voice class: '%s'\n"
692 "\t SIM class: '%s'\n"
693 "\t Data class: '%s'\n"
694 "\t SMS caps: '%s'\n"
695 "\t Ctrl caps: '%s'\n"
696 "\t Max sessions: '%u'\n"
697 "\tCustom data class: '%s'\n"
698 "\t Device ID: '%s'\n"
699 "\t Firmware info: '%s'\n"
700 "\t Hardware info: '%s'\n"
701 "\t Executor Index: '%u'\n",
702 mbim_device_get_path_display (device),
703 VALIDATE_UNKNOWN (device_type_str),
704 VALIDATE_UNKNOWN (cellular_class_str),
705 VALIDATE_UNKNOWN (voice_class_str),
706 VALIDATE_UNKNOWN (sim_class_str),
707 VALIDATE_UNKNOWN (data_class_str),
708 VALIDATE_UNKNOWN (sms_caps_str),
709 VALIDATE_UNKNOWN (ctrl_caps_str),
710 max_sessions,
711 VALIDATE_UNKNOWN (custom_data_class),
712 VALIDATE_UNKNOWN (device_id),
713 VALIDATE_UNKNOWN (firmware_info),
714 VALIDATE_UNKNOWN (hardware_info),
715 executor_index);
716
717 if (mbim_device_check_ms_mbimex_version (device, 3, 0)) {
718 g_autofree gchar *data_subclass_str = NULL;
719 guint i;
720 gboolean n_printed;
721
722 data_subclass_str = mbim_data_subclass_build_string_from_mask (data_subclass);
723 g_print ("\t Data subclass: '%s'\n", data_subclass_str);
724
725 g_print ("\t WCDMA band class: '");
726 for (n_printed = 0, i = 0; i < 31; i++) {
727 if (wcdma_band_class & (1 << i)) {
728 g_print ("%s%u", n_printed > 0 ? ", " : "", i + 1);
729 n_printed++;
730 }
731 }
732 g_print ("'\n");
733
734 g_print ("\t LTE band class: '");
735 for (i = 0; i < lte_band_class_array_size; i++)
736 g_print ("%s%" G_GUINT16_FORMAT, i > 0 ? ", " : "", lte_band_class_array[i]);
737 g_print ("'\n");
738
739 g_print ("\t NR band class: '");
740 for (i = 0; i < nr_band_class_array_size; i++)
741 g_print ("%s%" G_GUINT16_FORMAT, i > 0 ? ", " : "", nr_band_class_array[i]);
742 g_print ("'\n");
743 }
744
745 shutdown (TRUE);
746 }
747
748 static gboolean
749 query_slot_information_status_slot_index_parse (const gchar *str,
750 guint32 *slot_index,
751 GError **error)
752 {
753 gchar *endptr = NULL;
754 gint64 n;
755
756 g_assert (str != NULL);
757 g_assert (slot_index != NULL);
758
759 if (!str[0]) {
760 g_set_error (error,
761 MBIM_CORE_ERROR,
762 MBIM_CORE_ERROR_FAILED,
763 "slot index not given");
764 return FALSE;
765 }
766
767 errno = 0;
768 n = g_ascii_strtoll (str, &endptr, 10);
769 if (errno || ((size_t)(endptr - str) < strlen (str))) {
770 g_set_error (error,
771 MBIM_CORE_ERROR,
772 MBIM_CORE_ERROR_FAILED,
773 "couldn't parse slot index '%s'",
774 str);
775 return FALSE;
776 }
777 *slot_index = (guint32) n;
778
779 return TRUE;
780 }
781
782 static void
783 query_slot_information_status_ready (MbimDevice *device,
784 GAsyncResult *res)
785 {
786 g_autoptr(MbimMessage) response = NULL;
787 g_autoptr(GError) error = NULL;
788 guint32 slot_index;
789 MbimUiccSlotState slot_state;
790 const gchar *slot_state_str;
791
792 response = mbim_device_command_finish (device, res, &error);
793 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
794 g_printerr ("error: operation failed: %s\n", error->message);
795 shutdown (FALSE);
796 return;
797 }
798
799 if (!mbim_message_ms_basic_connect_extensions_slot_info_status_response_parse (
800 response,
801 &slot_index,
802 &slot_state,
803 &error)) {
804 g_printerr ("error: conldn't parse response message: %s\n", error->message);
805 shutdown (FALSE);
806 return;
807 }
808
809 slot_state_str = mbim_uicc_slot_state_get_string (slot_state);
810
811 g_print ("[%s] Slot info status retrieved:\n"
812 "\t Slot '%u': '%s'\n",
813 mbim_device_get_path_display (device),
814 slot_index,
815 VALIDATE_UNKNOWN (slot_state_str));
816 shutdown (TRUE);
817 }
818
819 static gboolean
820 set_device_slot_mappings_input_parse (const gchar *str,
821 GPtrArray **slot_array,
822 GError **error)
823 {
824 g_auto(GStrv) split = NULL;
825 gchar *endptr = NULL;
826 gint64 n;
827 MbimSlot *slot_index;
828 guint32 i = 0;
829
830 g_assert (slot_array != NULL);
831
832 split = g_strsplit (str, ",", 0);
833
834 if (g_strv_length (split) < 1) {
835 g_set_error (error,
836 MBIM_CORE_ERROR,
837 MBIM_CORE_ERROR_FAILED,
838 "missing arguments");
839 return FALSE;
840 }
841
842 *slot_array = g_ptr_array_new_with_free_func (g_free);
843
844 while (split[i] != NULL) {
845 errno = 0;
846 n = g_ascii_strtoll (split[i], &endptr, 10);
847 if (errno || n < 0 || n > G_MAXUINT32 || ((size_t)(endptr - split[i]) < strlen (split[i]))) {
848 g_set_error (error,
849 MBIM_CORE_ERROR,
850 MBIM_CORE_ERROR_FAILED,
851 "couldn't parse device slot index '%s'",
852 split[i]);
853 return FALSE;
854 }
855 slot_index = g_new (MbimSlot, 1);
856 slot_index->slot = (guint32) n;
857 g_ptr_array_add (*slot_array, slot_index);
858 i++;
859 }
860
861 return TRUE;
862 }
863
864 static void
865 query_device_slot_mappings_ready (MbimDevice *device,
866 GAsyncResult *res)
867 {
868 g_autoptr(MbimMessage) response = NULL;
869 g_autoptr(GError) error = NULL;
870 guint32 map_count = 0;
871 g_autoptr(MbimSlotArray) slot_mappings = NULL;
872 guint i;
873
874 response = mbim_device_command_finish (device, res, &error);
875 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
876 g_printerr ("error: operation failed: %s\n", error->message);
877 shutdown (FALSE);
878 return;
879 }
880
881 if (!mbim_message_ms_basic_connect_extensions_device_slot_mappings_response_parse (
882 response,
883 &map_count,
884 &slot_mappings,
885 &error)) {
886 g_printerr ("error: couldn't parse response message: %s\n", error->message);
887 shutdown (FALSE);
888 return;
889 }
890
891 if (set_device_slot_mappings_str) {
892 g_print ("[%s] Updated slot mappings retrieved:\n",
893 mbim_device_get_path_display (device));
894 } else {
895 g_print ("[%s] Slot mappings retrieved:\n",
896 mbim_device_get_path_display (device));
897 }
898
899 for (i = 0; i < map_count; i++) {
900 g_print ("\t Executor '%u': slot '%u'\n",
901 i,
902 slot_mappings[i]->slot);
903 }
904
905 shutdown (TRUE);
906 }
907
908 static void
909 query_location_info_status_ready (MbimDevice *device,
910 GAsyncResult *res)
911 {
912 g_autoptr(MbimMessage) response = NULL;
913 g_autoptr(GError) error = NULL;
914 guint32 location_area_code = 0;
915 guint32 tracking_area_code = 0;
916 guint32 cell_id = 0;
917
918 response = mbim_device_command_finish (device, res, &error);
919 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
920 g_printerr ("error: operation failed: %s\n", error->message);
921 shutdown (FALSE);
922 return;
923 }
924
925 g_print ("[%s] Successfully queried location info status\n",
926 mbim_device_get_path_display (device));
927
928 if (!mbim_message_ms_basic_connect_extensions_location_info_status_response_parse (
929 response,
930 &location_area_code,
931 &tracking_area_code,
932 &cell_id,
933 &error)) {
934 g_printerr ("error: couldn't parse response message: %s\n", error->message);
935 shutdown (FALSE);
936 return;
937 }
938
939 g_print (" Location area code: %04X\n", location_area_code);
940 g_print (" Tracking area code: %06X\n", tracking_area_code);
941 g_print (" Cell ID: %08X\n", cell_id);
942
943 shutdown (TRUE);
944 }
945
946 typedef struct {
947 MbimContextOperation operation;
948 MbimContextIpType ip_type;
949 MbimContextState state;
950 MbimContextRoamingControl roaming_control;
951 MbimContextMediaType media_type;
952 MbimContextSource source;
953 gchar *access_string;
954 gchar *username;
955 gchar *password;
956 MbimCompression compression;
957 MbimAuthProtocol auth_protocol;
958 MbimContextType context_type;
959 } ProvisionedContextProperties;
960
961 static void
962 provisioned_context_properties_clear (ProvisionedContextProperties *props)
963 {
964 g_free (props->access_string);
965 g_free (props->username);
966 g_free (props->password);
967 }
968
969 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ProvisionedContextProperties, provisioned_context_properties_clear)
970
971 static gboolean
972 set_provisioned_contexts_foreach_cb (const gchar *key,
973 const gchar *value,
974 GError **error,
975 ProvisionedContextProperties *props)
976 {
977 if (g_ascii_strcasecmp (key, "operation") == 0) {
978 if (!mbimcli_read_context_operation_from_string (value, &props->operation, error)) {
979 return FALSE;
980 }
981 } else if (g_ascii_strcasecmp (key, "context-type") == 0) {
982 if (!mbimcli_read_context_type_from_string (value, &props->context_type, error)) {
983 return FALSE;
984 }
985 } else if (g_ascii_strcasecmp (key, "ip-type") == 0) {
986 if (!mbimcli_read_context_ip_type_from_string (value, &props->ip_type, error)) {
987 return FALSE;
988 }
989 } else if (g_ascii_strcasecmp (key, "state") == 0) {
990 if (!mbimcli_read_context_state_from_string (value, &props->state, error)) {
991 return FALSE;
992 }
993 } else if (g_ascii_strcasecmp (key, "roaming-control") == 0) {
994 if (!mbimcli_read_context_roaming_control_from_string (value, &props->roaming_control, error)) {
995 return FALSE;
996 }
997 } else if (g_ascii_strcasecmp (key, "media-type") == 0) {
998 if (!mbimcli_read_context_media_type_from_string (value, &props->media_type, error)) {
999 return FALSE;
1000 }
1001 } else if (g_ascii_strcasecmp (key, "source") == 0) {
1002 if (!mbimcli_read_context_source_from_string (value, &props->source, error)) {
1003 return FALSE;
1004 }
1005 } else if (g_ascii_strcasecmp (key, "auth") == 0) {
1006 if (!mbimcli_read_auth_protocol_from_string (value, &props->auth_protocol, error)) {
1007 return FALSE;
1008 }
1009 } else if (g_ascii_strcasecmp (key, "compression") == 0) {
1010 if (!mbimcli_read_compression_from_string (value, &props->compression, error)) {
1011 return FALSE;
1012 }
1013 } else if (g_ascii_strcasecmp (key, "username") == 0) {
1014 g_free (props->username);
1015 props->username = g_strdup (value);
1016 } else if (g_ascii_strcasecmp (key, "password") == 0) {
1017 g_free (props->password);
1018 props->password = g_strdup (value);
1019 } else if (g_ascii_strcasecmp (key, "access-string") == 0) {
1020 g_free (props->access_string);
1021 props->access_string = g_strdup (value);
1022 } else {
1023 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
1024 "unrecognized option '%s'", key);
1025 return FALSE;
1026 }
1027
1028 return TRUE;
1029 }
1030
1031 static void
1032 provisioned_contexts_ready (MbimDevice *device,
1033 GAsyncResult *res)
1034 {
1035 g_autoptr(MbimMessage) response = NULL;
1036 g_autoptr(MbimProvisionedContextElementV2Array) provisioned_contexts = NULL;
1037 g_autoptr(GError) error = NULL;
1038 guint32 provisioned_contexts_count;
1039 guint32 i = 0;
1040
1041 response = mbim_device_command_finish (device, res, &error);
1042 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
1043 g_printerr ("error: operation failed: %s\n", error->message);
1044 shutdown (FALSE);
1045 return;
1046 }
1047
1048 if (!mbim_message_ms_basic_connect_extensions_provisioned_contexts_response_parse (
1049 response,
1050 &provisioned_contexts_count,
1051 &provisioned_contexts,
1052 &error)) {
1053 g_printerr ("error: couldn't parse response message: %s\n", error->message);
1054 shutdown (FALSE);
1055 return;
1056 }
1057
1058 g_print ("[%s] Provisioned contexts (%u):\n",
1059 mbim_device_get_path_display (device),
1060 provisioned_contexts_count);
1061
1062 for (i = 0; i < provisioned_contexts_count; i++) {
1063 g_print ("\tContext ID %u:\n"
1064 "\t Context type: '%s'\n"
1065 "\t IP type: '%s'\n"
1066 "\t State: '%s'\n"
1067 "\tRoaming control: '%s'\n"
1068 "\t Media type: '%s'\n"
1069 "\t Source: '%s'\n"
1070 "\t Access string: '%s'\n"
1071 "\t Username: '%s'\n"
1072 "\t Password: '%s'\n"
1073 "\t Compression: '%s'\n"
1074 "\t Auth protocol: '%s'\n",
1075 provisioned_contexts[i]->context_id,
1076 VALIDATE_UNKNOWN (mbim_context_type_get_string (
1077 mbim_uuid_to_context_type (&provisioned_contexts[i]->context_type))),
1078 VALIDATE_UNKNOWN (mbim_context_ip_type_get_string (
1079 provisioned_contexts[i]->ip_type)),
1080 VALIDATE_UNKNOWN (mbim_context_state_get_string (
1081 provisioned_contexts[i]->state)),
1082 VALIDATE_UNKNOWN (mbim_context_roaming_control_get_string (
1083 provisioned_contexts[i]->roaming)),
1084 VALIDATE_UNKNOWN (mbim_context_media_type_get_string (
1085 provisioned_contexts[i]->media_type)),
1086 VALIDATE_UNKNOWN (mbim_context_source_get_string (
1087 provisioned_contexts[i]->source)),
1088 VALIDATE_UNKNOWN (provisioned_contexts[i]->access_string),
1089 VALIDATE_UNKNOWN (provisioned_contexts[i]->user_name),
1090 VALIDATE_UNKNOWN (provisioned_contexts[i]->password),
1091 VALIDATE_UNKNOWN (mbim_compression_get_string (
1092 provisioned_contexts[i]->compression)),
1093 VALIDATE_UNKNOWN (mbim_auth_protocol_get_string (
1094 provisioned_contexts[i]->auth_protocol)));
1095 }
1096
1097 shutdown (TRUE);
1098 }
1099
1100 static void
1101 query_base_stations_ready (MbimDevice *device,
1102 GAsyncResult *res)
1103 {
1104 g_autoptr(MbimMessage) response = NULL;
1105 g_autoptr(GError) error = NULL;
1106 MbimDataClass system_type;
1107 MbimDataClassV3 system_type_v3;
1108 MbimDataSubclass system_subtype;
1109 g_autoptr(MbimCellInfoServingGsm) gsm_serving_cell = NULL;
1110 g_autoptr(MbimCellInfoServingUmts) umts_serving_cell = NULL;
1111 g_autoptr(MbimCellInfoServingTdscdma) tdscdma_serving_cell = NULL;
1112 g_autoptr(MbimCellInfoServingLte) lte_serving_cell = NULL;
1113 guint32 gsm_neighboring_cells_count;
1114 g_autoptr(MbimCellInfoNeighboringGsmArray) gsm_neighboring_cells = NULL;
1115 guint32 umts_neighboring_cells_count;
1116 g_autoptr(MbimCellInfoNeighboringUmtsArray) umts_neighboring_cells = NULL;
1117 guint32 tdscdma_neighboring_cells_count;
1118 g_autoptr(MbimCellInfoNeighboringTdscdmaArray) tdscdma_neighboring_cells = NULL;
1119 guint32 lte_neighboring_cells_count;
1120 g_autoptr(MbimCellInfoNeighboringLteArray) lte_neighboring_cells = NULL;
1121 guint32 cdma_cells_count;
1122 g_autoptr(MbimCellInfoCdmaArray) cdma_cells = NULL;
1123 guint32 nr_serving_cells_count;
1124 g_autoptr(MbimCellInfoServingNrArray) nr_serving_cells = NULL;
1125 guint32 nr_neighboring_cells_count;
1126 g_autoptr(MbimCellInfoNeighboringNrArray) nr_neighboring_cells = NULL;
1127
1128 response = mbim_device_command_finish (device, res, &error);
1129 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
1130 g_printerr ("error: operation failed: %s\n", error->message);
1131 shutdown (FALSE);
1132 return;
1133 }
1134
1135 /* MBIMEx 3.0 support */
1136 if (mbim_device_check_ms_mbimex_version (device, 3, 0)) {
1137 if (!mbim_message_ms_basic_connect_extensions_v3_base_stations_info_response_parse (
1138 response,
1139 &system_type_v3,
1140 &system_subtype,
1141 &gsm_serving_cell,
1142 &umts_serving_cell,
1143 &tdscdma_serving_cell,
1144 &lte_serving_cell,
1145 &gsm_neighboring_cells_count,
1146 &gsm_neighboring_cells,
1147 &umts_neighboring_cells_count,
1148 &umts_neighboring_cells,
1149 &tdscdma_neighboring_cells_count,
1150 &tdscdma_neighboring_cells,
1151 &lte_neighboring_cells_count,
1152 &lte_neighboring_cells,
1153 &cdma_cells_count,
1154 &cdma_cells,
1155 &nr_serving_cells_count,
1156 &nr_serving_cells,
1157 &nr_neighboring_cells_count,
1158 &nr_neighboring_cells,
1159 &error)) {
1160 g_printerr ("error: couldn't parse response message: %s\n", error->message);
1161 shutdown (FALSE);
1162 return;
1163 }
1164 g_debug ("Successfully parsed response as MBIMEx 3.0 Base Stations Info");
1165 }
1166 /* MBIMEx 1.0 support */
1167 else {
1168 if (!mbim_message_ms_basic_connect_extensions_base_stations_info_response_parse (
1169 response,
1170 &system_type,
1171 &gsm_serving_cell,
1172 &umts_serving_cell,
1173 &tdscdma_serving_cell,
1174 &lte_serving_cell,
1175 &gsm_neighboring_cells_count,
1176 &gsm_neighboring_cells,
1177 &umts_neighboring_cells_count,
1178 &umts_neighboring_cells,
1179 &tdscdma_neighboring_cells_count,
1180 &tdscdma_neighboring_cells,
1181 &lte_neighboring_cells_count,
1182 &lte_neighboring_cells,
1183 &cdma_cells_count,
1184 &cdma_cells,
1185 &error)) {
1186 g_printerr ("error: couldn't parse response message: %s\n", error->message);
1187 shutdown (FALSE);
1188 return;
1189 }
1190 g_debug ("Successfully parsed response as MBIMEx 1.0 Base Stations Info");
1191 }
1192
1193 #define PRINT_VALIDATED_UINT(number, invalid, format, units) do { \
1194 if (number == invalid) \
1195 g_print ("%s: unknown\n", format); \
1196 else \
1197 g_print ("%s: %u%s\n", format, number, units ? units : ""); \
1198 } while (0)
1199
1200 #define PRINT_VALIDATED_UINT64(number, invalid, format, units) do { \
1201 if (number == invalid) \
1202 g_print ("%s: unknown\n", format); \
1203 else \
1204 g_print ("%s: %" G_GUINT64_FORMAT "%s\n", format, number, units ? units : ""); \
1205 } while (0)
1206
1207 #define PRINT_VALIDATED_INT(number, invalid, format, units) do { \
1208 if (number == (gint32)invalid) \
1209 g_print ("%s: unknown\n", format); \
1210 else \
1211 g_print ("%s: %d%s\n", format, number, units ? units : ""); \
1212 } while (0)
1213
1214 #define PRINT_VALIDATED_SCALED_UINT(number, invalid, scale, format, units) do { \
1215 if (number == 0xFFFFFFFF) \
1216 g_print ("%s: unknown\n", format); \
1217 else \
1218 g_print ("%s: %d%s\n", format, ((gint32)number) + scale, units ? units : ""); \
1219 } while (0)
1220
1221 if (mbim_device_check_ms_mbimex_version (device, 3, 0)) {
1222 g_autofree gchar *system_type_str = NULL;
1223 g_autofree gchar *system_subtype_str = NULL;
1224
1225 system_type_str = mbim_data_class_v3_build_string_from_mask (system_type_v3);
1226 g_print ("System type: %s\n", system_type_str);
1227 system_subtype_str = mbim_data_subclass_build_string_from_mask (system_subtype);
1228 g_print ("System subtype: %s\n", VALIDATE_UNKNOWN (system_subtype_str));
1229 } else {
1230 g_autofree gchar *system_type_str = NULL;
1231
1232 system_type_str = mbim_data_class_build_string_from_mask (system_type);
1233 g_print ("System type: %s\n", system_type_str);
1234 }
1235
1236 if (gsm_serving_cell) {
1237 g_print ("GSM serving cell:\n"
1238 "\t Provider id: %s\n",
1239 VALIDATE_UNKNOWN (gsm_serving_cell->provider_id));
1240 PRINT_VALIDATED_UINT (gsm_serving_cell->location_area_code, 0xFFFFFFFF, "\t LAC", NULL);
1241 PRINT_VALIDATED_UINT (gsm_serving_cell->cell_id, 0xFFFFFFFF, "\t Cell ID", NULL);
1242 PRINT_VALIDATED_UINT (gsm_serving_cell->timing_advance, 0xFFFFFFFF, "\t Timing advance", " bit periods");
1243 PRINT_VALIDATED_UINT (gsm_serving_cell->arfcn, 0xFFFFFFFF, "\t ARFCN", NULL);
1244 PRINT_VALIDATED_UINT (gsm_serving_cell->base_station_id, 0xFFFFFFFF, "\tBase station ID", NULL);
1245 PRINT_VALIDATED_SCALED_UINT (gsm_serving_cell->rx_level, 0xFFFFFFFF, -110, "\t Rx level", " dBm");
1246 } else
1247 g_print ("GSM serving cell: n/a\n");
1248
1249 if (gsm_neighboring_cells_count && gsm_neighboring_cells) {
1250 guint i;
1251
1252 g_print ("Neighboring GSM cells: %d\n", gsm_neighboring_cells_count);
1253 for (i = 0; i < gsm_neighboring_cells_count; i++) {
1254 g_print ("\tNeighboring cell [%u]:\n"
1255 "\t\t Provider id: %s\n",
1256 i + 1,
1257 VALIDATE_UNKNOWN (gsm_neighboring_cells[i]->provider_id));
1258 PRINT_VALIDATED_UINT (gsm_neighboring_cells[i]->location_area_code, 0xFFFFFFFF, "\t\t LAC", NULL);
1259 PRINT_VALIDATED_UINT (gsm_neighboring_cells[i]->cell_id, 0xFFFFFFFF, "\t\t Cell ID", NULL);
1260 PRINT_VALIDATED_UINT (gsm_neighboring_cells[i]->arfcn, 0xFFFFFFFF, "\t\t ARFCN", NULL);
1261 PRINT_VALIDATED_UINT (gsm_neighboring_cells[i]->base_station_id, 0xFFFFFFFF, "\t\tBase station ID", NULL);
1262 PRINT_VALIDATED_SCALED_UINT (gsm_neighboring_cells[i]->rx_level, 0xFFFFFFFF, -110, "\t\t Rx level", " dBm");
1263 }
1264 } else
1265 g_print ("Neighboring GSM cells: n/a\n");
1266
1267 if (umts_serving_cell) {
1268 g_print ("UMTS Serving cell:\n"
1269 "\t Provider id: %s\n",
1270 VALIDATE_UNKNOWN (umts_serving_cell->provider_id));
1271 PRINT_VALIDATED_UINT (umts_serving_cell->location_area_code, 0xFFFFFFFF, "\t LAC", NULL);
1272 PRINT_VALIDATED_UINT (umts_serving_cell->cell_id, 0xFFFFFFFF, "\t Cell id", NULL);
1273 PRINT_VALIDATED_UINT (umts_serving_cell->frequency_info_ul, 0xFFFFFFFF, "\t Frequency info uplink", NULL);
1274 PRINT_VALIDATED_UINT (umts_serving_cell->frequency_info_dl, 0xFFFFFFFF, "\tFrequency info downlink", NULL);
1275 PRINT_VALIDATED_UINT (umts_serving_cell->frequency_info_nt, 0xFFFFFFFF, "\t Frequency info TDD", NULL);
1276 PRINT_VALIDATED_UINT (umts_serving_cell->uarfcn, 0xFFFFFFFF, "\t UARFCN", NULL);
1277 PRINT_VALIDATED_UINT (umts_serving_cell->primary_scrambling_code, 0xFFFFFFFF, "\tPrimary Scrambling Code", NULL);
1278 PRINT_VALIDATED_INT (umts_serving_cell->rscp, 0, "\t RSCP", " dBm");
1279 PRINT_VALIDATED_INT (umts_serving_cell->ecno, 1, "\t ECNO", " dBm");
1280 PRINT_VALIDATED_UINT (umts_serving_cell->path_loss, 0xFFFFFFFF, "\t Path loss", NULL);
1281 } else
1282 g_print ("UMTS serving cell: n/a\n");
1283
1284 if (umts_neighboring_cells_count && umts_neighboring_cells) {
1285 guint i;
1286
1287 g_print ("Neighboring UMTS cells: %d\n", umts_neighboring_cells_count);
1288 for (i = 0; i < umts_neighboring_cells_count; i++) {
1289 g_print ("\tNeighboring cell [%u]:\n"
1290 "\t\t Provider id: %s\n",
1291 i + 1,
1292 VALIDATE_UNKNOWN (umts_neighboring_cells[i]->provider_id));
1293 PRINT_VALIDATED_UINT (umts_neighboring_cells[i]->location_area_code, 0xFFFFFFFF, "\t\t LAC", NULL);
1294 PRINT_VALIDATED_UINT (umts_neighboring_cells[i]->cell_id, 0xFFFFFFFF, "\t\t Cell id", NULL);
1295 PRINT_VALIDATED_UINT (umts_neighboring_cells[i]->uarfcn, 0xFFFFFFFF, "\t\t UARFCN", NULL);
1296 PRINT_VALIDATED_UINT (umts_neighboring_cells[i]->primary_scrambling_code, 0xFFFFFFFF, "\t\tPrimary Scrambling Code", NULL);
1297 PRINT_VALIDATED_INT (umts_neighboring_cells[i]->rscp, 0, "\t\t RSCP", " dBm");
1298 PRINT_VALIDATED_INT (umts_neighboring_cells[i]->ecno, 1, "\t\t ECNO", " dBm");
1299 PRINT_VALIDATED_UINT (umts_neighboring_cells[i]->path_loss, 0xFFFFFFFF, "\t\t Path loss", NULL);
1300 }
1301 } else
1302 g_print ("Neighboring UMTS cells: n/a\n");
1303
1304 if (tdscdma_serving_cell) {
1305 g_print ("TDSCDMA Serving cell:\n"
1306 "\t Provider id: %s\n",
1307 VALIDATE_UNKNOWN (tdscdma_serving_cell->provider_id));
1308 PRINT_VALIDATED_UINT (tdscdma_serving_cell->location_area_code, 0xFFFFFFFF, "\t LAC", NULL);
1309 PRINT_VALIDATED_UINT (tdscdma_serving_cell->cell_id, 0xFFFFFFFF, "\t Cell id", NULL);
1310 PRINT_VALIDATED_UINT (tdscdma_serving_cell->uarfcn, 0xFFFFFFFF, "\t UARFCN", NULL);
1311 PRINT_VALIDATED_UINT (tdscdma_serving_cell->cell_parameter_id, 0xFFFFFFFF, "\tCell parameter id", NULL);
1312 PRINT_VALIDATED_UINT (tdscdma_serving_cell->timing_advance, 0xFFFFFFFF, "\t Timing advance", NULL);
1313 PRINT_VALIDATED_INT (tdscdma_serving_cell->rscp, 0xFFFFFFFF, "\t RSCP", " dBm");
1314 PRINT_VALIDATED_UINT (tdscdma_serving_cell->path_loss, 0xFFFFFFFF, "\t Path loss", NULL);
1315 } else
1316 g_print ("TDSCDMA serving cell: n/a\n");
1317
1318 if (tdscdma_neighboring_cells_count && tdscdma_neighboring_cells) {
1319 guint i;
1320
1321 g_print ("Neighboring TDSCDMA cells: %d\n", tdscdma_neighboring_cells_count);
1322 for (i = 0; i < tdscdma_neighboring_cells_count; i++) {
1323 g_print ("\tNeighboring cell [%u]:\n"
1324 "\t\t Provider id: %s\n",
1325 i + 1,
1326 VALIDATE_UNKNOWN (tdscdma_neighboring_cells[i]->provider_id));
1327 PRINT_VALIDATED_UINT (tdscdma_neighboring_cells[i]->location_area_code, 0xFFFFFFFF, "\t\t LAC", NULL);
1328 PRINT_VALIDATED_UINT (tdscdma_neighboring_cells[i]->cell_id, 0xFFFFFFFF, "\t\t Cell id", NULL);
1329 PRINT_VALIDATED_UINT (tdscdma_neighboring_cells[i]->uarfcn, 0xFFFFFFFF, "\t\t UARFCN", NULL);
1330 PRINT_VALIDATED_UINT (tdscdma_neighboring_cells[i]->cell_parameter_id, 0xFFFFFFFF, "\t\tCell parameter id", NULL);
1331 PRINT_VALIDATED_UINT (tdscdma_neighboring_cells[i]->timing_advance, 0xFFFFFFFF, "\t\t Timing advance", NULL);
1332 PRINT_VALIDATED_INT (tdscdma_neighboring_cells[i]->rscp, 0xFFFFFFFF, "\t\t RSCP", " dBm");
1333 PRINT_VALIDATED_UINT (tdscdma_neighboring_cells[i]->path_loss, 0xFFFFFFFF, "\t\t Path Loss", NULL);
1334 }
1335 } else
1336 g_print ("Neighboring TDSCDMA cells: n/a\n");
1337
1338 if (lte_serving_cell) {
1339 g_print ("LTE Serving cell:\n"
1340 "\t Provider id: %s\n",
1341 VALIDATE_UNKNOWN (lte_serving_cell->provider_id));
1342 PRINT_VALIDATED_UINT (lte_serving_cell->cell_id, 0xFFFFFFFF, "\t Cell id", NULL);
1343 PRINT_VALIDATED_UINT (lte_serving_cell->earfcn, 0xFFFFFFFF, "\t EARFCN", NULL);
1344 PRINT_VALIDATED_UINT (lte_serving_cell->physical_cell_id, 0xFFFFFFFF, "\t Physical cell id", NULL);
1345 PRINT_VALIDATED_UINT (lte_serving_cell->tac, 0xFFFFFFFF, "\t TAC", NULL);
1346 PRINT_VALIDATED_INT (lte_serving_cell->rsrp, 0xFFFFFFFF, "\t RSRP", " dBm");
1347 PRINT_VALIDATED_INT (lte_serving_cell->rsrq, 0xFFFFFFFF, "\t RSRQ", " dBm");
1348 PRINT_VALIDATED_UINT (lte_serving_cell->timing_advance, 0xFFFFFFFF, "\t Timing advance", NULL);
1349 } else
1350 g_print ("LTE serving cell: n/a\n");
1351
1352 if (lte_neighboring_cells_count && lte_neighboring_cells) {
1353 guint i;
1354
1355 g_print ("Neighboring LTE cells: %d\n", lte_neighboring_cells_count);
1356 for (i = 0; i < lte_neighboring_cells_count; i++) {
1357 g_print ("\tNeighboring cell [%u]:\n"
1358 "\t\t Provider id: %s\n",
1359 i + 1,
1360 VALIDATE_UNKNOWN (lte_neighboring_cells[i]->provider_id));
1361 PRINT_VALIDATED_UINT (lte_neighboring_cells[i]->cell_id, 0xFFFFFFFF, "\t\t Cell id", NULL);
1362 PRINT_VALIDATED_UINT (lte_neighboring_cells[i]->earfcn, 0xFFFFFFFF, "\t\t EARFCN", NULL);
1363 PRINT_VALIDATED_UINT (lte_neighboring_cells[i]->physical_cell_id, 0xFFFFFFFF, "\t\t Physical cell id", NULL);
1364 PRINT_VALIDATED_UINT (lte_neighboring_cells[i]->tac, 0xFFFFFFFF, "\t\t TAC", NULL);
1365 PRINT_VALIDATED_INT (lte_neighboring_cells[i]->rsrp, 0xFFFFFFFF, "\t\t RSRP", " dBm");
1366 PRINT_VALIDATED_INT (lte_neighboring_cells[i]->rsrq, 0xFFFFFFFF, "\t\t RSRQ", " dBm");
1367 }
1368 } else
1369 g_print ("Neighboring LTE cells: n/a\n");
1370
1371 if (cdma_cells_count && cdma_cells) {
1372 guint i;
1373
1374 g_print ("CDMA cells: %d\n", cdma_cells_count);
1375 for (i = 0; i < cdma_cells_count; i++)
1376 g_print ("Cell [%u]:\n"
1377 "\t Serving: %s\n",
1378 i + 1,
1379 cdma_cells[i]->serving_cell_flag ? "yes" : "no");
1380 PRINT_VALIDATED_UINT (cdma_cells[i]->nid, 0xFFFFFFFF, "\t NID", NULL);
1381 PRINT_VALIDATED_UINT (cdma_cells[i]->sid, 0xFFFFFFFF, "\t SID", NULL);
1382 PRINT_VALIDATED_UINT (cdma_cells[i]->base_station_id, 0xFFFFFFFF, "\tBase station id", NULL);
1383 /* TODO: The Base Station Latitude (0-4194303). This is encoded in units of 0.25 seconds, expressed
1384 * in two’s complement representation within the low 22 bits of the DWORD. As a signed value,
1385 * North latitudes are positive. Use 0xFFFFFFFF when this information is not available. */
1386 PRINT_VALIDATED_UINT (cdma_cells[i]->base_latitude, 0xFFFFFFFF, "\t Base latitude", NULL);
1387 /* TODO: The Base Station Longitude (0-8388607). This is encoded in units of 0.25 seconds, expressed
1388 * in two’s complement representation within the low 23 bits of the DWORD. As a signed value, East
1389 * longitudes are positive. Use 0xFFFFFFFF when this information is not available. */
1390 PRINT_VALIDATED_UINT (cdma_cells[i]->base_longitude, 0xFFFFFFFF, "\t Base longitude", NULL);
1391 PRINT_VALIDATED_UINT (cdma_cells[i]->ref_pn, 0xFFFFFFFF, "\t RefPN", NULL);
1392 PRINT_VALIDATED_UINT (cdma_cells[i]->gps_seconds, 0xFFFFFFFF, "\t GPS seconds", " seconds");
1393 PRINT_VALIDATED_UINT (cdma_cells[i]->pilot_strength, 0xFFFFFFFF, "\t Pilot strength", NULL);
1394 } else
1395 g_print ("CDMA cells: n/a\n");
1396
1397 if (nr_serving_cells_count && nr_serving_cells) {
1398 guint i;
1399
1400 g_print ("Serving NR cells: %d\n", nr_serving_cells_count);
1401 for (i = 0; i < nr_serving_cells_count; i++) {
1402 g_print ("\tServing cell [%u]:\n"
1403 "\t\t Provider id: %s\n",
1404 i + 1,
1405 VALIDATE_UNKNOWN (nr_serving_cells[i]->provider_id));
1406 PRINT_VALIDATED_UINT64 (nr_serving_cells[i]->nci, 0xFFFFFFFFFFFFFFFF, "\t\t NCI", NULL);
1407 PRINT_VALIDATED_UINT (nr_serving_cells[i]->physical_cell_id, 0xFFFFFFFF, "\t\tPhysical cell id", NULL);
1408 PRINT_VALIDATED_UINT (nr_serving_cells[i]->nrarfcn, 0xFFFFFFFF, "\t\t NRARFCN", NULL);
1409 PRINT_VALIDATED_UINT (nr_serving_cells[i]->tac, 0xFFFFFFFF, "\t\t TAC", NULL);
1410 PRINT_VALIDATED_SCALED_UINT (nr_serving_cells[i]->rsrp, 0xFFFFFFFF, -156, "\t\t RSRP", " dBm");
1411 PRINT_VALIDATED_SCALED_UINT (nr_serving_cells[i]->rsrq, 0xFFFFFFFF, -43, "\t\t RSRQ", " dB");
1412 PRINT_VALIDATED_SCALED_UINT (nr_serving_cells[i]->sinr, 0xFFFFFFFF, -23, "\t\t SINR", " dB");
1413 PRINT_VALIDATED_UINT64 (nr_serving_cells[i]->timing_advance, 0xFFFFFFFFFFFFFFFF, "\t\t Timing advance", " us");
1414 }
1415 } else
1416 g_print ("Serving NR cells: n/a\n");
1417
1418 if (nr_neighboring_cells_count && nr_neighboring_cells) {
1419 guint i;
1420
1421 g_print ("Neighboring NR cells: %d\n", nr_neighboring_cells_count);
1422 for (i = 0; i < nr_neighboring_cells_count; i++) {
1423 g_autofree gchar *system_subtype_str = NULL;
1424
1425 system_subtype_str = mbim_data_subclass_build_string_from_mask (nr_neighboring_cells[i]->system_sub_type);
1426 g_print ("\tNeighboring cell [%u]:\n"
1427 "\t\t System subtype: %s\n"
1428 "\t\t Provider id: %s\n"
1429 "\t\t Cell id: %s\n",
1430 i + 1,
1431 VALIDATE_UNKNOWN (system_subtype_str),
1432 VALIDATE_UNKNOWN (nr_neighboring_cells[i]->provider_id),
1433 VALIDATE_UNKNOWN (nr_neighboring_cells[i]->cell_id));
1434 PRINT_VALIDATED_UINT (nr_neighboring_cells[i]->physical_cell_id, 0xFFFFFFFF, "\t\tPhysical cell id", NULL);
1435 PRINT_VALIDATED_UINT (nr_neighboring_cells[i]->tac, 0xFFFFFFFF, "\t\t TAC", NULL);
1436 PRINT_VALIDATED_SCALED_UINT (nr_neighboring_cells[i]->rsrp, 0xFFFFFFFF, -156, "\t\t RSRP", " dBm");
1437 PRINT_VALIDATED_SCALED_UINT (nr_neighboring_cells[i]->rsrq, 0xFFFFFFFF, -43, "\t\t RSRQ", " dB");
1438 PRINT_VALIDATED_SCALED_UINT (nr_neighboring_cells[i]->sinr, 0xFFFFFFFF, -23, "\t\t SINR", " dB");
1439 }
1440 } else
1441 g_print ("Neighboring NR cells: n/a\n");
1442
1443 #undef PRINT_VALIDATED_SCALED_UINT
1444 #undef PRINT_VALIDATED_UINT64
1445 #undef PRINT_VALIDATED_UINT
1446 #undef PRINT_VALIDATED_INT
1447
1448 shutdown (TRUE);
1449 }
1450
1451 static void
1452 query_version_ready (MbimDevice *device,
1453 GAsyncResult *res)
1454 {
1455 g_autoptr(MbimMessage) response = NULL;
1456 g_autoptr(GError) error = NULL;
1457 guint16 mbim_version;
1458 guint16 mbim_ext_version;
1459
1460 response = mbim_device_command_finish (device, res, &error);
1461 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
1462 g_printerr ("error: operation failed: %s\n", error->message);
1463 shutdown (FALSE);
1464 return;
1465 }
1466
1467 g_print ("[%s] Successfully exchanged version information\n",
1468 mbim_device_get_path_display (device));
1469 if (!mbim_message_ms_basic_connect_extensions_v2_version_response_parse (
1470 response,
1471 &mbim_version,
1472 &mbim_ext_version,
1473 &error)) {
1474 g_printerr ("error: couldn't parse response message: %s\n", error->message);
1475 shutdown (FALSE);
1476 return;
1477 }
1478
1479 g_print (" MBIM version : %x.%02x\n", mbim_version >> 8, mbim_version & 0xFF);
1480 g_print (" MBIM extended version : %x.%02x\n", mbim_ext_version >> 8, mbim_ext_version & 0xFF);
1481
1482 shutdown (TRUE);
1483 return;
1484 }
1485
1486 typedef struct {
1487 MbimMicoMode mico_mode;
1488 gboolean mico_mode_set;
1489 MbimDrxCycle drx_cycle;
1490 gboolean drx_cycle_set;
1491 MbimLadnInfo ladn_info;
1492 gboolean ladn_info_set;
1493 MbimDefaultPduActivationHint pdu_hint;
1494 gboolean pdu_hint_set;
1495 gboolean re_register_if_needed;
1496 gboolean re_register_if_needed_set;
1497 } RegistrationParameters;
1498
1499 static gboolean
1500 set_registration_parameters_foreach_cb (const gchar *key,
1501 const gchar *value,
1502 GError **error,
1503 RegistrationParameters *params)
1504 {
1505 if (g_ascii_strcasecmp (key, "mico-mode") == 0) {
1506 if (!mbimcli_read_mico_mode_from_string (value, &params->mico_mode, error)) {
1507 return FALSE;
1508 }
1509 params->mico_mode_set = TRUE;
1510 } else if (g_ascii_strcasecmp (key, "drx-cycle") == 0) {
1511 if (!mbimcli_read_drx_cycle_from_string (value, &params->drx_cycle, error)) {
1512 return FALSE;
1513 }
1514 params->drx_cycle_set = TRUE;
1515 } else if (g_ascii_strcasecmp (key, "ladn-info") == 0) {
1516 if (!mbimcli_read_ladn_info_from_string (value, &params->ladn_info, error)) {
1517 return FALSE;
1518 }
1519 params->ladn_info_set = TRUE;
1520 } else if (g_ascii_strcasecmp (key, "default-pdu-activation-hint") == 0) {
1521 if (!mbimcli_read_default_pdu_activation_hint_from_string (value, &params->pdu_hint, error)) {
1522 return FALSE;
1523 }
1524 params->pdu_hint_set = TRUE;
1525 } else if (g_ascii_strcasecmp (key, "re-register-if-needed") == 0) {
1526 if (!mbimcli_read_boolean_from_string (value, &params->re_register_if_needed)) {
1527 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_INVALID_ARGS,
1528 "unknown re-register-if-needed: '%s'", value);
1529 return FALSE;
1530 }
1531 params->re_register_if_needed_set = TRUE;
1532 } else {
1533 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
1534 "unrecognized option '%s'", key);
1535 return FALSE;
1536 }
1537
1538 return TRUE;
1539 }
1540
1541 static void
1542 registration_parameters_ready (MbimDevice *device,
1543 GAsyncResult *res)
1544 {
1545 g_autoptr(MbimMessage) response = NULL;
1546 g_autoptr(GError) error = NULL;
1547 MbimMicoMode mico_mode;
1548 MbimDrxCycle drx_cycle;
1549 MbimLadnInfo ladn_info;
1550 MbimDefaultPduActivationHint pdu_hint;
1551 gboolean re_register_if_nedeed;
1552
1553 response = mbim_device_command_finish (device, res, &error);
1554 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
1555 g_printerr ("error: operation failed: %s\n", error->message);
1556 shutdown (FALSE);
1557 return;
1558 }
1559
1560 g_print ("[%s] Successfully received registration parameters information\n",
1561 mbim_device_get_path_display (device));
1562 if (!mbim_message_ms_basic_connect_extensions_v3_registration_parameters_response_parse (
1563 response,
1564 &mico_mode,
1565 &drx_cycle,
1566 &ladn_info,
1567 &pdu_hint,
1568 &re_register_if_nedeed,
1569 NULL, /* ignore unnamed IEs for now */
1570 &error)) {
1571 g_printerr ("error: couldn't parse response message: %s\n", error->message);
1572 shutdown (FALSE);
1573 return;
1574 }
1575
1576 g_print ("\t MICO mode: %s\n", mbim_mico_mode_get_string (mico_mode));
1577 g_print ("\t DRX cycle: %s\n", mbim_drx_cycle_get_string (drx_cycle));
1578 g_print ("\t LADN information: %s\n", mbim_ladn_info_get_string (ladn_info));
1579 g_print ("\tDefault PDU activation: %s\n", mbim_default_pdu_activation_hint_get_string (pdu_hint));
1580 g_print ("\t Re-register if needed: %s\n", re_register_if_nedeed ? "yes" : "no");
1581
1582 shutdown (TRUE);
1583 }
1584
1585 static void
1586 query_modem_configuration_ready (MbimDevice *device,
1587 GAsyncResult *res)
1588 {
1589 g_autoptr(MbimMessage) response = NULL;
1590 g_autoptr(GError) error = NULL;
1591 MbimModemConfigurationStatus configuration_status;
1592 g_autofree gchar *configuration_name = NULL;
1593
1594 response = mbim_device_command_finish (device, res, &error);
1595 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
1596 g_printerr ("error: operation failed: %s\n", error->message);
1597 shutdown (FALSE);
1598 return;
1599 }
1600
1601 if (!mbim_message_ms_basic_connect_extensions_v3_modem_configuration_response_parse (
1602 response,
1603 &configuration_status,
1604 &configuration_name,
1605 NULL, /* ignore unnamed IEs for now */
1606 &error)) {
1607 g_printerr ("error: couldn't parse response message: %s\n", error->message);
1608 shutdown (FALSE);
1609 return;
1610 }
1611
1612 g_print ("[%s] Modem configuration retrieved: \n",
1613 mbim_device_get_path_display (device));
1614 g_print ("\tStatus: '%s'\n"
1615 "\t Name: '%s'\n",
1616 VALIDATE_UNKNOWN (mbim_modem_configuration_status_get_string (configuration_status)),
1617 VALIDATE_UNKNOWN (configuration_name));
1618
1619 shutdown (TRUE);
1620 }
1621
1622 static void
1623 query_wake_reason_ready (MbimDevice *device,
1624 GAsyncResult *res)
1625 {
1626 g_autoptr(MbimMessage) response = NULL;
1627 g_autoptr(GError) error = NULL;
1628 MbimWakeType wake_type;
1629 guint32 session_id;
1630 MbimTlv *wake_tlv = NULL;
1631
1632 response = mbim_device_command_finish (device, res, &error);
1633 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
1634 g_printerr ("error: operation failed: %s\n", error->message);
1635 shutdown (FALSE);
1636 return;
1637 }
1638
1639 if (!mbim_message_ms_basic_connect_extensions_v3_wake_reason_response_parse (
1640 response,
1641 &wake_type,
1642 &session_id,
1643 &wake_tlv,
1644 &error)) {
1645 g_printerr ("error: couldn't parse response message: %s\n", error->message);
1646 shutdown (FALSE);
1647 return;
1648 }
1649
1650 g_print ("[%s] Successfully queried wake reason\n",
1651 mbim_device_get_path_display (device));
1652
1653 g_print ("\t Wake type: '%s'\n", mbim_wake_type_get_string (wake_type));
1654 g_print ("\tSession ID: '%u'\n", session_id);
1655
1656 if ((wake_type == MBIM_WAKE_TYPE_CID_RESPONSE) ||
1657 (wake_type == MBIM_WAKE_TYPE_CID_INDICATION)) {
1658 const MbimUuid *service = NULL;
1659 g_autofree gchar *service_str = NULL;
1660 guint32 cid = 0;
1661 guint32 payload_size = 0;
1662 g_autofree guint8 *payload = NULL;
1663 g_autofree gchar *payload_str = NULL;
1664
1665 if (!mbim_tlv_wake_command_get (wake_tlv,
1666 &service,
1667 &cid,
1668 &payload_size,
1669 &payload,
1670 &error)) {
1671 g_printerr ("error: couldn't parse wake command TLV: %s\n", error->message);
1672 shutdown (FALSE);
1673 return;
1674 }
1675
1676 /* Known payload defined right now only for the Connect CID */
1677 if ((mbim_uuid_to_service (service) == MBIM_SERVICE_BASIC_CONNECT) &&
1678 (cid == MBIM_CID_BASIC_CONNECT_CONNECT) &&
1679 (payload_size == 4)) {
1680 guint32 activate;
1681
1682 memcpy (&activate, payload, payload_size);
1683 activate = GUINT32_FROM_LE (activate);
1684 if (activate == 0x00000001 || activate == 0x00000000)
1685 payload_str = g_strdup (activate ? "activate" : "deactivate");
1686 }
1687
1688 if (!payload_str)
1689 payload_str = mbim_common_str_hex (payload, payload_size, ':');
1690
1691 service_str = mbim_uuid_get_printable (service);
1692
1693 g_print ("\t Service: '%s'\n", service_str);
1694 g_print ("\t CID: '0x%08x'\n", cid);
1695 g_print ("\t Payload: '%s'\n", payload_str);
1696 shutdown (TRUE);
1697 return;
1698 }
1699
1700 if (wake_type == MBIM_WAKE_TYPE_PACKET) {
1701 guint32 filter_id = 0;
1702 guint32 original_packet_size = 0;
1703 guint32 packet_size = 0;
1704 g_autofree guint8 *packet = NULL;
1705 g_autofree gchar *packet_str = NULL;
1706
1707 if (!mbim_tlv_wake_packet_get (wake_tlv,
1708 &filter_id,
1709 &original_packet_size,
1710 &packet_size,
1711 &packet,
1712 &error)) {
1713 g_printerr ("error: couldn't parse wake packet TLV: %s\n", error->message);
1714 shutdown (FALSE);
1715 return;
1716 }
1717
1718 packet_str = mbim_common_str_hex (packet, packet_size, ':');
1719
1720 g_print ("\t Filter ID: '%u'\n", filter_id);
1721 g_print ("\tOriginal size: '%u'\n", original_packet_size);
1722 g_print ("\t Saved size: '%u'\n", packet_size);
1723 g_print ("\t Packet: '%s'\n", packet_str);
1724
1725 shutdown (TRUE);
1726 return;
1727 }
1728
1729 g_printerr ("error: unknown wake type: 0x%08x\n", wake_type);
1730 shutdown (FALSE);
1731 }
1732
1733 static void
1734 device_reset_ready (MbimDevice *device,
1735 GAsyncResult *res)
1736 {
1737 g_autoptr(MbimMessage) response = NULL;
1738 g_autoptr(GError) error = NULL;
1739
1740 response = mbim_device_command_finish (device, res, &error);
1741 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
1742 g_printerr ("error: operation failed: %s\n", error->message);
1743 shutdown (FALSE);
1744 return;
1745 }
1746
1747 if (!mbim_message_ms_basic_connect_extensions_device_reset_response_parse (response, &error)) {
1748 g_printerr ("error: couldn't parse response message: %s\n", error->message);
1749 shutdown (FALSE);
1750 return;
1751 }
1752
1753 g_print ("[%s] Successfully requested device reset\n",
1754 mbim_device_get_path_display (device));
1755
1756 shutdown (TRUE);
1757 }
1758
1759 void
1760 mbimcli_ms_basic_connect_extensions_run (MbimDevice *device,
1761 GCancellable *cancellable)
1762 {
1763 g_autoptr(MbimMessage) request = NULL;
1764 g_autoptr(GError) error = NULL;
1765
1766 /* Initialize context */
1767 ctx = g_slice_new (Context);
1768 ctx->device = g_object_ref (device);
1769 ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
1770
1771 /* Request to get PCO? */
1772 if (query_pco_str) {
1773 MbimPcoValue pco_value;
1774
1775 if (!session_id_parse (query_pco_str, &pco_value.session_id, &error)) {
1776 g_printerr ("error: couldn't parse session ID: %s\n", error->message);
1777 shutdown (FALSE);
1778 return;
1779 }
1780
1781 pco_value.pco_data_size = 0;
1782 pco_value.pco_data_type = MBIM_PCO_TYPE_COMPLETE;
1783 pco_value.pco_data_buffer = NULL;
1784
1785 g_debug ("Asynchronously querying PCO...");
1786 request = mbim_message_ms_basic_connect_extensions_pco_query_new (&pco_value, NULL);
1787 mbim_device_command (ctx->device,
1788 request,
1789 10,
1790 ctx->cancellable,
1791 (GAsyncReadyCallback)query_pco_ready,
1792 NULL);
1793 return;
1794 }
1795
1796 if (query_lte_attach_configuration_flag) {
1797 g_debug ("Asynchronously querying LTE attach configuration...");
1798 request = mbim_message_ms_basic_connect_extensions_lte_attach_configuration_query_new (NULL);
1799 mbim_device_command (ctx->device,
1800 request,
1801 10,
1802 ctx->cancellable,
1803 (GAsyncReadyCallback)lte_attach_configuration_ready,
1804 NULL);
1805 return;
1806 }
1807
1808 if (set_lte_attach_configuration_str) {
1809 MbimLteAttachContextOperation operation = MBIM_LTE_ATTACH_CONTEXT_OPERATION_DEFAULT;
1810 g_autoptr(MbimLteAttachConfigurationArray) configurations = NULL;
1811 guint32 configuration_count = 0;
1812
1813 g_debug ("Asynchronously setting LTE attach configuration...");
1814
1815 if (!set_lte_attach_configuration_input_parse (
1816 set_lte_attach_configuration_str,
1817 &operation,
1818 &configuration_count,
1819 &configurations,
1820 &error)) {
1821 g_printerr ("error: couldn't parse setting argument: %s\n", error->message);
1822 shutdown (FALSE);
1823 return;
1824 }
1825
1826 request = mbim_message_ms_basic_connect_extensions_lte_attach_configuration_set_new (
1827 operation,
1828 configuration_count,
1829 (const MbimLteAttachConfiguration * const*)configurations,
1830 &error);
1831 if (!request) {
1832 g_printerr ("error: couldn't create request: %s\n", error->message);
1833 shutdown (FALSE);
1834 return;
1835 }
1836
1837 mbim_device_command (ctx->device,
1838 request,
1839 10,
1840 ctx->cancellable,
1841 (GAsyncReadyCallback)lte_attach_configuration_ready,
1842 NULL);
1843 return;
1844 }
1845
1846 if (query_lte_attach_status_flag || query_lte_attach_info_flag) {
1847 g_debug ("Asynchronously querying LTE attach info...");
1848 request = mbim_message_ms_basic_connect_extensions_lte_attach_info_query_new (NULL);
1849 mbim_device_command (ctx->device,
1850 request,
1851 10,
1852 ctx->cancellable,
1853 (GAsyncReadyCallback)query_lte_attach_info_ready,
1854 NULL);
1855 return;
1856 }
1857
1858 if (query_sys_caps_flag) {
1859 g_debug ("Asynchronously querying system capabilities...");
1860 request = mbim_message_ms_basic_connect_extensions_sys_caps_query_new (NULL);
1861 mbim_device_command (ctx->device,
1862 request,
1863 10,
1864 ctx->cancellable,
1865 (GAsyncReadyCallback)query_sys_caps_ready,
1866 NULL);
1867 return;
1868 }
1869
1870 if (query_device_caps_flag) {
1871 g_debug ("Asynchronously querying device capabilities...");
1872 request = mbim_message_ms_basic_connect_extensions_device_caps_query_new (NULL);
1873 mbim_device_command (ctx->device,
1874 request,
1875 10,
1876 ctx->cancellable,
1877 (GAsyncReadyCallback)query_device_caps_ready,
1878 NULL);
1879 return;
1880 }
1881
1882 if (query_slot_info_status_str) {
1883 guint32 slot_index;
1884
1885 if (!query_slot_information_status_slot_index_parse (query_slot_info_status_str, &slot_index, &error)) {
1886 g_printerr ("error: couldn't parse slot index: %s\n", error->message);
1887 shutdown (FALSE);
1888 return;
1889 }
1890
1891 g_debug ("Asynchronously querying slot information status...");
1892 request = mbim_message_ms_basic_connect_extensions_slot_info_status_query_new (slot_index, NULL);
1893 mbim_device_command (ctx->device,
1894 request,
1895 10,
1896 ctx->cancellable,
1897 (GAsyncReadyCallback)query_slot_information_status_ready,
1898 NULL);
1899 return;
1900 }
1901
1902 if (set_device_slot_mappings_str) {
1903 g_autoptr(GPtrArray) slot_array = NULL;
1904
1905 g_print ("Asynchronously set device slot mappings\n");
1906 if (!set_device_slot_mappings_input_parse (set_device_slot_mappings_str, &slot_array, &error)) {
1907 g_printerr ("error: couldn't parse setting argument: %s\n", error->message);
1908 shutdown (FALSE);
1909 return;
1910 }
1911
1912 request = mbim_message_ms_basic_connect_extensions_device_slot_mappings_set_new (slot_array->len,
1913 (const MbimSlot **)slot_array->pdata,
1914 NULL);
1915 mbim_device_command (ctx->device,
1916 request,
1917 10,
1918 ctx->cancellable,
1919 (GAsyncReadyCallback)query_device_slot_mappings_ready,
1920 NULL);
1921 return;
1922 }
1923
1924 if (query_device_slot_mappings_flag) {
1925 g_debug ("Asynchronously querying device slot mappings...");
1926 request = mbim_message_ms_basic_connect_extensions_device_slot_mappings_query_new (NULL);
1927 mbim_device_command (ctx->device,
1928 request,
1929 10,
1930 ctx->cancellable,
1931 (GAsyncReadyCallback)query_device_slot_mappings_ready,
1932 NULL);
1933 return;
1934 }
1935
1936 if (query_location_info_status_flag) {
1937 g_debug ("Asynchronously querying location info status...");
1938 request = mbim_message_ms_basic_connect_extensions_location_info_status_query_new (NULL);
1939 mbim_device_command (ctx->device,
1940 request,
1941 10,
1942 ctx->cancellable,
1943 (GAsyncReadyCallback)query_location_info_status_ready,
1944 NULL);
1945 return;
1946 }
1947
1948 if (set_provisioned_contexts_str) {
1949 g_auto(ProvisionedContextProperties) props = {
1950 .access_string = NULL,
1951 .operation = MBIM_CONTEXT_OPERATION_DELETE,
1952 .auth_protocol = MBIM_AUTH_PROTOCOL_NONE,
1953 .username = NULL,
1954 .password = NULL,
1955 .ip_type = MBIM_CONTEXT_IP_TYPE_DEFAULT,
1956 .state = MBIM_CONTEXT_STATE_DISABLED,
1957 .roaming_control = MBIM_CONTEXT_ROAMING_CONTROL_HOME_ONLY,
1958 .media_type = MBIM_CONTEXT_MEDIA_TYPE_CELLULAR_ONLY,
1959 .source = MBIM_CONTEXT_SOURCE_ADMIN,
1960 .compression = MBIM_COMPRESSION_NONE,
1961 .context_type = MBIM_CONTEXT_TYPE_INVALID
1962 };
1963
1964 if (!mbimcli_parse_key_value_string (set_provisioned_contexts_str,
1965 &error,
1966 (MbimParseKeyValueForeachFn)set_provisioned_contexts_foreach_cb,
1967 &props)) {
1968 g_printerr ("error: couldn't parse input string: %s\n", error->message);
1969 shutdown (FALSE);
1970 return;
1971 }
1972
1973 request = mbim_message_ms_basic_connect_extensions_provisioned_contexts_set_new (
1974 props.operation,
1975 mbim_uuid_from_context_type (props.context_type),
1976 props.ip_type,
1977 props.state,
1978 props.roaming_control,
1979 props.media_type,
1980 props.source,
1981 props.access_string,
1982 props.username,
1983 props.password,
1984 props.compression,
1985 props.auth_protocol,
1986 &error);
1987
1988 if (!request) {
1989 g_printerr ("error: couldn't create request: %s\n", error->message);
1990 shutdown (FALSE);
1991 return;
1992 }
1993
1994 mbim_device_command (ctx->device,
1995 request,
1996 60,
1997 ctx->cancellable,
1998 (GAsyncReadyCallback)provisioned_contexts_ready,
1999 NULL);
2000 return;
2001 }
2002
2003 /* Request to query Provisioned contexts? */
2004 if (query_provisioned_contexts_flag) {
2005 g_debug ("Asynchronously query provisioned contexts...");
2006
2007 request = mbim_message_ms_basic_connect_extensions_provisioned_contexts_query_new (NULL);
2008 if (!request) {
2009 g_printerr ("error: couldn't create request: %s\n", error->message);
2010 shutdown (FALSE);
2011 return;
2012 }
2013
2014 mbim_device_command (ctx->device,
2015 request,
2016 10,
2017 ctx->cancellable,
2018 (GAsyncReadyCallback)provisioned_contexts_ready,
2019 NULL);
2020 return;
2021 }
2022
2023 if (query_base_stations_flag) {
2024 g_debug ("Asynchronously querying base stations...");
2025 /* default capacity is 15, so use that value when querying */
2026 if (mbim_device_check_ms_mbimex_version (ctx->device, 3, 0))
2027 request = mbim_message_ms_basic_connect_extensions_v3_base_stations_info_query_new (15, 15, 15, 15, 15, 15, NULL);
2028 else
2029 request = mbim_message_ms_basic_connect_extensions_base_stations_info_query_new (15, 15, 15, 15, 15, NULL);
2030 mbim_device_command (ctx->device,
2031 request,
2032 10,
2033 ctx->cancellable,
2034 (GAsyncReadyCallback)query_base_stations_ready,
2035 NULL);
2036 return;
2037 }
2038
2039 if (query_version_str) {
2040 guint16 bcd_mbim_version = 0;
2041 guint16 bcd_mbim_extended_version = 0;
2042 guint8 mbim_version_major = 0;
2043 guint8 mbim_version_minor = 0;
2044 guint8 mbim_extended_version_major = 0;
2045 guint8 mbim_extended_version_minor = 0;
2046 g_auto(GStrv) split = NULL;
2047 g_auto(GStrv) mbim_version = NULL;
2048 g_auto(GStrv) mbim_extended_version = NULL;
2049
2050 split = g_strsplit (query_version_str, ",", -1);
2051
2052 if (g_strv_length (split) > 2) {
2053 g_printerr ("error: couldn't parse input string, too many arguments\n");
2054 return;
2055 }
2056
2057 if (g_strv_length (split) < 2) {
2058 g_printerr ("error: couldn't parse input string, missing arguments\n");
2059 return;
2060 }
2061
2062 mbim_version = g_strsplit (split[0], ".", -1);
2063 if (!mbimcli_read_uint8_from_bcd_string (mbim_version[0], &mbim_version_major) ||
2064 !mbimcli_read_uint8_from_bcd_string (mbim_version[1], &mbim_version_minor)) {
2065 g_printerr ("error: couldn't parse version string\n");
2066 return;
2067 }
2068 bcd_mbim_version = mbim_version_major << 8 | mbim_version_minor;
2069 g_debug ("BCD version built: 0x%x", bcd_mbim_version);
2070
2071 mbim_extended_version = g_strsplit (split[1], ".", -1);
2072 if (!mbimcli_read_uint8_from_bcd_string (mbim_extended_version[0], &mbim_extended_version_major) ||
2073 !mbimcli_read_uint8_from_bcd_string (mbim_extended_version[1], &mbim_extended_version_minor)) {
2074 g_printerr ("error: couldn't parse extended version string\n");
2075 return;
2076 }
2077 bcd_mbim_extended_version = mbim_extended_version_major << 8 | mbim_extended_version_minor;
2078 g_debug ("BCD extended version built: 0x%x", bcd_mbim_extended_version);
2079
2080 g_debug ("Asynchronously querying Version...");
2081 request = mbim_message_ms_basic_connect_extensions_v2_version_query_new (bcd_mbim_version, bcd_mbim_extended_version, NULL);
2082 mbim_device_command (ctx->device,
2083 request,
2084 10,
2085 ctx->cancellable,
2086 (GAsyncReadyCallback)query_version_ready,
2087 NULL);
2088 return;
2089 }
2090
2091 if (query_registration_parameters_flag) {
2092 g_debug (" Asynchronously querying registration parameters...");
2093 request = mbim_message_ms_basic_connect_extensions_v3_registration_parameters_query_new (NULL);
2094 mbim_device_command (ctx->device,
2095 request,
2096 10,
2097 ctx->cancellable,
2098 (GAsyncReadyCallback)registration_parameters_ready,
2099 NULL);
2100 return;
2101 }
2102
2103 if (device_reset_flag) {
2104 request = mbim_message_ms_basic_connect_extensions_device_reset_set_new (NULL);
2105
2106 mbim_device_command (ctx->device,
2107 request,
2108 10,
2109 ctx->cancellable,
2110 (GAsyncReadyCallback)device_reset_ready,
2111 NULL);
2112 return;
2113 }
2114
2115 if (set_registration_parameters_str) {
2116 RegistrationParameters params = { 0 };
2117
2118 if (!mbimcli_parse_key_value_string (set_registration_parameters_str,
2119 &error,
2120 (MbimParseKeyValueForeachFn)set_registration_parameters_foreach_cb,
2121 &params)) {
2122 g_printerr ("error: couldn't parse input string: %s\n", error->message);
2123 shutdown (FALSE);
2124 return;
2125 }
2126
2127 if (!params.mico_mode_set ||
2128 !params.drx_cycle_set ||
2129 !params.ladn_info_set ||
2130 !params.pdu_hint_set ||
2131 !params.re_register_if_needed_set) {
2132 g_printerr ("error: missing required keys\n");
2133 if (!params.mico_mode_set)
2134 g_printerr ("error: key 'mico-mode' is missing\n");
2135 if (!params.drx_cycle_set)
2136 g_printerr ("error: key 'drx-cycle' is missing\n");
2137 if (!params.ladn_info_set)
2138 g_printerr ("error: key 'ladn-info' is missing\n");
2139 if (!params.pdu_hint_set)
2140 g_printerr ("error: key 'default-pdu-activation-hint' is missing\n");
2141 if (!params.re_register_if_needed_set)
2142 g_printerr ("error: key 're-register-is-needed' is missing\n");
2143 shutdown (FALSE);
2144 return;
2145 }
2146
2147 g_debug ("Asynchronously set registration parameters\n");
2148 request = (mbim_message_ms_basic_connect_extensions_v3_registration_parameters_set_new (
2149 params.mico_mode,
2150 params.drx_cycle,
2151 params.ladn_info,
2152 params.pdu_hint,
2153 params.re_register_if_needed,
2154 NULL, /* ignore unnamed IEs for now */
2155 NULL));
2156 mbim_device_command (ctx->device,
2157 request,
2158 10,
2159 ctx->cancellable,
2160 (GAsyncReadyCallback)registration_parameters_ready,
2161 NULL);
2162 return;
2163 }
2164
2165 /* Request to query modem configuration? */
2166 if (query_modem_configuration_flag) {
2167 g_debug ("Asynchronously query modem configuration\n");
2168 request = mbim_message_ms_basic_connect_extensions_v3_modem_configuration_query_new (NULL);
2169 mbim_device_command (ctx->device,
2170 request,
2171 10,
2172 ctx->cancellable,
2173 (GAsyncReadyCallback)query_modem_configuration_ready,
2174 NULL);
2175 return;
2176 }
2177
2178 /* Request to query Wake Reason? */
2179 if (query_wake_reason_flag) {
2180 g_debug ("Asynchronously querying wake reason...");
2181 request = mbim_message_ms_basic_connect_extensions_v3_wake_reason_query_new (NULL);
2182 mbim_device_command (ctx->device,
2183 request,
2184 10,
2185 ctx->cancellable,
2186 (GAsyncReadyCallback)query_wake_reason_ready,
2187 NULL);
2188 return;
2189 }
2190
2191 g_warn_if_reached ();
2192 }