3
* oFono - Open Source Telephony
5
* Copyright (C) 2008-2009 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
#include <ofono/log.h>
34
#include <ofono/modem.h>
35
#include <ofono/gprs-context.h>
38
#include "gatresult.h"
42
#define MBM_E2NAP_DISCONNECTED 0
43
#define MBM_E2NAP_CONNECTED 1
44
#define MBM_E2NAP_CONNECTING 2
46
static const char *none_prefix[] = { NULL };
48
struct gprs_context_data {
50
unsigned active_context;
53
static void at_enap_down_cb(gboolean ok, GAtResult *result, gpointer user_data)
55
struct cb_data *cbd = user_data;
56
ofono_gprs_context_cb_t cb = cbd->cb;
57
struct ofono_gprs_context *gc = cbd->user;
58
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
59
struct ofono_error error;
62
gcd->active_context = 0;
64
dump_response("enap_down_cb", ok, result);
65
decode_at_error(&error, g_at_result_final_response(result));
67
cb(&error, cbd->data);
70
static void mbm_enap_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
72
struct cb_data *cbd = user_data;
73
ofono_gprs_context_cb_t cb = cbd->cb;
74
struct ofono_error error;
76
dump_response("enap_up_cb", ok, result);
77
decode_at_error(&error, g_at_result_final_response(result));
79
cb(&error, cbd->data);
82
static void mbm_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
84
struct cb_data *cbd = user_data;
85
ofono_gprs_context_cb_t cb = cbd->cb;
86
struct ofono_gprs_context *gc = cbd->user;
87
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
91
dump_response("cgdcont_cb", ok, result);
94
struct ofono_error error;
96
gcd->active_context = 0;
98
decode_at_error(&error, g_at_result_final_response(result));
99
cb(&error, cbd->data);
103
ncbd = g_memdup(cbd, sizeof(struct cb_data));
105
sprintf(buf, "AT*ENAP=1,%u", gcd->active_context);
107
if (g_at_chat_send(gcd->chat, buf, none_prefix,
108
mbm_enap_up_cb, ncbd, g_free) > 0)
114
gcd->active_context = 0;
116
CALLBACK_WITH_FAILURE(cb, cbd->data);
119
static void mbm_gprs_activate_primary(struct ofono_gprs_context *gc,
120
const struct ofono_gprs_primary_context *ctx,
121
ofono_gprs_context_cb_t cb, void *data)
123
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
124
struct cb_data *cbd = cb_data_new(cb, data);
125
char buf[OFONO_GPRS_MAX_APN_LENGTH + 128];
131
gcd->active_context = ctx->cid;
135
/* TODO: Handle username / password fields */
136
len = sprintf(buf, "AT+CGDCONT=%u,\"IP\"", ctx->cid);
139
snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"",
142
if (g_at_chat_send(gcd->chat, buf, none_prefix,
143
mbm_cgdcont_cb, cbd, g_free) > 0)
149
CALLBACK_WITH_FAILURE(cb, data);
152
static void mbm_gprs_deactivate_primary(struct ofono_gprs_context *gc,
154
ofono_gprs_context_cb_t cb, void *data)
156
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
157
struct cb_data *cbd = cb_data_new(cb, data);
164
if (g_at_chat_send(gcd->chat, "AT*ENAP=0", none_prefix,
165
at_enap_down_cb, cbd, g_free) > 0)
172
CALLBACK_WITH_FAILURE(cb, data);
175
static void e2nap_notifier(GAtResult *result, gpointer user_data)
177
struct ofono_gprs_context *gc = user_data;
178
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
182
if (gcd->active_context == 0)
185
g_at_result_iter_init(&iter, result);
187
if (g_at_result_iter_next(&iter, "*E2NAP:") == FALSE)
190
g_at_result_iter_next_number(&iter, &state);
193
case MBM_E2NAP_DISCONNECTED:
194
ofono_gprs_context_deactivated(gc, gcd->active_context);
195
gcd->active_context = 0;
197
case MBM_E2NAP_CONNECTED:
198
ofono_debug("MBM Context: connected");
200
case MBM_E2NAP_CONNECTING:
201
ofono_debug("MBM Context: connecting");
208
static int mbm_gprs_context_probe(struct ofono_gprs_context *gc,
209
unsigned int vendor, void *data)
211
GAtChat *chat = data;
212
struct gprs_context_data *gcd;
214
gcd = g_new0(struct gprs_context_data, 1);
217
g_at_chat_register(chat, "*E2NAP:", e2nap_notifier, FALSE, gc, NULL);
219
g_at_chat_send(chat, "AT*E2NAP=1", NULL, NULL, NULL, NULL);
221
ofono_gprs_context_set_data(gc, gcd);
226
static void mbm_gprs_context_remove(struct ofono_gprs_context *gc)
228
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
230
ofono_gprs_context_set_data(gc, NULL);
234
static struct ofono_gprs_context_driver driver = {
236
.probe = mbm_gprs_context_probe,
237
.remove = mbm_gprs_context_remove,
238
.activate_primary = mbm_gprs_activate_primary,
239
.deactivate_primary = mbm_gprs_deactivate_primary,
242
void mbm_gprs_context_init()
244
ofono_gprs_context_driver_register(&driver);
247
void mbm_gprs_context_exit()
249
ofono_gprs_context_driver_unregister(&driver);