3
* oFono - Open Source Telephony
5
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6
* Copyright (C) 2011 ST-Ericsson AB.
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License version 2 as
10
* published by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35
#include <ofono/log.h>
36
#include <ofono/modem.h>
37
#include <ofono/gnss.h>
40
#include "gatresult.h"
50
static const char *none_prefix[] = { NULL };
51
static const char *cpos_prefix[] = { "+CPOS:", NULL };
52
static const char *cposr_prefix[] = { "+CPOSR:", NULL };
54
static void gnss_pr_cb(gboolean ok, GAtResult *result, gpointer user_data)
56
struct cb_data *cbd = user_data;
57
ofono_gnss_cb_t cb = cbd->cb;
58
struct ofono_error error;
62
decode_at_error(&error, g_at_result_final_response(result));
64
cb(&error, cbd->data);
67
static void at_gnss_position_reporting(struct ofono_gnss *gnss,
72
struct gnss_data *ad = ofono_gnss_get_data(gnss);
73
struct cb_data *cbd = cb_data_new(cb, data);
78
g_at_chat_send(ad->chat, "AT+CPOSR=1",
79
cposr_prefix, gnss_pr_cb, cbd, g_free);
81
if (ad->vendor == OFONO_VENDOR_STE)
82
g_at_chat_send(ad->chat, "AT*EPOSADRR=1",
83
NULL, NULL, NULL, NULL);
85
g_at_chat_send(ad->chat, "AT+CPOSR=0",
86
cposr_prefix, gnss_pr_cb, cbd, g_free);
88
if (ad->vendor == OFONO_VENDOR_STE)
89
g_at_chat_send(ad->chat, "AT*EPOSADRR=0",
90
NULL, NULL, NULL, NULL);
94
static void gnss_se_cb(gboolean ok, GAtResult *result, gpointer user_data)
96
struct cb_data *cbd = user_data;
97
ofono_gnss_cb_t cb = cbd->cb;
98
struct ofono_error error;
102
decode_at_error(&error, g_at_result_final_response(result));
104
cb(&error, cbd->data);
107
static void at_gnss_send_element(struct ofono_gnss *gnss,
109
ofono_gnss_cb_t cb, void *data)
111
struct gnss_data *ad = ofono_gnss_get_data(gnss);
112
struct cb_data *cbd = cb_data_new(cb, data);
113
char *buf = g_try_new(char, strlen(xml) + 10);
121
len = sprintf(buf, "AT+CPOS\r");
122
len += sprintf(buf + len, "%s", xml);
124
if (g_at_chat_send_and_expect_short_prompt(ad->chat, buf, cpos_prefix,
135
CALLBACK_WITH_FAILURE(cb, data);
138
static gboolean gnss_parse_report(GAtResult *result, const char *prefix,
143
g_at_result_iter_init(&iter, result);
145
if (!g_at_result_iter_next(&iter, prefix))
148
if (!g_at_result_iter_next_unquoted_string(&iter, xml))
154
static void gnss_report(GAtResult *result, gpointer user_data)
162
if (!gnss_parse_report(result, "+CPOSR:", &xml)) {
163
ofono_error("Unable to parse CPOSR notification");
168
ofono_error("Unable to parse CPOSR notification");
175
static void at_gnss_reset_notify(GAtResult *result, gpointer user_data)
177
struct ofono_gnss *gnss = user_data;
181
ofono_gnss_notify_posr_reset(gnss);
184
static void at_gnss_not_supported(struct ofono_gnss *gnss)
186
ofono_error("gnss not supported by this modem.");
188
ofono_gnss_remove(gnss);
191
static void at_gnss_cposr_support_cb(gboolean ok, GAtResult *result,
194
struct ofono_gnss *gnss = user_data;
195
struct gnss_data *ad = ofono_gnss_get_data(gnss);
200
at_gnss_not_supported(gnss);
204
g_at_chat_register(ad->chat, "+CPOSR:", gnss_report,
207
if (ad->vendor == OFONO_VENDOR_STE)
208
g_at_chat_register(ad->chat, "*EPOSADRR:", at_gnss_reset_notify,
211
ofono_gnss_register(gnss);
214
static void at_gnss_cpos_support_cb(gboolean ok, GAtResult *result,
217
struct ofono_gnss *gnss = user_data;
218
struct gnss_data *ad = ofono_gnss_get_data(gnss);
223
at_gnss_not_supported(gnss);
227
g_at_chat_send(ad->chat, "AT+CPOSR=?",
228
none_prefix, at_gnss_cposr_support_cb, gnss, NULL);
231
static int at_gnss_probe(struct ofono_gnss *gnss, unsigned int vendor,
234
GAtChat *chat = user;
235
struct gnss_data *gd;
239
gd = g_try_new0(struct gnss_data, 1);
243
gd->chat = g_at_chat_clone(chat);
246
ofono_gnss_set_data(gnss, gd);
248
g_at_chat_send(gd->chat, "AT+CPOS=?",
249
none_prefix, at_gnss_cpos_support_cb, gnss, NULL);
254
static void at_gnss_remove(struct ofono_gnss *gnss)
256
struct gnss_data *gd = ofono_gnss_get_data(gnss);
260
ofono_gnss_set_data(gnss, NULL);
262
g_at_chat_unref(gd->chat);
266
static struct ofono_gnss_driver driver = {
268
.probe = at_gnss_probe,
269
.remove = at_gnss_remove,
270
.send_element = at_gnss_send_element,
271
.set_position_reporting = at_gnss_position_reporting,
274
void at_gnss_init(void)
276
ofono_gnss_driver_register(&driver);
279
void at_gnss_exit(void)
281
ofono_gnss_driver_unregister(&driver);