Esempio n. 1
0
void
mmcli_modem_cdma_run_synchronous (GDBusConnection *connection)
{
    GError *error = NULL;

    /* Initialize context */
    ctx = g_new0 (Context, 1);
    ctx->object = mmcli_get_modem_sync (connection,
                                        mmcli_get_common_modem_string (),
                                        &ctx->manager);
    ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);

    /* Setup operation timeout */
    if (ctx->modem_cdma)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));

    ensure_modem_cdma ();

    /* Request to activate the modem? */
    if (activate_str) {
        gboolean result;

        g_debug ("Synchronously activating the modem...");
        result = mm_modem_cdma_activate_sync (
            ctx->modem_cdma,
            activate_str,
            NULL,
            &error);
        activate_process_reply (result, error);
        return;
    }

    g_warn_if_reached ();
}
void
mmcli_modem_time_run_synchronous (GDBusConnection *connection)
{
    GError *error = NULL;

    /* Initialize context */
    ctx = g_new0 (Context, 1);
    ctx->object = mmcli_get_modem_sync (connection,
                                        mmcli_get_common_modem_string (),
                                        &ctx->manager);
    ctx->modem_time = mm_object_get_modem_time (ctx->object);

    /* Setup operation timeout */
    if (ctx->modem_time)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_time));

    ensure_modem_time ();

    /* Request to get network time from the modem? */
    if (time_flag) {
        gchar *time_string;
        MMNetworkTimezone *timezone;

        g_debug ("Synchronously getting network time from the modem...");

        time_string = mm_modem_time_get_network_time_sync (ctx->modem_time,
                                                           NULL,
                                                           &error);
        timezone = mm_modem_time_get_network_timezone (ctx->modem_time);
        get_network_time_process_reply (time_string, timezone, error);
        return;
    }

    g_warn_if_reached ();
}
Esempio n. 3
0
gboolean
mmcli_modem_options_enabled (void)
{
    static guint n_actions = 0;
    static gboolean checked = FALSE;

    if (checked)
        return !!n_actions;

    n_actions = (monitor_state_flag +
                 enable_flag +
                 disable_flag +
                 set_power_state_on_flag +
                 set_power_state_low_flag +
                 set_power_state_off_flag +
                 reset_flag +
                 list_bearers_flag +
                 !!create_bearer_str +
                 !!delete_bearer_str +
                 !!factory_reset_str +
                 !!command_str +
                 !!set_current_capabilities_str +
                 !!set_allowed_modes_str +
                 !!set_preferred_mode_str +
                 !!set_current_bands_str);

    if (n_actions == 0 && mmcli_get_common_modem_string ()) {
        /* default to info */
        info_flag = TRUE;
        n_actions++;
    }

    if (set_preferred_mode_str) {
        if (!set_allowed_modes_str) {
            g_printerr ("error: setting preferred mode requires list of allowed modes\n");
            exit (EXIT_FAILURE);
        }
        n_actions--;
    }

    if (n_actions > 1) {
        g_printerr ("error: too many modem actions requested\n");
        exit (EXIT_FAILURE);
    }

    if (monitor_state_flag)
        mmcli_force_async_operation ();

    if (info_flag)
        mmcli_force_sync_operation ();

    checked = TRUE;
    return !!n_actions;
}
void
mmcli_modem_simple_run_synchronous (GDBusConnection *connection)
{
    GError *error = NULL;

    /* Initialize context */
    ctx = g_new0 (Context, 1);
    ctx->object = mmcli_get_modem_sync (connection,
                                        mmcli_get_common_modem_string (),
                                        &ctx->manager);
    ctx->modem_simple = mm_object_get_modem_simple (ctx->object);

    /* Setup operation timeout */
    if (ctx->modem_simple)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_simple));

    ensure_modem_simple ();

    if (connect_str)
        g_assert_not_reached ();

    /* Request to disconnect all bearers in the modem? */
    if (disconnect_flag) {
        gboolean result;

        g_debug ("Synchronously disconnecting all bearers in the modem...");

        result = mm_modem_simple_disconnect_sync (ctx->modem_simple,
                                                  NULL,
                                                  NULL,
                                                  &error);
        disconnect_process_reply (result, error);
        return;
    }

    /* Request to get status from the modem? */
    if (status_flag) {
        MMSimpleStatus *result;

        g_debug ("Synchronously getting status from the modem...");

        result = mm_modem_simple_get_status_sync (ctx->modem_simple,
                                                  NULL,
                                                  &error);
        status_process_reply (result, error);
        return;
    }

    g_warn_if_reached ();
}
void
mmcli_modem_firmware_run_synchronous (GDBusConnection *connection)
{
    GError *error = NULL;

    /* Initialize context */
    ctx = g_new0 (Context, 1);
    ctx->object = mmcli_get_modem_sync (connection,
                                        mmcli_get_common_modem_string (),
                                        &ctx->manager);
    ctx->modem_firmware = mm_object_get_modem_firmware (ctx->object);

    /* Setup operation timeout */
    if (ctx->modem_firmware)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_firmware));

    ensure_modem_firmware ();

    /* Request to list firmware images? */
    if (list_flag) {
        GList *installed = NULL;
        MMFirmwareProperties *selected = NULL;

        g_debug ("Synchronously listing firmware images in modem...");
        mm_modem_firmware_list_sync (ctx->modem_firmware,
                                     &selected,
                                     &installed,
                                     NULL,
                                     &error);
        list_process_reply (selected, installed, error);
        return;
    }

    /* Request to select a given image? */
    if (select_str) {
        gboolean result;
        GError *error = NULL;

        g_debug ("Synchronously selecting firmware image in modem...");
        result = mm_modem_firmware_select_sync (ctx->modem_firmware,
                                                select_str,
                                                NULL,
                                                &error);
        select_process_reply (result, error);
        return;
    }

    g_warn_if_reached ();
}
Esempio n. 6
0
void
mmcli_modem_location_run_asynchronous (GDBusConnection *connection,
                                       GCancellable    *cancellable)
{
    /* Initialize context */
    ctx = g_new0 (Context, 1);
    if (cancellable)
        ctx->cancellable = g_object_ref (cancellable);

    /* Get proper modem */
    mmcli_get_modem (connection,
                     mmcli_get_common_modem_string (),
                     cancellable,
                     (GAsyncReadyCallback)get_modem_ready,
                     NULL);
}
Esempio n. 7
0
void
mmcli_modem_signal_run_synchronous (GDBusConnection *connection)
{
    GError *error = NULL;

    /* Initialize context */
    ctx = g_new0 (Context, 1);
    ctx->object = mmcli_get_modem_sync (connection,
                                        mmcli_get_common_modem_string (),
                                        &ctx->manager);
    ctx->modem_signal = mm_object_get_modem_signal (ctx->object);

    /* Setup operation timeout */
    if (ctx->modem_signal)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_signal));

    ensure_modem_signal ();

    /* Request to get signal info? */
    if (get_flag) {
        print_signal_info ();
        return;
    }

    /* Request to set rate? */
    if (setup_str) {
        guint rate;
        gboolean result;

        if (!mm_get_uint_from_str (setup_str, &rate)) {
            g_printerr ("error: invalid rate value '%s'", setup_str);
            exit (EXIT_FAILURE);
        }

        g_debug ("Synchronously setting up extended signal quality information retrieval...");
        result = mm_modem_signal_setup_sync (ctx->modem_signal,
                                             rate,
                                             NULL,
                                             &error);
        setup_process_reply (result, error);
        return;
    }


    g_warn_if_reached ();
}
Esempio n. 8
0
void
mmcli_modem_location_run_synchronous (GDBusConnection *connection)
{
    GError *error = NULL;

    /* Initialize context */
    ctx = g_new0 (Context, 1);
    ctx->object = mmcli_get_modem_sync (connection,
                                        mmcli_get_common_modem_string (),
                                        &ctx->manager);
    ctx->modem_location = mm_object_get_modem_location (ctx->object);

    /* Setup operation timeout */
    if (ctx->modem_location)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_location));

    ensure_modem_location ();

    /* Request to get location status? */
    if (status_flag) {
        g_debug ("Printing location status...");
        print_location_status ();
        return;
    }

    /* Request to setup location gathering? */
    if (enable_3gpp_flag ||
        disable_3gpp_flag ||
        enable_agps_flag ||
        disable_agps_flag ||
        enable_gps_nmea_flag ||
        disable_gps_nmea_flag ||
        enable_gps_raw_flag ||
        disable_gps_raw_flag ||
        enable_cdma_bs_flag ||
        disable_cdma_bs_flag ||
        enable_gps_unmanaged_flag ||
        disable_gps_unmanaged_flag ||
        set_enable_signal_flag ||
        set_disable_signal_flag) {
        gboolean result;

        g_debug ("Synchronously setting up location gathering...");
        result = mm_modem_location_setup_sync (ctx->modem_location,
                                               build_sources_from_flags (),
                                               build_signals_location_from_flags (),
                                               NULL,
                                               &error);
        setup_process_reply (result, error);
        return;
    }

    /* Request to get location from the modem? */
    if (get_3gpp_flag ||
        get_gps_nmea_flag ||
        get_gps_raw_flag ||
        get_cdma_bs_flag) {
        MMLocation3gpp *location_3gpp = NULL;
        MMLocationGpsNmea *location_gps_nmea = NULL;
        MMLocationGpsRaw *location_gps_raw = NULL;
        MMLocationCdmaBs *location_cdma_bs = NULL;

        g_debug ("Synchronously getting location from the modem...");
        mm_modem_location_get_full_sync (ctx->modem_location,
                                         get_3gpp_flag ? &location_3gpp : NULL,
                                         get_gps_nmea_flag ? &location_gps_nmea : NULL,
                                         get_gps_raw_flag ? &location_gps_raw : NULL,
                                         get_cdma_bs_flag ? &location_cdma_bs : NULL,
                                         NULL,
                                         &error);
        get_location_process_reply (location_3gpp, location_gps_nmea, location_gps_raw, location_cdma_bs, error);
        return;
    }

    /* Request to set SUPL server? */
    if (set_supl_server_str) {
        gboolean result;

        g_debug ("Synchronously setting SUPL server...");
        result = mm_modem_location_set_supl_server_sync (ctx->modem_location,
                                                         set_supl_server_str,
                                                         NULL,
                                                         &error);
        set_supl_server_process_reply (result, error);
        return;
    }

    /* Request to set GPS refresh rate? */
    if (set_gps_refresh_rate_str) {
        gboolean result;
        guint rate;

        if (!mm_get_uint_from_str (set_gps_refresh_rate_str, &rate)) {
            g_printerr ("error: couldn't set GPS refresh rate: invalid rate given: '%s'\n",
                        set_gps_refresh_rate_str);
            exit (EXIT_FAILURE);
        }

        g_debug ("Synchronously setting GPS refresh rate...");
        result = mm_modem_location_set_gps_refresh_rate_sync (ctx->modem_location,
                                                              rate,
                                                              NULL,
                                                              &error);
        set_gps_refresh_rate_process_reply (result, error);
        return;
    }

    g_warn_if_reached ();
}
void
mmcli_modem_messaging_run_synchronous (GDBusConnection *connection)
{
    GError *error = NULL;

    /* Initialize context */
    ctx = g_new0 (Context, 1);
    ctx->object = mmcli_get_modem_sync (connection,
                                        mmcli_get_common_modem_string (),
                                        &ctx->manager);
    ctx->modem_messaging = mm_object_get_modem_messaging (ctx->object);

    /* Setup operation timeout */
    if (ctx->modem_messaging)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_messaging));

    ensure_modem_messaging ();

    /* Request to get location status? */
    if (status_flag) {
        g_debug ("Printing messaging status...");
        print_messaging_status ();
        return;
    }

    /* Request to list the SMS? */
    if (list_flag) {
        GList *result;

        g_debug ("Synchronously listing SMS messages...");
        result = mm_modem_messaging_list_sync (ctx->modem_messaging, NULL, &error);
        list_process_reply (result, error);
        return;
    }

    /* Request to create a new SMS? */
    if (create_str) {
        MMSms *sms;
        GError *error = NULL;
        MMSmsProperties *properties;

        properties = build_sms_properties_from_input (create_str,
                                                      create_with_data_str);
        g_debug ("Synchronously creating new SMS in modem...");
        sms = mm_modem_messaging_create_sync (ctx->modem_messaging,
                                              properties,
                                              NULL,
                                              &error);
        g_object_unref (properties);

        create_process_reply (sms, error);
        return;
    }

    /* Request to delete a given SMS? */
    if (delete_str) {
        gboolean result;
        MMSms *sms;
        MMObject *obj = NULL;

        sms = mmcli_get_sms_sync (connection,
                                  delete_str,
                                  NULL,
                                  &obj);
        if (!g_str_equal (mm_object_get_path (obj), mm_modem_messaging_get_path (ctx->modem_messaging))) {
            g_printerr ("error: SMS '%s' not owned by modem '%s'",
                        mm_sms_get_path (sms),
                        mm_modem_messaging_get_path (ctx->modem_messaging));
            exit (EXIT_FAILURE);
        }

        result = mm_modem_messaging_delete_sync (ctx->modem_messaging,
                                                 mm_sms_get_path (sms),
                                                 NULL,
                                                 &error);
        g_object_unref (sms);
        g_object_unref (obj);

        delete_process_reply (result, error);
        return;
    }

    g_warn_if_reached ();
}
Esempio n. 10
0
void
mmcli_modem_run_synchronous (GDBusConnection *connection)
{
    GError *error = NULL;

    if (monitor_state_flag)
        g_assert_not_reached ();

    /* Initialize context */
    ctx = g_new0 (Context, 1);
    ctx->object = mmcli_get_modem_sync (connection,
                                        mmcli_get_common_modem_string (),
                                        &ctx->manager);
    ctx->modem = mm_object_get_modem (ctx->object);
    ctx->modem_3gpp = mm_object_get_modem_3gpp (ctx->object);
    ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);

    /* Setup operation timeout */
    if (ctx->modem)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem));
    if (ctx->modem_3gpp)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp));
    if (ctx->modem_cdma)
        mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));

    /* Request to get info from modem? */
    if (info_flag) {
        g_debug ("Printing modem info...");
        print_modem_info ();
        return;
    }

    /* Request to enable the modem? */
    if (enable_flag) {
        gboolean result;

        g_debug ("Synchronously enabling modem...");
        result = mm_modem_enable_sync (ctx->modem, NULL, &error);
        enable_process_reply (result, error);
        return;
    }

    /* Request to disable the modem? */
    if (disable_flag) {
        gboolean result;

        g_debug ("Synchronously disabling modem...");
        result = mm_modem_disable_sync (ctx->modem, NULL, &error);
        disable_process_reply (result, error);
        return;
    }

    /* Request to set full power state? */
    if (set_power_state_on_flag) {
        gboolean result;

        g_debug ("Synchronously setting full power...");
        result = mm_modem_set_power_state_sync (ctx->modem, MM_MODEM_POWER_STATE_ON, NULL, &error);
        set_power_state_process_reply (result, error);
        return;
    }

    /* Request to set low power state? */
    if (set_power_state_low_flag) {
        gboolean result;

        g_debug ("Synchronously setting low power...");
        result = mm_modem_set_power_state_sync (ctx->modem, MM_MODEM_POWER_STATE_LOW, NULL, &error);
        set_power_state_process_reply (result, error);
        return;
    }

    /* Request to power off? */
    if (set_power_state_off_flag) {
        gboolean result;

        g_debug ("Synchronously powering off...");
        result = mm_modem_set_power_state_sync (ctx->modem, MM_MODEM_POWER_STATE_OFF, NULL, &error);
        set_power_state_process_reply (result, error);
        return;
    }

    /* Request to reset the modem? */
    if (reset_flag) {
        gboolean result;

        g_debug ("Synchronously reseting modem...");
        result = mm_modem_reset_sync (ctx->modem, NULL, &error);
        reset_process_reply (result, error);
        return;
    }

    /* Request to reset the modem to factory state? */
    if (factory_reset_str) {
        gboolean result;

        g_debug ("Synchronously factory-reseting modem...");
        result = mm_modem_factory_reset_sync (ctx->modem,
                                              factory_reset_str,
                                              NULL,
                                              &error);
        factory_reset_process_reply (result, error);
        return;
    }


    /* Request to send a command to the modem? */
    if (command_str) {
        gchar *result;
        guint timeout;

        timeout = command_get_timeout (ctx->modem);

        g_debug ("Synchronously sending command to modem (%u seconds timeout)...",
                 timeout);

        result = mm_modem_command_sync (ctx->modem,
                                        command_str,
                                        timeout,
                                        NULL,
                                        &error);
        command_process_reply (result, error);
        return;
    }

    /* Request to list the bearers? */
    if (list_bearers_flag) {
        GList *result;

        g_debug ("Synchronously listing bearers...");
        result = mm_modem_list_bearers_sync (ctx->modem, NULL, &error);
        list_bearers_process_reply (result, error);
        return;
    }

    /* Request to create a new bearer? */
    if (create_bearer_str) {
        MMBearer *bearer;
        GError *error = NULL;
        MMBearerProperties *properties;

        properties = mm_bearer_properties_new_from_string (create_bearer_str, &error);
        if (!properties) {
            g_printerr ("Error parsing properties string: '%s'\n", error->message);
            exit (EXIT_FAILURE);
        }

        g_debug ("Synchronously creating new bearer in modem...");
        bearer = mm_modem_create_bearer_sync (ctx->modem,
                                              properties,
                                              NULL,
                                              &error);
        g_object_unref (properties);

        create_bearer_process_reply (bearer, error);
        return;
    }

    /* Request to delete a given bearer? */
    if (delete_bearer_str) {
        gboolean result;
        MMBearer *bearer;
        MMObject *obj = NULL;

        bearer = mmcli_get_bearer_sync (connection,
                                        delete_bearer_str,
                                        NULL,
                                        &obj);
        if (!g_str_equal (mm_object_get_path (obj), mm_modem_get_path (ctx->modem))) {
            g_printerr ("error: bearer '%s' not owned by modem '%s'",
                        mm_bearer_get_path (bearer),
                        mm_modem_get_path (ctx->modem));
            exit (EXIT_FAILURE);
        }

        result = mm_modem_delete_bearer_sync (ctx->modem,
                                              mm_bearer_get_path (bearer),
                                              NULL,
                                              &error);
        g_object_unref (bearer);
        g_object_unref (obj);

        delete_bearer_process_reply (result, error);
        return;
    }

    /* Request to set capabilities in a given modem? */
    if (set_current_capabilities_str) {
        gboolean result;
        MMModemCapability current_capabilities;

        parse_current_capabilities (&current_capabilities);
        result = mm_modem_set_current_capabilities_sync (ctx->modem,
                                                         current_capabilities,
                                                         NULL,
                                                         &error);
        set_current_capabilities_process_reply (result, error);
        return;
    }

    /* Request to set allowed modes in a given modem? */
    if (set_allowed_modes_str) {
        MMModemMode allowed;
        MMModemMode preferred;
        gboolean result;

        parse_modes (&allowed, &preferred);
        result = mm_modem_set_current_modes_sync (ctx->modem,
                                                  allowed,
                                                  preferred,
                                                  NULL,
                                                  &error);

        set_current_modes_process_reply (result, error);
        return;
    }

    /* Request to set allowed bands in a given modem? */
    if (set_current_bands_str) {
        gboolean result;
        MMModemBand *current_bands;
        guint n_current_bands;

        parse_current_bands (&current_bands, &n_current_bands);
        result = mm_modem_set_current_bands_sync (ctx->modem,
                                                  current_bands,
                                                  n_current_bands,
                                                  NULL,
                                                  &error);
        g_free (current_bands);
        set_current_bands_process_reply (result, error);
        return;
    }

    g_warn_if_reached ();
}