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

« back to all changes in this revision

Viewing changes to plugins/sim900.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/netreg.h>
 
38
#include <ofono/sim.h>
 
39
#include <ofono/sms.h>
 
40
#include <ofono/ussd.h>
 
41
#include <ofono/gprs.h>
 
42
#include <ofono/gprs-context.h>
 
43
#include <ofono/phonebook.h>
 
44
#include <ofono/history.h>
 
45
#include <ofono/log.h>
 
46
#include <ofono/voicecall.h>
 
47
 
 
48
#include <drivers/atmodem/vendor.h>
 
49
 
 
50
static const char *none_prefix[] = { NULL };
 
51
 
 
52
struct sim900_data {
 
53
        GAtChat *modem;
 
54
};
 
55
 
 
56
static int sim900_probe(struct ofono_modem *modem)
 
57
{
 
58
        struct sim900_data *data;
 
59
 
 
60
        DBG("%p", modem);
 
61
 
 
62
        data = g_try_new0(struct sim900_data, 1);
 
63
        if (data == NULL)
 
64
                return -ENOMEM;
 
65
 
 
66
        ofono_modem_set_data(modem, data);
 
67
 
 
68
        return 0;
 
69
}
 
70
 
 
71
static void sim900_remove(struct ofono_modem *modem)
 
72
{
 
73
        struct sim900_data *data = ofono_modem_get_data(modem);
 
74
 
 
75
        DBG("%p", modem);
 
76
 
 
77
        ofono_modem_set_data(modem, NULL);
 
78
 
 
79
        g_at_chat_unref(data->modem);
 
80
 
 
81
        g_free(data);
 
82
}
 
83
 
 
84
static void sim900_debug(const char *str, void *user_data)
 
85
{
 
86
        const char *prefix = user_data;
 
87
 
 
88
        ofono_info("%s%s", prefix, str);
 
89
}
 
90
 
 
91
static GAtChat *open_device(struct ofono_modem *modem,
 
92
                                const char *key, char *debug)
 
93
{
 
94
        const char *device;
 
95
        GAtSyntax *syntax;
 
96
        GIOChannel *channel;
 
97
        GAtChat *chat;
 
98
        GHashTable *options;
 
99
 
 
100
        device = ofono_modem_get_string(modem, key);
 
101
        if (device == NULL)
 
102
                return NULL;
 
103
 
 
104
        DBG("%s %s", key, device);
 
105
 
 
106
        options = g_hash_table_new(g_str_hash, g_str_equal);
 
107
        if (options == NULL)
 
108
                return NULL;
 
109
 
 
110
        g_hash_table_insert(options, "Baud", "115200");
 
111
        g_hash_table_insert(options, "Parity", "none");
 
112
        g_hash_table_insert(options, "StopBits", "1");
 
113
        g_hash_table_insert(options, "DataBits", "8");
 
114
        g_hash_table_insert(options, "XonXoff", "off");
 
115
        g_hash_table_insert(options, "Local", "off");
 
116
        g_hash_table_insert(options, "RtsCts", "off");
 
117
 
 
118
        channel = g_at_tty_open(device, options);
 
119
        if (channel == NULL)
 
120
                return NULL;
 
121
 
 
122
        syntax = g_at_syntax_new_gsm_permissive();
 
123
        chat = g_at_chat_new(channel, syntax);
 
124
        g_at_syntax_unref(syntax);
 
125
 
 
126
        g_io_channel_unref(channel);
 
127
 
 
128
        if (chat == NULL)
 
129
                return NULL;
 
130
 
 
131
        if (getenv("OFONO_AT_DEBUG"))
 
132
                g_at_chat_set_debug(chat, sim900_debug, debug);
 
133
 
 
134
        return chat;
 
135
}
 
136
 
 
137
static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 
138
{
 
139
        struct ofono_modem *modem = user_data;
 
140
        struct sim900_data *data = ofono_modem_get_data(modem);
 
141
 
 
142
        DBG("");
 
143
 
 
144
        if (!ok) {
 
145
                g_at_chat_unref(data->modem);
 
146
                data->modem = NULL;
 
147
        }
 
148
 
 
149
        ofono_modem_set_powered(modem, ok);
 
150
}
 
151
 
 
152
static int sim900_enable(struct ofono_modem *modem)
 
