3
* oFono - Open Source Telephony
5
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
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.
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.
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
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>
48
#include <drivers/atmodem/vendor.h>
50
static const char *none_prefix[] = { NULL };
56
static int sim900_probe(struct ofono_modem *modem)
58
struct sim900_data *data;
62
data = g_try_new0(struct sim900_data, 1);
66
ofono_modem_set_data(modem, data);
71
static void sim900_remove(struct ofono_modem *modem)
73
struct sim900_data *data = ofono_modem_get_data(modem);
77
ofono_modem_set_data(modem, NULL);
79
g_at_chat_unref(data->modem);
84
static void sim900_debug(const char *str, void *user_data)
86
const char *prefix = user_data;
88
ofono_info("%s%s", prefix, str);
91
static GAtChat *open_device(struct ofono_modem *modem,
92
const char *key, char *debug)
100
device = ofono_modem_get_string(modem, key);
104
DBG("%s %s", key, device);
106
options = g_hash_table_new(g_str_hash, g_str_equal);
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");
118
channel = g_at_tty_open(device, options);
122
syntax = g_at_syntax_new_gsm_permissive();
123
chat = g_at_chat_new(channel, syntax);
124
g_at_syntax_unref(syntax);
126
g_io_channel_unref(channel);
131
if (getenv("OFONO_AT_DEBUG"))
132
g_at_chat_set_debug(chat, sim900_debug, debug);
137
static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
139
struct ofono_modem *modem = user_data;
140
struct sim900_data *data = ofono_modem_get_data(modem);
145
g_at_chat_unref(data->modem);
149
ofono_modem_set_powered(modem, ok);
152
static int sim900_enable(struct ofono_modem *modem)
154
struct sim900_data *data = ofono_modem_get_data(modem);
158
data->modem = open_device(modem, "Device", "Device: ");
159
if (data->modem == NULL) {
160
DBG("return -EINVAL");
164
g_at_chat_send(data->modem, "ATE0", NULL, NULL, NULL, NULL);
166
/* For obtain correct sms service number */
167
g_at_chat_send(data->modem, "AT+CSCS=\"GSM\"", NULL,
170
g_at_chat_send(data->modem, "AT+CFUN=1", none_prefix,
171
cfun_enable, modem, NULL);
177
static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data)
179
struct ofono_modem *modem = user_data;
180
struct sim900_data *data = ofono_modem_get_data(modem);
184
g_at_chat_unref(data->modem);
188
ofono_modem_set_powered(modem, FALSE);
191
static int sim900_disable(struct ofono_modem *modem)
193
struct sim900_data *data = ofono_modem_get_data(modem);
197
g_at_chat_cancel_all(data->modem);
198
g_at_chat_unregister_all(data->modem);
200
g_at_chat_send(data->modem, "AT+CFUN=4", none_prefix,
201
cfun_disable, modem, NULL);
206
static void sim900_pre_sim(struct ofono_modem *modem)
208
struct sim900_data *data = ofono_modem_get_data(modem);
209
struct ofono_sim *sim;
213
ofono_devinfo_create(modem, 0, "atmodem", data->modem);
214
sim = ofono_sim_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
218
ofono_sim_inserted_notify(sim, TRUE);
221
static void sim900_post_sim(struct ofono_modem *modem)
223
struct sim900_data *data = ofono_modem_get_data(modem);
227
ofono_phonebook_create(modem, 0, "atmodem", data->modem);
228
ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
232
static void sim900_post_online(struct ofono_modem *modem)
234
struct sim900_data *data = ofono_modem_get_data(modem);
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);
243
static struct ofono_modem_driver sim900_driver = {
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,
254
static int sim900_init(void)
256
return ofono_modem_driver_register(&sim900_driver);
259
static void sim900_exit(void)
261
ofono_modem_driver_unregister(&sim900_driver);
264
OFONO_PLUGIN_DEFINE(sim900, "SIM900 modem driver", VERSION,
265
OFONO_PLUGIN_PRIORITY_DEFAULT, sim900_init, sim900_exit)