Debian Codegraph @

src/mbimcli/mbimcli-ms-uicc-low-level-access.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) 2022 Google, Inc.
7 */
8
9 #include "config.h"
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <locale.h>
14 #include <string.h>
15 #include <errno.h>
16
17 #include <glib.h>
18 #include <gio/gio.h>
19
20 #include <libmbim-glib.h>
21
22 #include "mbim-common.h"
23 #include "mbimcli.h"
24 #include "mbimcli-helpers.h"
25
26 /* Context */
27 typedef struct {
28 MbimDevice *device;
29 GCancellable *cancellable;
30 } Context;
31 static Context *ctx;
32
33 /* Options */
34 static gboolean query_uicc_application_list_flag;
35 static gchar *query_uicc_file_status_str;
36 static gchar *query_uicc_read_binary_str;
37 static gchar *query_uicc_read_record_str;
38 static gchar *set_uicc_open_channel_str;
39 static gchar *set_uicc_close_channel_str;
40 static gboolean query_uicc_atr_flag;
41 static gchar *set_uicc_apdu_str;
42 static gchar *set_uicc_reset_str;
43 static gboolean query_uicc_reset_flag;
44 static gchar *set_uicc_terminal_capability_str;
45 static gboolean query_uicc_terminal_capability_flag;
46
47 static GOptionEntry entries[] = {
48 { "ms-query-uicc-application-list", 0, 0, G_OPTION_ARG_NONE, &query_uicc_application_list_flag,
49 "Query UICC application list",
50 NULL
51 },
52 { "ms-query-uicc-file-status", 0, 0, G_OPTION_ARG_STRING, &query_uicc_file_status_str,
53 "Query UICC file status (allowed keys: application-id, file-path)",
54 "[\"key=value,...\"]"
55 },
56 { "ms-query-uicc-read-binary", 0, 0, G_OPTION_ARG_STRING, &query_uicc_read_binary_str,
57 "Read UICC binary file (allowed keys: application-id, file-path, read-offset, read-size, local-pin and data)",
58 "[\"key=value,...\"]"
59 },
60 { "ms-query-uicc-read-record", 0, 0, G_OPTION_ARG_STRING, &query_uicc_read_record_str,
61 "Read UICC record file (allowed keys: application-id, file-path, record-number, local-pin and data)",
62 "[\"key=value,...\"]"
63 },
64 { "ms-set-uicc-open-channel", 0, 0, G_OPTION_ARG_STRING, &set_uicc_open_channel_str,
65 "Set UICC open channel (allowed keys: application-id, selectp2arg, channel-group)",
66 "[\"key=value,...\"]"
67 },
68 { "ms-set-uicc-close-channel", 0, 0, G_OPTION_ARG_STRING, &set_uicc_close_channel_str,
69 "Set UICC close channel (allowed keys: channel, channel-group)",
70 "[\"key=value,...\"]"
71 },
72 { "ms-query-uicc-atr", 0, 0, G_OPTION_ARG_NONE, &query_uicc_atr_flag,
73 "Query UICC atr",
74 NULL
75 },
76 { "ms-set-uicc-apdu", 0, 0, G_OPTION_ARG_STRING, &set_uicc_apdu_str,
77 "Set UICC apdu (allowed keys: channel, secure-message, classbyte-type, command)",
78 "[\"key=value,...\"]"
79 },
80 { "ms-set-uicc-reset", 0, 0, G_OPTION_ARG_STRING, &set_uicc_reset_str,
81 "Set UICC reset",
82 "[(Pass Through Action)]"
83 },
84 { "ms-query-uicc-reset", 0, 0, G_OPTION_ARG_NONE, &query_uicc_reset_flag,
85 "Query UICC reset",
86 NULL
87 },
88 { "ms-set-uicc-terminal-capability", 0, 0, G_OPTION_ARG_STRING, &set_uicc_terminal_capability_str,
89 "Set UICC terminal capability (allowed keys: terminal-capability)",
90 "[\"key=value,...\"]"
91 },
92 { "ms-query-uicc-terminal-capability", 0, 0, G_OPTION_ARG_NONE, &query_uicc_terminal_capability_flag,
93 "Query UICC terminal capability",
94 NULL
95 },
96 { NULL, 0, 0, 0, NULL, NULL, NULL }
97 };
98
99 GOptionGroup *
100 mbimcli_ms_uicc_low_level_access_get_option_group (void)
101 {
102 GOptionGroup *group;
103
104 group = g_option_group_new ("ms-uicc-low-level-access",
105 "Microsoft UICC Low Level Access Service options:",
106 "Show Microsoft UICC Low Level Access Service options",
107 NULL,
108 NULL);
109 g_option_group_add_entries (group, entries);
110
111 return group;
112 }
113
114 gboolean
115 mbimcli_ms_uicc_low_level_access_options_enabled (void)
116 {
117 static guint n_actions = 0;
118 static gboolean checked = FALSE;
119
120 if (checked)
121 return !!n_actions;
122
123 n_actions = query_uicc_application_list_flag +
124 !!query_uicc_file_status_str +
125 !!query_uicc_read_binary_str +
126 !!query_uicc_read_record_str +
127 !!set_uicc_open_channel_str +
128 !!set_uicc_close_channel_str +
129 query_uicc_atr_flag +
130 !!set_uicc_apdu_str +
131 !!set_uicc_reset_str +
132 query_uicc_reset_flag +
133 !!set_uicc_terminal_capability_str +
134 query_uicc_terminal_capability_flag;
135
136 if (n_actions > 1) {
137 g_printerr ("error: too many Microsoft UICC Low Level Access Service actions requested\n");
138 exit (EXIT_FAILURE);
139 }
140
141 checked = TRUE;
142 return !!n_actions;
143 }
144
145 static void
146 context_free (Context *context)
147 {
148 if (!context)
149 return;
150
151 if (context->cancellable)
152 g_object_unref (context->cancellable);
153 if (context->device)
154 g_object_unref (context->device);
155 g_slice_free (Context, context);
156 }
157
158 static void
159 shutdown (gboolean operation_status)
160 {
161 /* Cleanup context and finish async operation */
162 context_free (ctx);
163 mbimcli_async_operation_done (operation_status);
164 }
165
166 static void
167 read_record_query_ready (MbimDevice *device,
168 GAsyncResult *res)
169 {
170 g_autoptr(MbimMessage) response = NULL;
171 g_autoptr(GError) error = NULL;
172 guint32 status_word_1;
173 guint32 status_word_2;
174 const guint8 *data;
175 guint32 data_size;
176 g_autofree gchar *data_str = NULL;
177
178 response = mbim_device_command_finish (device, res, &error);
179 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
180 g_printerr ("error: operation failed: %s\n", error->message);
181 shutdown (FALSE);
182 return;
183 }
184
185 if (!mbim_message_ms_uicc_low_level_access_read_record_response_parse (
186 response,
187 NULL, /* version */
188 &status_word_1,
189 &status_word_2,
190 &data_size,
191 &data,
192 &error)) {
193 g_printerr ("error: couldn't parse response message: %s\n", error->message);
194 shutdown (FALSE);
195 return;
196 }
197
198 data_str = mbim_common_str_hex (data, data_size, ':');
199
200 g_print ("[%s] UICC file record read:\n"
201 "\tStatus word 1: %u\n"
202 "\tStatus word 2: %u\n"
203 "\t Data: %s\n",
204 mbim_device_get_path_display (device),
205 status_word_1,
206 status_word_2,
207 data_str);
208
209 shutdown (TRUE);
210 }
211
212 typedef struct {
213 gsize application_id_size;
214 guint8 *application_id;
215 gsize file_path_size;
216 guint8 *file_path;
217 guint32 record_number;
218 gchar *local_pin;
219 gsize data_size;
220 guint8 *data;
221 } ReadRecordQueryProperties;
222
223 static void
224 read_record_query_properties_clear (ReadRecordQueryProperties *props)
225 {
226 g_clear_pointer (&props->application_id, g_free);
227 g_clear_pointer (&props->file_path, g_free);
228 g_clear_pointer (&props->local_pin, g_free);
229 g_clear_pointer (&props->data, g_free);
230 }
231
232 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ReadRecordQueryProperties, read_record_query_properties_clear);
233
234 static gboolean
235 read_record_query_properties_handle (const gchar *key,
236 const gchar *value,
237 GError **error,
238 gpointer user_data)
239 {
240 ReadRecordQueryProperties *props = user_data;
241
242 if (g_ascii_strcasecmp (key, "application-id") == 0) {
243 g_clear_pointer (&props->application_id, g_free);
244 props->application_id_size = 0;
245 props->application_id = mbimcli_read_buffer_from_string (value, -1, &props->application_id_size, error);
246 if (!props->application_id)
247 return FALSE;
248 } else if (g_ascii_strcasecmp (key, "file-path") == 0) {
249 g_clear_pointer (&props->file_path, g_free);
250 props->file_path_size = 0;
251 props->file_path = mbimcli_read_buffer_from_string (value, -1, &props->file_path_size, error);
252 if (!props->file_path)
253 return FALSE;
254 } else if (g_ascii_strcasecmp (key, "record-number") == 0) {
255 if (!mbimcli_read_uint_from_string (value, &props->record_number)) {
256 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
257 "Failed to parse field as an integer");
258 return FALSE;
259 }
260 } else if (g_ascii_strcasecmp (key, "local-pin") == 0) {
261 g_clear_pointer (&props->local_pin, g_free);
262 props->local_pin = g_strdup (value);
263 } else if (g_ascii_strcasecmp (key, "data") == 0) {
264 g_clear_pointer (&props->data, g_free);
265 props->data_size = 0;
266 props->data = mbimcli_read_buffer_from_string (value, -1, &props->data_size, error);
267 if (!props->data)
268 return FALSE;
269 } else {
270 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
271 "unrecognized option '%s'", key);
272 return FALSE;
273 }
274
275 return TRUE;
276 }
277
278 static gboolean
279 read_record_query_input_parse (const gchar *str,
280 ReadRecordQueryProperties *props,
281 GError **error)
282 {
283
284 if (!mbimcli_parse_key_value_string (str,
285 error,
286 read_record_query_properties_handle,
287 props))
288 return FALSE;
289
290 if (!props->application_id_size || !props->application_id) {
291 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
292 "Option 'application-id' is missing");
293 return FALSE;
294 }
295
296 if (!props->file_path_size || !props->file_path) {
297 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
298 "Option 'file-path' is missing");
299 return FALSE;
300 }
301
302 /* all the other fields are optional */
303
304 return TRUE;
305 }
306
307 static void
308 read_binary_query_ready (MbimDevice *device,
309 GAsyncResult *res)
310 {
311 g_autoptr(MbimMessage) response = NULL;
312 g_autoptr(GError) error = NULL;
313 guint32 status_word_1;
314 guint32 status_word_2;
315 const guint8 *data;
316 guint32 data_size;
317 g_autofree gchar *data_str = NULL;
318
319 response = mbim_device_command_finish (device, res, &error);
320 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
321 g_printerr ("error: operation failed: %s\n", error->message);
322 shutdown (FALSE);
323 return;
324 }
325
326 if (!mbim_message_ms_uicc_low_level_access_read_binary_response_parse (
327 response,
328 NULL, /* version */
329 &status_word_1,
330 &status_word_2,
331 &data_size,
332 &data,
333 &error)) {
334 g_printerr ("error: couldn't parse response message: %s\n", error->message);
335 shutdown (FALSE);
336 return;
337 }
338
339 data_str = mbim_common_str_hex (data, data_size, ':');
340
341 g_print ("[%s] UICC file binary read:\n"
342 "\tStatus word 1: %u\n"
343 "\tStatus word 2: %u\n"
344 "\t Data: %s\n",
345 mbim_device_get_path_display (device),
346 status_word_1,
347 status_word_2,
348 data_str);
349
350 shutdown (TRUE);
351 }
352
353 typedef struct {
354 gsize application_id_size;
355 guint8 *application_id;
356 gsize file_path_size;
357 guint8 *file_path;
358 guint32 read_offset;
359 guint32 read_size;
360 gchar *local_pin;
361 gsize data_size;
362 guint8 *data;
363 } ReadBinaryQueryProperties;
364
365 static void
366 read_binary_query_properties_clear (ReadBinaryQueryProperties *props)
367 {
368 g_clear_pointer (&props->application_id, g_free);
369 g_clear_pointer (&props->file_path, g_free);
370 g_clear_pointer (&props->local_pin, g_free);
371 g_clear_pointer (&props->data, g_free);
372 }
373
374 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ReadBinaryQueryProperties, read_binary_query_properties_clear);
375
376 static gboolean
377 read_binary_query_properties_handle (const gchar *key,
378 const gchar *value,
379 GError **error,
380 gpointer user_data)
381 {
382 ReadBinaryQueryProperties *props = user_data;
383
384 if (g_ascii_strcasecmp (key, "application-id") == 0) {
385 g_clear_pointer (&props->application_id, g_free);
386 props->application_id_size = 0;
387 props->application_id = mbimcli_read_buffer_from_string (value, -1, &props->application_id_size, error);
388 if (!props->application_id)
389 return FALSE;
390 } else if (g_ascii_strcasecmp (key, "file-path") == 0) {
391 g_clear_pointer (&props->file_path, g_free);
392 props->file_path_size = 0;
393 props->file_path = mbimcli_read_buffer_from_string (value, -1, &props->file_path_size, error);
394 if (!props->file_path)
395 return FALSE;
396 } else if (g_ascii_strcasecmp (key, "read-offset") == 0) {
397 if (!mbimcli_read_uint_from_string (value, &props->read_offset)) {
398 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
399 "Failed to parse field as an integer");
400 return FALSE;
401 }
402 } else if (g_ascii_strcasecmp (key, "read-size") == 0) {
403 if (!mbimcli_read_uint_from_string (value, &props->read_size)) {
404 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
405 "Failed to parse field as an integer");
406 return FALSE;
407 }
408 } else if (g_ascii_strcasecmp (key, "local-pin") == 0) {
409 g_clear_pointer (&props->local_pin, g_free);
410 props->local_pin = g_strdup (value);
411 } else if (g_ascii_strcasecmp (key, "data") == 0) {
412 g_clear_pointer (&props->data, g_free);
413 props->data_size = 0;
414 props->data = mbimcli_read_buffer_from_string (value, -1, &props->data_size, error);
415 if (!props->data)
416 return FALSE;
417 } else {
418 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
419 "unrecognized option '%s'", key);
420 return FALSE;
421 }
422
423 return TRUE;
424 }
425
426 static gboolean
427 read_binary_query_input_parse (const gchar *str,
428 ReadBinaryQueryProperties *props,
429 GError **error)
430 {
431
432 if (!mbimcli_parse_key_value_string (str,
433 error,
434 read_binary_query_properties_handle,
435 props))
436 return FALSE;
437
438 if (!props->application_id_size || !props->application_id) {
439 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
440 "Option 'application-id' is missing");
441 return FALSE;
442 }
443
444 if (!props->file_path_size || !props->file_path) {
445 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
446 "Option 'file-path' is missing");
447 return FALSE;
448 }
449
450 /* all the other fields are optional */
451
452 return TRUE;
453 }
454
455 static void
456 file_status_query_ready (MbimDevice *device,
457 GAsyncResult *res)
458 {
459 g_autoptr(MbimMessage) response = NULL;
460 g_autoptr(GError) error = NULL;
461 guint32 status_word_1;
462 guint32 status_word_2;
463 MbimUiccFileAccessibility file_accessibility;
464 MbimUiccFileType file_type;
465 MbimUiccFileStructure file_structure;
466 guint32 file_item_count;
467 guint32 file_item_size;
468 MbimPinType access_condition_read;
469 MbimPinType access_condition_update;
470 MbimPinType access_condition_activate;
471 MbimPinType access_condition_deactivate;
472
473 response = mbim_device_command_finish (device, res, &error);
474 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
475 g_printerr ("error: operation failed: %s\n", error->message);
476 shutdown (FALSE);
477 return;
478 }
479
480 if (!mbim_message_ms_uicc_low_level_access_file_status_response_parse (
481 response,
482 NULL, /* version */
483 &status_word_1,
484 &status_word_2,
485 &file_accessibility,
486 &file_type,
487 &file_structure,
488 &file_item_count,
489 &file_item_size,
490 &access_condition_read,
491 &access_condition_update,
492 &access_condition_activate,
493 &access_condition_deactivate,
494 &error)) {
495 g_printerr ("error: couldn't parse response message: %s\n", error->message);
496 shutdown (FALSE);
497 return;
498 }
499
500 g_print ("[%s] UICC file status retrieved:\n"
501 "\t Status word 1: %u\n"
502 "\t Status word 2: %u\n"
503 "\t Accessibility: %s\n"
504 "\t Type: %s\n"
505 "\t Structure: %s\n"
506 "\t Item count: %u\n"
507 "\t Item size: %u\n"
508 "\tAccess conditions:\n"
509 "\t Read: %s\n"
510 "\t Update: %s\n"
511 "\t Activate: %s\n"
512 "\t Deactivate: %s\n",
513 mbim_device_get_path_display (device),
514 status_word_1,
515 status_word_2,
516 mbim_uicc_file_accessibility_get_string (file_accessibility),
517 mbim_uicc_file_type_get_string (file_type),
518 mbim_uicc_file_structure_get_string (file_structure),
519 file_item_count,
520 file_item_size,
521 mbim_pin_type_get_string (access_condition_read),
522 mbim_pin_type_get_string (access_condition_update),
523 mbim_pin_type_get_string (access_condition_activate),
524 mbim_pin_type_get_string (access_condition_deactivate));
525
526 shutdown (TRUE);
527 }
528
529 typedef struct {
530 gsize application_id_size;
531 guint8 *application_id;
532 gsize file_path_size;
533 guint8 *file_path;
534 } FileStatusQueryProperties;
535
536 static void
537 file_status_query_properties_clear (FileStatusQueryProperties *props)
538 {
539 g_clear_pointer (&props->application_id, g_free);
540 g_clear_pointer (&props->file_path, g_free);
541 }
542
543 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(FileStatusQueryProperties, file_status_query_properties_clear);
544
545 static gboolean
546 file_status_query_properties_handle (const gchar *key,
547 const gchar *value,
548 GError **error,
549 gpointer user_data)
550 {
551 FileStatusQueryProperties *props = user_data;
552
553 if (g_ascii_strcasecmp (key, "application-id") == 0) {
554 g_clear_pointer (&props->application_id, g_free);
555 props->application_id_size = 0;
556 props->application_id = mbimcli_read_buffer_from_string (value, -1, &props->application_id_size, error);
557 if (!props->application_id)
558 return FALSE;
559 } else if (g_ascii_strcasecmp (key, "file-path") == 0) {
560 g_clear_pointer (&props->file_path, g_free);
561 props->file_path_size = 0;
562 props->file_path = mbimcli_read_buffer_from_string (value, -1, &props->file_path_size, error);
563 if (!props->file_path)
564 return FALSE;
565 } else {
566 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
567 "unrecognized option '%s'", key);
568 return FALSE;
569 }
570
571 return TRUE;
572 }
573
574 static gboolean
575 file_status_query_input_parse (const gchar *str,
576 FileStatusQueryProperties *props,
577 GError **error)
578 {
579
580 if (!mbimcli_parse_key_value_string (str,
581 error,
582 file_status_query_properties_handle,
583 props))
584 return FALSE;
585
586 if (!props->application_id_size || !props->application_id) {
587 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
588 "Option 'application-id' is missing");
589 return FALSE;
590 }
591
592 if (!props->file_path_size || !props->file_path) {
593 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
594 "Option 'file-path' is missing");
595 return FALSE;
596 }
597
598 return TRUE;
599 }
600
601 static void
602 application_list_query_ready (MbimDevice *device,
603 GAsyncResult *res)
604 {
605 g_autoptr(MbimMessage) response = NULL;
606 g_autoptr(GError) error = NULL;
607 guint32 application_count;
608 guint32 active_application_index;
609 g_autoptr(MbimUiccApplicationArray) applications = NULL;
610 guint32 i;
611
612 response = mbim_device_command_finish (device, res, &error);
613 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
614 g_printerr ("error: operation failed: %s\n", error->message);
615 shutdown (FALSE);
616 return;
617 }
618
619 if (!mbim_message_ms_uicc_low_level_access_application_list_response_parse (
620 response,
621 NULL, /* version */
622 &application_count,
623 &active_application_index,
624 NULL, /* application_list_size_bytes */
625 &applications,
626 &error)) {
627 g_printerr ("error: couldn't parse response message: %s\n", error->message);
628 shutdown (FALSE);
629 return;
630 }
631
632 g_print ("[%s] UICC applications: (%u)\n",
633 mbim_device_get_path_display (device),
634 application_count);
635
636 for (i = 0; i < application_count; i++) {
637 g_autofree gchar *application_id_str = NULL;
638 g_autofree gchar *pin_key_references_str = NULL;
639
640 application_id_str = mbim_common_str_hex (applications[i]->application_id, applications[i]->application_id_size, ':');
641 pin_key_references_str = mbim_common_str_hex (applications[i]->pin_key_references, applications[i]->pin_key_references_size, ':');
642
643 g_print ("Application %u:%s\n", i, (i == active_application_index) ? " (active)" : "");
644 g_print ("\tApplication type: %s\n", mbim_uicc_application_type_get_string (applications[i]->application_type));
645 g_print ("\tApplication ID: %s\n", application_id_str);
646 g_print ("\tApplication name: %s\n", applications[i]->application_name);
647 g_print ("\tPIN key reference count: %u\n", applications[i]->pin_key_reference_count);
648 g_print ("\tPIN key references: %s\n", pin_key_references_str);
649 }
650
651 shutdown (TRUE);
652 }
653
654 static void
655 open_channel_ready (MbimDevice *device,
656 GAsyncResult *res)
657 {
658 g_autoptr(MbimMessage) response = NULL;
659 g_autoptr(GError) error = NULL;
660 guint32 status = 0;
661 guint32 channel = 0;
662 const guint8 *open_channel_response = NULL;
663 guint32 open_channel_response_size = 0;
664 g_autofree gchar *open_channel_response_str = NULL;
665
666 response = mbim_device_command_finish (device, res, &error);
667 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
668 g_printerr ("error: operation failed: %s\n", error->message);
669 shutdown (FALSE);
670 return;
671 }
672
673 if (!mbim_message_ms_uicc_low_level_access_open_channel_response_parse (
674 response,
675 &status,
676 &channel,
677 &open_channel_response_size,
678 &open_channel_response,
679 &error)) {
680 g_printerr ("error: couldn't parse response message: %s\n", error->message);
681 shutdown (FALSE);
682 return;
683 }
684
685 open_channel_response_str = mbim_common_str_hex (open_channel_response, open_channel_response_size, ':');
686 g_print ("Succesfully retrieved open channel info:\n"
687 "\t status: %u\n"
688 "\t channel: %u\n"
689 "\tresponse: %s\n",
690 status,
691 channel,
692 open_channel_response_str);
693
694 shutdown (TRUE);
695 }
696
697 typedef struct {
698 guint32 channel_group;
699 guint32 selectprg;
700 gsize application_id_size;
701 guint8 *application_id;
702 } OpenChannelProperties;
703
704 static void
705 open_channel_properties_clear (OpenChannelProperties *props)
706 {
707 g_clear_pointer (&props->application_id, g_free);
708 }
709
710 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(OpenChannelProperties, open_channel_properties_clear);
711
712 static gboolean
713 open_channel_properties_handle (const gchar *key,
714 const gchar *value,
715 GError **error,
716 gpointer user_data)
717 {
718 OpenChannelProperties *props = user_data;
719
720 if (g_ascii_strcasecmp (key, "application-id") == 0) {
721 g_clear_pointer (&props->application_id, g_free);
722 props->application_id_size = 0;
723 props->application_id = mbimcli_read_buffer_from_string (value, -1, &props->application_id_size, error);
724 if (!props->application_id)
725 return FALSE;
726 } else if (g_ascii_strcasecmp (key, "selectp2arg") == 0) {
727 if (!mbimcli_read_uint_from_string (value, &props->selectprg)) {
728 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
729 "Failed to parse selectp2arg field as an integer");
730 return FALSE;
731 }
732 } else if (g_ascii_strcasecmp (key, "channel-group") == 0) {
733 if (!mbimcli_read_uint_from_string (value, &props->channel_group)) {
734 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
735 "Failed to parse channel-group field as an integer");
736 return FALSE;
737 }
738 } else {
739 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
740 "unrecognized option '%s'", key);
741 return FALSE;
742 }
743
744 return TRUE;
745 }
746
747 static gboolean
748 open_channel_input_parse (const gchar *str,
749 OpenChannelProperties *props,
750 GError **error)
751 {
752 if (!mbimcli_parse_key_value_string (str,
753 error,
754 open_channel_properties_handle,
755 props))
756 return FALSE;
757
758 if (!props->application_id_size || !props->application_id) {
759 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
760 "Option 'application-id' is missing");
761 return FALSE;
762 }
763
764 return TRUE;
765 }
766
767 static void
768 close_channel_ready (MbimDevice *device,
769 GAsyncResult *res)
770 {
771 g_autoptr(MbimMessage) response = NULL;
772 g_autoptr(GError) error = NULL;
773 guint32 status = 0;
774
775 response = mbim_device_command_finish (device, res, &error);
776 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
777 g_printerr ("error: operation failed: %s\n", error->message);
778 shutdown (FALSE);
779 return;
780 }
781
782 if (!mbim_message_ms_uicc_low_level_access_close_channel_response_parse (
783 response,
784 &status,
785 &error)) {
786 g_printerr ("error: couldn't parse response message: %s\n", error->message);
787 shutdown (FALSE);
788 return;
789 }
790
791 g_print ("Succesfully retrieved close channel info:\n"
792 "\tstatus: %u\n", status);
793
794 shutdown (TRUE);
795 }
796
797 typedef struct {
798 guint32 channel;
799 guint32 channel_group;
800 } CloseChannelProperties;
801
802 static gboolean
803 close_channel_properties_handle (const gchar *key,
804 const gchar *value,
805 GError **error,
806 gpointer user_data)
807 {
808 CloseChannelProperties *props = user_data;
809
810 if (g_ascii_strcasecmp (key, "channel") == 0) {
811 if (!mbimcli_read_uint_from_string (value, &props->channel)) {
812 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
813 "Failed to parse channel field as an integer");
814 return FALSE;
815 }
816 } else if (g_ascii_strcasecmp (key, "channel-group") == 0) {
817 if (!mbimcli_read_uint_from_string (value, &props->channel_group)) {
818 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
819 "Failed to parse channel-group field as an integer");
820 return FALSE;
821 }
822 } else {
823 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
824 "unrecognized option '%s'", key);
825 return FALSE;
826 }
827
828 return TRUE;
829 }
830
831 static void
832 query_atr_ready (MbimDevice *device,
833 GAsyncResult *res)
834 {
835 g_autoptr(MbimMessage) response = NULL;
836 g_autoptr(GError) error = NULL;
837 const guint8 *atr = NULL;
838 g_autofree gchar *atr_buffer = NULL;
839 guint32 atr_size = 0;
840
841 response = mbim_device_command_finish (device, res, &error);
842 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
843 g_printerr ("error: operation failed: %s\n", error->message);
844 shutdown (FALSE);
845 return;
846 }
847
848 if (!mbim_message_ms_uicc_low_level_access_atr_response_parse (
849 response,
850 &atr_size,
851 &atr,
852 &error)) {
853 g_printerr ("error: couldn't parse response message: %s\n", error->message);
854 shutdown (FALSE);
855 return;
856 }
857
858 atr_buffer = mbim_common_str_hex (atr, atr_size, ':');
859 g_print ("Succesfully retrieved ATR info:\n"
860 "\tresponse: %s\n", atr_buffer);
861
862 shutdown (TRUE);
863 }
864
865 static void
866 set_apdu_ready (MbimDevice *device,
867 GAsyncResult *res)
868 {
869 g_autoptr(MbimMessage) response = NULL;
870 g_autoptr(GError) error = NULL;
871 guint32 status = 0;
872 const guint8 *apdu_response;
873 guint32 apdu_response_size = 0;
874 g_autofree gchar *apdu_response_str = NULL;
875
876 response = mbim_device_command_finish (device, res, &error);
877 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
878 g_printerr ("error: operation failed: %s\n", error->message);
879 shutdown (FALSE);
880 return;
881 }
882
883 if (!mbim_message_ms_uicc_low_level_access_apdu_response_parse (
884 response,
885 &status,
886 &apdu_response_size,
887 &apdu_response,
888 &error)) {
889 g_printerr ("error: couldn't parse response message: %s\n", error->message);
890 shutdown (FALSE);
891 return;
892 }
893
894 apdu_response_str = mbim_common_str_hex (apdu_response, apdu_response_size, ':');
895 g_print ("Succesfully retrieved UICC APDU response:\n"
896 "\t status: %u\n"
897 "\tresponse: %s\n",
898 status,
899 apdu_response_str);
900
901 shutdown (TRUE);
902 }
903
904 typedef struct {
905 MbimUiccSecureMessaging secure_messaging;
906 MbimUiccClassByteType class_byte_type;
907 guint32 channel;
908 gsize command_size;
909 guint8 *command;
910 } ApduProperties;
911
912 static void
913 apdu_properties_clear (ApduProperties *props)
914 {
915 g_clear_pointer (&props->command, g_free);
916 }
917
918 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ApduProperties, apdu_properties_clear);
919
920 static gboolean
921 apdu_properties_handle (const gchar *key,
922 const gchar *value,
923 GError **error,
924 gpointer user_data)
925 {
926 ApduProperties *props = user_data;
927
928 if (g_ascii_strcasecmp (key, "command") == 0) {
929 g_clear_pointer (&props->command, g_free);
930 props->command_size = 0;
931 props->command = mbimcli_read_buffer_from_string (value, -1, &props->command_size, error);
932 if (!props->command)
933 return FALSE;
934 } else if (g_ascii_strcasecmp (key, "secure-message") == 0) {
935 if (!mbimcli_read_uicc_secure_messaging_from_string (value, &props->secure_messaging, error)) {
936 return FALSE;
937 }
938 } else if (g_ascii_strcasecmp (key, "channel") == 0) {
939 if (!mbimcli_read_uint_from_string (value, &props->channel)) {
940 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
941 "Failed to parse channel field as an integer");
942 return FALSE;
943 }
944 } else if (g_ascii_strcasecmp (key, "classbyte-type") == 0) {
945 if (!mbimcli_read_uicc_class_byte_type_from_string (value, &props->class_byte_type, error)) {
946 return FALSE;
947 }
948 } else {
949 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
950 "unrecognized option '%s'", key);
951 return FALSE;
952 }
953
954 return TRUE;
955 }
956
957 static gboolean
958 apdu_input_parse (const gchar *str,
959 ApduProperties *props,
960 GError **error)
961 {
962 if (!mbimcli_parse_key_value_string (str,
963 error,
964 apdu_properties_handle,
965 props))
966 return FALSE;
967
968 if (!props->command_size || !props->command) {
969 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
970 "Option 'command' is missing");
971 return FALSE;
972 }
973
974 return TRUE;
975 }
976
977 static void
978 uicc_reset_ready (MbimDevice *device,
979 GAsyncResult *res)
980 {
981 g_autoptr(MbimMessage) response = NULL;
982 g_autoptr(GError) error = NULL;
983 MbimUiccPassThroughStatus pass_through_status;
984
985 response = mbim_device_command_finish (device, res, &error);
986 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
987 g_printerr ("error: operation failed: %s\n", error->message);
988 shutdown (FALSE);
989 return;
990 }
991
992 if (!mbim_message_ms_uicc_low_level_access_reset_response_parse (
993 response,
994 &pass_through_status,
995 &error)) {
996 g_printerr ("error: couldn't parse response message: %s\n", error->message);
997 shutdown (FALSE);
998 return;
999 }
1000
1001 g_print ("Succesfully retrieved reset info:\n"
1002 "\tpass through action: %s\n",
1003 mbim_uicc_pass_through_status_get_string (pass_through_status));
1004
1005 shutdown (TRUE);
1006 }
1007
1008 static void
1009 set_terminal_capability_ready (MbimDevice *device,
1010 GAsyncResult *res)
1011 {
1012 g_autoptr(MbimMessage) response = NULL;
1013 g_autoptr(GError) error = NULL;
1014
1015 response = mbim_device_command_finish (device, res, &error);
1016 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
1017 g_printerr ("error: operation failed: %s\n", error->message);
1018 shutdown (FALSE);
1019 return;
1020 }
1021
1022 g_print ("Succesfully set terminal capability info\n");
1023
1024 shutdown (TRUE);
1025 }
1026
1027 static void
1028 query_terminal_capability_ready (MbimDevice *device,
1029 GAsyncResult *res)
1030 {
1031 g_autoptr(MbimMessage) response = NULL;
1032 g_autoptr(GError) error = NULL;
1033 g_autoptr(MbimTerminalCapabilityInfoArray) terminal_capability = NULL;
1034 guint32 terminal_capability_count;
1035 guint32 i = 0;
1036
1037 response = mbim_device_command_finish (device, res, &error);
1038 if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
1039 g_printerr ("error: operation failed: %s\n", error->message);
1040 shutdown (FALSE);
1041 return;
1042 }
1043
1044 if (!mbim_message_ms_uicc_low_level_access_terminal_capability_response_parse (
1045 response,
1046 &terminal_capability_count,
1047 &terminal_capability,
1048 &error)) {
1049 g_printerr ("error: couldn't parse response message: %s\n", error->message);
1050 shutdown (FALSE);
1051 return;
1052 }
1053
1054 g_debug ("Successfully queried terminal capability information");
1055 g_print ("Terminal capability: (%u)\n", terminal_capability_count);
1056
1057 for (i = 0; i < terminal_capability_count; i++) {
1058 g_autofree gchar *terminal_caps = NULL;
1059 guint32 terminal_size = 0;
1060
1061 if (terminal_capability) {
1062 terminal_size = terminal_capability[i]->terminal_capability_data_size;
1063 terminal_caps = mbim_common_str_hex (terminal_capability[i]->terminal_capability_data, terminal_size, ':');
1064 } else {
1065 g_assert_not_reached ();
1066 }
1067
1068 g_print ("\t terminal capability count: %u\n", i);
1069 g_print ("\t terminal capability size : %u\n", terminal_size);
1070 g_print ("\t terminal capability : %s\n", VALIDATE_UNKNOWN (terminal_caps));
1071 }
1072
1073 shutdown (TRUE);
1074 }
1075
1076 typedef struct {
1077 GPtrArray *array;
1078 gchar *terminal_capability;
1079 } terminalcapabilityProperties;
1080
1081 static void
1082 mbim_terminal_capability_free (MbimTerminalCapabilityInfo *var)
1083 {
1084 if (!var)
1085 return;
1086
1087 g_free (var->terminal_capability_data);
1088 g_free (var);
1089 }
1090
1091 static void
1092 terminal_capability_properties_clear (terminalcapabilityProperties *props)
1093 {
1094 g_free(props->terminal_capability);
1095 g_ptr_array_unref (props->array);
1096 }
1097
1098 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(terminalcapabilityProperties, terminal_capability_properties_clear);
1099
1100 static gboolean
1101 check_terminal_add (terminalcapabilityProperties *props,
1102 GError **error)
1103 {
1104 MbimTerminalCapabilityInfo *terminal;
1105 g_autofree guint8 *terminal_capability = NULL;
1106 gsize terminal_capability_data_size = 0;
1107
1108 if (!props->terminal_capability) {
1109 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
1110 "Option 'Terminal Capability' is missing");
1111 return FALSE;
1112 }
1113
1114 terminal_capability = mbimcli_read_buffer_from_string (props->terminal_capability, -1, &terminal_capability_data_size, error);
1115 if (!terminal_capability)
1116 return FALSE;
1117
1118 terminal = g_new0 (MbimTerminalCapabilityInfo, 1);
1119 terminal->terminal_capability_data_size = terminal_capability_data_size;
1120 terminal->terminal_capability_data = g_steal_pointer (&terminal_capability);
1121 g_ptr_array_add (props->array, terminal);
1122
1123 g_clear_pointer (&props->terminal_capability, g_free);
1124
1125 return TRUE;
1126 }
1127
1128 static gboolean
1129 set_terminal_foreach_cb (const gchar *key,
1130 const gchar *value,
1131 GError **error,
1132 terminalcapabilityProperties *props)
1133 {
1134 if (g_ascii_strcasecmp (key, "terminal-capability") == 0) {
1135 if (props->terminal_capability) {
1136 if (!check_terminal_add (props, error))
1137 return FALSE;
1138 g_clear_pointer (&props->terminal_capability, g_free);
1139 }
1140 props->terminal_capability = g_strdup (value);
1141 } else {
1142 g_set_error (error, MBIM_CORE_ERROR, MBIM_CORE_ERROR_FAILED,
1143 "unrecognized option '%s'", key);
1144 return FALSE;
1145 }
1146
1147 return TRUE;
1148 }
1149
1150 static gboolean
1151 terminal_capability_parse (const gchar *str,
1152 terminalcapabilityProperties *props)
1153 {
1154 g_autoptr(GError) error = NULL;
1155
1156 if (!mbimcli_parse_key_value_string (str,
1157 &error,
1158 (MbimParseKeyValueForeachFn)set_terminal_foreach_cb,
1159 props)) {
1160 g_printerr ("error: couldn't parse input string: %s\n", error->message);
1161 shutdown (FALSE);
1162 return FALSE;
1163 }
1164
1165 if (props->terminal_capability && !check_terminal_add (props, &error)) {
1166 g_printerr ("error: failed to add last terminal item: %s\n", error->message);
1167 return FALSE;
1168 }
1169
1170 return TRUE;
1171 }
1172
1173 void
1174 mbimcli_ms_uicc_low_level_access_run (MbimDevice *device,
1175 GCancellable *cancellable)
1176 {
1177 g_autoptr(MbimMessage) request = NULL;
1178 g_autoptr(GError) error = NULL;
1179
1180 /* Initialize context */
1181 ctx = g_slice_new (Context);
1182 ctx->device = g_object_ref (device);
1183 ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
1184
1185 /* Request to query UICC application list? */
1186 if (query_uicc_application_list_flag) {
1187 g_debug ("Asynchronously querying UICC application list...");
1188 request = mbim_message_ms_uicc_low_level_access_application_list_query_new (NULL);
1189 mbim_device_command (ctx->device,
1190 request,
1191 10,
1192 ctx->cancellable,
1193 (GAsyncReadyCallback)application_list_query_ready,
1194 NULL);
1195 return;
1196 }
1197
1198 /* Request to query UICC file status? */
1199 if (query_uicc_file_status_str) {
1200 g_auto(FileStatusQueryProperties) props = {
1201 .application_id_size = 0,
1202 .application_id = NULL,
1203 .file_path_size = 0,
1204 .file_path = NULL,
1205 };
1206
1207 g_debug ("Asynchronously querying UICC file status...");
1208
1209 if (!file_status_query_input_parse (query_uicc_file_status_str, &props, &error)) {
1210 g_printerr ("error: couldn't parse input arguments: %s\n", error->message);
1211 shutdown (FALSE);
1212 return;
1213 }
1214
1215 request = mbim_message_ms_uicc_low_level_access_file_status_query_new (1, /* version fixed */
1216 props.application_id_size,
1217 props.application_id,
1218 props.file_path_size,
1219 props.file_path,
1220 NULL);
1221 mbim_device_command (ctx->device,
1222 request,
1223 10,
1224 ctx->cancellable,
1225 (GAsyncReadyCallback)file_status_query_ready,
1226 NULL);
1227 return;
1228 }
1229
1230 /* Request to UICC read binary? */
1231 if (query_uicc_read_binary_str) {
1232 g_auto(ReadBinaryQueryProperties) props = {
1233 .application_id_size = 0,
1234 .application_id = NULL,
1235 .file_path_size = 0,
1236 .file_path = NULL,
1237 .read_offset = 0,
1238 .read_size = 0,
1239 .local_pin = NULL,
1240 .data_size = 0,
1241 .data = NULL,
1242 };
1243
1244 g_debug ("Asynchronously reading from UICC in binary...");
1245
1246 if (!read_binary_query_input_parse (query_uicc_read_binary_str, &props, &error)) {
1247 g_printerr ("error: couldn't parse input arguments: %s\n", error->message);
1248 shutdown (FALSE);
1249 return;
1250 }
1251
1252 request = mbim_message_ms_uicc_low_level_access_read_binary_query_new (1, /* version fixed */
1253 props.application_id_size,
1254 props.application_id,
1255 props.file_path_size,
1256 props.file_path,
1257 props.read_offset,
1258 props.read_size,
1259 props.local_pin,
1260 props.data_size,
1261 props.data,
1262 NULL);
1263 mbim_device_command (ctx->device,
1264 request,
1265 10,
1266 ctx->cancellable,
1267 (GAsyncReadyCallback)read_binary_query_ready,
1268 NULL);
1269 return;
1270 }
1271
1272 /* Request to UICC read record? */
1273 if (query_uicc_read_record_str) {
1274 g_auto(ReadRecordQueryProperties) props = {
1275 .application_id_size = 0,
1276 .application_id = NULL,
1277 .file_path_size = 0,
1278 .file_path = NULL,
1279 .record_number = 0,
1280 .local_pin = NULL,
1281 .data_size = 0,
1282 .data = NULL,
1283 };
1284
1285 g_debug ("Asynchronously reading from UICC record...");
1286
1287 if (!read_record_query_input_parse (query_uicc_read_record_str, &props, &error)) {
1288 g_printerr ("error: couldn't parse input arguments: %s\n", error->message);
1289 shutdown (FALSE);
1290 return;
1291 }
1292
1293 request = mbim_message_ms_uicc_low_level_access_read_record_query_new (1, /* version fixed */
1294 props.application_id_size,
1295 props.application_id,
1296 props.file_path_size,
1297 props.file_path,
1298 props.record_number,
1299 props.local_pin,
1300 props.data_size,
1301 props.data,
1302 NULL);
1303 mbim_device_command (ctx->device,
1304 request,
1305 10,
1306 ctx->cancellable,
1307 (GAsyncReadyCallback)read_record_query_ready,
1308 NULL);
1309 return;
1310 }
1311
1312 /* Request to Set UICC open channel */
1313 if (set_uicc_open_channel_str) {
1314 g_auto(OpenChannelProperties) props = {
1315 .application_id_size = 0,
1316 .application_id = NULL,
1317 .selectprg = 0,
1318 .channel_group = 0,
1319 };
1320
1321 if (!open_channel_input_parse (set_uicc_open_channel_str, &props, &error)) {
1322 g_printerr ("error: couldn't parse input arguments: %s\n", error->message);
1323 shutdown (FALSE);
1324 return;
1325 }
1326
1327 g_debug ("Asynchronously setting UICC open channel.");
1328 request = mbim_message_ms_uicc_low_level_access_open_channel_set_new (props.application_id_size,
1329 props.application_id,
1330 props.selectprg,
1331 props.channel_group,
1332 &error);
1333 if (!request) {
1334 g_printerr ("error: couldn't create open channel Request %s\n", error->message);
1335 shutdown (FALSE);
1336 return;
1337 }
1338
1339 mbim_device_command (ctx->device,
1340 request,
1341 30,
1342 ctx->cancellable,
1343 (GAsyncReadyCallback)open_channel_ready,
1344 NULL);
1345 return;
1346 }
1347
1348 /* Request to Set UICC close channel */
1349 if (set_uicc_close_channel_str) {
1350 CloseChannelProperties props = {
1351 .channel = 0,
1352 .channel_group = 0,
1353 };
1354
1355 if (!mbimcli_parse_key_value_string (set_uicc_close_channel_str,
1356 &error,
1357 close_channel_properties_handle,
1358 &props)) {
1359 g_printerr ("error: couldn't parse input arguments: %s\n", error->message);
1360 shutdown (FALSE);
1361 return;
1362 }
1363
1364 g_debug ("Asynchronously setting UICC close channel...");
1365 request = mbim_message_ms_uicc_low_level_access_close_channel_set_new (props.channel,
1366 props.channel_group,
1367 &error);
1368 if (!request) {
1369 g_printerr ("error: couldn't create close channel request %s\n", error->message);
1370 shutdown (FALSE);
1371 return;
1372 }
1373
1374 mbim_device_command (ctx->device,
1375 request,
1376 30,
1377 ctx->cancellable,
1378 (GAsyncReadyCallback)close_channel_ready,
1379 NULL);
1380 return;
1381 }
1382
1383 /* Request to UICC atr? */
1384 if (query_uicc_atr_flag) {
1385 g_debug ("Asynchronously querying UICC atr Info...");
1386 request = mbim_message_ms_uicc_low_level_access_atr_query_new (NULL);
1387 mbim_device_command (ctx->device,
1388 request,
1389 10,
1390 ctx->cancellable,
1391 (GAsyncReadyCallback)query_atr_ready,
1392 NULL);
1393 return;
1394 }
1395
1396 /* Request to set UICC Apdu */
1397 if (set_uicc_apdu_str) {
1398 g_auto(ApduProperties) props = {
1399 .secure_messaging = MBIM_UICC_SECURE_MESSAGING_NONE,
1400 .class_byte_type = MBIM_UICC_CLASS_BYTE_TYPE_INTER_INDUSTRY,
1401 .channel = 0,
1402 .command_size = 0,
1403 .command = NULL,
1404 };
1405
1406 if (!apdu_input_parse (set_uicc_apdu_str, &props, &error)) {
1407 g_printerr ("error: couldn't parse input arguments: %s\n", error->message);
1408 shutdown (FALSE);
1409 return;
1410 }
1411
1412 g_debug ("Asynchronously sending UICC set apdu command.");
1413 request = mbim_message_ms_uicc_low_level_access_apdu_set_new (props.channel,
1414 props.secure_messaging,
1415 props.class_byte_type,
1416 props.command_size,
1417 props.command,
1418 &error);
1419 if (!request) {
1420 g_printerr ("error: couldn't create APDU request %s\n", error->message);
1421 shutdown (FALSE);
1422 return;
1423 }
1424
1425 mbim_device_command (ctx->device,
1426 request,
1427 30,
1428 ctx->cancellable,
1429 (GAsyncReadyCallback)set_apdu_ready,
1430 NULL);
1431 return;
1432 }
1433
1434 /* Request to set UICC reset */
1435 if (set_uicc_reset_str) {
1436 MbimUiccPassThroughAction pass_through_action;
1437
1438 if(!mbimcli_read_uicc_pass_through_action_from_string (set_uicc_reset_str, &pass_through_action, &error)) {
1439 g_printerr ("error: couldn't parse pass-through action: %s\n", error->message);
1440 shutdown (FALSE);
1441 return;
1442 }
1443
1444 request = mbim_message_ms_uicc_low_level_access_reset_set_new (pass_through_action, &error);
1445 if (!request) {
1446 g_printerr ("error: couldn't create Reset request %s\n", error->message);
1447 shutdown (FALSE);
1448 return;
1449 }
1450
1451 mbim_device_command (ctx->device,
1452 request,
1453 30,
1454 ctx->cancellable,
1455 (GAsyncReadyCallback)uicc_reset_ready,
1456 NULL);
1457 return;
1458 }
1459
1460 /* Request to query UICC reset */
1461 if (query_uicc_reset_flag) {
1462 g_debug ("Asynchronously querying UICC reset...");
1463 request = mbim_message_ms_uicc_low_level_access_reset_query_new (NULL);
1464 mbim_device_command (ctx->device,
1465 request,
1466 30,
1467 ctx->cancellable,
1468 (GAsyncReadyCallback)uicc_reset_ready,
1469 NULL);
1470 return;
1471 }
1472
1473 /* Request to set UICC terminal capability */
1474 if (set_uicc_terminal_capability_str) {
1475 g_auto(terminalcapabilityProperties) props = {NULL, NULL};
1476
1477 props.array = g_ptr_array_new_with_free_func ((GDestroyNotify)mbim_terminal_capability_free);
1478 if (!terminal_capability_parse (set_uicc_terminal_capability_str, &props)) {
1479 shutdown (FALSE);
1480 return;
1481 }
1482
1483 g_debug ("Asynchronously set UICC terminal capability.");
1484 request = mbim_message_ms_uicc_low_level_access_terminal_capability_set_new ((guint32)props.array->len,
1485 (const MbimTerminalCapabilityInfo *const *)props.array->pdata,
1486 &error);
1487 if (!request) {
1488 g_printerr ("error: couldn't create Terminal Capability request %s\n", error->message);
1489 shutdown (FALSE);
1490 return;
1491 }
1492
1493 mbim_device_command (ctx->device,
1494 request,
1495 30,
1496 ctx->cancellable,
1497 (GAsyncReadyCallback)set_terminal_capability_ready,
1498 NULL);
1499 return;
1500 }
1501
1502 /* Request to query UICC terminal capability */
1503 if (query_uicc_terminal_capability_flag) {
1504 g_debug ("Asynchronously querying UICC terminal capability...");
1505 request = mbim_message_ms_uicc_low_level_access_terminal_capability_query_new (NULL);
1506 mbim_device_command (ctx->device,
1507 request,
1508 10,
1509 ctx->cancellable,
1510 (GAsyncReadyCallback)query_terminal_capability_ready,
1511 NULL);
1512 return;
1513 }
1514
1515 g_warn_if_reached ();
1516 }