From 28f13c09ecf6433385d9b7a8cff5be825d74c9c8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 26 Mar 2012 13:00:07 +0200 Subject: [PATCH] mmcli: abort certain operations if modem is unlocked Do not try to perform feature/capability specific actions if we're still unlocked, as the modem didn't yet export the feature/capability specific interface. The only interfaces expected while modem is unlocked are the Modem and Simple interfaces, as well as the SIM interface in the SIM object, of course. --- cli/mmcli-modem-3gpp.c | 28 ++++++++++++++++++++-------- cli/mmcli-modem-cdma.c | 14 ++++++++++---- cli/mmcli-modem-location.c | 14 ++++++++++---- cli/mmcli-modem-messaging.c | 14 ++++++++++---- cli/mmcli-modem-simple.c | 9 +++++---- cli/mmcli-modem-time.c | 14 ++++++++++---- 6 files changed, 65 insertions(+), 28 deletions(-) diff --git a/cli/mmcli-modem-3gpp.c b/cli/mmcli-modem-3gpp.c index 7e141be5..75b8ee14 100644 --- a/cli/mmcli-modem-3gpp.c +++ b/cli/mmcli-modem-3gpp.c @@ -161,21 +161,33 @@ context_free (Context *ctx) static void ensure_modem_3gpp (void) { - if (ctx->modem_3gpp) - return; + if (mm_modem_get_unlock_required (mm_object_peek_modem (ctx->object)) != MM_MODEM_LOCK_NONE) { + g_printerr ("error: modem not unlocked yet\n"); + exit (EXIT_FAILURE); + } - g_printerr ("error: modem has no 3GPP capabilities\n"); - exit (EXIT_FAILURE); + if (!ctx->modem_3gpp) { + g_printerr ("error: modem has no 3GPP capabilities\n"); + exit (EXIT_FAILURE); + } + + /* Success */ } static void ensure_modem_3gpp_ussd (void) { - if (ctx->modem_3gpp_ussd) - return; + if (mm_modem_get_unlock_required (mm_object_peek_modem (ctx->object)) != MM_MODEM_LOCK_NONE) { + g_printerr ("error: modem not unlocked yet\n"); + exit (EXIT_FAILURE); + } - g_printerr ("error: modem has no USSD capabilities\n"); - exit (EXIT_FAILURE); + if (!ctx->modem_3gpp_ussd) { + g_printerr ("error: modem has no USSD capabilities\n"); + exit (EXIT_FAILURE); + } + + /* Success */ } void diff --git a/cli/mmcli-modem-cdma.c b/cli/mmcli-modem-cdma.c index 2e8cdb77..00979a42 100644 --- a/cli/mmcli-modem-cdma.c +++ b/cli/mmcli-modem-cdma.c @@ -108,11 +108,17 @@ context_free (Context *ctx) static void ensure_modem_cdma (void) { - if (ctx->modem_cdma) - return; + if (mm_modem_get_unlock_required (mm_object_peek_modem (ctx->object)) != MM_MODEM_LOCK_NONE) { + g_printerr ("error: modem not unlocked yet\n"); + exit (EXIT_FAILURE); + } - g_printerr ("error: modem has no CDMA capabilities\n"); - exit (EXIT_FAILURE); + if (!ctx->modem_cdma) { + g_printerr ("error: modem has no CDMA capabilities\n"); + exit (EXIT_FAILURE); + } + + /* Success */ } void diff --git a/cli/mmcli-modem-location.c b/cli/mmcli-modem-location.c index 49afd0ac..22e7aa1a 100644 --- a/cli/mmcli-modem-location.c +++ b/cli/mmcli-modem-location.c @@ -120,11 +120,17 @@ context_free (Context *ctx) static void ensure_modem_location (void) { - if (ctx->modem_location) - return; + if (mm_modem_get_unlock_required (mm_object_peek_modem (ctx->object)) != MM_MODEM_LOCK_NONE) { + g_printerr ("error: modem not unlocked yet\n"); + exit (EXIT_FAILURE); + } - g_printerr ("error: modem has no location capabilities\n"); - exit (EXIT_FAILURE); + if (!ctx->modem_location) { + g_printerr ("error: modem has no location capabilities\n"); + exit (EXIT_FAILURE); + } + + /* Success */ } void diff --git a/cli/mmcli-modem-messaging.c b/cli/mmcli-modem-messaging.c index b8052e07..f717552c 100644 --- a/cli/mmcli-modem-messaging.c +++ b/cli/mmcli-modem-messaging.c @@ -120,11 +120,17 @@ context_free (Context *ctx) static void ensure_modem_messaging (void) { - if (ctx->modem_messaging) - return; + if (mm_modem_get_unlock_required (mm_object_peek_modem (ctx->object)) != MM_MODEM_LOCK_NONE) { + g_printerr ("error: modem not unlocked yet\n"); + exit (EXIT_FAILURE); + } - g_printerr ("error: modem has no messaging capabilities\n"); - exit (EXIT_FAILURE); + if (!ctx->modem_messaging) { + g_printerr ("error: modem has no messaging capabilities\n"); + exit (EXIT_FAILURE); + } + + /* Success */ } void diff --git a/cli/mmcli-modem-simple.c b/cli/mmcli-modem-simple.c index 29df8a34..53277038 100644 --- a/cli/mmcli-modem-simple.c +++ b/cli/mmcli-modem-simple.c @@ -125,11 +125,12 @@ context_free (Context *ctx) static void ensure_modem_simple (void) { - if (ctx->modem_simple) - return; + if (!ctx->modem_simple) { + g_printerr ("error: modem has no Simple capabilities\n"); + exit (EXIT_FAILURE); + } - g_printerr ("error: modem has no Simple capabilities\n"); - exit (EXIT_FAILURE); + /* Success */ } void diff --git a/cli/mmcli-modem-time.c b/cli/mmcli-modem-time.c index 8ec5740c..7bc277c6 100644 --- a/cli/mmcli-modem-time.c +++ b/cli/mmcli-modem-time.c @@ -108,11 +108,17 @@ context_free (Context *ctx) static void ensure_modem_time (void) { - if (ctx->modem_time) - return; + if (mm_modem_get_unlock_required (mm_object_peek_modem (ctx->object)) != MM_MODEM_LOCK_NONE) { + g_printerr ("error: modem not unlocked yet\n"); + exit (EXIT_FAILURE); + } - g_printerr ("error: modem has no time capabilities\n"); - exit (EXIT_FAILURE); + if (!ctx->modem_time) { + g_printerr ("error: modem has no time capabilities\n"); + exit (EXIT_FAILURE); + } + + /* Success */ } void