static void modem_object_removed (MMManager *manager, MMObject *modem_object, NmaBtDevice *self) { g_message ("%s: (%s) modem removed", __func__, mm_object_get_path (modem_object)); }
static MMObject * find_modem (MMManager *manager, const gchar *modem_path) { GList *modems; GList *l; MMObject *found = NULL; modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); for (l = modems; l; l = g_list_next (l)) { MMObject *modem = MM_OBJECT (l->data); if (g_str_equal (mm_object_get_path (modem), modem_path)) { found = g_object_ref (modem); break; } } g_list_free_full (modems, (GDestroyNotify) g_object_unref); if (!found) { g_printerr ("error: couldn't find modem at '%s'\n", modem_path); exit (EXIT_FAILURE); } g_debug ("Modem found at '%s'\n", modem_path); return found; }
static void look_for_sms_in_modem (GetSmsContext *ctx) { MMModemMessaging *modem; if (!ctx->modems) { g_printerr ("error: couldn't find SMS at '%s': 'not found in any modem'\n", ctx->sms_path); exit (EXIT_FAILURE); } /* Loop looking for the sms in each modem found */ ctx->current = MM_OBJECT (ctx->modems->data); ctx->modems = g_list_delete_link (ctx->modems, ctx->modems); modem = mm_object_get_modem_messaging (ctx->current); if (modem) { g_debug ("Looking for sms '%s' in modem '%s'...", ctx->sms_path, mm_object_get_path (ctx->current)); mm_modem_messaging_list (modem, ctx->cancellable, (GAsyncReadyCallback)list_sms_ready, ctx); g_object_unref (modem); return; } /* Current modem has no messaging capabilities, try with next modem */ look_for_sms_in_modem (ctx); }
static void on_mm_object_added (GDBusObjectManager *manager, GDBusObject *object, gpointer user_data) { MMObject *mm_object = MM_OBJECT (object); GClueModemSource *source= GCLUE_MODEM_SOURCE (user_data); GClueModemSourceClass *klass = GCLUE_MODEM_SOURCE_GET_CLASS (source); MMModemLocation *modem_location; MMModemLocationSource req_caps, caps; const char *caps_name; if (source->priv->mm_object != NULL) return; g_debug ("New modem '%s'", mm_object_get_path (mm_object)); modem_location = mm_object_peek_modem_location (mm_object); if (modem_location == NULL) return; g_debug ("Modem '%s' has location capabilities", mm_object_get_path (mm_object)); caps = mm_modem_location_get_capabilities (modem_location); req_caps = klass->get_req_modem_location_caps (source, &caps_name); if ((caps & req_caps) == 0) return; g_debug ("Modem '%s' has %s capabilities", mm_object_get_path (mm_object), caps_name); source->priv->mm_object = g_object_ref (mm_object); source->priv->modem = mm_object_get_modem (mm_object); source->priv->modem_location = mm_object_get_modem_location (mm_object); mm_modem_enable (source->priv->modem, source->priv->cancellable, on_modem_enabled, user_data); }
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); }
static void look_for_bearer_in_modem (GetBearerContext *ctx) { MMModem *modem; if (!ctx->modems) { g_printerr ("error: couldn't find bearer at '%s': 'not found in any modem'\n", ctx->bearer_path); exit (EXIT_FAILURE); } /* Loop looking for the bearer in each modem found */ ctx->current = MM_OBJECT (ctx->modems->data); ctx->modems = g_list_delete_link (ctx->modems, ctx->modems); modem = mm_object_get_modem (ctx->current); /* Don't look for bearers in modems which are not fully initialized */ if (mm_modem_get_state (modem) < MM_MODEM_STATE_DISABLED) { g_debug ("Skipping modem '%s' when looking for bearers " "(not fully initialized)", mm_object_get_path (ctx->current)); g_object_unref (modem); look_for_bearer_in_modem (ctx); return; } g_debug ("Looking for bearer '%s' in modem '%s'...", ctx->bearer_path, mm_object_get_path (ctx->current)); mm_modem_list_bearers (modem, ctx->cancellable, (GAsyncReadyCallback)list_bearers_ready, ctx); g_object_unref (modem); }
static void get_sms_to_delete_ready (GDBusConnection *connection, GAsyncResult *res) { MMSms *sms; MMObject *obj = NULL; sms = mmcli_get_sms_finish (res, 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); } mm_modem_messaging_delete (ctx->modem_messaging, mm_sms_get_path (sms), ctx->cancellable, (GAsyncReadyCallback)delete_ready, NULL); g_object_unref (sms); g_object_unref (obj); }
static void get_bearer_to_delete_ready (GDBusConnection *connection, GAsyncResult *res) { MMBearer *bearer; MMObject *obj = NULL; bearer = mmcli_get_bearer_finish (res, 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); } mm_modem_delete_bearer (ctx->modem, mm_bearer_get_path (bearer), ctx->cancellable, (GAsyncReadyCallback)delete_bearer_ready, NULL); g_object_unref (bearer); g_object_unref (obj); }
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 (); }
MMBearer * mmcli_get_bearer_sync (GDBusConnection *connection, const gchar *path_or_index, MMManager **o_manager, MMObject **o_object) { MMManager *manager; GList *modems; GList *l; MMBearer *found = NULL; gchar *bearer_path; bearer_path = get_bearer_path (path_or_index); manager = mmcli_get_manager_sync (connection); modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); if (!modems) { g_printerr ("error: couldn't find bearer at '%s': 'no modems found'\n", bearer_path); exit (EXIT_FAILURE); } for (l = modems; !found && l; l = g_list_next (l)) { GError *error = NULL; MMObject *object; MMModem *modem; GList *bearers; object = MM_OBJECT (l->data); modem = mm_object_get_modem (object); /* Don't look for bearers in modems which are not fully initialized */ if (mm_modem_get_state (modem) < MM_MODEM_STATE_DISABLED) { g_debug ("Skipping modem '%s' when looking for bearers " "(not fully initialized)", mm_object_get_path (object)); g_object_unref (modem); continue; } bearers = mm_modem_list_bearers_sync (modem, NULL, &error); if (error) { g_printerr ("error: couldn't list bearers at '%s': '%s'\n", mm_modem_get_path (modem), error->message); exit (EXIT_FAILURE); } found = find_bearer_in_list (bearers, bearer_path); g_list_free_full (bearers, (GDestroyNotify) g_object_unref); if (found && o_object) *o_object = g_object_ref (object); g_object_unref (modem); } if (!found) { g_printerr ("error: couldn't find bearer at '%s': 'not found in any modem'\n", bearer_path); exit (EXIT_FAILURE); } g_list_free_full (modems, (GDestroyNotify) g_object_unref); g_free (bearer_path); if (o_manager) *o_manager = manager; else g_object_unref (manager); return found; }
static void get_modem_ready (GObject *source, GAsyncResult *result, gpointer none) { ctx->object = mmcli_get_modem_finish (result, &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)); if (info_flag) g_assert_not_reached (); /* Request to monitor modems? */ if (monitor_state_flag) { MMModemState current; g_signal_connect (ctx->modem, "state-changed", G_CALLBACK (state_changed), NULL); current = mm_modem_get_state (ctx->modem); g_print ("\t%s: Initial state, '%s'\n", mm_object_get_path (ctx->object), mm_modem_state_get_string (current)); /* If we get cancelled, operation done */ g_cancellable_connect (ctx->cancellable, G_CALLBACK (cancelled), NULL, NULL); return; } /* Request to enable the modem? */ if (enable_flag) { g_debug ("Asynchronously enabling modem..."); mm_modem_enable (ctx->modem, ctx->cancellable, (GAsyncReadyCallback)enable_ready, NULL); return; } /* Request to disable the modem? */ if (disable_flag) { g_debug ("Asynchronously disabling modem..."); mm_modem_disable (ctx->modem, ctx->cancellable, (GAsyncReadyCallback)disable_ready, NULL); return; } /* Request to full power the modem? */ if (set_power_state_on_flag) { g_debug ("Asynchronously setting full power..."); mm_modem_set_power_state (ctx->modem, MM_MODEM_POWER_STATE_ON, ctx->cancellable, (GAsyncReadyCallback)set_power_state_ready, NULL); return; } /* Request to low power the modem? */ if (set_power_state_low_flag) { g_debug ("Asynchronously setting low power..."); mm_modem_set_power_state (ctx->modem, MM_MODEM_POWER_STATE_LOW, ctx->cancellable, (GAsyncReadyCallback)set_power_state_ready, NULL); return; } /* Request to power off the modem? */ if (set_power_state_off_flag) { g_debug ("Asynchronously powering off..."); mm_modem_set_power_state (ctx->modem, MM_MODEM_POWER_STATE_OFF, ctx->cancellable, (GAsyncReadyCallback)set_power_state_ready, NULL); return; } /* Request to reset the modem? */ if (reset_flag) { g_debug ("Asynchronously reseting modem..."); mm_modem_reset (ctx->modem, ctx->cancellable, (GAsyncReadyCallback)reset_ready, NULL); return; } /* Request to reset the modem to factory state? */ if (factory_reset_str) { g_debug ("Asynchronously factory-reseting modem..."); mm_modem_factory_reset (ctx->modem, factory_reset_str, ctx->cancellable, (GAsyncReadyCallback)factory_reset_ready, NULL); return; } /* Request to send a command to the modem? */ if (command_str) { guint timeout; timeout = command_get_timeout (ctx->modem); g_debug ("Asynchronously sending a command to the modem (%u seconds timeout)...", timeout); mm_modem_command (ctx->modem, command_str, timeout, ctx->cancellable, (GAsyncReadyCallback)command_ready, NULL); return; } /* Request to list bearers? */ if (list_bearers_flag) { g_debug ("Asynchronously listing bearers in modem..."); mm_modem_list_bearers (ctx->modem, ctx->cancellable, (GAsyncReadyCallback)list_bearers_ready, NULL); return; } /* Request to create a new bearer? */ if (create_bearer_str) { 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 ("Asynchronously creating new bearer in modem..."); mm_modem_create_bearer (ctx->modem, properties, ctx->cancellable, (GAsyncReadyCallback)create_bearer_ready, NULL); g_object_unref (properties); return; } /* Request to delete a given bearer? */ if (delete_bearer_str) { mmcli_get_bearer (ctx->connection, delete_bearer_str, ctx->cancellable, (GAsyncReadyCallback)get_bearer_to_delete_ready, NULL); return; } /* Request to set current capabilities in a given modem? */ if (set_current_capabilities_str) { MMModemCapability current_capabilities; parse_current_capabilities (¤t_capabilities); mm_modem_set_current_capabilities (ctx->modem, current_capabilities, ctx->cancellable, (GAsyncReadyCallback)set_current_capabilities_ready, NULL); return; } /* Request to set allowed modes in a given modem? */ if (set_allowed_modes_str) { MMModemMode allowed; MMModemMode preferred; parse_modes (&allowed, &preferred); mm_modem_set_current_modes (ctx->modem, allowed, preferred, ctx->cancellable, (GAsyncReadyCallback)set_current_modes_ready, NULL); return; } /* Request to set current bands in a given modem? */ if (set_current_bands_str) { MMModemBand *current_bands; guint n_current_bands; parse_current_bands (¤t_bands, &n_current_bands); mm_modem_set_current_bands (ctx->modem, current_bands, n_current_bands, ctx->cancellable, (GAsyncReadyCallback)set_current_bands_ready, NULL); g_free (current_bands); return; } g_warn_if_reached (); }
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 (¤t_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 (¤t_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 (); }