~modemmanager/modemmanager/oneiric-proposed

« back to all changes in this revision

Viewing changes to plugins/mm-plugin-x22x.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2011-02-25 00:08:15 UTC
  • mfrom: (9.1.5 natty)
  • Revision ID: james.westby@ubuntu.com-20110225000815-pyu83ugcxxvdt37l
Tags: 0.4+git.20110124t203624.00b6cce-1
* Upload to unstable.
* Fixes GTest build failures. (Closes: #614448)
* Switch to source format 3.0 (quilt)
  - Add debian/source/format.
  - Drop Build-Depends on quilt.
  - Remove /usr/share/cdbs/1/rules/patchsys-quilt.mk from debian/rules.
* Bump Standards-Version to 3.9.1. No further changes.
* Bump Build-Depends on libdbus-glib-1-dev to (>= 0.86).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/*
 
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.
 
7
 *
 
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:
 
12
 *
 
13
 * Copyright (C) 2008 - 2009 Novell, Inc.
 
14
 * Copyright (C) 2009 - 2010 Red Hat, Inc.
 
15
 */
 
16
 
 
17
#include <string.h>
 
18
#include <gmodule.h>
 
19
#include "mm-plugin-x22x.h"
 
20
#include "mm-modem-x22x-gsm.h"
 
21
#include "mm-generic-gsm.h"
 
22
 
 
23
G_DEFINE_TYPE (MMPluginX22x, mm_plugin_x22x, MM_TYPE_PLUGIN_BASE)
 
24
 
 
25
int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
 
26
int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
 
27
 
 
28
G_MODULE_EXPORT MMPlugin *
 
29
mm_plugin_create (void)
 
30
{
 
31
    return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_X22X,
 
32
                                    MM_PLUGIN_BASE_NAME, "X22X",
 
33
                                    NULL));
 
34
}
 
35
 
 
36
/*****************************************************************************/
 
37
 
 
38
static guint32
 
39
get_level_for_capabilities (guint32 capabilities)
 
40
{
 
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.
 
45
     */
 
46
    if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM)
 
47
        return 20;
 
48
    if (capabilities & MM_PLUGIN_BASE_PORT_CAP_QCDM)
 
49
        return 20;
 
50
    return 0;
 
51
}
 
52
 
 
53
static void
 
54
probe_result (MMPluginBase *base,
 
55
              MMPluginBaseSupportsTask *task,
 
56
              guint32 capabilities,
 
57
              gpointer user_data)
 
58
{
 
59
    mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities));
 
60
}
 
61
 
 
62
static MMPluginSupportsResult
 
63
supports_port (MMPluginBase *base,
 
64
               MMModem *existing,
 
65
               MMPluginBaseSupportsTask *task)
 
66
{
 
67
    GUdevDevice *port;
 
68
    guint32 cached = 0, level;
 
69
    guint16 vendor = 0;
 
70
    const char *subsys, *name;
 
71
 
 
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;
 
76
 
 
77
    subsys = g_udev_device_get_subsystem (port);
 
78
    name = g_udev_device_get_name (port);
 
79
 
 
80
    if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, NULL))
 
81
        return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
 
82
 
 
83
    /* Only TCT/T&A for now */
 
84
    if (vendor != 0x1bbb)
 
85
        return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
 
86
 
 
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;
 
90
 
 
91
    if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) {
 
92
        level = get_level_for_capabilities (cached);
 
93
        if (level) {
 
94
            mm_plugin_base_supports_task_complete (task, level);
 
95
            return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS;
 
96
        }
 
97
        return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
 
98
    }
 
99
 
 
100
    /* Otherwise kick off a probe */
 
101
    if (mm_plugin_base_probe_port (base, task, NULL))
 
102
        return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS;
 
103
 
 
104
    return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
 
105
}
 
106
 
 
107
static MMModem *
 
108
grab_port (MMPluginBase *base,
 
109
           MMModem *existing,
 
110
           MMPluginBaseSupportsTask *task,
 
111
           GError **error)
 
112
{
 
113
    GUdevDevice *port = NULL;
 
114
    MMModem *modem = NULL;
 
115
    const char *name, *subsys, *sysfs_path;
 
116
    guint32 caps;
 
117
    MMPortType ptype = MM_PORT_TYPE_UNKNOWN;
 
118
    guint16 vendor = 0, product = 0;
 
119
 
 
120
    port = mm_plugin_base_supports_task_get_port (task);
 
121
    g_assert (port);
 
122
 
 
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.
 
126
     */
 
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;
 
131
 
 
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.
 
135
     */
 
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;
 
139
 
 
140
    subsys = g_udev_device_get_subsystem (port);
 
141
    name = g_udev_device_get_name (port);
 
142
 
 
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.");
 
145
        return NULL;
 
146
    }
 
147
 
 
148
    caps = mm_plugin_base_supports_task_get_probed_capabilities (task);
 
149
    sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task);
 
150
    if (!existing) {
 
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)),
 
155
                                           vendor,
 
156
                                           product);
 
157
        }
 
158
 
 
159
        if (modem) {
 
160
            if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) {
 
161
                g_object_unref (modem);
 
162
                return NULL;
 
163
            }
 
164
        }
 
165
    } else if (get_level_for_capabilities (caps)) {
 
166
        if (caps & MM_PLUGIN_BASE_PORT_CAP_QCDM)
 
167
            ptype = MM_PORT_TYPE_QCDM;
 
168
 
 
169
        modem = existing;
 
170
        if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error))
 
171
            return NULL;
 
172
    }
 
173
 
 
174
    return modem;
 
175
}
 
176
 
 
177
/*****************************************************************************/
 
178
 
 
179
static void
 
180
mm_plugin_x22x_init (MMPluginX22x *self)
 
181
{
 
182
    g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL);
 
183
}
 
184
 
 
185
static void
 
186
mm_plugin_x22x_class_init (MMPluginX22xClass *klass)
 
187
{
 
188
    MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass);
 
189
 
 
190
    pb_class->supports_port = supports_port;
 
191
    pb_class->grab_port = grab_port;
 
192
}