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/log.h>
36
#include <ofono/modem.h>
37
#include <ofono/call-barring.h>
38
#include <ofono/call-forwarding.h>
39
#include <ofono/call-meter.h>
40
#include <ofono/call-settings.h>
41
#include <ofono/devinfo.h>
42
#include <ofono/message-waiting.h>
43
#include <ofono/netreg.h>
44
#include <ofono/phonebook.h>
45
#include <ofono/sim.h>
46
#include <ofono/sms.h>
47
#include <ofono/ussd.h>
48
#include <ofono/voicecall.h>
50
#include <drivers/atmodem/atutil.h>
52
#include <ofono/gprs.h>
53
#include <ofono/gprs-context.h>
55
static int tc65_probe(struct ofono_modem *modem)
60
static void tc65_remove(struct ofono_modem *modem)
64
static void tc65_debug(const char *str, void *user_data)
66
const char *prefix = user_data;
68
ofono_info("%s%s", prefix, str);
71
static int tc65_enable(struct ofono_modem *modem)
81
options = g_hash_table_new(g_str_hash, g_str_equal);
85
device = ofono_modem_get_string(modem, "Device");
89
g_hash_table_insert(options, "Baud", "115200");
90
g_hash_table_insert(options, "StopBits", "1");
91
g_hash_table_insert(options, "DataBits", "8");
92
g_hash_table_insert(options, "Parity", "none");
93
g_hash_table_insert(options, "XonXoff", "off");
94
g_hash_table_insert(options, "RtsCts", "on");
95
g_hash_table_insert(options, "Local", "on");
96
g_hash_table_insert(options, "Read", "on");
98
channel = g_at_tty_open(device, options);
99
g_hash_table_destroy(options);
105
* TC65 works almost as the 27.007 says. But for example after
106
* AT+CRSM the modem replies with the data in the queried EF and
107
* writes three pairs of <CR><LF> after the data and before OK.
109
syntax = g_at_syntax_new_gsm_permissive();
111
chat = g_at_chat_new(channel, syntax);
112
g_at_syntax_unref(syntax);
113
g_io_channel_unref(channel);
118
if (getenv("OFONO_AT_DEBUG"))
119
g_at_chat_set_debug(chat, tc65_debug, "");
121
ofono_modem_set_data(modem, chat);
126
static int tc65_disable(struct ofono_modem *modem)
128
GAtChat *chat = ofono_modem_get_data(modem);
132
ofono_modem_set_data(modem, NULL);
134
g_at_chat_send(chat, "AT+CFUN=7", NULL, NULL, NULL, NULL);
136
g_at_chat_unref(chat);
141
static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
143
struct cb_data *cbd = user_data;
144
ofono_modem_online_cb_t cb = cbd->cb;
145
struct ofono_error error;
147
decode_at_error(&error, g_at_result_final_response(result));
149
cb(&error, cbd->data);
152
static void tc65_set_online(struct ofono_modem *modem, ofono_bool_t online,
153
ofono_modem_online_cb_t cb, void *user_data)
155
GAtChat *chat = ofono_modem_get_data(modem);
156
struct cb_data *cbd = cb_data_new(cb, user_data);
157
char const *command = online ? "AT+CFUN=1" : "AT+CFUN=7";
159
DBG("modem %p %s", modem, online ? "online" : "offline");
161
if (g_at_chat_send(chat, command, NULL, set_online_cb, cbd, g_free))
166
CALLBACK_WITH_FAILURE(cb, cbd->data);
169
static void tc65_pre_sim(struct ofono_modem *modem)
171
GAtChat *chat = ofono_modem_get_data(modem);
172
struct ofono_sim *sim;
176
ofono_devinfo_create(modem, 0, "atmodem", chat);
177
sim = ofono_sim_create(modem, 0, "atmodem", chat);
178
ofono_voicecall_create(modem, 0, "atmodem", chat);
181
ofono_sim_inserted_notify(sim, TRUE);
184
static void tc65_post_sim(struct ofono_modem *modem)
186
GAtChat *chat = ofono_modem_get_data(modem);
190
ofono_phonebook_create(modem, 0, "atmodem", chat);
192
ofono_sms_create(modem, 0, "atmodem", chat);
195
static void tc65_post_online(struct ofono_modem *modem)
197
GAtChat *chat = ofono_modem_get_data(modem);
198
struct ofono_message_waiting *mw;
199
struct ofono_gprs *gprs;
200
struct ofono_gprs_context *gc;
204
ofono_ussd_create(modem, 0, "atmodem", chat);
205
ofono_call_forwarding_create(modem, 0, "atmodem", chat);
206
ofono_call_settings_create(modem, 0, "atmodem", chat);
207
ofono_netreg_create(modem, 0, "atmodem", chat);
208
ofono_call_meter_create(modem, 0, "atmodem", chat);
209
ofono_call_barring_create(modem, 0, "atmodem", chat);
211
gprs = ofono_gprs_create(modem, 0, "atmodem", chat);
212
gc = ofono_gprs_context_create(modem, 0, "atmodem", chat);
215
ofono_gprs_add_context(gprs, gc);
217
mw = ofono_message_waiting_create(modem);
219
ofono_message_waiting_register(mw);
222
static struct ofono_modem_driver tc65_driver = {
225
.remove = tc65_remove,
226
.enable = tc65_enable,
227
.disable = tc65_disable,
228
.set_online = tc65_set_online,
229
.pre_sim = tc65_pre_sim,
230
.post_sim = tc65_post_sim,
231
.post_online = tc65_post_online,
234
static int tc65_init(void)
236
return ofono_modem_driver_register(&tc65_driver);
239
static void tc65_exit(void)
241
ofono_modem_driver_unregister(&tc65_driver);
244
OFONO_PLUGIN_DEFINE(tc65, "Cinterion TC65 driver plugin", VERSION,
245
OFONO_PLUGIN_PRIORITY_DEFAULT, tc65_init, tc65_exit)