~phablet-team/ofono/ofono-bug-updates

« back to all changes in this revision

Viewing changes to drivers/qmimodem/devinfo.c

  • Committer: Denis Kenzior
  • Author(s): Lucas De Marchi
  • Date: 2011-03-18 23:31:14 UTC
  • Revision ID: git-v1:888e07863b24026413bac8f449de377c879e1044
message: add cancelled state

Based on patch from Yang Gu <gyagp0@gmail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 *  oFono - Open Source Telephony
4
 
 *
5
 
 *  Copyright (C) 2011-2012  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
 
#include <ofono/log.h>
27
 
#include <ofono/modem.h>
28
 
#include <ofono/devinfo.h>
29
 
 
30
 
#include "qmi.h"
31
 
#include "dms.h"
32
 
 
33
 
#include "qmimodem.h"
34
 
 
35
 
struct devinfo_data {
36
 
        struct qmi_service *dms;
37
 
};
38
 
 
39
 
static void string_cb(struct qmi_result *result, void *user_data)
40
 
{
41
 
        struct cb_data *cbd = user_data;
42
 
        ofono_devinfo_query_cb_t cb = cbd->cb;
43
 
        char *str;
44
 
 
45
 
        DBG("");
46
 
 
47
 
        if (qmi_result_set_error(result, NULL)) {
48
 
                CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
49
 
                return;
50
 
        }
51
 
 
52
 
        str = qmi_result_get_string(result, 0x01);
53
 
        if (!str) {
54
 
                CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
55
 
                return;
56
 
        }
57
 
 
58
 
        CALLBACK_WITH_SUCCESS(cb, str, cbd->data);
59
 
 
60
 
        qmi_free(str);
61
 
}
62
 
 
63
 
static void qmi_query_manufacturer(struct ofono_devinfo *devinfo,
64
 
                                ofono_devinfo_query_cb_t cb, void *user_data)
65
 
{
66
 
        struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
67
 
        struct cb_data *cbd = cb_data_new(cb, user_data);
68
 
 
69
 
        DBG("");
70
 
 
71
 
        if (qmi_service_send(data->dms, QMI_DMS_GET_MANUFACTURER, NULL,
72
 
                                                string_cb, cbd, g_free) > 0)
73
 
                return;
74
 
 
75
 
        CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
76
 
 
77
 
        g_free(cbd);
78
 
}
79
 
 
80
 
static void qmi_query_model(struct ofono_devinfo *devinfo,
81
 
                                ofono_devinfo_query_cb_t cb, void *user_data)
82
 
{
83
 
        struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
84
 
        struct cb_data *cbd = cb_data_new(cb, user_data);
85
 
 
86
 
        DBG("");
87
 
 
88
 
        if (qmi_service_send(data->dms, QMI_DMS_GET_MODEL_ID, NULL,
89
 
                                        string_cb, cbd, g_free) > 0)
90
 
                return;
91
 
 
92
 
        CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
93
 
 
94
 
        g_free(cbd);
95
 
}
96
 
 
97
 
static void qmi_query_revision(struct ofono_devinfo *devinfo,
98
 
                                ofono_devinfo_query_cb_t cb, void *user_data)
99
 
{
100
 
        struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
101
 
        struct cb_data *cbd = cb_data_new(cb, user_data);
102
 
 
103
 
        DBG("");
104
 
 
105
 
        if (qmi_service_send(data->dms, QMI_DMS_GET_REV_ID, NULL,
106
 
                                        string_cb, cbd, g_free) > 0)
107
 
                return;
108
 
 
109
 
        CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
110
 
 
111
 
        g_free(cbd);
112
 
}
113
 
 
114
 
static void get_ids_cb(struct qmi_result *result, void *user_data)
115
 
{
116
 
        struct cb_data *cbd = user_data;
117
 
        ofono_devinfo_query_cb_t cb = cbd->cb;
118
 
        char *str;
119
 
 
120
 
        DBG("");
121
 
 
122
 
        if (qmi_result_set_error(result, NULL)) {
123
 
                CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
124
 
                return;
125
 
        }
126
 
 
127
 
        str = qmi_result_get_string(result, QMI_DMS_RESULT_ESN);
128
 
        if (!str) {
129
 
                str = qmi_result_get_string(result, QMI_DMS_RESULT_IMEI);
130
 
                if (!str) {
131
 
                        CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
132
 
                        return;
133
 
                }
134
 
        }
135
 
 
136
 
        CALLBACK_WITH_SUCCESS(cb, str, cbd->data);
137
 
 
138
 
        qmi_free(str);
139
 
}
140
 
 
141
 
static void qmi_query_serial(struct ofono_devinfo *devinfo,
142
 
                                ofono_devinfo_query_cb_t cb, void *user_data)
143
 
{
144
 
        struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
145
 
        struct cb_data *cbd = cb_data_new(cb, user_data);
146
 
 
147
 
        DBG("");
148
 
 
149
 
        if (qmi_service_send(data->dms, QMI_DMS_GET_IDS, NULL,
150
 
                                        get_ids_cb, cbd, g_free) > 0)
151
 
                return;
152
 
 
153
 
        CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
154
 
 
155
 
        g_free(cbd);
156
 
}
157
 
 
158
 
static void create_dms_cb(struct qmi_service *service, void *user_data)
159
 
{
160
 
        struct ofono_devinfo *devinfo = user_data;
161
 
        struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
162
 
 
163
 
        DBG("");
164
 
 
165
 
        if (!service) {
166
 
                ofono_error("Failed to request DMS service");
167
 
                ofono_devinfo_remove(devinfo);
168
 
                return;
169
 
        }
170
 
 
171
 
        data->dms = qmi_service_ref(service);
172
 
 
173
 
        ofono_devinfo_register(devinfo);
174
 
}
175
 
 
176
 
static int qmi_devinfo_probe(struct ofono_devinfo *devinfo,
177
 
                                unsigned int vendor, void *user_data)
178
 
{
179
 
        struct qmi_device *device = user_data;
180
 
        struct devinfo_data *data;
181
 
 
182
 
        DBG("");
183
 
 
184
 
        data = g_new0(struct devinfo_data, 1);
185
 
 
186
 
        ofono_devinfo_set_data(devinfo, data);
187
 
 
188
 
        qmi_service_create_shared(device, QMI_SERVICE_DMS,
189
 
                                        create_dms_cb, devinfo, NULL);
190
 
 
191
 
        return 0;
192
 
}
193
 
 
194
 
static void qmi_devinfo_remove(struct ofono_devinfo *devinfo)
195
 
{
196
 
        struct devinfo_data *data = ofono_devinfo_get_data(devinfo);
197
 
 
198
 
        DBG("");
199
 
 
200
 
        ofono_devinfo_set_data(devinfo, NULL);
201
 
 
202
 
        qmi_service_unref(data->dms);
203
 
 
204
 
        g_free(data);
205
 
}
206
 
 
207
 
static struct ofono_devinfo_driver driver = {
208
 
        .name                   = "qmimodem",
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,
215
 
};
216
 
 
217
 
void qmi_devinfo_init(void)
218
 
{
219
 
        ofono_devinfo_driver_register(&driver);
220
 
}
221
 
 
222
 
void qmi_devinfo_exit(void)
223
 
{
224
 
        ofono_devinfo_driver_unregister(&driver);
225
 
}