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

« back to all changes in this revision

Viewing changes to plugins/samsung.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 <stdio.h>
 
27
#include <errno.h>
 
28
#include <stdlib.h>
 
29
 
 
30
#include <glib.h>
 
31
#include <gatchat.h>
 
32
#include <gattty.h>
 
33
 
 
34
#define OFONO_API_SUBJECT_TO_CHANGE
 
35
#include <ofono/plugin.h>
 
36
#include <ofono/modem.h>
 
37
#include <ofono/devinfo.h>
 
38
#include <ofono/sim.h>
 
39
#include <ofono/netreg.h>
 
40
#include <ofono/log.h>
 
41
 
 
42
#include <drivers/atmodem/atutil.h>
 
43
#include <drivers/atmodem/vendor.h>
 
44
 
 
45
static const char *none_prefix[] = { NULL };
 
46
 
 
47
struct samsung_data {
 
48
        GAtChat *chat;
 
49
        gboolean have_sim;
 
50
        struct at_util_sim_state_query *sim_state_query;
 
51
};
 
52
 
 
53
static void samsung_debug(const char *str, void *data)
 
54
{
 
55
        const char *prefix = data;
 
56
 
 
57
        ofono_info("%s%s", prefix, str);
 
58
}
 
59
 
 
60
static int samsung_probe(struct ofono_modem *modem)
 
61
{
 
62
        struct samsung_data *data;
 
63
 
 
64
        DBG("%p", modem);
 
65
 
 
66
        data = g_try_new0(struct samsung_data, 1);
 
67
        if (data == NULL)
 
68
                return -ENOMEM;
 
69
 
 
70
        ofono_modem_set_data(modem, data);
 
71
 
 
72
        return 0;
 
73
}
 
74
 
 
75
static void samsung_remove(struct ofono_modem *modem)
 
76
{
 
77
        struct samsung_data *data = ofono_modem_get_data(modem);
 
78
 
 
79
        DBG("%p", modem);
 
80
 
 
81
        ofono_modem_set_data(modem, NULL);
 
82
 
 
83
        /* Cleanup potential SIM state polling */
 
84
        at_util_sim_state_query_free(data->sim_state_query);
 
85
 
 
86
        /* Cleanup after hot-unplug */
 
87
        g_at_chat_unref(data->chat);
 
88
 
 
89
        g_free(data);
 
90
}
 
91
 
 
92
static void mode_select(gboolean ok, GAtResult *result, gpointer user_data)
 
93
{
 
94
        struct ofono_modem *modem = user_data;
 
95
        struct samsung_data *data = ofono_modem_get_data(modem);
 
96
 
 
97
        DBG("%p", modem);
 
98
 
 
99
        if (!ok) {
 
100
                g_at_chat_unref(data->chat);
 
101
                data->chat = NULL;
 
102
 
 
103
                ofono_modem_set_powered(modem, FALSE);
 
104
                return;
 
105
        }
 
106
 
 
107
        g_at_chat_send(data->chat, "AT+VERSNAME=1,0", NULL, NULL, NULL, NULL);
 
108
        g_at_chat_send(data->chat, "AT+VERSNAME=1,1", NULL, NULL, NULL, NULL);
 
109
 
 
110
        ofono_modem_set_powered(modem, TRUE);
 
111
}
 
112
 
 
113
static void sim_state_cb(gboolean present, gpointer user_data)
 
114
{
 
115
        struct ofono_modem *modem = user_data;
 
116
        struct samsung_data *data = ofono_modem_get_data(modem);
 
117
 
 
118
        DBG("%p", modem);
 
119
 
 
120
        at_util_sim_state_query_free(data->sim_state_query);
 
121
        data->sim_state_query = NULL;
 
122
 
 
123
        data->have_sim = present;
 
124
 
 
125
        g_at_chat_send(data->chat, "AT+MODESELECT=3", none_prefix,
 
126
                                                mode_select, modem, NULL);
 
127
}
 
128
 
 
129
static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 
130
{
 
131
        struct ofono_modem *modem = user_data;
 
132
        struct samsung_data *data = ofono_modem_get_data(modem);
 
133
 
 
134
        DBG("%p", modem);
 
135
 
 
136
        if (!ok) {
 
137
                g_at_chat_unref(data->chat);
 
138
                data->chat = NULL;
 
139
 
 
140
                ofono_modem_set_powered(modem, FALSE);
 
141
                return;
 
142
        }
 
143
 
 
144
        data->sim_state_query = at_util_sim_state_query_new(data->chat,
 
145
                                                1, 5, sim_state_cb, modem,
 
146
                                                NULL);
 
147
}
 
148
 
 
149
static int samsung_enable(struct ofono_modem *modem)
 
