1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details:
13
* Copyright (C) 2008 - 2009 Novell, Inc.
14
* Copyright (C) 2009 - 2010 Red Hat, Inc.
19
#include "mm-plugin-x22x.h"
20
#include "mm-modem-x22x-gsm.h"
21
#include "mm-generic-gsm.h"
23
G_DEFINE_TYPE (MMPluginX22x, mm_plugin_x22x, MM_TYPE_PLUGIN_BASE)
25
int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
26
int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
28
G_MODULE_EXPORT MMPlugin *
29
mm_plugin_create (void)
31
return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_X22X,
32
MM_PLUGIN_BASE_NAME, "X22X",
36
/*****************************************************************************/
39
get_level_for_capabilities (guint32 capabilities)
41
/* These modems have the same vendor ID as a few of the other
42
* Alcatel/TCT/T&A modems, and the longcheer plugin will try to claim them
43
* too. So we provide a higher support level here to make sure this
44
* plugin tries to grab it's supported devices first.
46
if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM)
48
if (capabilities & MM_PLUGIN_BASE_PORT_CAP_QCDM)
54
probe_result (MMPluginBase *base,
55
MMPluginBaseSupportsTask *task,
59
mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities));
62
static MMPluginSupportsResult
63
supports_port (MMPluginBase *base,
65
MMPluginBaseSupportsTask *task)
68
guint32 cached = 0, level;
70
const char *subsys, *name;
72
/* Can't do anything with non-serial ports */
73
port = mm_plugin_base_supports_task_get_port (task);
74
if (strcmp (g_udev_device_get_subsystem (port), "tty"))
75
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
77
subsys = g_udev_device_get_subsystem (port);
78
name = g_udev_device_get_name (port);
80
if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, NULL))
81
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
83
/* Only TCT/T&A for now */
85
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
87
/* If the port wasn't tagged, we don't support it */
88
if (!g_udev_device_get_property_as_boolean (port, "ID_MM_X22X_TAGGED"))
89
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
91
if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) {
92
level = get_level_for_capabilities (cached);
94
mm_plugin_base_supports_task_complete (task, level);
95
return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS;
97
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
100
/* Otherwise kick off a probe */
101
if (mm_plugin_base_probe_port (base, task, NULL))
102
return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS;
104
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
108
grab_port (MMPluginBase *base,
110
MMPluginBaseSupportsTask *task,
113
GUdevDevice *port = NULL;
114
MMModem *modem = NULL;
115
const char *name, *subsys, *sysfs_path;
117
MMPortType ptype = MM_PORT_TYPE_UNKNOWN;
118
guint16 vendor = 0, product = 0;
120
port = mm_plugin_base_supports_task_get_port (task);
123
/* Look for port type hints; just probing can't distinguish which port should
124
* be the data/primary port on these devices. We have to tag them based on
125
* what the Windows .INF files say the port layout should be.
127
if (g_udev_device_get_property_as_boolean (port, "ID_MM_X22X_PORT_TYPE_MODEM"))
128
ptype = MM_PORT_TYPE_PRIMARY;
129
else if (g_udev_device_get_property_as_boolean (port, "ID_MM_X22X_PORT_TYPE_AUX"))
130
ptype = MM_PORT_TYPE_SECONDARY;
132
/* If the device was tagged by the udev rules, then ignore any other ports
133
* to guard against race conditions if a device just happens to show up
134
* with more than two AT-capable ports.
136
if ( (ptype == MM_PORT_TYPE_UNKNOWN)
137
&& g_udev_device_get_property_as_boolean (port, "ID_MM_X22X_TAGGED"))
138
ptype = MM_PORT_TYPE_IGNORED;
140
subsys = g_udev_device_get_subsystem (port);
141
name = g_udev_device_get_name (port);
143
if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) {
144
g_set_error (error, 0, 0, "Could not get modem product ID.");
148
caps = mm_plugin_base_supports_task_get_probed_capabilities (task);
149
sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task);
151
if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) {
152
modem = mm_modem_x22x_gsm_new (sysfs_path,
153
mm_plugin_base_supports_task_get_driver (task),
154
mm_plugin_get_name (MM_PLUGIN (base)),
160
if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) {
161
g_object_unref (modem);
165
} else if (get_level_for_capabilities (caps)) {
166
if (caps & MM_PLUGIN_BASE_PORT_CAP_QCDM)
167
ptype = MM_PORT_TYPE_QCDM;
170
if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error))
177
/*****************************************************************************/
180
mm_plugin_x22x_init (MMPluginX22x *self)
182
g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL);
186
mm_plugin_x22x_class_init (MMPluginX22xClass *klass)
188
MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass);
190
pb_class->supports_port = supports_port;
191
pb_class->grab_port = grab_port;