-
Notifications
You must be signed in to change notification settings - Fork 2
/
commands-dms.c
418 lines (362 loc) · 13.2 KB
/
commands-dms.c
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*
* uqmi -- tiny QMI support implementation
*
* Copyright (C) 2014-2015 Felix Fietkau <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
#include "qmi-message.h"
static struct {
QmiDmsUimPinId pin_id;
char* pin;
char* new_pin;
char* puk;
} dms_req_data;
static void cmd_dms_get_capabilities_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
void *t, *networks;
int i;
struct qmi_dms_get_capabilities_response res;
const char *radio_cap[] = {
[QMI_DMS_RADIO_INTERFACE_CDMA20001X] = "cdma1x",
[QMI_DMS_RADIO_INTERFACE_EVDO] = "cdma1xevdo",
[QMI_DMS_RADIO_INTERFACE_GSM] = "gsm",
[QMI_DMS_RADIO_INTERFACE_UMTS] = "umts",
[QMI_DMS_RADIO_INTERFACE_LTE] = "lte",
};
const char *service_cap[] = {
[QMI_DMS_DATA_SERVICE_CAPABILITY_NONE] = "none",
[QMI_DMS_DATA_SERVICE_CAPABILITY_CS] = "cs",
[QMI_DMS_DATA_SERVICE_CAPABILITY_PS] = "ps",
[QMI_DMS_DATA_SERVICE_CAPABILITY_SIMULTANEOUS_CS_PS] = "simultaneous_cs_ps",
[QMI_DMS_DATA_SERVICE_CAPABILITY_NON_SIMULTANEOUS_CS_PS] = "non_simultaneous_cs_ps",
};
qmi_parse_dms_get_capabilities_response(msg, &res);
t = blobmsg_open_table(&status, NULL);
blobmsg_add_u32(&status, "max_tx_channel_rate", (int32_t) res.data.info.max_tx_channel_rate);
blobmsg_add_u32(&status, "max_rx_channel_rate", (int32_t) res.data.info.max_rx_channel_rate);
if ((int)res.data.info.data_service_capability >= 0 && res.data.info.data_service_capability < ARRAY_SIZE(service_cap))
blobmsg_add_string(&status, "data_service", service_cap[res.data.info.data_service_capability]);
if(res.data.info.sim_capability == QMI_DMS_SIM_CAPABILITY_NOT_SUPPORTED)
blobmsg_add_string(&status, "sim", "not supported");
else if(res.data.info.sim_capability == QMI_DMS_SIM_CAPABILITY_SUPPORTED)
blobmsg_add_string(&status, "sim", "supported");
networks = blobmsg_open_array(&status, "networks");
for (i = 0; i < res.data.info.radio_interface_list_n; i++) {
if ((int)res.data.info.radio_interface_list[i] >= 0 && res.data.info.radio_interface_list[i] < ARRAY_SIZE(radio_cap))
blobmsg_add_string(&status, NULL, radio_cap[res.data.info.radio_interface_list[i]]);
else
blobmsg_add_string(&status, NULL, "unknown");
}
blobmsg_close_array(&status, networks);
blobmsg_close_table(&status, t);
}
static enum qmi_cmd_result
cmd_dms_get_capabilities_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
qmi_set_dms_get_capabilities_request(msg);
return QMI_CMD_REQUEST;
}
static const char *get_pin_status(int status)
{
static const char *pin_status[] = {
[QMI_DMS_UIM_PIN_STATUS_NOT_INITIALIZED] = "not_initialized",
[QMI_DMS_UIM_PIN_STATUS_ENABLED_NOT_VERIFIED] = "not_verified",
[QMI_DMS_UIM_PIN_STATUS_ENABLED_VERIFIED] = "verified",
[QMI_DMS_UIM_PIN_STATUS_DISABLED] = "disabled",
[QMI_DMS_UIM_PIN_STATUS_BLOCKED] = "blocked",
[QMI_DMS_UIM_PIN_STATUS_PERMANENTLY_BLOCKED] = "permanently_blocked",
[QMI_DMS_UIM_PIN_STATUS_UNBLOCKED] = "unblocked",
[QMI_DMS_UIM_PIN_STATUS_CHANGED] = "changed",
};
const char *res = "Unknown";
if (status < ARRAY_SIZE(pin_status) && pin_status[status])
res = pin_status[status];
return res;
}
static void cmd_dms_get_pin_status_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
struct qmi_dms_uim_get_pin_status_response res;
void *c;
qmi_parse_dms_uim_get_pin_status_response(msg, &res);
c = blobmsg_open_table(&status, NULL);
if (res.set.pin1_status) {
blobmsg_add_string(&status, "pin1_status", get_pin_status(res.data.pin1_status.current_status));
blobmsg_add_u32(&status, "pin1_verify_tries", (int32_t) res.data.pin1_status.verify_retries_left);
blobmsg_add_u32(&status, "pin1_unblock_tries", (int32_t) res.data.pin1_status.unblock_retries_left);
}
if (res.set.pin2_status) {
blobmsg_add_string(&status, "pin2_status", get_pin_status(res.data.pin2_status.current_status));
blobmsg_add_u32(&status, "pin2_verify_tries", (int32_t) res.data.pin2_status.verify_retries_left);
blobmsg_add_u32(&status, "pin2_unblock_tries", (int32_t) res.data.pin2_status.unblock_retries_left);
}
blobmsg_close_table(&status, c);
}
static enum qmi_cmd_result
cmd_dms_get_pin_status_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
qmi_set_dms_uim_get_pin_status_request(msg);
return QMI_CMD_REQUEST;
}
#define cmd_dms_verify_pin1_cb no_cb
static enum qmi_cmd_result
cmd_dms_verify_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
struct qmi_dms_uim_verify_pin_request data = {
QMI_INIT_SEQUENCE(info,
.pin_id = QMI_DMS_UIM_PIN_ID_PIN,
.pin = arg
)
};
qmi_set_dms_uim_verify_pin_request(msg, &data);
return QMI_CMD_REQUEST;
}
#define cmd_dms_verify_pin2_cb no_cb
static enum qmi_cmd_result
cmd_dms_verify_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
struct qmi_dms_uim_verify_pin_request data = {
QMI_INIT_SEQUENCE(info,
.pin_id = QMI_DMS_UIM_PIN_ID_PIN2,
.pin = arg
)
};
qmi_set_dms_uim_verify_pin_request(msg, &data);
return QMI_CMD_REQUEST;
}
#define cmd_dms_set_pin_cb no_cb
static enum qmi_cmd_result
cmd_dms_set_pin_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
dms_req_data.pin = arg;
return QMI_CMD_DONE;
}
static enum qmi_cmd_result
cmd_dms_set_pin_protection_prepare(struct qmi_msg *msg, char *arg)
{
if (!dms_req_data.pin) {
uqmi_add_error("Missing argument");
return QMI_CMD_EXIT;
}
int is_enabled;
if (strcasecmp(arg, "disabled") == 0)
is_enabled = false;
else if (strcasecmp(arg, "enabled") == 0)
is_enabled = true;
else {
uqmi_add_error("Invalid value (valid: disabled, enabled)");
return QMI_CMD_EXIT;
}
struct qmi_dms_uim_set_pin_protection_request dms_pin_protection_req = {
QMI_INIT_SEQUENCE(info,
.pin_id = dms_req_data.pin_id
),
QMI_INIT_PTR(info.pin, dms_req_data.pin),
QMI_INIT_PTR(info.protection_enabled, is_enabled)
};
qmi_set_dms_uim_set_pin_protection_request(msg, &dms_pin_protection_req);
return QMI_CMD_REQUEST;
}
#define cmd_dms_set_pin1_protection_cb no_cb
static enum qmi_cmd_result
cmd_dms_set_pin1_protection_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN;
return cmd_dms_set_pin_protection_prepare(msg, arg);
}
#define cmd_dms_set_pin2_protection_cb no_cb
static enum qmi_cmd_result
cmd_dms_set_pin2_protection_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN2;
return cmd_dms_set_pin_protection_prepare(msg, arg);
}
static enum qmi_cmd_result
cmd_dms_change_pin_prepare(struct qmi_msg *msg, char *arg)
{
if (!dms_req_data.pin || !dms_req_data.new_pin) {
uqmi_add_error("Missing argument");
return QMI_CMD_EXIT;
}
struct qmi_dms_uim_change_pin_request dms_change_pin_req = {
QMI_INIT_SEQUENCE(info,
.pin_id = dms_req_data.pin_id
),
QMI_INIT_PTR(info.old_pin, dms_req_data.pin),
QMI_INIT_PTR(info.new_pin, dms_req_data.new_pin)
};
qmi_set_dms_uim_change_pin_request(msg, &dms_change_pin_req);
return QMI_CMD_REQUEST;
}
#define cmd_dms_change_pin1_cb no_cb
static enum qmi_cmd_result
cmd_dms_change_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN;
return cmd_dms_change_pin_prepare(msg, arg);
}
#define cmd_dms_change_pin2_cb no_cb
static enum qmi_cmd_result
cmd_dms_change_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN2;
return cmd_dms_change_pin_prepare(msg, arg);
}
#define cmd_dms_set_new_pin_cb no_cb
static enum qmi_cmd_result
cmd_dms_set_new_pin_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
dms_req_data.new_pin = arg;
return QMI_CMD_DONE;
}
#define cmd_dms_set_puk_cb no_cb
static enum qmi_cmd_result
cmd_dms_set_puk_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
dms_req_data.puk = arg;
return QMI_CMD_DONE;
}
#define cmd_dms_unblock_pin1_cb no_cb
static enum qmi_cmd_result
cmd_dms_unblock_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
if (!dms_req_data.puk || !dms_req_data.new_pin) {
uqmi_add_error("Missing argument");
return QMI_CMD_EXIT;
}
struct qmi_dms_uim_unblock_pin_request dms_unlock_pin_req = {
QMI_INIT_SEQUENCE(info,
.pin_id = QMI_DMS_UIM_PIN_ID_PIN
),
QMI_INIT_PTR(info.puk, dms_req_data.puk),
QMI_INIT_PTR(info.new_pin, dms_req_data.new_pin)
};
qmi_set_dms_uim_unblock_pin_request(msg, &dms_unlock_pin_req);
return QMI_CMD_REQUEST;
}
#define cmd_dms_unblock_pin2_cb no_cb
static enum qmi_cmd_result
cmd_dms_unblock_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
if (!dms_req_data.puk || !dms_req_data.new_pin) {
uqmi_add_error("Missing argument");
return QMI_CMD_EXIT;
}
struct qmi_dms_uim_unblock_pin_request dms_unlock_pin_req = {
QMI_INIT_SEQUENCE(info,
.pin_id = QMI_DMS_UIM_PIN_ID_PIN2
),
QMI_INIT_PTR(info.puk, dms_req_data.puk),
QMI_INIT_PTR(info.new_pin, dms_req_data.new_pin)
};
qmi_set_dms_uim_unblock_pin_request(msg, &dms_unlock_pin_req);
return QMI_CMD_REQUEST;
}
static void cmd_dms_get_iccid_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
struct qmi_dms_uim_get_iccid_response res;
qmi_parse_dms_uim_get_iccid_response(msg, &res);
if (res.data.iccid)
blobmsg_add_string(&status, NULL, res.data.iccid);
}
static enum qmi_cmd_result
cmd_dms_get_iccid_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
qmi_set_dms_uim_get_iccid_request(msg);
return QMI_CMD_REQUEST;
}
static void cmd_dms_get_imsi_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
struct qmi_dms_uim_get_imsi_response res;
qmi_parse_dms_uim_get_imsi_response(msg, &res);
if (res.data.imsi)
blobmsg_add_string(&status, NULL, res.data.imsi);
}
static enum qmi_cmd_result
cmd_dms_get_imsi_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
qmi_set_dms_uim_get_imsi_request(msg);
return QMI_CMD_REQUEST;
}
static void cmd_dms_get_msisdn_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
struct qmi_dms_get_msisdn_response res;
qmi_parse_dms_get_msisdn_response(msg, &res);
if (res.data.msisdn)
blobmsg_add_string(&status, NULL, res.data.msisdn);
}
static enum qmi_cmd_result
cmd_dms_get_msisdn_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
qmi_set_dms_get_msisdn_request(msg);
return QMI_CMD_REQUEST;
}
static void cmd_dms_get_imei_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
struct qmi_dms_get_ids_response res;
qmi_parse_dms_get_ids_response(msg, &res);
if (res.data.imei)
blobmsg_add_string(&status, NULL, res.data.imei);
}
static enum qmi_cmd_result
cmd_dms_get_imei_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
qmi_set_dms_get_ids_request(msg);
return QMI_CMD_REQUEST;
}
#define cmd_dms_reset_cb no_cb
static enum qmi_cmd_result
cmd_dms_reset_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
qmi_set_dms_reset_request(msg);
return QMI_CMD_REQUEST;
}
#define cmd_dms_set_operating_mode_cb no_cb
static enum qmi_cmd_result
cmd_dms_set_operating_mode_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
static const char *modes[] = {
[QMI_DMS_OPERATING_MODE_ONLINE] = "online",
[QMI_DMS_OPERATING_MODE_LOW_POWER] = "low_power",
[QMI_DMS_OPERATING_MODE_FACTORY_TEST] = "factory_test",
[QMI_DMS_OPERATING_MODE_OFFLINE] = "offline",
[QMI_DMS_OPERATING_MODE_RESET] = "reset",
[QMI_DMS_OPERATING_MODE_SHUTTING_DOWN] = "shutting_down",
[QMI_DMS_OPERATING_MODE_PERSISTENT_LOW_POWER] = "persistent_low_power",
[QMI_DMS_OPERATING_MODE_MODE_ONLY_LOW_POWER] = "mode_only_low_power",
};
static struct qmi_dms_set_operating_mode_request sreq = {
QMI_INIT(mode, QMI_DMS_OPERATING_MODE_ONLINE),
};
int i;
for (i = 0; i < ARRAY_SIZE(modes); i++) {
if (!modes[i])
continue;
if (strcmp(arg, modes[i]) != 0)
continue;
sreq.data.mode = i;
qmi_set_dms_set_operating_mode_request(msg, &sreq);
return QMI_CMD_REQUEST;
}
return uqmi_add_error("Invalid argument");
}
#define cmd_dms_set_fcc_authentication_cb no_cb
static enum qmi_cmd_result
cmd_dms_set_fcc_authentication_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
qmi_set_dms_set_fcc_authentication_request(msg);
return QMI_CMD_REQUEST;
}