~morphis/phablet-extras/ofono-sms-status-report

« back to all changes in this revision

Viewing changes to plugins/speedupcdma.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-08-22 19:59:08 UTC
  • mfrom: (1.3.3) (6.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20120822195908-0bmmk1hlh989bgk6
Tags: 1.9-1ubuntu1
* Merge with Debian experimental; remaining changes:
  - debian/control: explicitly Conflicts with modemmanager: having both
    installed / running at the same time causes issues causes issues with
    both claiming modem devices.
  - debian/patches/02-dont-handle-stacktraces.patch: stop catching stacktraces
    and printing the information internally, so apport can catch and report
    the possible bugs.
  - debian/ofono.postinst: on configure, notify the user that a reboot is
    required (so ofono can get started by upstart). (LP: #600501)
  - debian/rules: pass --no-restart-on-upgrade so ofono isn't automatically
    restarted when upgrades.
  - Adding upstart config / Removing standard init script
  - Adding Apport support
  - Patch for recognizing special Huawei devices with weird serial
  - Override lintian to avoid script-in-etc-init.d... warnings.
  - Update debian/compat to 7
* debian/series: add our patches to debian/patches/series now that the package
  uses quilt.
* debian/patches/02-dont-handle-stacktraces.patch: refreshed.
* debian/ofono-dev.install, debian/ofono.install:
  - Install usr/sbin/dundee and ofono.pc to the proper packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  oFono - Open Source Telephony
 
4
 *
 
5
 *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License version 2 as
 
9
 *  published by the Free Software Foundation.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 *
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#include <errno.h>
 
27
#include <stdlib.h>
 
28
 
 
29
#include <glib.h>
 
30
#include <gatchat.h>
 
31
#include <gattty.h>
 
32
 
 
33
#define OFONO_API_SUBJECT_TO_CHANGE
 
34
#include <ofono/plugin.h>
 
35
#include <ofono/modem.h>
 
36
#include <ofono/devinfo.h>
 
37
#include <ofono/cdma-netreg.h>
 
38
#include <ofono/cdma-connman.h>
 
39
#include <ofono/log.h>
 
40
 
 
41
#include "drivers/atmodem/vendor.h"
 
42
 
 
43
struct speedupcdma_data {
 
44
        GAtChat *modem;
 
45
        GAtChat *aux;
 
46
};
 
47
 
 
48
static void speedupcdma_debug(const char *str, void *data)
 
49
{
 
50
        const char *prefix = data;
 
51
 
 
52
        ofono_info("%s%s", prefix, str);
 
53
}
 
54
 
 
55
static int speedupcdma_probe(struct ofono_modem *modem)
 
56
{
 
57
        struct speedupcdma_data *data;
 
58
 
 
59
        DBG("%p", modem);
 
60
 
 
61
        data = g_try_new0(struct speedupcdma_data, 1);
 
62
        if (data == NULL)
 
63
                return -ENOMEM;
 
64
 
 
65
        ofono_modem_set_data(modem, data);
 
66
 
 
67
        return 0;
 
68
}
 
69
 
 
70
static void speedupcdma_remove(struct ofono_modem *modem)
 
71
{
 
72
        struct speedupcdma_data *data = ofono_modem_get_data(modem);
 
73
 
 
74
        DBG("%p", modem);
 
75
 
 
76
        ofono_modem_set_data(modem, NULL);
 
77
 
 
78
        /* Cleanup after hot-unplug */
 
79
        g_at_chat_unref(data->aux);
 
80
 
 
81
        g_free(data);
 
82
}
 
83
 
 
84
static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 
85
{
 
86
        struct ofono_modem *modem = user_data;
 
87
        struct speedupcdma_data *data = ofono_modem_get_data(modem);
 
88
 
 
89
        DBG("");
 
90
 
 
91
        if (!ok) {
 
92
                g_at_chat_unref(data->modem);
 
93
                data->modem = NULL;
 
94
 
 
95
                g_at_chat_unref(data->aux);
 
96
                data->aux = NULL;
 
97
        }
 
98
 
 
99
        ofono_modem_set_powered(modem, ok);
 
100
}
 
101
 
 
102
static GAtChat *open_device(struct ofono_modem *modem,
 
103
                                const char *key, char *debug)
 
104
{
 
105
        const char *device;
 
106
        GIOChannel *channel;
 
107
        GAtSyntax *syntax;
 
108
        GAtChat *chat;
 
109
 
 
110
        device = ofono_modem_get_string(modem, key);
 
111
        if (device == NULL)
 
112
                return NULL;
 
113
 
 
114
        DBG("%s %s", key, device);
 
115
 
 
116
        channel = g_at_tty_open(device, NULL);
 
117
        if (channel == NULL)
 
118
                return NULL;
 
119
 
 
120
        syntax = g_at_syntax_new_gsm_permissive();
 
121
        chat = g_at_chat_new(channel, syntax);
 
122
        g_at_syntax_unref(syntax);
 
123
 
 
124
        g_io_channel_unref(channel);
 
125
 
 
126
        if (chat == NULL)
 
127
                return NULL;
 
128
 
 
129
        if (getenv("OFONO_AT_DEBUG"))
 
130
                g_at_chat_set_debug(chat, speedupcdma_debug, debug);
 
131
 
 
132
        return chat;
 
133
}
 
134
 
 
135
static int speedupcdma_enable(struct ofono_modem *modem)
 
136
{
 
137
        struct speedupcdma_data *data = ofono_modem_get_data(modem);
 
138
 
 
139
        DBG("");
 
140
 
 
141
        data->modem = open_device(modem, "Modem", "Modem: ");
 
142
        if (data->modem == NULL)
 
143
                return -EINVAL;
 
144
 
 
145
        data->aux = open_device(modem, "Aux", "Aux: ");
 
146
        if (data->aux == NULL) {
 
147
                g_at_chat_unref(data->modem);
 
148
                data->modem = NULL;
 
149
                return -EIO;
 
150
        }
 
151
 
 
152
        g_at_chat_set_slave(data->modem, data->aux);
 
153
 
 
154
        g_at_chat_send(data->modem, "ATE0 &C0 +CMEE=1", NULL, NULL, NULL, NULL);
 
155
        g_at_chat_send(data->aux, "ATE0 &C0 +CMEE=1", NULL, NULL, NULL, NULL);
 
156
 
 
157
        g_at_chat_send(data->aux, "AT+CFUN=1", NULL,
 
158
                                        cfun_enable, modem, NULL);
 
159
 
 
160
        return -EINPROGRESS;
 
161
}
 
162
 
 
163
static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data)
 
164
{
 
165
        struct ofono_modem *modem = user_data;
 
166
        struct speedupcdma_data *data = ofono_modem_get_data(modem);
 
167
 
 
168
        DBG("");
 
169
 
 
170
        g_at_chat_unref(data->aux);
 
171
        data->aux = NULL;
 
172
 
 
173
        if (ok)
 
174
                ofono_modem_set_powered(modem, FALSE);
 
175
}
 
176
 
 
177
static int speedupcdma_disable(struct ofono_modem *modem)
 
178
{
 
179
        struct speedupcdma_data *data = ofono_modem_get_data(modem);
 
180
 
 
181
        DBG("%p", modem);
 
182
 
 
183
        g_at_chat_cancel_all(data->modem);
 
184
        g_at_chat_unregister_all(data->modem);
 
185
 
 
186
        g_at_chat_unref(data->modem);
 
187
        data->modem = NULL;
 
188
 
 
189
        g_at_chat_cancel_all(data->aux);
 
190
        g_at_chat_unregister_all(data->aux);
 
191
 
 
192
        g_at_chat_send(data->aux, "AT+CFUN=0", NULL,
 
193
                                        cfun_disable, modem, NULL);
 
194
 
 
195
        return -EINPROGRESS;
 
196
}
 
197
 
 
198
static void speedupcdma_pre_sim(struct ofono_modem *modem)
 
199
{
 
200
        struct speedupcdma_data *data = ofono_modem_get_data(modem);
 
201
 
 
202
        DBG("%p", modem);
 
203
 
 
204
        ofono_devinfo_create(modem, 0, "cdmamodem", data->aux);
 
205
}
 
206
 
 
207
static void speedupcdma_post_sim(struct ofono_modem *modem)
 
208
{
 
209
        DBG("%p", modem);
 
210
}
 
211
 
 
212
static void speedupcdma_post_online(struct ofono_modem *modem)
 
213
{
 
214
        struct speedupcdma_data *data = ofono_modem_get_data(modem);
 
215
 
 
216
        DBG("%p", modem);
 
217
 
 
218
        ofono_cdma_netreg_create(modem, 0, "huaweicdmamodem", data->aux);
 
219
 
 
220
        ofono_cdma_connman_create(modem, OFONO_VENDOR_HUAWEI, "cdmamodem",
 
221
                                        data->modem);
 
222
}
 
223
 
 
224
static struct ofono_modem_driver speedupcdma_driver = {
 
225
        .name           = "speedupcdma",
 
226
        .probe          = speedupcdma_probe,
 
227
        .remove         = speedupcdma_remove,
 
228
        .enable         = speedupcdma_enable,
 
229
        .disable        = speedupcdma_disable,
 
230
        .pre_sim        = speedupcdma_pre_sim,
 
231
        .post_sim       = speedupcdma_post_sim,
 
232
        .post_online    = speedupcdma_post_online,
 
233
};
 
234
 
 
235
static int speedupcdma_init(void)
 
236
{
 
237
        return ofono_modem_driver_register(&speedupcdma_driver);
 
238
}
 
239
 
 
240
static void speedupcdma_exit(void)
 
241
{
 
242
        ofono_modem_driver_unregister(&speedupcdma_driver);
 
243
}
 
244
 
 
245
OFONO_PLUGIN_DEFINE(speedupcdma, "Speed Up CDMA modem driver", VERSION,
 
246
                                OFONO_PLUGIN_PRIORITY_DEFAULT,
 
247
                                speedupcdma_init, speedupcdma_exit)