~phablet-team/ofono/midori-support

« back to all changes in this revision

Viewing changes to plugins/tc65.c

  • Committer: Alfonso Sanchez-Beato
  • Date: 2015-09-28 08:10:59 UTC
  • mfrom: (6830.1.168)
  • mto: This revision was merged to the branch mainline in revision 6904.
  • Revision ID: alfonso.sanchez-beato@canonical.com-20150928081059-1o08e2a9pkit6ar6
* Update to upstream release 1.17
* Do not assert when the radio is unavailable (LP: #1490991)
* Fix crash when importing phonebook (LP: #1486004)
* Check only destination port when receiving push (LP: #1490673)
* Fix crash when retrying to close context (LP: #1492483)

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/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>
49
 
 
50
 
#include <drivers/atmodem/atutil.h>
51
 
 
52
 
#include <ofono/gprs.h>
53
 
#include <ofono/gprs-context.h>
54
 
 
55
 
static int tc65_probe(struct ofono_modem *modem)
56
 
{
57
 
        return 0;
58
 
}
59
 
 
60
 
static void tc65_remove(struct ofono_modem *modem)
61
 
{
62
 
}
63
 
 
64
 
static void tc65_debug(const char *str, void *user_data)
65
 
{
66
 
        const char *prefix = user_data;
67
 
 
68
 
        ofono_info("%s%s", prefix, str);
69
 
}
70
 
 
71
 
static int tc65_enable(struct ofono_modem *modem)
72
 
{
73
 
        GAtChat *chat;
74
 
        GIOChannel *channel;
75
 
        GAtSyntax *syntax;
76
 
        GHashTable *options;
77
 
        const char *device;
78
 
 
79
 
        DBG("%p", modem);
80
 
 
81
 
        options = g_hash_table_new(g_str_hash, g_str_equal);
82
 
        if (options == NULL)
83
 
                return -ENOMEM;
84
 
 
85
 
        device = ofono_modem_get_string(modem, "Device");
86
 
        if (device == NULL)
87
 
                return -EINVAL;
88
 
 
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");
97
 
 
98
 
        channel = g_at_tty_open(device, options);
99
 
        g_hash_table_destroy(options);
100
 
 
101
 
        if (channel == NULL)
102
 
                return -EIO;
103
 
 
104
 
        /*
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.
108
 
         */
109
 
        syntax = g_at_syntax_new_gsm_permissive();
110
 
 
111
 
        chat = g_at_chat_new(channel, syntax);
112
 
        g_at_syntax_unref(syntax);
113
 
        g_io_channel_unref(channel);
114
 
 
115
 
        if (chat == NULL)
116
 
                return -ENOMEM;
117
 
 
118
 
        if (getenv("OFONO_AT_DEBUG"))
119
 
                g_at_chat_set_debug(chat, tc65_debug, "");
120
 
 
121
 
        ofono_modem_set_data(modem, chat);
122
 
 
123
 
        return 0;
124
 
}
125
 
 
126
 
static int tc65_disable(struct ofono_modem *modem)
127
 
{
128
 
        GAtChat *chat = ofono_modem_get_data(modem);
129
 
 
130
 
        DBG("%p", modem);
131
 
 
132
 
        ofono_modem_set_data(modem, NULL);
133
 
 
134
 
        g_at_chat_send(chat, "AT+CFUN=7", NULL, NULL, NULL, NULL);
135
 
 
136
 
        g_at_chat_unref(chat);
137
 
 
138
 
        return 0;
139
 
}
140
 
 
141
 
static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
142
 
{
143
 
        struct cb_data *cbd = user_data;
144
 
        ofono_modem_online_cb_t cb = cbd->cb;
145
 
        struct ofono_error error;
146
 
 
147
 
        decode_at_error(&error, g_at_result_final_response(result));
148
 
 
149
 
        cb(&error, cbd->data);
150
 
}
151
 
 
152
 
static void tc65_set_online(struct ofono_modem *modem, ofono_bool_t online,
153
 
                        ofono_modem_online_cb_t cb, void *user_data)
154
 
{
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";
158
 
 
159
 
        DBG("modem %p %s", modem, online ? "online" : "offline");
160
 
 
161
 
        if (g_at_chat_send(chat, command, NULL, set_online_cb, cbd, g_free))
162
 
                return;
163
 
 
164
 
        g_free(cbd);
165
 
 
166
 
        CALLBACK_WITH_FAILURE(cb, cbd->data);
167
 
}
168
 
 
169
 
static void tc65_pre_sim(struct ofono_modem *modem)
170
 
{
171
 
        GAtChat *chat = ofono_modem_get_data(modem);
172
 
        struct ofono_sim *sim;
173
 
 
174
 
        DBG("%p", modem);
175
 
 
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);
179
 
 
180
 
        if (sim)
181
 
                ofono_sim_inserted_notify(sim, TRUE);
182
 
}
183
 
 
184
 
static void tc65_post_sim(struct ofono_modem *modem)
185
 
{
186
 
        GAtChat *chat = ofono_modem_get_data(modem);
187
 
 
188
 
        DBG("%p", modem);
189
 
 
190
 
        ofono_phonebook_create(modem, 0, "atmodem", chat);
191
 
 
192
 
        ofono_sms_create(modem, 0, "atmodem", chat);
193
 
}
194
 
 
195
 
static void tc65_post_online(struct ofono_modem *modem)
196
 
{
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;
201
 
 
202
 
        DBG("%p", modem);
203
 
 
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);
210
 
 
211
 
        gprs = ofono_gprs_create(modem, 0, "atmodem", chat);
212
 
        gc = ofono_gprs_context_create(modem, 0, "atmodem", chat);
213
 
 
214
 
        if (gprs && gc)
215
 
                ofono_gprs_add_context(gprs, gc);
216
 
 
217
 
        mw = ofono_message_waiting_create(modem);
218
 
        if (mw)
219
 
                ofono_message_waiting_register(mw);
220
 
}
221
 
 
222
 
static struct ofono_modem_driver tc65_driver = {
223
 
        .name           = "tc65",
224
 
        .probe          = tc65_probe,
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,
232
 
};
233
 
 
234
 
static int tc65_init(void)
235
 
{
236
 
        return ofono_modem_driver_register(&tc65_driver);
237
 
}
238
 
 
239
 
static void tc65_exit(void)
240
 
{
241
 
        ofono_modem_driver_unregister(&tc65_driver);
242
 
}
243
 
 
244
 
OFONO_PLUGIN_DEFINE(tc65, "Cinterion TC65 driver plugin", VERSION,
245
 
                OFONO_PLUGIN_PRIORITY_DEFAULT, tc65_init, tc65_exit)