3
* oFono - Open Source Telephony
5
* Copyright (C) 2011-2012 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
26
#include <ofono/log.h>
27
#include <ofono/modem.h>
28
#include <ofono/devinfo.h>
36
struct qmi_service *dms;
39
static void string_cb(struct qmi_result *result, void *user_data)
41
struct cb_data *cbd = user_data;
42
ofono_devinfo_query_cb_t cb = cbd->cb;
47
if (qmi_result_set_error(result, NULL)) {
48
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
52
str = qmi_result_get_string(result, 0x01);
54
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
58
CALLBACK_WITH_SUCCESS(cb, str, cbd->data);
63
static void qmi_query_manufacturer(struct ofono_devinfo *devinfo,
64
ofono_devinfo_query_cb_t cb, void *user_data)
66
struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
67
struct cb_data *cbd = cb_data_new(cb, user_data);
71
if (qmi_service_send(data->dms, QMI_DMS_GET_MANUFACTURER, NULL,
72
string_cb, cbd, g_free) > 0)
75
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
80
static void qmi_query_model(struct ofono_devinfo *devinfo,
81
ofono_devinfo_query_cb_t cb, void *user_data)
83
struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
84
struct cb_data *cbd = cb_data_new(cb, user_data);
88
if (qmi_service_send(data->dms, QMI_DMS_GET_MODEL_ID, NULL,
89
string_cb, cbd, g_free) > 0)
92
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
97
static void qmi_query_revision(struct ofono_devinfo *devinfo,
98
ofono_devinfo_query_cb_t cb, void *user_data)
100
struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
101
struct cb_data *cbd = cb_data_new(cb, user_data);
105
if (qmi_service_send(data->dms, QMI_DMS_GET_REV_ID, NULL,
106
string_cb, cbd, g_free) > 0)
109
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
114
static void get_ids_cb(struct qmi_result *result, void *user_data)
116
struct cb_data *cbd = user_data;
117
ofono_devinfo_query_cb_t cb = cbd->cb;
122
if (qmi_result_set_error(result, NULL)) {
123
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
127
str = qmi_result_get_string(result, QMI_DMS_RESULT_ESN);
129
str = qmi_result_get_string(result, QMI_DMS_RESULT_IMEI);
131
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
136
CALLBACK_WITH_SUCCESS(cb, str, cbd->data);
141
static void qmi_query_serial(struct ofono_devinfo *devinfo,
142
ofono_devinfo_query_cb_t cb, void *user_data)
144
struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
145
struct cb_data *cbd = cb_data_new(cb, user_data);
149
if (qmi_service_send(data->dms, QMI_DMS_GET_IDS, NULL,
150
get_ids_cb, cbd, g_free) > 0)
153
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
158
static void create_dms_cb(struct qmi_service *service, void *user_data)
160
struct ofono_devinfo *devinfo = user_data;
161
struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
166
ofono_error("Failed to request DMS service");
167
ofono_devinfo_remove(devinfo);
171
data->dms = qmi_service_ref(service);
173
ofono_devinfo_register(devinfo);
176
static int qmi_devinfo_probe(struct ofono_devinfo *devinfo,
177
unsigned int vendor, void *user_data)
179
struct qmi_device *device = user_data;
180
struct devinfo_data *data;
184
data = g_new0(struct devinfo_data, 1);
186
ofono_devinfo_set_data(devinfo, data);
188
qmi_service_create_shared(device, QMI_SERVICE_DMS,
189
create_dms_cb, devinfo, NULL);
194
static void qmi_devinfo_remove(struct ofono_devinfo *devinfo)
196
struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
200
ofono_devinfo_set_data(devinfo, NULL);
202
qmi_service_unref(data->dms);
207
static struct ofono_devinfo_driver driver = {
209
.probe = qmi_devinfo_probe,
210
.remove = qmi_devinfo_remove,
211
.query_manufacturer = qmi_query_manufacturer,
212
.query_model = qmi_query_model,
213
.query_revision = qmi_query_revision,
214
.query_serial = qmi_query_serial,
217
void qmi_devinfo_init(void)
219
ofono_devinfo_driver_register(&driver);
222
void qmi_devinfo_exit(void)
224
ofono_devinfo_driver_unregister(&driver);