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

« back to all changes in this revision

Viewing changes to drivers/swmodem/gprs-context.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
#define _GNU_SOURCE
 
27
#include <string.h>
 
28
#include <stdlib.h>
 
29
#include <stdio.h>
 
30
#include <errno.h>
 
31
#include <sys/stat.h>
 
32
 
 
33
#include <glib.h>
 
34
 
 
35
#include <ofono/log.h>
 
36
#include <ofono/modem.h>
 
37
#include <ofono/gprs-context.h>
 
38
 
 
39
#include "gatchat.h"
 
40
#include "gatresult.h"
 
41
#include "gattty.h"
 
42
 
 
43
#include "swmodem.h"
 
44
 
 
45
static const char *none_prefix[] = { NULL };
 
46
 
 
47
struct gprs_context_data {
 
48
        GAtChat *chat;
 
49
        unsigned int active_context;
 
50
        ofono_gprs_context_cb_t cb;
 
51
        void *cb_data;
 
52
};
 
53
 
 
54
static void at_scact_down_cb(gboolean ok, GAtResult *result,
 
55
                                                gpointer user_data)
 
56
{
 
57
        struct cb_data *cbd = user_data;
 
58
        ofono_gprs_context_cb_t cb = cbd->cb;
 
59
        struct ofono_gprs_context *gc = cbd->user;
 
60
        struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
 
61
        struct ofono_error error;
 
62
 
 
63
        DBG("ok %d", ok);
 
64
 
 
65
        if (ok) {
 
66
                gcd->cb = cb;
 
67
                gcd->cb_data = cbd->data;
 
68
        }
 
69
 
 
70
        decode_at_error(&error, g_at_result_final_response(result));
 
71
        cb(&error, cbd->data);
 
72
}
 
73
 
 
74
static void at_scact_up_cb(gboolean ok, GAtResult *result,
 
75
                                                gpointer user_data)
 
76
{
 
77
        struct cb_data *cbd = user_data;
 
78
        ofono_gprs_context_cb_t cb = cbd->cb;
 
79
        struct ofono_gprs_context *gc = cbd->user;
 
80
        struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
 
81
        struct ofono_modem *modem;
 
82
        const char *interface;
 
83
        char buf[64];
 
84
 
 
85
        DBG("ok %d", ok);
 
86
 
 
87
        if (!ok) {
 
88
                struct ofono_error error;
 
89
 
 
90
                gcd->active_context = 0;
 
91
 
 
92
                decode_at_error(&error, g_at_result_final_response(result));
 
93
                cb(&error, cbd->data);
 
94
                return;
 
95
        }
 
96
 
 
97
        gcd->cb = cb;
 
98
        gcd->cb_data = cbd->data;
 
99
 
 
100
        snprintf(buf, sizeof(buf), "AT!SCPADDR=%u", gcd->active_context);
 
101
        g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
 
102
 
 
103
        snprintf(buf, sizeof(buf), "AT+CGCONTRDP=%u", gcd->active_context);
 
104
        g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
 
105
 
 
106
        modem = ofono_gprs_context_get_modem(gc);
 
107
        interface = ofono_modem_get_string(modem, "NetworkInterface");
 
108
 
 
109
        ofono_gprs_context_set_interface(gc, interface);
 
110
        ofono_gprs_context_set_ipv4_address(gc, NULL, FALSE);
 
111
 
 
112
        CALLBACK_WITH_SUCCESS(gcd->cb, gcd->cb_data);
 
113
}
 
114
 
 
115
static void at_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
116
{
 
117
        struct cb_data *cbd = user_data;
 
118
        ofono_gprs_context_cb_t cb = cbd->cb;
 
119
        struct ofono_gprs_context *gc = cbd->user;
 
120
        struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
 
121
        struct cb_data *ncbd;
 
122
        char buf[64];
 
123
 
 
124
        DBG("ok %d", ok);
 
125
 
 
126
        if (!ok) {
 
127
                struct ofono_error error;
 
128
 
 
129
                gcd->active_context = 0;
 
130
 
 
131
                decode_at_error(&error, g_at_result_final_response(result));
 
132
                cb(&error, cbd->data);
 
133
                return;
 
134
        }
 
135
 
 
136
        ncbd = g_memdup(cbd, sizeof(struct cb_data));
 
137
 
 
138
        snprintf(buf, sizeof(buf), "AT!SCACT=1,%u", gcd->active_context);
 
139
 
 
140
        if (g_at_chat_send(gcd->chat, buf, none_prefix,
 
141
                                at_scact_up_cb, ncbd, g_free) > 0)
 
142
                return;
 
143
 
 
144
        g_free(ncbd);
 
145
 
 
146
        gcd->active_context = 0;
 
147
 
 
148
        CALLBACK_WITH_FAILURE(cb, cbd->data);
 
149
}
 
