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

« back to all changes in this revision

Viewing changes to plugins/hso.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:
2
2
 *
3
3
 *  oFono - Open Source Telephony
4
4
 *
5
 
 *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
 
5
 *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
8
8
 *  it under the terms of the GNU General Public License version 2 as
44
44
#include <ofono/gprs.h>
45
45
#include <ofono/gprs-context.h>
46
46
#include <ofono/radio-settings.h>
 
47
#include <ofono/voicecall.h>
47
48
#include <ofono/log.h>
48
49
 
49
50
#include <drivers/atmodem/atutil.h>
52
53
static const char *none_prefix[] = { NULL };
53
54
static const char *opmn_prefix[] = { "_OPMN:", NULL };
54
55
static const char *obls_prefix[] = { "_OBLS:", NULL };
 
56
static const char *opcm_prefix[] = { "_OPCMENABLE:", NULL };
55
57
 
56
58
struct hso_data {
57
59
        GAtChat *app;
58
60
        GAtChat *control;
 
61
        GAtChat *modem;
59
62
        guint sim_poll_source;
60
63
        guint sim_poll_count;
61
 
        gboolean have_sim;
 
64
        ofono_bool_t have_sim;
 
65
        ofono_bool_t have_voice;
62
66
};
63
67
 
64
68
static int hso_probe(struct ofono_modem *modem)
99
103
        ofono_info("%s%s", prefix, str);
100
104
}
101
105
 
 
106
static void opcm_query(gboolean ok, GAtResult *result, gpointer user_data)
 
107
{
 
108
        struct ofono_modem *modem = user_data;
 
109
        struct hso_data *data = ofono_modem_get_data(modem);
 
110
        GAtResultIter iter;
 
111
 
 
112
        DBG("");
 
113
 
 
114
        if (!ok)
 
115
                return;
 
116
 
 
117
        g_at_result_iter_init(&iter, result);
 
118
 
 
119
        if (!g_at_result_iter_next(&iter, "_OPCMENABLE:"))
 
120
                return;
 
121
 
 
122
        g_at_chat_send(data->app, "AT_OPCMENABLE=1", none_prefix,
 
123
                                                NULL, NULL, NULL);
 
124
}
 
125
 
 
126
static void opcm_support(gboolean ok, GAtResult *result, gpointer user_data)
 
127
{
 
128
        struct ofono_modem *modem = user_data;
 
129
        struct hso_data *data = ofono_modem_get_data(modem);
 
130
        GAtResultIter iter;
 
131
 
 
132
        DBG("");
 
133
 
 
134
        if (!ok)
 
135
                return;
 
136
 
 
137
        g_at_result_iter_init(&iter, result);
 
138
 
 
139
        if (!g_at_result_iter_next(&iter, "_OPCMENABLE:"))
 
140
                return;
 
141
 
 
142
        data->have_voice = TRUE;
 
143
 
 
144
        g_at_chat_send(data->app, "AT_OPCMENABLE?", opcm_prefix,
 
145
                                        opcm_query, modem, NULL);
 
146
}
 
147
 
102
148
static gboolean init_sim_check(gpointer user_data);
103
149
 
104
150
static void sim_status(gboolean ok, GAtResult *result, gpointer user_data)
144
190
 
145
191
        DBG("status sim %d pb %d sms %d", sim, pb, sms);
146
192
 
147
 
        if (sim == 0) {
 
193
        switch (sim) {
 
194
        case 0:         /* not ready */
148
195
                data->have_sim = FALSE;
149
196
 
150
197
                if (data->sim_poll_count++ < 5) {
152
199
                                                        init_sim_check, modem);
153
200
                        return;
154
201
                }
155
 
        } else
 
202
                break;
 
203
        case 1:         /* SIM card ready */
156
204
                data->have_sim = TRUE;
 
205
                break;
 
206
        case 2:         /* no SIM card */
 
