1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
/*
* This file is part of oFono - Open Source Telephony
*
* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: Aki Niemi <aki.niemi@nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <glib.h>
#include <gisi/client.h>
#include <gisi/iter.h>
#include <ofono/log.h>
#include <ofono/modem.h>
#include <ofono/devinfo.h>
#include "isi.h"
#define PN_PHONE_INFO 0x1B
#define INFO_TIMEOUT 5
enum return_code {
INFO_OK = 0x00,
INFO_FAIL = 0x01,
INFO_NO_NUMBER = 0x02,
INFO_NOT_SUPPORTED = 0x03
};
enum message_id {
INFO_SERIAL_NUMBER_READ_REQ = 0x00,
INFO_SERIAL_NUMBER_READ_RESP = 0x01,
INFO_VERSION_READ_REQ = 0x07,
INFO_VERSION_READ_RESP = 0x08,
INFO_PRODUCT_INFO_READ_REQ = 0x15,
INFO_PRODUCT_INFO_READ_RESP = 0x16
};
enum sub_block_id {
INFO_SB_PRODUCT_INFO_NAME = 0x01,
INFO_SB_PRODUCT_INFO_MANUFACTURER = 0x07,
INFO_SB_SN_IMEI_PLAIN = 0x41,
INFO_SB_MCUSW_VERSION = 0x48
};
enum product_info_type {
INFO_PRODUCT_NAME = 0x01,
INFO_PRODUCT_MANUFACTURER = 0x07
};
enum serial_number_type {
INFO_SN_IMEI_PLAIN = 0x41
};
enum version_type {
INFO_MCUSW = 0x01
};
struct devinfo_data {
GIsiClient *client;
};
static bool info_resp_cb(GIsiClient *client, const void *restrict data,
size_t len, uint16_t object, void *opaque)
{
const unsigned char *msg = data;
struct isi_cb_data *cbd = opaque;
ofono_devinfo_query_cb_t cb = cbd->cb;
GIsiSubBlockIter iter;
char *info = NULL;
guint8 chars;
if(!msg) {
DBG("ISI client error: %d", g_isi_client_error(client));
goto error;
}
if (len < 3) {
DBG("Truncated message.");
goto error;
}
if (msg[0] != INFO_PRODUCT_INFO_READ_RESP &&
msg[0] != INFO_VERSION_READ_RESP &&
msg[0] != INFO_SERIAL_NUMBER_READ_RESP) {
DBG("Unexpected message ID: 0x%02x", msg[0]);
goto error;
}
if (msg[1] != INFO_OK) {
DBG("Request failed: 0x%02X", msg[1]);
goto error;
}
if (!g_isi_sb_iter_init(msg+3, len-3, &iter, false))
goto error;
while (g_isi_sb_iter_is_valid(&iter)) {
switch (g_isi_sb_iter_get_id(&iter)) {
case INFO_SB_PRODUCT_INFO_MANUFACTURER:
case INFO_SB_PRODUCT_INFO_NAME:
case INFO_SB_MCUSW_VERSION:
case INFO_SB_SN_IMEI_PLAIN:
if (g_isi_sb_iter_get_len(&iter) < 5)
goto error;
if (!g_isi_sb_iter_get_byte(&iter, &chars, 3))
goto error;
if (!g_isi_sb_iter_get_latin_tag(&iter,
&info, chars, 4))
goto error;
DBG("info=<%s>", info);
CALLBACK_WITH_SUCCESS(cb, info, cbd->data);
g_free(info);
goto out;
default:
DBG("Unknown sub-block: 0x%02X (%u bytes)",
g_isi_sb_iter_get_id(&iter),
g_isi_sb_iter_get_len(&iter));
break;
}
g_isi_sb_iter_next(&iter);
}
error:
CALLBACK_WITH_FAILURE(cb, "", cbd->data);
out:
g_free(cbd);
return true;
}
static void isi_query_manufacturer(struct ofono_devinfo *info,
ofono_devinfo_query_cb_t cb,
void *data)
{
struct devinfo_data *dev = ofono_devinfo_get_data(info);
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
const unsigned char msg[] = {
INFO_PRODUCT_INFO_READ_REQ,
INFO_PRODUCT_MANUFACTURER
};
if (!cbd)
goto error;
if (g_isi_request_make(dev->client, msg, sizeof(msg), INFO_TIMEOUT,
info_resp_cb, cbd))
return;
error:
if (cbd)
g_free(cbd);
CALLBACK_WITH_FAILURE(cb, "", data);
}
static void isi_query_model(struct ofono_devinfo *info,
ofono_devinfo_query_cb_t cb,
void *data)
{
struct devinfo_data *dev = ofono_devinfo_get_data(info);
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
const unsigned char msg[] = {
INFO_PRODUCT_INFO_READ_REQ,
INFO_PRODUCT_NAME
};
if (!cbd)
goto error;
if (g_isi_request_make(dev->client, msg, sizeof(msg), INFO_TIMEOUT,
info_resp_cb, cbd))
return;
error:
if (cbd)
g_free(cbd);
CALLBACK_WITH_FAILURE(cb, "", data);
}
static void isi_query_revision(struct ofono_devinfo *info,
ofono_devinfo_query_cb_t cb,
void *data)
{
struct devinfo_data *dev = ofono_devinfo_get_data(info);
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
const unsigned char msg[] = {
INFO_VERSION_READ_REQ,
0x00, INFO_MCUSW,
0x00, 0x00, 0x00, 0x00
};
if (!cbd)
goto error;
if (g_isi_request_make(dev->client, msg, sizeof(msg), INFO_TIMEOUT,
info_resp_cb, cbd))
return;
error:
if (cbd)
g_free(cbd);
CALLBACK_WITH_FAILURE(cb, "", data);
}
static void isi_query_serial(struct ofono_devinfo *info,
ofono_devinfo_query_cb_t cb,
void *data)
{
struct devinfo_data *dev = ofono_devinfo_get_data(info);
struct isi_cb_data *cbd = isi_cb_data_new(dev, cb, data);
const unsigned char msg[] = {
INFO_SERIAL_NUMBER_READ_REQ,
INFO_SN_IMEI_PLAIN
};
if (!cbd)
goto error;
if (g_isi_request_make(dev->client, msg, sizeof(msg), INFO_TIMEOUT,
info_resp_cb, cbd))
return;
error:
if (cbd)
g_free(cbd);
CALLBACK_WITH_FAILURE(cb, "", data);
}
static gboolean isi_devinfo_register(gpointer user)
{
struct ofono_devinfo *info = user;
ofono_devinfo_register(info);
return FALSE;
}
static int isi_devinfo_probe(struct ofono_devinfo *info, unsigned int vendor,
void *user)
{
GIsiModem *idx = user;
struct devinfo_data *data = g_try_new0(struct devinfo_data, 1);
if (!data)
return -ENOMEM;
DBG("idx=%p", idx);
data->client = g_isi_client_create(idx, PN_PHONE_INFO);
if (!data->client) {
g_free(data);
return -ENOMEM;
}
ofono_devinfo_set_data(info, data);
g_idle_add(isi_devinfo_register, info);
return 0;
}
static void isi_devinfo_remove(struct ofono_devinfo *info)
{
struct devinfo_data *data = ofono_devinfo_get_data(info);
if (data) {
g_isi_client_destroy(data->client);
g_free(data);
}
}
static struct ofono_devinfo_driver driver = {
.name = "isimodem",
.probe = isi_devinfo_probe,
.remove = isi_devinfo_remove,
.query_manufacturer = isi_query_manufacturer,
.query_model = isi_query_model,
.query_revision = isi_query_revision,
.query_serial = isi_query_serial
};
void isi_devinfo_init()
{
ofono_devinfo_driver_register(&driver);
}
void isi_devinfo_exit()
{
ofono_devinfo_driver_unregister(&driver);
}
|