150
 
 
151
static void sw_gprs_activate_primary(struct ofono_gprs_context *gc,
 
152
                                const struct ofono_gprs_primary_context *ctx,
 
153
                                ofono_gprs_context_cb_t cb, void *data)
 
154
{
 
155
        struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
 
156
        struct cb_data *cbd = cb_data_new(cb, data);
 
157
        char buf[OFONO_GPRS_MAX_APN_LENGTH + 128];
 
158
        int len = 0;
 
159
 
 
160
        DBG("cid %u", ctx->cid);
 
161
 
 
162
        gcd->active_context = ctx->cid;
 
163
 
 
164
        cbd->user = gc;
 
165
 
 
166
        switch (ctx->proto) {
 
167
        case OFONO_GPRS_PROTO_IP:
 
168
                len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IP\"",
 
169
                                                                ctx->cid);
 
170
                break;
 
171
        case OFONO_GPRS_PROTO_IPV6:
 
172
                len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IPV6\"",
 
173
                                                                ctx->cid);
 
174
                break;
 
175
        case OFONO_GPRS_PROTO_IPV4V6:
 
176
                len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IPV4V6\"",
 
177
                                                                ctx->cid);
 
178
                break;
 
179
        }
 
180
 
 
181
        if (ctx->apn)
 
182
                snprintf(buf + len, sizeof(buf) - len - 3,
 
183
                                        ",\"%s\"", ctx->apn);
 
184
 
 
185
        if (g_at_chat_send(gcd->chat, buf, none_prefix,
 
186
                                at_cgdcont_cb, cbd, g_free) > 0)
 
187
                return;
 
188
 
 
189
        g_free(cbd);
 
190
 
 
191
        CALLBACK_WITH_FAILURE(cb, data);
 
192
}
 
193
 
 
194
static void sw_gprs_deactivate_primary(struct ofono_gprs_context *gc,
 
195
                                        unsigned int cid,
 
196
                                        ofono_gprs_context_cb_t cb, void *data)
 
197
{
 
198
        struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
 
199
        struct cb_data *cbd = cb_data_new(cb, data);
 
200
        char buf[128];
 
201
 
 
202
        DBG("cid %u", cid);
 
203
 
 
204
        cbd->user = gc;
 
205
 
 
206
        snprintf(buf, sizeof(buf), "AT!SCACT=0,%u", cid);
 
207
 
 
208
        if (g_at_chat_send(gcd->chat, buf, none_prefix,
 
209
                                at_scact_down_cb, cbd, g_free) > 0)
 
210
                return;
 
211
 
 
212
        g_free(cbd);
 
213
 
 
214
        CALLBACK_WITH_FAILURE(cb, data);
 
215
}
 
216
 
 
217
static int sw_gprs_context_probe(struct ofono_gprs_context *gc,
 
218
                                        unsigned int vendor, void *data)
 
219
{
 
220
        GAtChat *chat = data;
 
221
        struct gprs_context_data *gcd;
 
222
 
 
223
        DBG("");
 
224
 
 
225
        gcd = g_try_new0(struct gprs_context_data, 1);
 
226
        if (gcd == NULL)
 
227
                return -ENOMEM;
 
228
 
 
229
        gcd->chat = g_at_chat_clone(chat);
 
230
 
 
231
        ofono_gprs_context_set_data(gc, gcd);
 
232
 
 
233
        return 0;
 
234
}
 
235
 
 
236
static void sw_gprs_context_remove(struct ofono_gprs_context *gc)
 
237
{
 
238
        struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
 
239
 
 
240
        DBG("");
 
241
 
 
242
        ofono_gprs_context_set_data(gc, NULL);
 
243
 
 
244
        g_at_chat_unref(gcd->chat);
 
245
        g_free(gcd);
 
246
}
 
247
 
 
248
static struct ofono_gprs_context_driver driver = {
 
249
        .name                   = "swmodem",
 
250
        .probe                  = sw_gprs_context_probe,
 
251
        .remove                 = sw_gprs_context_remove,
 
252
        .activate_primary       = sw_gprs_activate_primary,
 
253
        .deactivate_primary     = sw_gprs_deactivate_primary,
 
254
};
 
255
 
 
256
void sw_gprs_context_init(void)
 
257
{
 
258
        ofono_gprs_context_driver_register(&driver);
 
259
}
 
260
 
 
261
void sw_gprs_context_exit(void)
 
262
{
 
263
        ofono_gprs_context_driver_unregister(&driver);
 
264
}