| 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) 2023 Dylan Van Assche <[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 |
#include <assert.h> |
| 28 |
|
| 29 |
#include <glib.h> |
| 30 |
#include <gio/gio.h> |
| 31 |
|
| 32 |
#include <libqmi-glib.h> |
| 33 |
|
| 34 |
#include "qmicli.h" |
| 35 |
#include "qmicli-helpers.h" |
| 36 |
|
| 37 |
#if defined HAVE_QMI_SERVICE_IMSA |
| 38 |
|
| 39 |
/* Context */ |
| 40 |
typedef struct { |
| 41 |
QmiDevice *device; |
| 42 |
QmiClientImsa *client; |
| 43 |
GCancellable *cancellable; |
| 44 |
} Context; |
| 45 |
static Context *ctx; |
| 46 |
|
| 47 |
/* Options */ |
| 48 |
static gint bind_flag = -1; |
| 49 |
static gboolean get_ims_registration_status_flag; |
| 50 |
static gboolean get_ims_services_status_flag; |
| 51 |
static gboolean noop_flag; |
| 52 |
|
| 53 |
static GOptionEntry entries[] = { |
| 54 |
#if defined HAVE_QMI_MESSAGE_IMSA_BIND |
| 55 |
{ "imsa-bind", 0, 0, G_OPTION_ARG_INT, &bind_flag, |
| 56 |
"Bind to IMSA (use with --client-no-release-cid)", |
| 57 |
"[binding]" |
| 58 |
}, |
| 59 |
#endif |
| 60 |
#if defined HAVE_QMI_MESSAGE_IMSA_GET_IMS_REGISTRATION_STATUS |
| 61 |
{ "imsa-get-ims-registration-status", 0, 0, G_OPTION_ARG_NONE, &get_ims_registration_status_flag, |
| 62 |
"Get IMS registration status", |
| 63 |
NULL |
| 64 |
}, |
| 65 |
#endif |
| 66 |
#if defined HAVE_QMI_MESSAGE_IMSA_GET_IMS_SERVICES_STATUS |
| 67 |
{ "imsa-get-ims-services-status", 0, 0, G_OPTION_ARG_NONE, &get_ims_services_status_flag, |
| 68 |
"Get IMS services status", |
| 69 |
NULL |
| 70 |
}, |
| 71 |
#endif |
| 72 |
{ "imsa-noop", 0, 0, G_OPTION_ARG_NONE, &noop_flag, |
| 73 |
"Just allocate or release a IMSA client. Use with `--client-no-release-cid' and/or `--client-cid'", |
| 74 |
NULL |
| 75 |
}, |
| 76 |
{ NULL } |
| 77 |
}; |
| 78 |
|
| 79 |
GOptionGroup * |
| 80 |
qmicli_imsa_get_option_group (void) |
| 81 |
{ |
| 82 |
GOptionGroup *group; |
| 83 |
|
| 84 |
group = g_option_group_new ("imsa", |
| 85 |
"IMSA options:", |
| 86 |
"Show IP Multimedia Subsystem Application Service options", |
| 87 |
NULL, |
| 88 |
NULL); |
| 89 |
g_option_group_add_entries (group, entries); |
| 90 |
|
| 91 |
return group; |
| 92 |
} |
| 93 |
|
| 94 |
gboolean |
| 95 |
qmicli_imsa_options_enabled (void) |
| 96 |
{ |
| 97 |
static guint n_actions = 0; |
| 98 |
static gboolean checked = FALSE; |
| 99 |
|
| 100 |
if (checked) |
| 101 |
return !!n_actions; |
| 102 |
|
| 103 |
n_actions = ((bind_flag >= 0) + |
| 104 |
get_ims_registration_status_flag + |
| 105 |
get_ims_services_status_flag + |
| 106 |
noop_flag); |
| 107 |
|
| 108 |
if (n_actions > 1) { |
| 109 |
g_printerr ("error: too many IMSA actions requested\n"); |
| 110 |
exit (EXIT_FAILURE); |
| 111 |
} |
| 112 |
|
| 113 |
checked = TRUE; |
| 114 |
return !!n_actions; |
| 115 |
} |
| 116 |
|
| 117 |
static void |
| 118 |
context_free (Context *context) |
| 119 |
{ |
| 120 |
if (!context) |
| 121 |
return; |
| 122 |
|
| 123 |
if (context->cancellable) |
| 124 |
g_object_unref (context->cancellable); |
| 125 |
if (context->device) |
| 126 |
g_object_unref (context->device); |
| 127 |
if (context->client) |
| 128 |
g_object_unref (context->client); |
| 129 |
g_slice_free (Context, context); |
| 130 |
} |
| 131 |
|
| 132 |
static void |
| 133 |
operation_shutdown (gboolean operation_status) |
| 134 |
{ |
| 135 |
/* Cleanup context and finish async operation */ |
| 136 |
context_free (ctx); |
| 137 |
qmicli_async_operation_done (operation_status, FALSE); |
| 138 |
} |
| 139 |
|
| 140 |
#if defined HAVE_QMI_MESSAGE_IMSA_BIND |
| 141 |
|
| 142 |
static void |
| 143 |
bind_ready (QmiClientImsa *client, |
| 144 |
GAsyncResult *res) |
| 145 |
{ |
| 146 |
QmiMessageImsaBindOutput *output; |
| 147 |
g_autoptr(GError) error = NULL; |
| 148 |
|
| 149 |
output = qmi_client_imsa_bind_finish (client, res, &error); |
| 150 |
if (!output) { |
| 151 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 152 |
operation_shutdown (FALSE); |
| 153 |
return; |
| 154 |
} |
| 155 |
|
| 156 |
if (!qmi_message_imsa_bind_output_get_result (output, &error)) { |
| 157 |
g_printerr ("error: couldn't bind to IMSA: %s\n", error->message); |
| 158 |
qmi_message_imsa_bind_output_unref (output); |
| 159 |
operation_shutdown (FALSE); |
| 160 |
return; |
| 161 |
} |
| 162 |
|
| 163 |
g_print ("[%s] IMSA bind successful\n", qmi_device_get_path_display (ctx->device)); |
| 164 |
|
| 165 |
qmi_message_imsa_bind_output_unref (output); |
| 166 |
operation_shutdown (TRUE); |
| 167 |
} |
| 168 |
|
| 169 |
#endif /* HAVE_QMI_MESSAGE_IMSA_BIND */ |
| 170 |
|
| 171 |
#if defined HAVE_QMI_MESSAGE_IMSA_GET_IMS_REGISTRATION_STATUS |
| 172 |
|
| 173 |
static void |
| 174 |
get_ims_registration_status_ready (QmiClientImsa *client, |
| 175 |
GAsyncResult *res) |
| 176 |
{ |
| 177 |
QmiMessageImsaGetImsRegistrationStatusOutput *output; |
| 178 |
QmiImsaImsRegistrationStatus registration_status; |
| 179 |
QmiImsaRegistrationTechnology registration_technology; |
| 180 |
GError *error = NULL; |
| 181 |
|
| 182 |
output = qmi_client_imsa_get_ims_registration_status_finish (client, res, &error); |
| 183 |
if (!output) { |
| 184 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 185 |
g_error_free (error); |
| 186 |
operation_shutdown (FALSE); |
| 187 |
return; |
| 188 |
} |
| 189 |
|
| 190 |
if (!qmi_message_imsa_get_ims_registration_status_output_get_result (output, &error)) { |
| 191 |
g_printerr ("error: couldn't get IMS registration status: %s\n", error->message); |
| 192 |
g_error_free (error); |
| 193 |
qmi_message_imsa_get_ims_registration_status_output_unref (output); |
| 194 |
operation_shutdown (FALSE); |
| 195 |
return; |
| 196 |
} |
| 197 |
|
| 198 |
g_print ("[%s] IMS registration:\n", qmi_device_get_path_display (ctx->device)); |
| 199 |
|
| 200 |
if (qmi_message_imsa_get_ims_registration_status_output_get_ims_registration_status (output, ®istration_status, NULL)) |
| 201 |
g_print ("\t Status: '%s'\n", qmi_imsa_ims_registration_status_get_string (registration_status)); |
| 202 |
|
| 203 |
if (qmi_message_imsa_get_ims_registration_status_output_get_ims_registration_technology (output, ®istration_technology, NULL)) |
| 204 |
g_print ("\tTechnology: '%s'\n", qmi_imsa_registration_technology_get_string (registration_technology)); |
| 205 |
|
| 206 |
qmi_message_imsa_get_ims_registration_status_output_unref (output); |
| 207 |
operation_shutdown (TRUE); |
| 208 |
} |
| 209 |
|
| 210 |
#endif /* HAVE_QMI_MESSAGE_IMSA_GET_IMS_REGISTRATION_STATUS */ |
| 211 |
|
| 212 |
#if defined HAVE_QMI_MESSAGE_IMSA_GET_IMS_SERVICES_STATUS |
| 213 |
|
| 214 |
static void |
| 215 |
get_ims_services_status_ready (QmiClientImsa *client, |
| 216 |
GAsyncResult *res) |
| 217 |
{ |
| 218 |
QmiMessageImsaGetImsServicesStatusOutput *output; |
| 219 |
QmiImsaServiceStatus service_sms_status; |
| 220 |
QmiImsaRegistrationTechnology service_sms_technology; |
| 221 |
QmiImsaServiceStatus service_voice_status; |
| 222 |
QmiImsaRegistrationTechnology service_voice_technology; |
| 223 |
QmiImsaServiceStatus service_vt_status; |
| 224 |
QmiImsaRegistrationTechnology service_vt_technology; |
| 225 |
QmiImsaServiceStatus service_ut_status; |
| 226 |
QmiImsaRegistrationTechnology service_ut_technology; |
| 227 |
QmiImsaServiceStatus service_vs_status; |
| 228 |
QmiImsaRegistrationTechnology service_vs_technology; |
| 229 |
GError *error = NULL; |
| 230 |
|
| 231 |
output = qmi_client_imsa_get_ims_services_status_finish (client, res, &error); |
| 232 |
if (!output) { |
| 233 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 234 |
g_error_free (error); |
| 235 |
operation_shutdown (FALSE); |
| 236 |
return; |
| 237 |
} |
| 238 |
|
| 239 |
if (!qmi_message_imsa_get_ims_services_status_output_get_result (output, &error)) { |
| 240 |
g_printerr ("error: couldn't get IMS services status: %s\n", error->message); |
| 241 |
g_error_free (error); |
| 242 |
qmi_message_imsa_get_ims_services_status_output_unref (output); |
| 243 |
operation_shutdown (FALSE); |
| 244 |
return; |
| 245 |
} |
| 246 |
|
| 247 |
g_print ("[%s] IMS services:\n", qmi_device_get_path_display (ctx->device)); |
| 248 |
|
| 249 |
g_print ("\tSMS service\n"); |
| 250 |
|
| 251 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_sms_service_status (output, &service_sms_status, NULL)) |
| 252 |
g_print ("\t\t Status: '%s'\n", qmi_imsa_service_status_get_string (service_sms_status)); |
| 253 |
|
| 254 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_sms_service_registration_technology (output, &service_sms_technology, NULL)) |
| 255 |
g_print ("\t\tTechnology: '%s'\n", qmi_imsa_registration_technology_get_string (service_sms_technology)); |
| 256 |
|
| 257 |
g_print ("\tVoice service\n"); |
| 258 |
|
| 259 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_voice_service_status (output, &service_voice_status, NULL)) |
| 260 |
g_print ("\t\t Status: '%s'\n", qmi_imsa_service_status_get_string (service_voice_status)); |
| 261 |
|
| 262 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_voice_service_registration_technology (output, &service_voice_technology, NULL)) |
| 263 |
g_print ("\t\tTechnology: '%s'\n", qmi_imsa_registration_technology_get_string (service_voice_technology)); |
| 264 |
|
| 265 |
g_print ("\tVideo Telephony service\n"); |
| 266 |
|
| 267 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_video_telephony_service_status (output, &service_vt_status, NULL)) |
| 268 |
g_print ("\t\t Status: '%s'\n", qmi_imsa_service_status_get_string (service_vt_status)); |
| 269 |
|
| 270 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_video_telephony_service_registration_technology (output, &service_vt_technology, NULL)) |
| 271 |
g_print ("\t\tTechnology: '%s'\n", qmi_imsa_registration_technology_get_string (service_vt_technology)); |
| 272 |
|
| 273 |
g_print ("\tUE to TAS service\n"); |
| 274 |
|
| 275 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_ue_to_tas_service_status (output, &service_ut_status, NULL)) |
| 276 |
g_print ("\t\t Status: '%s'\n", qmi_imsa_service_status_get_string (service_ut_status)); |
| 277 |
|
| 278 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_ue_to_tas_service_registration_technology (output, &service_ut_technology, NULL)) |
| 279 |
g_print ("\t\tTechnology: '%s'\n", qmi_imsa_registration_technology_get_string (service_ut_technology)); |
| 280 |
|
| 281 |
g_print ("\tVideo Share service\n"); |
| 282 |
|
| 283 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_video_share_service_status (output, &service_vs_status, NULL)) |
| 284 |
g_print ("\t\t Status: '%s'\n", qmi_imsa_service_status_get_string (service_vs_status)); |
| 285 |
|
| 286 |
if (qmi_message_imsa_get_ims_services_status_output_get_ims_video_share_service_registration_technology (output, &service_vs_technology, NULL)) |
| 287 |
g_print ("\t\tTechnology: '%s'\n", qmi_imsa_registration_technology_get_string (service_vs_technology)); |
| 288 |
|
| 289 |
qmi_message_imsa_get_ims_services_status_output_unref (output); |
| 290 |
operation_shutdown (TRUE); |
| 291 |
} |
| 292 |
|
| 293 |
#endif /* HAVE_QMI_MESSAGE_IMSA_GET_IMS_SERVICES_STATUS */ |
| 294 |
|
| 295 |
static gboolean |
| 296 |
noop_cb (gpointer unused) |
| 297 |
{ |
| 298 |
operation_shutdown (TRUE); |
| 299 |
return FALSE; |
| 300 |
} |
| 301 |
|
| 302 |
void |
| 303 |
qmicli_imsa_run (QmiDevice *device, |
| 304 |
QmiClientImsa *client, |
| 305 |
GCancellable *cancellable) |
| 306 |
{ |
| 307 |
/* Initialize context */ |
| 308 |
ctx = g_slice_new (Context); |
| 309 |
ctx->device = g_object_ref (device); |
| 310 |
ctx->client = g_object_ref (client); |
| 311 |
ctx->cancellable = g_object_ref (cancellable); |
| 312 |
|
| 313 |
#if defined HAVE_QMI_MESSAGE_IMSA_BIND |
| 314 |
if (bind_flag >= 0) { |
| 315 |
QmiMessageImsaBindInput *input; |
| 316 |
|
| 317 |
input = qmi_message_imsa_bind_input_new (); |
| 318 |
qmi_message_imsa_bind_input_set_binding (input, bind_flag, NULL); |
| 319 |
g_debug ("Asynchronously binding to IMSA service..."); |
| 320 |
qmi_client_imsa_bind (ctx->client, |
| 321 |
input, |
| 322 |
10, |
| 323 |
ctx->cancellable, |
| 324 |
(GAsyncReadyCallback)bind_ready, |
| 325 |
NULL); |
| 326 |
qmi_message_imsa_bind_input_unref (input); |
| 327 |
return; |
| 328 |
} |
| 329 |
#endif /* HAVE_QMI_MESSAGE_IMSA_BIND */ |
| 330 |
#if defined HAVE_QMI_MESSAGE_IMSA_GET_IMS_REGISTRATION_STATUS |
| 331 |
if (get_ims_registration_status_flag) { |
| 332 |
g_debug ("Asynchronously getting IMS registration status..."); |
| 333 |
|
| 334 |
qmi_client_imsa_get_ims_registration_status (ctx->client, |
| 335 |
NULL, |
| 336 |
10, |
| 337 |
ctx->cancellable, |
| 338 |
(GAsyncReadyCallback)get_ims_registration_status_ready, |
| 339 |
NULL); |
| 340 |
return; |
| 341 |
} |
| 342 |
#endif /* HAVE_QMI_MESSAGE_IMSA_GET_IMS_REGISTRATION_STATUS */ |
| 343 |
#if defined HAVE_QMI_MESSAGE_IMSA_GET_IMS_SERVICES_STATUS |
| 344 |
if (get_ims_services_status_flag) { |
| 345 |
g_debug ("Asynchronously getting IMS services status..."); |
| 346 |
|
| 347 |
qmi_client_imsa_get_ims_services_status (ctx->client, |
| 348 |
NULL, |
| 349 |
10, |
| 350 |
ctx->cancellable, |
| 351 |
(GAsyncReadyCallback)get_ims_services_status_ready, |
| 352 |
NULL); |
| 353 |
return; |
| 354 |
} |
| 355 |
#endif /* HAVE_QMI_MESSAGE_IMSA_GET_IMS_SERVICES_STATUS */ |
| 356 |
|
| 357 |
/* Just client allocate/release? */ |
| 358 |
if (noop_flag) { |
| 359 |
g_idle_add (noop_cb, NULL); |
| 360 |
return; |
| 361 |
} |
| 362 |
|
| 363 |
g_warn_if_reached (); |
| 364 |
} |
| 365 |
|
| 366 |
#endif /* HAVE_QMI_SERVICE_IMSA */ |
| 367 |
|