static void
modem_object_added (MMManager *modem_manager,
                    MMObject  *modem_object,
                    NmaBtDevice *self)
{
	NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self);
	NMDeviceType devtype = NM_DEVICE_TYPE_UNKNOWN;
	MMModem *modem_iface;
	const gchar *path;
	const gchar *primary_port;
	const gchar *iface_basename;
	MMModemCapability caps;

	path = mm_object_get_path (modem_object);
	g_message ("%s: (%s) modem found", __func__, path);

	/* Ensure we have the 'Modem' interface at least */
	modem_iface = mm_object_peek_modem (modem_object);
	g_return_if_fail (modem_iface != NULL);

	/* Get modem's primary port */
	primary_port = mm_modem_get_primary_port (modem_iface);
	g_return_if_fail (primary_port != NULL);

	/* Get rfcomm iface name */
	iface_basename = g_path_get_basename (priv->rfcomm_iface);

	/* If not matched, just return */
	if (!g_str_equal (primary_port, iface_basename)) {
		g_message ("%s: (%s) (%s) not the modem we're looking for (%s)",
		           __func__, path, primary_port, iface_basename);
		return;
	}

	/* This is the modem we were waiting for, so keep on */
	caps = mm_modem_get_current_capabilities (modem_iface);
	/* CDMA-only? */
	if (caps == MM_MODEM_CAPABILITY_CDMA_EVDO)
		devtype = NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO;
	/* GSM/UMTS-only? */
	else if (caps == MM_MODEM_CAPABILITY_GSM_UMTS)
		devtype = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
	/* LTE? */
	else if (caps & MM_MODEM_CAPABILITY_LTE)
		devtype = NM_DEVICE_MODEM_CAPABILITY_LTE;
	else
		g_message ("%s: (%s) unknown modem type", __func__, path);

	/* Launch wizard! */
	start_wizard (self, path, devtype);
}
Beispiel #2
0
static void
print_modem_info (void)
{
    gchar *drivers_string;
    gchar *prefixed_revision;
    gchar *supported_capabilities_string;
    MMModemCapability *capabilities = NULL;
    guint n_capabilities = 0;
    gchar *current_capabilities_string;
    gchar *access_technologies_string;
    MMModemModeCombination *modes = NULL;
    guint n_modes = 0;
    gchar *supported_modes_string;
    MMModemMode allowed_modes;
    gchar *allowed_modes_string = NULL;
    MMModemMode preferred_mode;
    gchar *preferred_mode_string = NULL;
    gchar *supported_bands_string;
    gchar *current_bands_string;
    gchar *supported_ip_families_string;
    gchar *unlock_retries_string;
    gchar *own_numbers_string;
    MMModemBand *bands = NULL;
    guint n_bands = 0;
    MMModemPortInfo *ports = NULL;
    guint n_ports = 0;
    gchar *ports_string;
    MMUnlockRetries *unlock_retries;
    guint signal_quality = 0;
    gboolean signal_quality_recent = FALSE;
    gchar *bearer_paths_string;

    /* Not the best thing to do, as we may be doing _get() calls twice, but
     * easiest to maintain */
#undef VALIDATE_UNKNOWN
#define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
#undef VALIDATE_PATH
#define VALIDATE_PATH(str) ((str && !g_str_equal (str, "/")) ? str : "none")

    /* Strings in heap */
    mm_modem_get_supported_capabilities (ctx->modem, &capabilities, &n_capabilities);
    supported_capabilities_string = mm_common_build_capabilities_string (capabilities, n_capabilities);
    g_free (capabilities);
    current_capabilities_string = mm_modem_capability_build_string_from_mask (
        mm_modem_get_current_capabilities (ctx->modem));
    access_technologies_string = mm_modem_access_technology_build_string_from_mask (
        mm_modem_get_access_technologies (ctx->modem));
    mm_modem_get_supported_modes (ctx->modem, &modes, &n_modes);
    supported_modes_string = mm_common_build_mode_combinations_string (modes, n_modes);
    g_free (modes);
    mm_modem_get_current_bands (ctx->modem, &bands, &n_bands);
    current_bands_string = mm_common_build_bands_string (bands, n_bands);
    g_free (bands);
    mm_modem_get_supported_bands (ctx->modem, &bands, &n_bands);
    supported_bands_string = mm_common_build_bands_string (bands, n_bands);
    g_free (bands);
    mm_modem_get_ports (ctx->modem, &ports, &n_ports);
    ports_string = mm_common_build_ports_string (ports, n_ports);
    mm_modem_port_info_array_free (ports, n_ports);
    if (mm_modem_get_current_modes (ctx->modem, &allowed_modes, &preferred_mode)) {
        allowed_modes_string = mm_modem_mode_build_string_from_mask (allowed_modes);
        preferred_mode_string = mm_modem_mode_build_string_from_mask (preferred_mode);
    }
    supported_ip_families_string = mm_bearer_ip_family_build_string_from_mask (
        mm_modem_get_supported_ip_families (ctx->modem));

    unlock_retries = mm_modem_get_unlock_retries (ctx->modem);
    unlock_retries_string = mm_unlock_retries_build_string (unlock_retries);
    g_object_unref (unlock_retries);

    if (mm_modem_get_own_numbers (ctx->modem)) {
        own_numbers_string = g_strjoinv (", ", (gchar **)mm_modem_get_own_numbers (ctx->modem));
        if (!own_numbers_string[0]) {
            g_free (own_numbers_string);
            own_numbers_string = NULL;
        }
    } else
        own_numbers_string = NULL;

    if (mm_modem_get_drivers (ctx->modem)) {
        drivers_string = g_strjoinv (", ", (gchar **)mm_modem_get_drivers (ctx->modem));
        if (!drivers_string[0]) {
            g_free (drivers_string);
            drivers_string = NULL;
        }
    } else
        drivers_string = NULL;

    /* Rework possible multiline strings */
    if (mm_modem_get_revision (ctx->modem))
        prefixed_revision = mmcli_prefix_newlines ("           |                  ",
                                                   mm_modem_get_revision (ctx->modem));
    else
        prefixed_revision = NULL;

    if (supported_modes_string) {
        gchar *prefixed;

        prefixed = mmcli_prefix_newlines ("           |                  ",
                                          supported_modes_string);
        g_free (supported_modes_string);
        supported_modes_string = prefixed;
    }

    if (supported_capabilities_string) {
        gchar *prefixed;

        prefixed = mmcli_prefix_newlines ("           |                  ",
                                          supported_capabilities_string);
        g_free (supported_capabilities_string);
        supported_capabilities_string = prefixed;
    }

    /* Get signal quality info */
    signal_quality = mm_modem_get_signal_quality (ctx->modem, &signal_quality_recent);

    if (mm_modem_get_bearer_paths (ctx->modem)) {
        bearer_paths_string = g_strjoinv (", ", (gchar **)mm_modem_get_bearer_paths (ctx->modem));
        if (!bearer_paths_string[0]) {
            g_free (bearer_paths_string);
            bearer_paths_string = NULL;
        }
    } else
        bearer_paths_string = NULL;

    /* Global IDs */
    g_print ("\n"
             "%s (device id '%s')\n",
             VALIDATE_UNKNOWN (mm_modem_get_path (ctx->modem)),
             VALIDATE_UNKNOWN (mm_modem_get_device_identifier (ctx->modem)));

    /* Hardware related stuff */
    g_print ("  -------------------------\n"
             "  Hardware |   manufacturer: '%s'\n"
             "           |          model: '%s'\n"
             "           |       revision: '%s'\n"
             "           |      supported: '%s'\n"
             "           |        current: '%s'\n"
             "           |   equipment id: '%s'\n",
             VALIDATE_UNKNOWN (mm_modem_get_manufacturer (ctx->modem)),
             VALIDATE_UNKNOWN (mm_modem_get_model (ctx->modem)),
             VALIDATE_UNKNOWN (prefixed_revision),
             VALIDATE_UNKNOWN (supported_capabilities_string),
             VALIDATE_UNKNOWN (current_capabilities_string),
             VALIDATE_UNKNOWN (mm_modem_get_equipment_identifier (ctx->modem)));

    /* System related stuff */
    g_print ("  -------------------------\n"
             "  System   |         device: '%s'\n"
             "           |        drivers: '%s'\n"
             "           |         plugin: '%s'\n"
             "           |   primary port: '%s'\n"
             "           |          ports: '%s'\n",
             VALIDATE_UNKNOWN (mm_modem_get_device (ctx->modem)),
             VALIDATE_UNKNOWN (drivers_string),
             VALIDATE_UNKNOWN (mm_modem_get_plugin (ctx->modem)),
             VALIDATE_UNKNOWN (mm_modem_get_primary_port (ctx->modem)),
             VALIDATE_UNKNOWN (ports_string));

    /* Numbers related stuff */
    g_print ("  -------------------------\n"
             "  Numbers  |           own : '%s'\n",
             VALIDATE_UNKNOWN (own_numbers_string));

    /* Status related stuff */
    g_print ("  -------------------------\n"
             "  Status   |           lock: '%s'\n"
             "           | unlock retries: '%s'\n"
             "           |          state: '%s'\n",
             mm_modem_lock_get_string (mm_modem_get_unlock_required (ctx->modem)),
             VALIDATE_UNKNOWN (unlock_retries_string),
             VALIDATE_UNKNOWN (mm_modem_state_get_string (mm_modem_get_state (ctx->modem))));

    if (mm_modem_get_state (ctx->modem) == MM_MODEM_STATE_FAILED)
        g_print ("           |  failed reason: '%s'\n",
                 VALIDATE_UNKNOWN (mm_modem_state_failed_reason_get_string (mm_modem_get_state_failed_reason (ctx->modem))));

    g_print ("           |    power state: '%s'\n"
             "           |    access tech: '%s'\n"
             "           | signal quality: '%u' (%s)\n",
             VALIDATE_UNKNOWN (mm_modem_power_state_get_string (mm_modem_get_power_state (ctx->modem))),
             VALIDATE_UNKNOWN (access_technologies_string),
             signal_quality, signal_quality_recent ? "recent" : "cached");

    /* Modes */
    g_print ("  -------------------------\n"
             "  Modes    |      supported: '%s'\n"
             "           |        current: 'allowed: %s; preferred: %s'\n",
             VALIDATE_UNKNOWN (supported_modes_string),
             VALIDATE_UNKNOWN (allowed_modes_string),
             VALIDATE_UNKNOWN (preferred_mode_string));

    /* Band related stuff */
    g_print ("  -------------------------\n"
             "  Bands    |      supported: '%s'\n"
             "           |        current: '%s'\n",
             VALIDATE_UNKNOWN (supported_bands_string),
             VALIDATE_UNKNOWN (current_bands_string));

    /* IP families */
    g_print ("  -------------------------\n"
             "  IP       |      supported: '%s'\n",
             VALIDATE_UNKNOWN (supported_ip_families_string));

    /* If available, 3GPP related stuff */
    if (ctx->modem_3gpp) {
        gchar *facility_locks;

        facility_locks = (mm_modem_3gpp_facility_build_string_from_mask (
                              mm_modem_3gpp_get_enabled_facility_locks (ctx->modem_3gpp)));
        g_print ("  -------------------------\n"
                 "  3GPP     |           imei: '%s'\n"
                 "           |  enabled locks: '%s'\n"
                 "           |    operator id: '%s'\n"
                 "           |  operator name: '%s'\n"
                 "           |   subscription: '%s'\n"
                 "           |   registration: '%s'\n",
                 VALIDATE_UNKNOWN (mm_modem_3gpp_get_imei (ctx->modem_3gpp)),
                 facility_locks,
                 VALIDATE_UNKNOWN (mm_modem_3gpp_get_operator_code (ctx->modem_3gpp)),
                 VALIDATE_UNKNOWN (mm_modem_3gpp_get_operator_name (ctx->modem_3gpp)),
                 mm_modem_3gpp_subscription_state_get_string (
                     mm_modem_3gpp_get_subscription_state ((ctx->modem_3gpp))),
                 mm_modem_3gpp_registration_state_get_string (
                     mm_modem_3gpp_get_registration_state ((ctx->modem_3gpp))));

        g_free (facility_locks);
    }

    /* If available, CDMA related stuff */
    if (ctx->modem_cdma) {
        guint sid;
        guint nid;
        gchar *sid_str;
        gchar *nid_str;

        sid = mm_modem_cdma_get_sid (ctx->modem_cdma);
        sid_str = (sid != MM_MODEM_CDMA_SID_UNKNOWN ?
                   g_strdup_printf ("%u", sid) :
                   NULL);
        nid = mm_modem_cdma_get_nid (ctx->modem_cdma);
        nid_str = (nid != MM_MODEM_CDMA_NID_UNKNOWN ?
                   g_strdup_printf ("%u", nid) :
                   NULL);

        g_print ("  -------------------------\n"
                 "  CDMA     |           meid: '%s'\n"
                 "           |            esn: '%s'\n"
                 "           |            sid: '%s'\n"
                 "           |            nid: '%s'\n"
                 "           |   registration: CDMA1x '%s'\n"
                 "           |                 EV-DO  '%s'\n"
                 "           |     activation: '%s'\n",
                 VALIDATE_UNKNOWN (mm_modem_cdma_get_meid (ctx->modem_cdma)),
                 VALIDATE_UNKNOWN (mm_modem_cdma_get_esn (ctx->modem_cdma)),
                 VALIDATE_UNKNOWN (sid_str),
                 VALIDATE_UNKNOWN (nid_str),
                 mm_modem_cdma_registration_state_get_string (
                     mm_modem_cdma_get_cdma1x_registration_state (ctx->modem_cdma)),
                 mm_modem_cdma_registration_state_get_string (
                     mm_modem_cdma_get_evdo_registration_state (ctx->modem_cdma)),
                 mm_modem_cdma_activation_state_get_string (
                     mm_modem_cdma_get_activation_state (ctx->modem_cdma)));

        g_free (sid_str);
        g_free (nid_str);
    }

    /* SIM */
    g_print ("  -------------------------\n"
             "  SIM      |           path: '%s'\n",
             VALIDATE_PATH (mm_modem_get_sim_path (ctx->modem)));
    g_print ("\n");

    /* Bearers */
    g_print ("  -------------------------\n"
             "  Bearers  |          paths: '%s'\n",
             VALIDATE_PATH (bearer_paths_string));
    g_print ("\n");

    g_free (ports_string);
    g_free (supported_ip_families_string);
    g_free (current_bands_string);
    g_free (supported_bands_string);
    g_free (access_technologies_string);
    g_free (supported_capabilities_string);
    g_free (current_capabilities_string);
    g_free (prefixed_revision);
    g_free (allowed_modes_string);
    g_free (preferred_mode_string);
    g_free (supported_modes_string);
    g_free (unlock_retries_string);
    g_free (own_numbers_string);
    g_free (drivers_string);
    g_free (bearer_paths_string);
}