| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* qmicli -- Command line interface to control QMI devices |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* Copyright (C) 2014-2017 Aleksander Morgado <[email protected]> |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include <stdio.h> |
| 24 |
#include <stdlib.h> |
| 25 |
#include <locale.h> |
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
#include <glib.h> |
| 29 |
#include <gio/gio.h> |
| 30 |
|
| 31 |
#include <libqmi-glib.h> |
| 32 |
|
| 33 |
#include "qmicli.h" |
| 34 |
#include "qmicli-helpers.h" |
| 35 |
|
| 36 |
#if defined HAVE_QMI_SERVICE_VOICE |
| 37 |
|
| 38 |
#undef VALIDATE_MASK_NONE |
| 39 |
#define VALIDATE_MASK_NONE(str) (str ? str : "none") |
| 40 |
|
| 41 |
/* Context */ |
| 42 |
typedef struct { |
| 43 |
QmiDevice *device; |
| 44 |
QmiClientVoice *client; |
| 45 |
GCancellable *cancellable; |
| 46 |
} Context; |
| 47 |
static Context *ctx; |
| 48 |
|
| 49 |
/* Options */ |
| 50 |
static gboolean get_config_flag; |
| 51 |
static gboolean get_supported_messages_flag; |
| 52 |
static gboolean noop_flag; |
| 53 |
|
| 54 |
static GOptionEntry entries[] = { |
| 55 |
#if defined HAVE_QMI_MESSAGE_VOICE_GET_CONFIG |
| 56 |
{ "voice-get-config", 0, 0, G_OPTION_ARG_NONE, &get_config_flag, |
| 57 |
"Get Voice service configuration", |
| 58 |
NULL |
| 59 |
}, |
| 60 |
#endif |
| 61 |
#if defined HAVE_QMI_MESSAGE_VOICE_GET_SUPPORTED_MESSAGES |
| 62 |
{ "voice-get-supported-messages", 0, 0, G_OPTION_ARG_NONE, &get_supported_messages_flag, |
| 63 |
"Get supported messages", |
| 64 |
NULL |
| 65 |
}, |
| 66 |
#endif |
| 67 |
{ "voice-noop", 0, 0, G_OPTION_ARG_NONE, &noop_flag, |
| 68 |
"Just allocate or release a VOICE client. Use with `--client-no-release-cid' and/or `--client-cid'", |
| 69 |
NULL |
| 70 |
}, |
| 71 |
{ NULL, 0, 0, 0, NULL, NULL, NULL } |
| 72 |
}; |
| 73 |
|
| 74 |
GOptionGroup * |
| 75 |
qmicli_voice_get_option_group (void) |
| 76 |
{ |
| 77 |
GOptionGroup *group; |
| 78 |
|
| 79 |
group = g_option_group_new ("voice", |
| 80 |
"VOICE options:", |
| 81 |
"Show Voice Service options", |
| 82 |
NULL, |
| 83 |
NULL); |
| 84 |
g_option_group_add_entries (group, entries); |
| 85 |
|
| 86 |
return group; |
| 87 |
} |
| 88 |
|
| 89 |
gboolean |
| 90 |
qmicli_voice_options_enabled (void) |
| 91 |
{ |
| 92 |
static guint n_actions = 0; |
| 93 |
static gboolean checked = FALSE; |
| 94 |
|
| 95 |
if (checked) |
| 96 |
return !!n_actions; |
| 97 |
|
| 98 |
n_actions = (get_config_flag + |
| 99 |
get_supported_messages_flag + |
| 100 |
noop_flag); |
| 101 |
|
| 102 |
if (n_actions > 1) { |
| 103 |
g_printerr ("error: too many VOICE actions requested\n"); |
| 104 |
exit (EXIT_FAILURE); |
| 105 |
} |
| 106 |
|
| 107 |
checked = TRUE; |
| 108 |
return !!n_actions; |
| 109 |
} |
| 110 |
|
| 111 |
static void |
| 112 |
context_free (Context *context) |
| 113 |
{ |
| 114 |
if (!context) |
| 115 |
return; |
| 116 |
|
| 117 |
if (context->client) |
| 118 |
g_object_unref (context->client); |
| 119 |
g_object_unref (context->cancellable); |
| 120 |
g_object_unref (context->device); |
| 121 |
g_slice_free (Context, context); |
| 122 |
} |
| 123 |
|
| 124 |
static void |
| 125 |
operation_shutdown (gboolean operation_status) |
| 126 |
{ |
| 127 |
/* Cleanup context and finish async operation */ |
| 128 |
context_free (ctx); |
| 129 |
qmicli_async_operation_done (operation_status, FALSE); |
| 130 |
} |
| 131 |
|
| 132 |
#if defined HAVE_QMI_MESSAGE_VOICE_GET_CONFIG |
| 133 |
|
| 134 |
static void |
| 135 |
get_config_ready (QmiClientVoice *client, |
| 136 |
GAsyncResult *res) |
| 137 |
{ |
| 138 |
QmiMessageVoiceGetConfigOutput *output; |
| 139 |
GError *error = NULL; |
| 140 |
QmiVoiceDomain current_voice_domain_preference; |
| 141 |
QmiVoicePrivacy current_voice_privacy_preference; |
| 142 |
gboolean current_amr_status_gsm; |
| 143 |
QmiVoiceWcdmaAmrStatus current_amr_status_wcdma; |
| 144 |
guint8 current_preferred_voice_so_nam_id; |
| 145 |
gboolean current_preferred_voice_so_evrc_capability; |
| 146 |
QmiVoiceServiceOption current_preferred_voice_so_home_page_voice_service_option; |
| 147 |
QmiVoiceServiceOption current_preferred_voice_so_home_origination_voice_service_option; |
| 148 |
QmiVoiceServiceOption current_preferred_voice_so_roaming_origination_voice_service_option; |
| 149 |
QmiVoiceTtyMode current_tty_mode; |
| 150 |
guint8 roam_timer_count_nam_id; |
| 151 |
guint32 roam_timer_count_roam_timer; |
| 152 |
guint8 air_timer_count_nam_id; |
| 153 |
guint32 air_timer_count_air_timer; |
| 154 |
gboolean auto_answer_status; |
| 155 |
|
| 156 |
output = qmi_client_voice_get_config_finish (client, res, &error); |
| 157 |
if (!output) { |
| 158 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 159 |
g_error_free (error); |
| 160 |
operation_shutdown (FALSE); |
| 161 |
return; |
| 162 |
} |
| 163 |
|
| 164 |
if (!qmi_message_voice_get_config_output_get_result (output, &error)) { |
| 165 |
g_printerr ("error: couldn't get Voice configuration: %s\n", error->message); |
| 166 |
g_error_free (error); |
| 167 |
qmi_message_voice_get_config_output_unref (output); |
| 168 |
operation_shutdown (FALSE); |
| 169 |
return; |
| 170 |
} |
| 171 |
|
| 172 |
g_print ("[%s] Successfully retrieved Voice configuration:\n", |
| 173 |
qmi_device_get_path_display (ctx->device)); |
| 174 |
|
| 175 |
if (qmi_message_voice_get_config_output_get_auto_answer_status ( |
| 176 |
output, |
| 177 |
&auto_answer_status, |
| 178 |
NULL)) |
| 179 |
g_print ("Auto Answer Status: '%s'", |
| 180 |
auto_answer_status ? "enabled" : "disabled"); |
| 181 |
|
| 182 |
if (qmi_message_voice_get_config_output_get_air_timer_count ( |
| 183 |
output, |
| 184 |
&air_timer_count_nam_id, |
| 185 |
&air_timer_count_air_timer, |
| 186 |
NULL)) |
| 187 |
g_print ("Air Timer Count:\n" |
| 188 |
"\tNAM ID: '%u'" |
| 189 |
"\tTimer: '%u'", |
| 190 |
air_timer_count_nam_id, |
| 191 |
air_timer_count_air_timer); |
| 192 |
|
| 193 |
if (qmi_message_voice_get_config_output_get_roam_timer_count ( |
| 194 |
output, |
| 195 |
&roam_timer_count_nam_id, |
| 196 |
&roam_timer_count_roam_timer, |
| 197 |
NULL)) |
| 198 |
g_print ("Roam Timer Count:\n" |
| 199 |
"\tNAM ID: '%u'" |
| 200 |
"\tTimer: '%u'", |
| 201 |
roam_timer_count_nam_id, |
| 202 |
roam_timer_count_roam_timer); |
| 203 |
|
| 204 |
if (qmi_message_voice_get_config_output_get_current_tty_mode ( |
| 205 |
output, |
| 206 |
¤t_tty_mode, |
| 207 |
NULL)) |
| 208 |
g_print ("Current TTY mode: '%s'", |
| 209 |
qmi_voice_tty_mode_get_string (current_tty_mode)); |
| 210 |
|
| 211 |
if (qmi_message_voice_get_config_output_get_current_preferred_voice_so ( |
| 212 |
output, |
| 213 |
¤t_preferred_voice_so_nam_id, |
| 214 |
¤t_preferred_voice_so_evrc_capability, |
| 215 |
¤t_preferred_voice_so_home_page_voice_service_option, |
| 216 |
¤t_preferred_voice_so_home_origination_voice_service_option, |
| 217 |
¤t_preferred_voice_so_roaming_origination_voice_service_option, |
| 218 |
NULL)) { |
| 219 |
g_print ("Current Preferred Voice SO:\n" |
| 220 |
"\tNAM ID: '%u'\n" |
| 221 |
"\tEVRC capability: '%s'\n" |
| 222 |
"\tHome Page Voice SO: '%s'\n" |
| 223 |
"\tHome Origination Voice SO: '%s'\n" |
| 224 |
"\tRoaming Origination Voice SO: '%s'\n", |
| 225 |
current_preferred_voice_so_nam_id, |
| 226 |
current_preferred_voice_so_evrc_capability ? "enabled" : "disabled", |
| 227 |
qmi_voice_service_option_get_string (current_preferred_voice_so_home_page_voice_service_option), |
| 228 |
qmi_voice_service_option_get_string (current_preferred_voice_so_home_origination_voice_service_option), |
| 229 |
qmi_voice_service_option_get_string (current_preferred_voice_so_roaming_origination_voice_service_option)); |
| 230 |
} |
| 231 |
|
| 232 |
if (qmi_message_voice_get_config_output_get_current_amr_status ( |
| 233 |
output, |
| 234 |
¤t_amr_status_gsm, ¤t_amr_status_wcdma, |
| 235 |
NULL)) { |
| 236 |
gchar *current_amr_status_wcdma_str; |
| 237 |
|
| 238 |
current_amr_status_wcdma_str = qmi_voice_wcdma_amr_status_build_string_from_mask (current_amr_status_wcdma); |
| 239 |
g_print ("AMR Status:\n" |
| 240 |
"\tGSM: '%s'\n" |
| 241 |
"\tWCDMA: '%s' (0x%04X)\n", |
| 242 |
current_amr_status_gsm ? "enabled" : "disabled", |
| 243 |
VALIDATE_MASK_NONE (current_amr_status_wcdma_str), |
| 244 |
current_amr_status_wcdma); |
| 245 |
g_free (current_amr_status_wcdma_str); |
| 246 |
} |
| 247 |
|
| 248 |
if (qmi_message_voice_get_config_output_get_current_voice_privacy_preference ( |
| 249 |
output, |
| 250 |
¤t_voice_privacy_preference, |
| 251 |
NULL)) |
| 252 |
g_print ("Current Voice Privacy Preference: '%s'\n", |
| 253 |
qmi_voice_privacy_get_string (current_voice_privacy_preference)); |
| 254 |
|
| 255 |
if (qmi_message_voice_get_config_output_get_current_voice_domain_preference ( |
| 256 |
output, |
| 257 |
¤t_voice_domain_preference, |
| 258 |
NULL)) |
| 259 |
g_print ("Current Voice Domain Preference: '%s'\n", |
| 260 |
qmi_voice_domain_get_string (current_voice_domain_preference)); |
| 261 |
|
| 262 |
qmi_message_voice_get_config_output_unref (output); |
| 263 |
operation_shutdown (TRUE); |
| 264 |
} |
| 265 |
|
| 266 |
#endif /* HAVE_QMI_MESSAGE_VOICE_GET_CONFIG */ |
| 267 |
|
| 268 |
#if defined HAVE_QMI_MESSAGE_VOICE_GET_SUPPORTED_MESSAGES |
| 269 |
|
| 270 |
static void |
| 271 |
get_supported_messages_ready (QmiClientVoice *client, |
| 272 |
GAsyncResult *res) |
| 273 |
{ |
| 274 |
QmiMessageVoiceGetSupportedMessagesOutput *output; |
| 275 |
GError *error = NULL; |
| 276 |
GArray *bytearray = NULL; |
| 277 |
gchar *str; |
| 278 |
|
| 279 |
output = qmi_client_voice_get_supported_messages_finish (client, res, &error); |
| 280 |
if (!output) { |
| 281 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 282 |
g_error_free (error); |
| 283 |
operation_shutdown (FALSE); |
| 284 |
return; |
| 285 |
} |
| 286 |
|
| 287 |
if (!qmi_message_voice_get_supported_messages_output_get_result (output, &error)) { |
| 288 |
g_printerr ("error: couldn't get supported VOICE messages: %s\n", error->message); |
| 289 |
g_error_free (error); |
| 290 |
qmi_message_voice_get_supported_messages_output_unref (output); |
| 291 |
operation_shutdown (FALSE); |
| 292 |
return; |
| 293 |
} |
| 294 |
|
| 295 |
g_print ("[%s] Successfully got supported VOICE messages:\n", |
| 296 |
qmi_device_get_path_display (ctx->device)); |
| 297 |
|
| 298 |
qmi_message_voice_get_supported_messages_output_get_list (output, &bytearray, NULL); |
| 299 |
str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL, |
| 300 |
bytearray ? bytearray->len : 0); |
| 301 |
g_print ("%s", str); |
| 302 |
g_free (str); |
| 303 |
|
| 304 |
qmi_message_voice_get_supported_messages_output_unref (output); |
| 305 |
operation_shutdown (TRUE); |
| 306 |
} |
| 307 |
|
| 308 |
#endif /* HAVE_QMI_MESSAGE_VOICE_GET_SUPPORTED_MESSAGES */ |
| 309 |
|
| 310 |
static gboolean |
| 311 |
noop_cb (gpointer unused) |
| 312 |
{ |
| 313 |
operation_shutdown (TRUE); |
| 314 |
return FALSE; |
| 315 |
} |
| 316 |
|
| 317 |
void |
| 318 |
qmicli_voice_run (QmiDevice *device, |
| 319 |
QmiClientVoice *client, |
| 320 |
GCancellable *cancellable) |
| 321 |
{ |
| 322 |
/* Initialize context */ |
| 323 |
ctx = g_slice_new (Context); |
| 324 |
ctx->device = g_object_ref (device); |
| 325 |
ctx->client = g_object_ref (client); |
| 326 |
ctx->cancellable = g_object_ref (cancellable); |
| 327 |
|
| 328 |
#if defined HAVE_QMI_MESSAGE_VOICE_GET_CONFIG |
| 329 |
if (get_config_flag) { |
| 330 |
QmiMessageVoiceGetConfigInput *input; |
| 331 |
|
| 332 |
input = qmi_message_voice_get_config_input_new (); |
| 333 |
qmi_message_voice_get_config_input_set_auto_answer (input, TRUE, NULL); |
| 334 |
qmi_message_voice_get_config_input_set_air_timer (input, TRUE, NULL); |
| 335 |
qmi_message_voice_get_config_input_set_roam_timer (input, TRUE, NULL); |
| 336 |
qmi_message_voice_get_config_input_set_tty_mode (input, TRUE, NULL); |
| 337 |
qmi_message_voice_get_config_input_set_preferred_voice_service_option (input, TRUE, NULL); |
| 338 |
qmi_message_voice_get_config_input_set_amr_status (input, TRUE, NULL); |
| 339 |
qmi_message_voice_get_config_input_set_preferred_voice_privacy (input, TRUE, NULL); |
| 340 |
if (qmi_client_check_version (QMI_CLIENT (ctx->client), 2, 3)) |
| 341 |
qmi_message_voice_get_config_input_set_nam_index (input, TRUE, NULL); |
| 342 |
if (qmi_client_check_version (QMI_CLIENT (ctx->client), 2, 9)) |
| 343 |
qmi_message_voice_get_config_input_set_voice_domain_preference (input, TRUE, NULL); |
| 344 |
|
| 345 |
g_debug ("Asynchronously getting voice configuration..."); |
| 346 |
qmi_client_voice_get_config (ctx->client, |
| 347 |
input, |
| 348 |
10, |
| 349 |
ctx->cancellable, |
| 350 |
(GAsyncReadyCallback)get_config_ready, |
| 351 |
NULL); |
| 352 |
qmi_message_voice_get_config_input_unref (input); |
| 353 |
return; |
| 354 |
} |
| 355 |
#endif |
| 356 |
|
| 357 |
#if defined HAVE_QMI_MESSAGE_VOICE_GET_SUPPORTED_MESSAGES |
| 358 |
if (get_supported_messages_flag) { |
| 359 |
g_debug ("Asynchronously getting supported voice messages..."); |
| 360 |
qmi_client_voice_get_supported_messages (ctx->client, |
| 361 |
NULL, |
| 362 |
10, |
| 363 |
ctx->cancellable, |
| 364 |
(GAsyncReadyCallback)get_supported_messages_ready, |
| 365 |
NULL); |
| 366 |
return; |
| 367 |
} |
| 368 |
#endif |
| 369 |
|
| 370 |
/* Just client allocate/release? */ |
| 371 |
if (noop_flag) { |
| 372 |
g_idle_add (noop_cb, NULL); |
| 373 |
return; |
| 374 |
} |
| 375 |
|
| 376 |
g_warn_if_reached (); |
| 377 |
} |
| 378 |
|
| 379 |
#endif /* HAVE_QMI_SERVICE_VOICE */ |