150
{
 
151
        struct samsung_data *data = ofono_modem_get_data(modem);
 
152
        GAtSyntax *syntax;
 
153
        GIOChannel *channel;
 
154
        GHashTable *options;
 
155
        const char *device;
 
156
 
 
157
        device = ofono_modem_get_string(modem, "ControlPort");
 
158
        if (device == NULL)
 
159
                return -EINVAL;
 
160
 
 
161
        options = g_hash_table_new(g_str_hash, g_str_equal);
 
162
        if (options == NULL)
 
163
                return -ENOMEM;
 
164
 
 
165
        g_hash_table_insert(options, "Baud", "115200");
 
166
        g_hash_table_insert(options, "Parity", "none");
 
167
        g_hash_table_insert(options, "StopBits", "1");
 
168
        g_hash_table_insert(options, "DataBits", "8");
 
169
        g_hash_table_insert(options, "XonXoff", "off");
 
170
        g_hash_table_insert(options, "RtsCts", "on");
 
171
        g_hash_table_insert(options, "Local", "on");
 
172
        g_hash_table_insert(options, "Read", "on");
 
173
 
 
174
        channel = g_at_tty_open(device, options);
 
175
 
 
176
        g_hash_table_destroy(options);
 
177
 
 
178
        if (channel == NULL)
 
179
                return -EIO;
 
180
 
 
181
        syntax = g_at_syntax_new_gsm_permissive();
 
182
        data->chat = g_at_chat_new(channel, syntax);
 
183
        g_at_syntax_unref(syntax);
 
184
 
 
185
        g_io_channel_unref(channel);
 
186
 
 
187
        if (data->chat == NULL)
 
188
                return -ENOMEM;
 
189
 
 
190
        if (getenv("OFONO_AT_DEBUG"))
 
191
                g_at_chat_set_debug(data->chat, samsung_debug, "Device: ");
 
192
 
 
193
        g_at_chat_send(data->chat, "ATE0", NULL, NULL, NULL, NULL);
 
194
        g_at_chat_send(data->chat, "AT+CMEE=1", NULL, NULL, NULL, NULL);
 
195
 
 
196
        g_at_chat_send(data->chat, "AT+CFUN=?", none_prefix, NULL, NULL, NULL);
 
197
        g_at_chat_send(data->chat, "AT+CFUN?", none_prefix, NULL, NULL, NULL);
 
198
 
 
199
        g_at_chat_send(data->chat, "AT+CFUN=5", none_prefix,
 
200
                                        cfun_enable, modem, NULL);
 
201
 
 
202
        return -EINPROGRESS;
 
203
}
 
204
 
 
205
static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data)
 
206
{
 
207
        struct ofono_modem *modem = user_data;
 
208
        struct samsung_data *data = ofono_modem_get_data(modem);
 
209
 
 
210
        DBG("%p", modem);
 
211
 
 
212
        g_at_chat_unref(data->chat);
 
213
        data->chat = NULL;
 
214
 
 
215
        if (ok)
 
216
                ofono_modem_set_powered(modem, FALSE);
 
217
}
 
218
 
 
219
static int samsung_disable(struct ofono_modem *modem)
 
220
{
 
221
        struct samsung_data *data = ofono_modem_get_data(modem);
 
222
 
 
223
        DBG("%p", modem);
 
224
 
 
225
        g_at_chat_cancel_all(data->chat);
 
226
        g_at_chat_unregister_all(data->chat);
 
227
 
 
228
        g_at_chat_send(data->chat, "AT+MODESELECT=2", none_prefix,
 
229
                                        cfun_disable, modem, NULL);
 
230
 
 
231
        return -EINPROGRESS;
 
232
}
 
233
 
 
234
static void samsung_pre_sim(struct ofono_modem *modem)
 
235
{
 
236
        struct samsung_data *data = ofono_modem_get_data(modem);
 
237
        struct ofono_sim *sim;
 
238
 
 
239
        DBG("%p", modem);
 
240
 
 
241
        ofono_devinfo_create(modem, 0, "atmodem", data->chat);
 
242
        sim = ofono_sim_create(modem, 0, "atmodem", data->chat);
 
243
 
 
244
        if (sim && data->have_sim == TRUE)
 
245
                ofono_sim_inserted_notify(sim, TRUE);
 
246
}
 
247
 
 
248
static void samsung_post_sim(struct ofono_modem *modem)
 
249
{
 
250
        DBG("%p", modem);
 
251
}
 
252
 
 
253
static void samsung_post_online(struct ofono_modem *modem)
 
254
{
 
255
        struct samsung_data *data = ofono_modem_get_data(modem);
 
256
 
 
257
        DBG("%p", modem);
 
258
 
 
259
        ofono_netreg_create(modem, OFONO_VENDOR_SAMSUNG, "atmodem", data->chat);
 
260
}
 
261
 
 
262
static struct ofono_modem_driver samsung_driver = {
 
263
        .name           = "samsung",
 
264
        .probe          = samsung_probe,
 
265
        .remove         = samsung_remove,
 
266
        .enable         = samsung_enable,
 
267
        .disable        = samsung_disable,
 
268
        .pre_sim        = samsung_pre_sim,
 
269
        .post_sim       = samsung_post_sim,
 
270
        .post_online    = samsung_post_online,
 
271
};
 
272
 
 
273
static int samsung_init(void)
 
274
{
 
275
        return ofono_modem_driver_register(&samsung_driver);
 
276
}
 
277
 
 
278
static void samsung_exit(void)
 
279
{
 
280
        ofono_modem_driver_unregister(&samsung_driver);
 
281
}
 
282
 
 
283
OFONO_PLUGIN_DEFINE(samsung, "Samsung modem driver", VERSION,
 
284
                OFONO_PLUGIN_PRIORITY_DEFAULT, samsung_init, samsung_exit)