207
                data->have_sim = FALSE;
 
208
                break;
 
209
        default:
 
210
                data->have_sim = FALSE;
 
211
                break;
 
212
        }
157
213
 
158
214
        data->sim_poll_count = 0;
159
215
 
160
 
        ofono_modem_set_powered(modem, TRUE);
 
216
        ofono_modem_set_powered(modem, data->have_sim);
 
217
 
 
218
        if (data->have_sim == FALSE)
 
219
                return;
 
220
 
 
221
        /*
 
222
         * Ensure that the modem is using GSM character set and not IRA,
 
223
         * otherwise weirdness with umlauts and other non-ASCII characters
 
224
         * can result
 
225
         */
 
226
        g_at_chat_send(data->control, "AT+CSCS=\"GSM\"", none_prefix,
 
227
                                                        NULL, NULL, NULL);
 
228
        g_at_chat_send(data->app, "AT+CSCS=\"GSM\"", none_prefix,
 
229
                                                        NULL, NULL, NULL);
161
230
 
162
231
        /*
163
232
         * Option has the concept of Speech Service versus
172
241
         */
173
242
        g_at_chat_send(data->app, "AT_ODO?", none_prefix, NULL, NULL, NULL);
174
243
        g_at_chat_send(data->app, "AT_ODO=0", none_prefix, NULL, NULL, NULL);
 
244
 
 
245
        g_at_chat_send(data->app, "AT_OPCMENABLE=?", opcm_prefix,
 
246
                                        opcm_support, modem, NULL);
175
247
}
176
248
 
177
249
static gboolean init_sim_check(gpointer user_data)
226
298
                                        check_model, modem, NULL);
227
299
}
228
300
 
229
 
static GAtChat *create_port(const char *device)
 
301
static GAtChat *open_device(struct ofono_modem *modem,
 
302
                                const char *key, char *debug)
230
303
{
 
304
        const char *device;
 
305
        GIOChannel *channel;
231
306
        GAtSyntax *syntax;
232
 
        GIOChannel *channel;
233
307
        GAtChat *chat;
234
308
 
 
309
        device = ofono_modem_get_string(modem, key);
 
310
        if (device == NULL)
 
311
                return NULL;
 
312
 
 
313
        DBG("%s %s", key, device);
 
314
 
235
315
        channel = g_at_tty_open(device, NULL);
236
316
        if (channel == NULL)
237
317
                return NULL;
239
319
        syntax = g_at_syntax_new_gsm_permissive();
240
320
        chat = g_at_chat_new(channel, syntax);
241
321
        g_at_syntax_unref(syntax);
 
322
 
242
323
        g_io_channel_unref(channel);
243
324
 
244
325
        if (chat == NULL)
245
326
                return NULL;
246
327
 
 
328
        if (getenv("OFONO_AT_DEBUG"))
 
329
                g_at_chat_set_debug(chat, hso_debug, debug);
 
330
 
247
331
        return chat;
248
332
}
249
333
 
