static MMPluginSupportsResult supports_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task) { GUdevDevice *port; guint32 cached = 0, level; const char *driver; /* Can't do anything with non-serial ports */ port = mm_plugin_base_supports_task_get_port (task); if (strcmp (g_udev_device_get_subsystem (port), "tty")) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; driver = mm_plugin_base_supports_task_get_driver (task); if (!driver || strcmp (driver, "sierra")) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) { level = get_level_for_capabilities (cached); if (level) { mm_plugin_base_supports_task_complete (task, level); return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; } return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; } /* Otherwise kick off a probe */ if (mm_plugin_base_probe_port (base, task, NULL)) return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; }
static MMModem * grab_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task, GError **error) { GUdevDevice *port = NULL; MMModem *modem = NULL; const char *name, *subsys, *devfile, *sysfs_path; guint32 caps; MMPortType ptype = MM_PORT_TYPE_UNKNOWN; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); devfile = g_udev_device_get_device_file (port); if (!devfile) { g_set_error (error, 0, 0, "Could not get port's sysfs file."); return NULL; } subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); /* Is it a GSM secondary port? */ if (g_object_get_data (G_OBJECT (task), TAG_SIERRA_SECONDARY_PORT)) ptype = MM_PORT_TYPE_SECONDARY; caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if ((caps & MM_PLUGIN_BASE_PORT_CAP_GSM) || (ptype != MM_PORT_TYPE_UNKNOWN)) { modem = mm_modem_sierra_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base))); } else if (caps & CAP_CDMA) { modem = mm_modem_sierra_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); } if (modem) { if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) { g_object_unref (modem); return NULL; } } } else if (get_level_for_capabilities (caps) || (ptype != MM_PORT_TYPE_UNKNOWN)) { modem = existing; if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) return NULL; } return modem; }
static MMModem * grab_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task, GError **error) { GUdevDevice *port = NULL; MMModem *modem = NULL; const char *name, *subsys, *sysfs_path; guint32 caps; guint16 vendor = 0, product = 0; MMPortType ptype; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { g_set_error (error, 0, 0, "Could not get modem product ID."); return NULL; } caps = mm_plugin_base_supports_task_get_probed_capabilities (task); ptype = mm_plugin_base_probed_capabilities_to_port_type (caps); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_wavecom_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), vendor, product); } if (modem) { if (!mm_modem_grab_port (modem, subsys, name, ptype, MM_AT_PORT_FLAG_NONE, NULL, error)) { g_object_unref (modem); return NULL; } } } else if (get_level_for_capabilities (caps)) { modem = existing; if (!mm_modem_grab_port (modem, subsys, name, ptype, MM_AT_PORT_FLAG_NONE, NULL, error)) return NULL; } return modem; }
static MMPluginSupportsResult supports_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task) { GUdevDevice *port; const char *subsys, *name; guint16 vendor = 0; /* Can't do anything with non-serial ports */ port = mm_plugin_base_supports_task_get_port (task); if (strcmp (g_udev_device_get_subsystem (port), "tty")) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, NULL)) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; /* Vendor: Wavecom */ if (vendor != 0x114f) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; /* Check if a previous probing was already launched in this port */ if (mm_plugin_base_supports_task_propagate_cached (task)) { guint32 level; /* A previous probing was already done, use its results */ level = get_level_for_capabilities (mm_plugin_base_supports_task_get_probed_capabilities (task)); if (level) { mm_plugin_base_supports_task_complete (task, level); return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; } return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; } /* Otherwise kick off a probe */ if (mm_plugin_base_probe_port (base, task, 100000, NULL)) return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; }
static gboolean try_open (gpointer user_data) { MMPluginBaseSupportsTask *task = MM_PLUGIN_BASE_SUPPORTS_TASK (user_data); MMPluginBaseSupportsTaskPrivate *task_priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task); GError *error = NULL; task_priv->open_id = 0; if (!mm_serial_port_open (MM_SERIAL_PORT (task_priv->probe_port), &error)) { if (++task_priv->open_tries > 4) { /* took too long to open the port; give up */ g_warning ("(%s): failed to open after 4 tries.", mm_port_get_device (MM_PORT (task_priv->probe_port))); probe_complete (task); } else if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_OPEN_FAILED_NO_DEVICE)) { /* this is nozomi being dumb; try again */ task_priv->open_id = g_timeout_add_seconds (1, try_open, task); } else { /* some other hard error */ probe_complete (task); } g_clear_error (&error); } else { /* success, start probing */ GUdevDevice *port; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); task_priv->full_id = g_signal_connect (task_priv->probe_port, "buffer-full", G_CALLBACK (port_buffer_full), task); g_debug ("(%s): probe requested by plugin '%s'", g_udev_device_get_name (port), mm_plugin_get_name (MM_PLUGIN (task_priv->plugin))); mm_serial_port_flash (MM_SERIAL_PORT (task_priv->probe_port), 100, TRUE, flash_done, task); } return FALSE; }
gboolean mm_plugin_base_probe_port (MMPluginBase *self, MMPluginBaseSupportsTask *task, GError **error) { MMPluginBaseSupportsTaskPrivate *task_priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task); MMAtSerialPort *serial; const char *name; GUdevDevice *port; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (MM_IS_PLUGIN_BASE (self), FALSE); g_return_val_if_fail (task != NULL, FALSE); port = mm_plugin_base_supports_task_get_port (task); g_assert (port); name = g_udev_device_get_name (port); g_assert (name); serial = mm_at_serial_port_new (name, MM_PORT_TYPE_PRIMARY); if (serial == NULL) { g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Failed to create new serial port."); return FALSE; } g_object_set (serial, MM_SERIAL_PORT_SEND_DELAY, (guint64) 100000, MM_PORT_CARRIER_DETECT, FALSE, NULL); mm_at_serial_port_set_response_parser (serial, mm_serial_parser_v1_parse, mm_serial_parser_v1_new (), mm_serial_parser_v1_destroy); /* Open the port */ task_priv->probe_port = serial; task_priv->open_id = g_idle_add (try_open, task); return TRUE; }
static MMPluginSupportsResult supports_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task) { GUdevDevice *port; guint32 cached = 0, level; guint16 vendor = 0; const char *subsys, *name; /* Can't do anything with non-serial ports */ port = mm_plugin_base_supports_task_get_port (task); if (strcmp (g_udev_device_get_subsystem (port), "tty")) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, NULL)) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; /* Longcheer and TAMobile */ if (vendor != 0x1c9e && vendor != 0x1bbb) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) { level = get_level_for_capabilities (cached); if (level) { mm_plugin_base_supports_task_complete (task, level); return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; } return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; } /* Otherwise kick off a probe */ if (mm_plugin_base_probe_port (base, task, NULL)) return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; }
static MMModem * grab_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task, GError **error) { GUdevDevice *port = NULL; MMModem *modem = NULL; const char *name, *subsys, *devfile, *sysfs_path; guint32 caps; guint16 vendor = 0, product = 0; MMPortType ptype; int usbif; MMAtPortFlags pflags = MM_AT_PORT_FLAG_NONE; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); devfile = g_udev_device_get_device_file (port); if (!devfile) { g_set_error (error, 0, 0, "Could not get port's sysfs file."); return NULL; } subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { g_set_error (error, 0, 0, "Could not get modem product ID."); return NULL; } usbif = g_udev_device_get_property_as_int (port, "ID_USB_INTERFACE_NUM"); if (usbif < 0) { g_set_error (error, 0, 0, "Could not get USB device interface number."); return NULL; } caps = mm_plugin_base_supports_task_get_probed_capabilities (task); ptype = mm_plugin_base_probed_capabilities_to_port_type (caps); if (usbif + 1 == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (base), TAG_HUAWEI_PCUI_PORT))) pflags = MM_AT_PORT_FLAG_PRIMARY; else if (usbif + 1 == GPOINTER_TO_INT (g_object_get_data (G_OBJECT (base), TAG_HUAWEI_MODEM_PORT))) pflags = MM_AT_PORT_FLAG_PPP; else if (!g_object_get_data (G_OBJECT (base), TAG_GETPORTMODE_SUPPORTED)) { /* If GETPORTMODE is not supported, we assume usbif 0 is the modem port */ if ((usbif == 0) && (ptype == MM_PORT_TYPE_AT)) { pflags = MM_AT_PORT_FLAG_PPP; /* 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; } } sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_huawei_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), vendor, product); } else if (caps & CAP_CDMA) { modem = mm_modem_huawei_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), vendor, product); } if (modem) { if (!mm_modem_grab_port (modem, subsys, name, ptype, pflags, NULL, error)) { g_object_unref (modem); return NULL; } } } else { modem = existing; if (!mm_modem_grab_port (modem, subsys, name, ptype, pflags, NULL, error)) return NULL; } return modem; }
static MMPluginSupportsResult supports_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task) { GUdevDevice *port; const char *subsys, *name, *driver; int usbif; guint16 vendor = 0, product = 0; /* Can't do anything with non-serial ports */ port = mm_plugin_base_supports_task_get_port (task); if (strcmp (g_udev_device_get_subsystem (port), "tty")) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; if (vendor != 0x12d1) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; /* The Gobi driver should claim Huawei Gobi modems */ driver = mm_plugin_base_supports_task_get_driver (task); if (g_strcmp0 (driver, "qcserial") == 0) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; usbif = g_udev_device_get_property_as_int (port, "ID_USB_INTERFACE_NUM"); if (usbif < 0) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; /* The primary port (called the "modem" port in the Windows drivers) is * always USB interface 0, and we need to detect that interface first for * two reasons: (1) to disable unsolicited messages on other ports that * may fill up the buffer and crash the device, and (2) to attempt to get * the port layout for hints about what the secondary port is (called the * "pcui" port in Windows). Thus we probe USB interface 0 first and defer * probing other interfaces until we've got if0, at which point we allow * the other ports to be probed too. */ if (!existing && usbif != 0) return MM_PLUGIN_SUPPORTS_PORT_DEFER; /* Check if a previous probing was already launched in this port */ if (mm_plugin_base_supports_task_propagate_cached (task)) { guint32 level; /* A previous probing was already done, use its results */ level = get_level_for_capabilities (mm_plugin_base_supports_task_get_probed_capabilities (task)); if (level) { mm_plugin_base_supports_task_complete (task, level); return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; } return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; } /* Turn off unsolicited messages on secondary ports until needed, * and try to get a port map from the modem. The response will * get handled in custom_init_response(). */ if (usbif == 0) { mm_plugin_base_supports_task_add_custom_init_command (task, "AT^CURC=0", 3, /* delay */ curc_response_cb, NULL); mm_plugin_base_supports_task_add_custom_init_command (task, "AT^GETPORTMODE", 3, /* delay */ getportmode_response_cb, NULL); } /* Kick off a probe */ if (mm_plugin_base_probe_port (base, task, 100000, NULL)) return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; }
static MMPluginSupportsResult supports_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task) { GUdevDevice *port; guint16 vendor = 0; const char *subsys, *name; /* Can't do anything with non-serial ports */ port = mm_plugin_base_supports_task_get_port (task); subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, NULL)) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; if (vendor != 0x19d2) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; if (!strcmp (subsys, "net")) { /* If we don't know the modem's type yet, defer grabbing the port * until we know the type. */ if (!existing) return MM_PLUGIN_SUPPORTS_PORT_DEFER; mm_plugin_base_supports_task_complete (task, 10); return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; } if (strcmp (subsys, "tty")) return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; /* Check if a previous probing was already launched in this port */ if (mm_plugin_base_supports_task_propagate_cached (task)) { guint32 level; /* A previous probing was already done, use its results */ level = get_level_for_capabilities (mm_plugin_base_supports_task_get_probed_capabilities (task)); if (level) { mm_plugin_base_supports_task_complete (task, level); return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; } return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; } /* Otherwise kick off a probe */ /* Many ZTE devices will flood the port with "Message waiting" indications * and eventually fill up the serial buffer and crash. We need to turn off * that indicator. See NetworkManager commits * 1235f71b20c92cded4abd976ccc5010649aae1a0 and * f38ad328acfdc6ce29dd1380602c546b064161ae for more details. */ mm_plugin_base_supports_task_add_custom_init_command (task, "ATE0+CPMS?", 3, custom_init_response_cb, NULL); if (mm_plugin_base_probe_port (base, task, 100000, NULL)) return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; }
static MMModem * grab_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task, GError **error) { GUdevDevice *port = NULL; MMModem *modem = NULL; const char *name, *subsys, *sysfs_path; guint32 caps; MMPortType ptype; MMAtPortFlags pflags = MM_AT_PORT_FLAG_NONE; guint16 vendor = 0, product = 0; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); /* Look for port type hints */ if (g_udev_device_get_property_as_boolean (port, "ID_MM_ZTE_PORT_TYPE_MODEM")) pflags = MM_AT_PORT_FLAG_PRIMARY; else if (g_udev_device_get_property_as_boolean (port, "ID_MM_ZTE_PORT_TYPE_AUX")) pflags = MM_AT_PORT_FLAG_SECONDARY; subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { g_set_error (error, 0, 0, "Could not get modem product ID."); return NULL; } caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); ptype = mm_plugin_base_probed_capabilities_to_port_type (caps); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_zte_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), vendor, product); } else if (caps & CAP_CDMA) { modem = mm_generic_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A), vendor, product); } if (modem) { if (!mm_modem_grab_port (modem, subsys, name, ptype, pflags, NULL, error)) { g_object_unref (modem); return NULL; } } } else if (get_level_for_capabilities (caps) || (!strcmp (subsys, "net"))) { modem = existing; if (!mm_modem_grab_port (modem, subsys, name, ptype, pflags, NULL, error)) return NULL; } return modem; }
static MMModem * grab_port (MMPluginBase *base, MMModem *existing, MMPluginBaseSupportsTask *task, GError **error) { GUdevDevice *port = NULL; MMModem *modem = NULL; const char *name, *subsys, *sysfs_path; guint32 caps; MMPortType ptype = MM_PORT_TYPE_UNKNOWN; port = mm_plugin_base_supports_task_get_port (task); g_assert (port); /* Look for port type hints; just probing can't distinguish which port should * be the data/primary port on these devices. We have to tag them based on * what the Windows .INF files say the port layout should be. */ if (g_udev_device_get_property_as_boolean (port, "ID_MM_LONGCHEER_PORT_TYPE_MODEM")) ptype = MM_PORT_TYPE_PRIMARY; else if (g_udev_device_get_property_as_boolean (port, "ID_MM_LONGCHEER_PORT_TYPE_AUX")) ptype = MM_PORT_TYPE_SECONDARY; /* If the device was tagged by the udev rules, then ignore any other ports * to guard against race conditions if a device just happens to show up * with more than two AT-capable ports. */ if ( (ptype == MM_PORT_TYPE_UNKNOWN) && g_udev_device_get_property_as_boolean (port, "ID_MM_LONGCHEER_TAGGED")) ptype = MM_PORT_TYPE_IGNORED; subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); caps = mm_plugin_base_supports_task_get_probed_capabilities (task); sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); if (!existing) { if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { modem = mm_modem_longcheer_gsm_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base))); } else if (caps & CAP_CDMA) { modem = mm_generic_cdma_new (sysfs_path, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base)), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); } if (modem) { if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) { g_object_unref (modem); return NULL; } } } else if (get_level_for_capabilities (caps)) { if (caps & MM_PLUGIN_BASE_PORT_CAP_QCDM) ptype = MM_PORT_TYPE_QCDM; modem = existing; if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) return NULL; } return modem; }