cinterion: handle RS232 modems
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <gmodule.h>
|
||||
#include "mm-plugin-cinterion.h"
|
||||
#include "mm-modem-cinterion-gsm.h"
|
||||
#include "mm-log.h"
|
||||
|
||||
G_DEFINE_TYPE (MMPluginCinterion, mm_plugin_cinterion, MM_TYPE_PLUGIN_BASE)
|
||||
|
||||
@@ -45,13 +46,68 @@ get_level_for_capabilities (guint32 capabilities)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_vendor_cinterion (MMPluginBase *base,
|
||||
GUdevDevice *port)
|
||||
{
|
||||
const char *subsys, *name;
|
||||
guint16 vendor = 0;
|
||||
gchar *probed_vendor;
|
||||
gchar *probed_vendor_strdown;
|
||||
gboolean probed_vendor_correct;
|
||||
|
||||
/* Try to get device IDs from udev. Note that it is not an error
|
||||
* if we can't get them in our case, as we also support serial
|
||||
* modems. */
|
||||
subsys = g_udev_device_get_subsystem (port);
|
||||
name = g_udev_device_get_name (port);
|
||||
mm_plugin_base_get_device_ids (base, subsys, name, &vendor, NULL);
|
||||
|
||||
/* Vendors: Cinterion (0x1e2d)
|
||||
* Siemens (0x0681)
|
||||
*/
|
||||
if (vendor == 0x1e2d || vendor == 0x0681) {
|
||||
mm_dbg ("Cinterion/Siemens USB modem detected");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* We may get Cinterion modems connected in RS232 port, try to get
|
||||
* probed Vendor ID string to check */
|
||||
if (!mm_plugin_base_get_cached_product_info (base, port, &probed_vendor, NULL) ||
|
||||
!probed_vendor)
|
||||
return FALSE;
|
||||
|
||||
/* Lowercase the vendor string and compare */
|
||||
probed_vendor_strdown = g_utf8_strdown (probed_vendor, -1);
|
||||
probed_vendor_correct = ((strstr (probed_vendor_strdown, "cinterion") ||
|
||||
strstr (probed_vendor_strdown, "siemens")) ?
|
||||
TRUE : FALSE);
|
||||
g_free (probed_vendor_strdown);
|
||||
g_free (probed_vendor);
|
||||
|
||||
if (!probed_vendor_correct)
|
||||
return FALSE;
|
||||
|
||||
mm_dbg ("Cinterion/Siemens RS232 modem detected");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
probe_result (MMPluginBase *base,
|
||||
MMPluginBaseSupportsTask *task,
|
||||
guint32 capabilities,
|
||||
gpointer user_data)
|
||||
{
|
||||
mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities));
|
||||
GUdevDevice *port;
|
||||
|
||||
/* Note: the signal contains only capabilities, but we can also query the
|
||||
* probed vendor and product strings here. */
|
||||
|
||||
/* Check vendor */
|
||||
port = mm_plugin_base_supports_task_get_port (task);
|
||||
mm_plugin_base_supports_task_complete (task,
|
||||
(check_vendor_cinterion (base, port) ?
|
||||
get_level_for_capabilities (capabilities) : 0));
|
||||
}
|
||||
|
||||
static MMPluginSupportsResult
|
||||
@@ -60,41 +116,31 @@ supports_port (MMPluginBase *base,
|
||||
MMPluginBaseSupportsTask *task)
|
||||
{
|
||||
GUdevDevice *port;
|
||||
guint32 cached = 0, level;
|
||||
const char *subsys, *name;
|
||||
guint16 vendor = 0;
|
||||
guint32 cached = 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;
|
||||
|
||||
/* Vendors: Cinterion (0x1e2d)
|
||||
* Siemens (0x0681)
|
||||
*/
|
||||
if (vendor != 0x1e2d && vendor != 0x0681)
|
||||
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);
|
||||
/* First thing to check in this plugin is if we got capabilities already.
|
||||
* This is because we have a later check of the probed vendor, which is
|
||||
* taken also during port probing. */
|
||||
if (!mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Otherwise kick off a probe */
|
||||
if (mm_plugin_base_probe_port (base, task, 100000, NULL))
|
||||
return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS;
|
||||
/* Check vendor */
|
||||
if (!check_vendor_cinterion (base, port))
|
||||
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
|
||||
|
||||
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
|
||||
/* Completed! */
|
||||
mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (cached));
|
||||
return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static MMModem *
|
||||
@@ -107,18 +153,18 @@ grab_port (MMPluginBase *base,
|
||||
MMModem *modem = NULL;
|
||||
const char *name, *subsys, *sysfs_path;
|
||||
guint32 caps;
|
||||
guint16 vendor = 0, product = 0;
|
||||
guint16 vendor = 0x1e2d;
|
||||
guint16 product = 0;
|
||||
|
||||
port = mm_plugin_base_supports_task_get_port (task);
|
||||
g_assert (port);
|
||||
|
||||
/* Try to get Product IDs from udev. Note that it is not an error
|
||||
* if we can't get them in our case, as we also support serial
|
||||
* modems. */
|
||||
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;
|
||||
}
|
||||
mm_plugin_base_get_device_ids (base, subsys, name, NULL, &product);
|
||||
|
||||
caps = mm_plugin_base_supports_task_get_probed_capabilities (task);
|
||||
sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task);
|
||||
|
Reference in New Issue
Block a user