static void propagate_port_mode_results (GList *probes) { MMDevice *device; GList *l; gboolean primary_flagged = FALSE; g_assert (probes != NULL); device = mm_port_probe_peek_device (MM_PORT_PROBE (probes->data)); /* Now we propagate the tags to the specific port probes */ for (l = probes; l; l = g_list_next (l)) { MMPortSerialAtFlag at_port_flags = MM_PORT_SERIAL_AT_FLAG_NONE; gint usbif; usbif = g_udev_device_get_property_as_int (mm_port_probe_peek_port (MM_PORT_PROBE (l->data)), "ID_USB_INTERFACE_NUM"); if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED))) { if (usbif + 1 == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_PCUI_PORT))) { at_port_flags = MM_PORT_SERIAL_AT_FLAG_PRIMARY; primary_flagged = TRUE; } else if (usbif + 1 == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_MODEM_PORT))) at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP; else if (!g_object_get_data (G_OBJECT (device), TAG_HUAWEI_MODEM_PORT) && usbif + 1 == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_NDIS_PORT))) /* If NDIS reported only instead of MDM, use it */ at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP; } else if (usbif == 0 && mm_port_probe_is_at (MM_PORT_PROBE (l->data))) { /* If GETPORTMODE is not supported, we assume usbif 0 is the modem port */ at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP; /* /\* TODO. */ /* * For CDMA modems we assume usbif0 is both primary and PPP, since */ /* * they don't have problems with talking on secondary ports. */ /* *\/ */ /* if (caps & CAP_CDMA) */ /* pflags |= MM_PORT_SERIAL_AT_FLAG_PRIMARY; */ } g_object_set_data (G_OBJECT (l->data), TAG_AT_PORT_FLAGS, GUINT_TO_POINTER (at_port_flags)); } if (primary_flagged) return; /* For devices exposing a cdc-wdm port, make sure it gets flagged as primary, if there is none * already */ for (l = probes; l; l = g_list_next (l)) { MMPortProbe *probe = MM_PORT_PROBE (l->data); if (mm_port_probe_is_at (probe) && g_str_has_prefix (mm_port_probe_get_port_subsys (probe), "usb") && g_str_has_prefix (mm_port_probe_get_port_name (probe), "cdc-wdm")) { /* Flag as PRIMARY and do nothing else */ g_object_set_data (G_OBJECT (probe), TAG_AT_PORT_FLAGS, GUINT_TO_POINTER (MM_PORT_SERIAL_AT_FLAG_PRIMARY)); break; } } }
static void try_next_usbif (MMDevice *device) { FirstInterfaceContext *fi_ctx; GList *l; gint closest; fi_ctx = g_object_get_data (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT); g_assert (fi_ctx != NULL); /* Look for the next closest one among the list of interfaces in the device, * and enable that one as being first */ closest = G_MAXINT; for (l = mm_device_peek_port_probe_list (device); l; l = g_list_next (l)) { gint usbif; usbif = g_udev_device_get_property_as_int (mm_port_probe_peek_port (MM_PORT_PROBE (l->data)), "ID_USB_INTERFACE_NUM"); if (usbif == fi_ctx->first_usbif) { g_warn_if_reached (); } else if (usbif > fi_ctx->first_usbif && usbif < closest) { closest = usbif; } } if (closest == G_MAXINT) { /* Retry with interface 0... */ closest = 0; } mm_dbg ("(Huawei) Will try initial probing with interface '%d' instead", closest); fi_ctx->first_usbif = closest; }
MMPortProbe * mm_port_probe_new (MMDevice *device, GUdevDevice *port) { return MM_PORT_PROBE (g_object_new (MM_TYPE_PORT_PROBE, MM_PORT_PROBE_DEVICE, device, MM_PORT_PROBE_PORT, port, NULL)); }
static void propagate_port_mode_results (GList *probes) { MMDevice *device; GList *l; g_assert (probes != NULL); device = mm_port_probe_peek_device (MM_PORT_PROBE (probes->data)); /* Now we propagate the tags to the specific port probes */ for (l = probes; l; l = g_list_next (l)) { MMAtPortFlag at_port_flags = MM_AT_PORT_FLAG_NONE; gint usbif; usbif = g_udev_device_get_property_as_int (mm_port_probe_peek_port (MM_PORT_PROBE (l->data)), "ID_USB_INTERFACE_NUM"); if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (device), TAG_GETPORTMODE_SUPPORTED))) { if (usbif + 1 == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_PCUI_PORT))) at_port_flags = MM_AT_PORT_FLAG_PRIMARY; else if (usbif + 1 == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_MODEM_PORT))) at_port_flags = MM_AT_PORT_FLAG_PPP; else if (!g_object_get_data (G_OBJECT (device), TAG_HUAWEI_MODEM_PORT) && usbif + 1 == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (device), TAG_HUAWEI_NDIS_PORT))) /* If NDIS reported only instead of MDM, use it */ at_port_flags = MM_AT_PORT_FLAG_PPP; } else if (usbif == 0 && mm_port_probe_is_at (MM_PORT_PROBE (l->data))) { /* If GETPORTMODE is not supported, we assume usbif 0 is the modem port */ at_port_flags = MM_AT_PORT_FLAG_PPP; /* /\* TODO. */ /* * For CDMA modems we assume usbif0 is both primary and PPP, since */ /* * they don't have problems with talking on secondary ports. */ /* *\/ */ /* if (caps & CAP_CDMA) */ /* pflags |= MM_AT_PORT_FLAG_PRIMARY; */ } g_object_set_data (G_OBJECT (l->data), TAG_AT_PORT_FLAGS, GUINT_TO_POINTER (at_port_flags)); } }
static void dispose (GObject *object) { MMPortProbe *self = MM_PORT_PROBE (object); /* We didn't get a reference to the device */ self->priv->device = NULL; g_clear_object (&self->priv->port); G_OBJECT_CLASS (mm_port_probe_parent_class)->dispose (object); }
gboolean mm_port_probe_list_is_icera (GList *probes) { GList *l; for (l = probes; l; l = g_list_next (l)) { if (mm_port_probe_is_icera (MM_PORT_PROBE (l->data))) return TRUE; } return FALSE; }
gboolean mm_port_probe_list_has_qmi_port (GList *list) { GList *l; for (l = list; l; l = g_list_next (l)) { if (mm_port_probe_is_qmi (MM_PORT_PROBE (l->data))) return TRUE; } return FALSE; }
static void finalize (GObject *object) { MMPortProbe *self = MM_PORT_PROBE (object); /* We should never have a task here */ g_assert (self->priv->task == NULL); g_free (self->priv->vendor); g_free (self->priv->product); G_OBJECT_CLASS (mm_port_probe_parent_class)->finalize (object); }
gboolean mm_port_probe_list_has_at_port (GList *list) { GList *l; for (l = list; l; l = g_list_next (l)){ MMPortProbe *probe = MM_PORT_PROBE (l->data); if (probe->priv->flags & MM_PORT_PROBE_AT && probe->priv->is_at) return TRUE; } return FALSE; }
MMPortProbe * mm_port_probe_new (GUdevDevice *port, const gchar *physdev_path, const gchar *driver) { MMPortProbe *self; self = MM_PORT_PROBE (g_object_new (MM_TYPE_PORT_PROBE, NULL)); self->priv->port = g_object_ref (port); self->priv->subsys = g_strdup (g_udev_device_get_subsystem (port)); self->priv->name = g_strdup (g_udev_device_get_name (port)); self->priv->physdev_path = g_strdup (physdev_path); self->priv->driver = g_strdup (driver); return self; }
static gboolean sierra_port_probe_list_is_icera (GList *probes) { GList *l; for (l = probes; l; l = g_list_next (l)) { /* Only assume the Icera probing check is valid IF the port is not * secondary. This will skip the stupid ports which reply OK to every * AT command, even the one we use to check for Icera support */ if (mm_port_probe_is_icera (MM_PORT_PROBE (l->data)) && !g_object_get_data (G_OBJECT (l->data), TAG_SIERRA_APP_PORT)) return TRUE; } return FALSE; }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { MMPortProbe *self = MM_PORT_PROBE (object); switch (prop_id) { case PROP_DEVICE: g_value_set_object (value, self->priv->device); break; case PROP_PORT: g_value_set_object (value, self->priv->port); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void try_next_usbif (MMDevice *device) { FirstInterfaceContext *fi_ctx; GList *l; gint closest; fi_ctx = g_object_get_data (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT); g_assert (fi_ctx != NULL); /* Look for the next closest one among the list of interfaces in the device, * and enable that one as being first */ closest = G_MAXINT; for (l = mm_device_peek_port_probe_list (device); l; l = g_list_next (l)) { MMPortProbe *probe = MM_PORT_PROBE (l->data); /* Only expect ttys for next probing attempt */ if (g_str_equal (mm_port_probe_get_port_subsys (probe), "tty")) { gint usbif; usbif = g_udev_device_get_property_as_int (mm_port_probe_peek_port (probe), "ID_USB_INTERFACE_NUM"); if (usbif == fi_ctx->first_usbif) { /* This is the one we just probed, which wasn't yet removed, so just skip it */ } else if (usbif > fi_ctx->first_usbif && usbif < closest) { closest = usbif; } } } if (closest == G_MAXINT) { /* No more ttys to try! Just return something */ closest = 0; mm_dbg ("(Huawei) No more ports to run initial probing"); } else { mm_dbg ("(Huawei) Will try initial probing with interface '%d' instead", closest); } fi_ctx->first_usbif = closest; }
static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { MMPortProbe *self = MM_PORT_PROBE (object); switch (prop_id) { case PROP_DEVICE: /* construct only, no new reference! */ self->priv->device = g_value_get_object (value); break; case PROP_PORT: /* construct only */ self->priv->port = g_value_dup_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void port_probe_run_ready (MMPortProbe *probe, GAsyncResult *probe_result, PortProbeRunContext *ctx) { GError *error = NULL; if (!mm_port_probe_run_finish (probe, probe_result, &error)) { /* Probing failed saying the port is unsupported. This is not to be * treated as a generic error, the plugin is just telling us as nicely * as it can that the port is not supported, so don't warn these cases. */ if (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED)) { g_simple_async_result_set_op_res_gpointer (ctx->result, GUINT_TO_POINTER (MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED), NULL); } /* Probing failed but the plugin tells us to retry; so we'll defer the * probing a bit */ else if (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_RETRY)) { g_simple_async_result_set_op_res_gpointer (ctx->result, GUINT_TO_POINTER (MM_PLUGIN_SUPPORTS_PORT_DEFER), NULL); } /* For remaining errors, just propagate them */ else { g_simple_async_result_take_error (ctx->result, error); } } else { /* Probing succeeded */ MMPluginSupportsResult supports_result; if (!apply_post_probing_filters (ctx->self, ctx->flags, probe)) { /* Port is supported! */ supports_result = MM_PLUGIN_SUPPORTS_PORT_SUPPORTED; /* If we were looking for AT ports, and the port is AT, * and we were told that only one AT port is expected, cancel AT * probings in the other available support tasks of the SAME * device. */ if (ctx->self->priv->single_at && ctx->flags & MM_PORT_PROBE_AT && mm_port_probe_is_at (probe)) { GList *l; for (l = mm_device_peek_port_probe_list (ctx->device); l; l = g_list_next (l)) { if (l->data != probe) { mm_port_probe_run_cancel_at_probing (MM_PORT_PROBE (l->data)); } } } } else { /* Unsupported port, remove from internal tracking HT */ supports_result = MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; } g_simple_async_result_set_op_res_gpointer (ctx->result, GUINT_TO_POINTER (supports_result), NULL); } /* Complete the async supports port request */ g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->device); g_object_unref (ctx->result); g_object_unref (ctx->self); g_free (ctx); }
MMBaseModem * mm_plugin_create_modem (MMPlugin *self, MMDevice *device, GError **error) { MMBaseModem *modem = NULL; GList *port_probes, *l; port_probes = mm_device_peek_port_probe_list (device); /* Let the plugin create the modem from the port probe results */ modem = MM_PLUGIN_GET_CLASS (self)->create_modem (MM_PLUGIN (self), mm_device_get_path (device), mm_device_get_drivers (device), mm_device_get_vendor (device), mm_device_get_product (device), port_probes, error); if (modem) { /* Grab each port */ for (l = port_probes; l; l = g_list_next (l)) { GError *inner_error = NULL; MMPortProbe *probe = MM_PORT_PROBE (l->data); gboolean grabbed; /* If grabbing a port fails, just warn. We'll decide if the modem is * valid or not when all ports get organized */ /* We apply again the subsystem filter, as the port may have been * probed and accepted by the generic plugin, which is overwritten * by the specific one when needed. */ if (apply_subsystem_filter (self, mm_port_probe_peek_port (probe))) { grabbed = FALSE; inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "unsupported subsystem: '%s'", mm_port_probe_get_port_subsys (probe)); } #if !defined WITH_QMI else if (mm_port_probe_get_port_type (probe) == MM_PORT_TYPE_NET && g_str_equal (mm_device_utils_get_port_driver (mm_port_probe_peek_port (probe)), "qmi_wwan")) { grabbed = FALSE; inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, "ignoring QMI net port"); } #endif else if (MM_PLUGIN_GET_CLASS (self)->grab_port) grabbed = MM_PLUGIN_GET_CLASS (self)->grab_port (MM_PLUGIN (self), modem, probe, &inner_error); else grabbed = mm_base_modem_grab_port (modem, mm_port_probe_get_port_subsys (probe), mm_port_probe_get_port_name (probe), mm_port_probe_get_port_type (probe), MM_AT_PORT_FLAG_NONE, &inner_error); if (!grabbed) { mm_warn ("Could not grab port (%s/%s): '%s'", mm_port_probe_get_port_subsys (MM_PORT_PROBE (l->data)), mm_port_probe_get_port_name (MM_PORT_PROBE (l->data)), inner_error ? inner_error->message : "unknown error"); g_clear_error (&inner_error); } } /* If organizing ports fails, consider the modem invalid */ if (!mm_base_modem_organize_ports (modem, error)) g_clear_object (&modem); } return modem; }
void mm_plugin_supports_port (MMPlugin *self, MMDevice *device, GUdevDevice *port, GAsyncReadyCallback callback, gpointer user_data) { MMPortProbe *probe; GSimpleAsyncResult *async_result; PortProbeRunContext *ctx; gboolean need_vendor_probing; gboolean need_product_probing; MMPortProbeFlag probe_run_flags; gchar *probe_list_str; async_result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, mm_plugin_supports_port); /* Apply filters before launching the probing */ if (apply_pre_probing_filters (self, device, port, &need_vendor_probing, &need_product_probing)) { /* Filtered! */ g_simple_async_result_set_op_res_gpointer (async_result, GUINT_TO_POINTER (MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED), NULL); g_simple_async_result_complete_in_idle (async_result); goto out; } /* Need to launch new probing */ probe = MM_PORT_PROBE (mm_device_get_port_probe (device, port)); if (!probe) { /* This may happen if the ports get removed from the device while * probing is ongoing */ g_simple_async_result_set_error (async_result, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "(%s) Missing port probe for port (%s/%s)", self->priv->name, g_udev_device_get_subsystem (port), g_udev_device_get_name (port)); g_simple_async_result_complete_in_idle (async_result); goto out; } /* Before launching any probing, check if the port is a net device. */ if (g_str_equal (g_udev_device_get_subsystem (port), "net")) { mm_dbg ("(%s) [%s] probing deferred until result suggested", self->priv->name, g_udev_device_get_name (port)); g_simple_async_result_set_op_res_gpointer ( async_result, GUINT_TO_POINTER (MM_PLUGIN_SUPPORTS_PORT_DEFER_UNTIL_SUGGESTED), NULL); g_simple_async_result_complete_in_idle (async_result); goto out; } /* Build flags depending on what probing needed */ if (!g_str_has_prefix (g_udev_device_get_name (port), "cdc-wdm")) { /* Serial ports... */ probe_run_flags = MM_PORT_PROBE_NONE; if (self->priv->at) probe_run_flags |= MM_PORT_PROBE_AT; else if (self->priv->single_at) probe_run_flags |= MM_PORT_PROBE_AT; if (need_vendor_probing) probe_run_flags |= (MM_PORT_PROBE_AT | MM_PORT_PROBE_AT_VENDOR); if (need_product_probing) probe_run_flags |= (MM_PORT_PROBE_AT | MM_PORT_PROBE_AT_PRODUCT); if (self->priv->qcdm) probe_run_flags |= MM_PORT_PROBE_QCDM; if (self->priv->icera_probe || self->priv->allowed_icera || self->priv->forbidden_icera) probe_run_flags |= (MM_PORT_PROBE_AT | MM_PORT_PROBE_AT_ICERA); } else { /* cdc-wdm ports... */ probe_run_flags = MM_PORT_PROBE_QMI; } g_assert (probe_run_flags != MM_PORT_PROBE_NONE); /* If a modem is already available and the plugin says that only one AT port is * expected, check if we alredy got the single AT port. And if so, we know this * port being probed won't be AT. */ if (self->priv->single_at && mm_port_probe_list_has_at_port (mm_device_peek_port_probe_list (device)) && !mm_port_probe_is_at (probe)) { mm_dbg ("(%s) [%s] not setting up AT probing tasks: " "modem already has the expected single AT port", self->priv->name, g_udev_device_get_name (port)); /* Assuming it won't be an AT port. We still run the probe anyway, in * case we need to check for other port types (e.g. QCDM) */ mm_port_probe_set_result_at (probe, FALSE); } /* Setup async call context */ ctx = g_new (PortProbeRunContext, 1); ctx->self = g_object_ref (self); ctx->device = g_object_ref (device); ctx->result = g_object_ref (async_result); ctx->flags = probe_run_flags; /* Launch the probe */ probe_list_str = mm_port_probe_flag_build_string_from_mask (ctx->flags); mm_dbg ("(%s) [%s] probe required: '%s'", self->priv->name, g_udev_device_get_name (port), probe_list_str); g_free (probe_list_str); mm_port_probe_run (probe, ctx->flags, self->priv->send_delay, self->priv->remove_echo, self->priv->custom_at_probe, self->priv->custom_init, (GAsyncReadyCallback)port_probe_run_ready, ctx); out: g_object_unref (async_result); }