250
334
static int hso_enable(struct ofono_modem *modem)
251
335
{
252
336
        struct hso_data *data = ofono_modem_get_data(modem);
253
 
        const char *app;
254
 
        const char *control;
255
337
 
256
338
        DBG("%p", modem);
257
339
 
258
 
        control = ofono_modem_get_string(modem, "ControlPort");
259
 
        app = ofono_modem_get_string(modem, "ApplicationPort");
260
 
 
261
 
        if (app == NULL || control == NULL)
 
340
        data->control = open_device(modem, "Control", "Control: ");
 
341
        if (data->control == NULL)
262
342
                return -EINVAL;
263
343
 
264
 
        data->control = create_port(control);
265
 
 
266
 
        if (data->control == NULL)
267
 
                return -EIO;
268
 
 
269
 
        if (getenv("OFONO_AT_DEBUG"))
270
 
                g_at_chat_set_debug(data->control, hso_debug, "Control: ");
271
 
 
272
 
        data->app = create_port(app);
273
 
 
 
344
        data->app = open_device(modem, "Application", "App: ");
274
345
        if (data->app == NULL) {
275
346
                g_at_chat_unref(data->control);
276
347
                data->control = NULL;
277
 
 
278
348
                return -EIO;
279
349
        }
280
350
 
281
 
        if (getenv("OFONO_AT_DEBUG"))
282
 
                g_at_chat_set_debug(data->app, hso_debug, "App: ");
 
351
        data->modem = open_device(modem, "Modem", "Modem: ");
283
352
 
284
 
        g_at_chat_send(data->control, "ATE0", none_prefix, NULL, NULL, NULL);
285
 
        g_at_chat_send(data->app, "ATE0", none_prefix, NULL, NULL, NULL);
 
353
        g_at_chat_send(data->control, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL);
 
354
        g_at_chat_send(data->app, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL);
286
355
 
287
356
        g_at_chat_send(data->control, "AT+CFUN=4", none_prefix,
288
357
                                        cfun_enable, modem, NULL);
316
385
        g_at_chat_cancel_all(data->control);
317
386
        g_at_chat_unregister_all(data->control);
318
387
 
 
388
        g_at_chat_unref(data->modem);
 
389
        data->modem = NULL;
 
390
 
319
391
        g_at_chat_unref(data->app);
320
392
        data->app = NULL;
321
393
 
349
421
        if (g_at_chat_send(chat, command, NULL, set_online_cb, cbd, g_free))
350
422
                return;
351
423
 
 
424
        CALLBACK_WITH_FAILURE(cb, cbd->data);
 
425
 
352
426
        g_free(cbd);
353
 
 
354
 
        CALLBACK_WITH_FAILURE(cb, cbd->data);
355
427
}
356
428
 
357
429
static void hso_pre_sim(struct ofono_modem *modem)
363
435
 
364
436
        ofono_devinfo_create(modem, 0, "atmodem", data->control);
365
437
        sim = ofono_sim_create(modem, OFONO_VENDOR_OPTION_HSO,
366
 
                                "atmodem", data->control);
 
438
                                        "atmodem", data->control);
367
439
 
368
440
        if (sim && data->have_sim == TRUE)
369
441
                ofono_sim_inserted_notify(sim, TRUE);
375
447
 
376
448
        DBG("%p", modem);
377
449
 
 
450
        if (data->have_voice == TRUE) {
 
451
                ofono_voicecall_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
 
452
                                                "atmodem", data->app);
 
453
        }
 
454
 
378
455
        ofono_phonebook_create(modem, 0, "atmodem", data->app);
379
456
        ofono_radio_settings_create(modem, 0, "hsomodem", data->app);
380
457
 
390
467
        DBG("%p", modem);
391
468
 
392
469
        ofono_netreg_create(modem, OFONO_VENDOR_OPTION_HSO,
393
 
                                "atmodem", data->app);
 
470
                                        "atmodem", data->app);
394
471
 
395
472
        ofono_cbs_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
396
 
                                "atmodem", data->app);
 
473
                                        "atmodem", data->app);
397
474
        ofono_ussd_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
398
 
                                "atmodem", data->app);
 
475
                                        "atmodem", data->app);
399
476
 
400
477
        gprs = ofono_gprs_create(modem, 0, "atmodem", data->app);
401
478
        gc = ofono_gprs_context_create(modem, 0, "hsomodem", data->control);
410
487
        .remove         = hso_remove,
411
488
        .enable         = hso_enable,
412
489
        .disable        = hso_disable,
413
 
        .set_online     = hso_set_online,
 
490
        .set_online     = hso_set_online,
414
491
        .pre_sim        = hso_pre_sim,
415
492
        .post_sim       = hso_post_sim,
416
493
        .post_online    = hso_post_online,