153
{
 
154
        struct sim900_data *data = ofono_modem_get_data(modem);
 
155
 
 
156
        DBG("%p", modem);
 
157
 
 
158
        data->modem = open_device(modem, "Device", "Device: ");
 
159
        if (data->modem == NULL) {
 
160
                DBG("return -EINVAL");
 
161
                return -EINVAL;
 
162
        }
 
163
 
 
164
        g_at_chat_send(data->modem, "ATE0", NULL, NULL, NULL, NULL);
 
165
 
 
166
        /* For obtain correct sms service number */
 
167
        g_at_chat_send(data->modem, "AT+CSCS=\"GSM\"", NULL,
 
168
                                        NULL, NULL, NULL);
 
169
 
 
170
        g_at_chat_send(data->modem, "AT+CFUN=1", none_prefix,
 
171
                                        cfun_enable, modem, NULL);
 
172
 
 
173
        return -EINPROGRESS;
 
174
}
 
175
 
 
176
 
 
177
static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data)
 
178
{
 
179
        struct ofono_modem *modem = user_data;
 
180
        struct sim900_data *data = ofono_modem_get_data(modem);
 
181
 
 
182
        DBG("");
 
183
 
 
184
        g_at_chat_unref(data->modem);
 
185
        data->modem = NULL;
 
186
 
 
187
        if (ok)
 
188
                ofono_modem_set_powered(modem, FALSE);
 
189
}
 
190
 
 
191
static int sim900_disable(struct ofono_modem *modem)
 
192
{
 
193
        struct sim900_data *data = ofono_modem_get_data(modem);
 
194
 
 
195
        DBG("%p", modem);
 
196
 
 
197
        g_at_chat_cancel_all(data->modem);
 
198
        g_at_chat_unregister_all(data->modem);
 
199
 
 
200
        g_at_chat_send(data->modem, "AT+CFUN=4", none_prefix,
 
201
                                        cfun_disable, modem, NULL);
 
202
 
 
203
        return -EINPROGRESS;
 
204
}
 
205
 
 
206
static void sim900_pre_sim(struct ofono_modem *modem)
 
207
{
 
208
        struct sim900_data *data = ofono_modem_get_data(modem);
 
209
        struct ofono_sim *sim;
 
210
 
 
211
        DBG("%p", modem);
 
212
 
 
213
        ofono_devinfo_create(modem, 0, "atmodem", data->modem);
 
214
        sim = ofono_sim_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
 
215
                                data->modem);
 
216
 
 
217
        if (sim)
 
218
                ofono_sim_inserted_notify(sim, TRUE);
 
219
}
 
220
 
 
221
static void sim900_post_sim(struct ofono_modem *modem)
 
222
{
 
223
        struct sim900_data *data = ofono_modem_get_data(modem);
 
224
 
 
225
        DBG("%p", modem);
 
226
 
 
227
        ofono_phonebook_create(modem, 0, "atmodem", data->modem);
 
228
        ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
 
229
                                data->modem);
 
230
}
 
231
 
 
232
static void sim900_post_online(struct ofono_modem *modem)
 
233
{
 
234
        struct sim900_data *data = ofono_modem_get_data(modem);
 
235
 
 
236
        DBG("%p", modem);
 
237
 
 
238
        ofono_netreg_create(modem, OFONO_VENDOR_SIMCOM, "atmodem", data->modem);
 
239
        ofono_ussd_create(modem, 0, "atmodem", data->modem);
 
240
        ofono_voicecall_create(modem, 0, "atmodem", data->modem);
 
241
}
 
242
 
 
243
static struct ofono_modem_driver sim900_driver = {
 
244
        .name           = "sim900",
 
245
        .probe          = sim900_probe,
 
246
        .remove         = sim900_remove,
 
247
        .enable         = sim900_enable,
 
248
        .disable        = sim900_disable,
 
249
        .pre_sim        = sim900_pre_sim,
 
250
        .post_sim       = sim900_post_sim,
 
251
        .post_online    = sim900_post_online,
 
252
};
 
253
 
 
254
static int sim900_init(void)
 
255
{
 
256
        return ofono_modem_driver_register(&sim900_driver);
 
257
}
 
258
 
 
259
static void sim900_exit(void)
 
260
{
 
261
        ofono_modem_driver_unregister(&sim900_driver);
 
262
}
 
263
 
 
264
OFONO_PLUGIN_DEFINE(sim900, "SIM900 modem driver", VERSION,
 
265
                OFONO_PLUGIN_PRIORITY_DEFAULT, sim900_init, sim900_exit)