1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* qmicli -- Command line interface to control QMI devices
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2013-2017 Aleksander Morgado <aleksander@aleksander.es>
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <libqmi-glib.h>
#include "qmicli.h"
/* Context */
typedef struct {
QmiDevice *device;
QmiClientPbm *client;
GCancellable *cancellable;
} Context;
static Context *ctx;
/* Options */
static gboolean get_all_capabilities_flag;
static gboolean noop_flag;
static GOptionEntry entries[] = {
{ "pbm-get-all-capabilities", 0, 0, G_OPTION_ARG_NONE, &get_all_capabilities_flag,
"Get all phonebook capabilities",
NULL
},
{ "pbm-noop", 0, 0, G_OPTION_ARG_NONE, &noop_flag,
"Just allocate or release a PBM client. Use with `--client-no-release-cid' and/or `--client-cid'",
NULL
},
{ NULL }
};
GOptionGroup *
qmicli_pbm_get_option_group (void)
{
GOptionGroup *group;
group = g_option_group_new ("pbm",
"PBM options",
"Show Phonebook Management options",
NULL,
NULL);
g_option_group_add_entries (group, entries);
return group;
}
gboolean
qmicli_pbm_options_enabled (void)
{
static guint n_actions = 0;
static gboolean checked = FALSE;
if (checked)
return !!n_actions;
n_actions = (get_all_capabilities_flag +
noop_flag);
if (n_actions > 1) {
g_printerr ("error: too many PBM actions requested\n");
exit (EXIT_FAILURE);
}
checked = TRUE;
return !!n_actions;
}
static void
context_free (Context *context)
{
if (!context)
return;
if (context->client)
g_object_unref (context->client);
g_object_unref (context->cancellable);
g_object_unref (context->device);
g_slice_free (Context, context);
}
static void
operation_shutdown (gboolean operation_status)
{
/* Cleanup context and finish async operation */
context_free (ctx);
qmicli_async_operation_done (operation_status, FALSE);
}
static void
get_all_capabilities_ready (QmiClientPbm *client,
GAsyncResult *res)
{
GError *error = NULL;
QmiMessagePbmGetAllCapabilitiesOutput *output;
GArray *capability_basic_information = NULL;
GArray *group_capability = NULL;
GArray *additional_number_capability = NULL;
GArray *email_capability = NULL;
GArray *second_name_capability = NULL;
GArray *hidden_records_capability = NULL;
GArray *grouping_information_alpha_string_capability = NULL;
GArray *additional_number_alpha_string_capability = NULL;
guint i, j;
output = qmi_client_pbm_get_all_capabilities_finish (client, res, &error);
if (!output) {
g_printerr ("error: operation failed: %s\n",
error->message);
g_error_free (error);
operation_shutdown (FALSE);
return;
}
if (!qmi_message_pbm_get_all_capabilities_output_get_result (output, &error)) {
g_printerr ("error: couldn't get capabilities: %s\n", error->message);
g_error_free (error);
qmi_message_pbm_get_all_capabilities_output_unref (output);
operation_shutdown (FALSE);
return;
}
qmi_message_pbm_get_all_capabilities_output_get_capability_basic_information (output, &capability_basic_information, NULL);
qmi_message_pbm_get_all_capabilities_output_get_group_capability (output, &group_capability, NULL);
qmi_message_pbm_get_all_capabilities_output_get_additional_number_capability (output, &additional_number_capability, NULL);
qmi_message_pbm_get_all_capabilities_output_get_email_capability (output, &email_capability, NULL);
qmi_message_pbm_get_all_capabilities_output_get_second_name_capability (output, &second_name_capability, NULL);
qmi_message_pbm_get_all_capabilities_output_get_hidden_records_capability (output, &hidden_records_capability, NULL);
qmi_message_pbm_get_all_capabilities_output_get_grouping_information_alpha_string_capability (output, &grouping_information_alpha_string_capability, NULL);
qmi_message_pbm_get_all_capabilities_output_get_additional_number_alpha_string_capability (output, &additional_number_alpha_string_capability, NULL);
g_print ("[%s] Phonebook capabilities:%s\n",
qmi_device_get_path_display (ctx->device),
(capability_basic_information ||
group_capability ||
additional_number_capability ||
email_capability ||
second_name_capability ||
hidden_records_capability ||
grouping_information_alpha_string_capability ||
additional_number_alpha_string_capability) ? "" : " none");
if (capability_basic_information) {
g_print ("Capability basic information:\n");
for (i = 0; i < capability_basic_information->len; i++) {
QmiMessagePbmGetAllCapabilitiesOutputCapabilityBasicInformationElement *session;
session = &g_array_index (capability_basic_information,
QmiMessagePbmGetAllCapabilitiesOutputCapabilityBasicInformationElement,
i);
g_print ("\t[%s]:\n", qmi_pbm_session_type_get_string (session->session_type));
for (j = 0; j < session->phonebooks->len; j++) {
QmiMessagePbmGetAllCapabilitiesOutputCapabilityBasicInformationElementPhonebooksElement *phonebook;
gchar *phonebook_type_str;
phonebook = &g_array_index (session->phonebooks,
QmiMessagePbmGetAllCapabilitiesOutputCapabilityBasicInformationElementPhonebooksElement,
j);
phonebook_type_str = qmi_pbm_phonebook_type_build_string_from_mask (phonebook->phonebook_type);
g_print ("\t\t[%s]:\n", phonebook_type_str);
g_print ("\t\t\tUsed records: %" G_GUINT16_FORMAT "\n", phonebook->used_records);
g_print ("\t\t\tMaximum records: %" G_GUINT16_FORMAT "\n", phonebook->maximum_records);
g_print ("\t\t\tMaximum number length: %u\n", phonebook->maximum_number_length);
g_print ("\t\t\tMaximum name length: %u\n", phonebook->maximum_name_length);
g_free (phonebook_type_str);
}
}
}
if (group_capability) {
g_print ("Group capability:\n");
for (i = 0; i < group_capability->len; i++) {
QmiMessagePbmGetAllCapabilitiesOutputGroupCapabilityElement *session;
session = &g_array_index (group_capability,
QmiMessagePbmGetAllCapabilitiesOutputGroupCapabilityElement,
i);
g_print ("\t[%s]:\n", qmi_pbm_session_type_get_string (session->session_type));
g_print ("\t\tMaximum groups: %u\n", session->maximum_groups);
g_print ("\t\tMaximum group tag length: %u\n", session->maximum_group_tag_length);
}
}
if (additional_number_capability) {
g_print ("Additional number capability:\n");
for (i = 0; i < additional_number_capability->len; i++) {
QmiMessagePbmGetAllCapabilitiesOutputAdditionalNumberCapabilityElement *session;
session = &g_array_index (additional_number_capability,
QmiMessagePbmGetAllCapabilitiesOutputAdditionalNumberCapabilityElement,
i);
g_print ("\t[%s]:\n", qmi_pbm_session_type_get_string (session->session_type));
g_print ("\t\tMaximum additional numbers: %u\n", session->maximum_additional_numbers);
g_print ("\t\tMaximum additional number length: %u\n", session->maximum_additional_number_length);
g_print ("\t\tMaximum additional number tag length: %u\n", session->maximum_additional_number_tag_length);
}
}
if (email_capability) {
g_print ("Email capability:\n");
for (i = 0; i < email_capability->len; i++) {
QmiMessagePbmGetAllCapabilitiesOutputEmailCapabilityElement *session;
session = &g_array_index (email_capability,
QmiMessagePbmGetAllCapabilitiesOutputEmailCapabilityElement,
i);
g_print ("\t[%s]:\n", qmi_pbm_session_type_get_string (session->session_type));
g_print ("\t\tMaximum emails: %u\n", session->maximum_emails);
g_print ("\t\tMaximum email address length: %u\n", session->maximum_email_address_length);
}
}
if (second_name_capability) {
g_print ("Second name capability:\n");
for (i = 0; i < second_name_capability->len; i++) {
QmiMessagePbmGetAllCapabilitiesOutputSecondNameCapabilityElement *session;
session = &g_array_index (second_name_capability,
QmiMessagePbmGetAllCapabilitiesOutputSecondNameCapabilityElement,
i);
g_print ("\t[%s]:\n", qmi_pbm_session_type_get_string (session->session_type));
g_print ("\t\tMaximum second name length: %u\n", session->maximum_second_name_length);
}
}
if (hidden_records_capability) {
g_print ("Hidden records capability:\n");
for (i = 0; i < hidden_records_capability->len; i++) {
QmiMessagePbmGetAllCapabilitiesOutputHiddenRecordsCapabilityElement *session;
session = &g_array_index (hidden_records_capability,
QmiMessagePbmGetAllCapabilitiesOutputHiddenRecordsCapabilityElement,
i);
g_print ("\t[%s]:\n", qmi_pbm_session_type_get_string (session->session_type));
g_print ("\t\tSupported: %s\n", session->supported ? "yes" : "no");
}
}
if (grouping_information_alpha_string_capability) {
g_print ("Alpha string capability:\n");
for (i = 0; i < grouping_information_alpha_string_capability->len; i++) {
QmiMessagePbmGetAllCapabilitiesOutputGroupingInformationAlphaStringCapabilityElement *session;
session = &g_array_index (grouping_information_alpha_string_capability,
QmiMessagePbmGetAllCapabilitiesOutputGroupingInformationAlphaStringCapabilityElement,
i);
g_print ("\t[%s]:\n", qmi_pbm_session_type_get_string (session->session_type));
g_print ("\t\tMaximum records: %u\n", session->maximum_records);
g_print ("\t\tUsed records: %u\n", session->used_records);
g_print ("\t\tMaximum string length: %u\n", session->maximum_string_length);
}
}
if (additional_number_alpha_string_capability) {
g_print ("Additional number alpha string capability:\n");
for (i = 0; i < additional_number_alpha_string_capability->len; i++) {
QmiMessagePbmGetAllCapabilitiesOutputAdditionalNumberAlphaStringCapabilityElement *session;
session = &g_array_index (additional_number_alpha_string_capability,
QmiMessagePbmGetAllCapabilitiesOutputAdditionalNumberAlphaStringCapabilityElement,
i);
g_print ("\t[%s]:\n", qmi_pbm_session_type_get_string (session->session_type));
g_print ("\t\tMaximum records: %u\n", session->maximum_records);
g_print ("\t\tUsed records: %u\n", session->used_records);
g_print ("\t\tMaximum string length: %u\n", session->maximum_string_length);
}
}
qmi_message_pbm_get_all_capabilities_output_unref (output);
operation_shutdown (TRUE);
}
static gboolean
noop_cb (gpointer unused)
{
operation_shutdown (TRUE);
return FALSE;
}
void
qmicli_pbm_run (QmiDevice *device,
QmiClientPbm *client,
GCancellable *cancellable)
{
/* Initialize context */
ctx = g_slice_new (Context);
ctx->device = g_object_ref (device);
ctx->client = g_object_ref (client);
ctx->cancellable = g_object_ref (cancellable);
/* Request to get all capabilities? */
if (get_all_capabilities_flag) {
g_debug ("Asynchronously getting phonebook capabilities...");
qmi_client_pbm_get_all_capabilities (ctx->client,
NULL,
10,
ctx->cancellable,
(GAsyncReadyCallback)get_all_capabilities_ready,
NULL);
return;
}
/* Just client allocate/release? */
if (noop_flag) {
g_idle_add (noop_cb, NULL);
return;
}
g_warn_if_reached ();
}
|