• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/uqmi/commands-dms.c

  1 /*
  2  * uqmi -- tiny QMI support implementation
  3  *
  4  * Copyright (C) 2014-2015 Felix Fietkau <nbd@openwrt.org>
  5  *
  6  * This library is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU Lesser General Public
  8  * License as published by the Free Software Foundation; either
  9  * version 2 of the License, or (at your option) any later version.
 10  *
 11  * This library 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 GNU
 14  * Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public
 17  * License along with this library; if not, write to the
 18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 19  * Boston, MA 02110-1301 USA.
 20  */
 21 #include "qmi-message.h"
 22 
 23 static struct {
 24         QmiDmsUimPinId pin_id;
 25         char* pin;
 26         char* new_pin;
 27         char* puk;
 28 } dms_req_data;
 29 
 30 static void cmd_dms_get_capabilities_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
 31 {
 32         void *t, *networks;
 33         int i;
 34         struct qmi_dms_get_capabilities_response res;
 35         const char *radio_cap[] = {
 36                 [QMI_DMS_RADIO_INTERFACE_CDMA20001X] = "cdma1x",
 37                 [QMI_DMS_RADIO_INTERFACE_EVDO] = "cdma1xevdo",
 38                 [QMI_DMS_RADIO_INTERFACE_GSM] = "gsm",
 39                 [QMI_DMS_RADIO_INTERFACE_UMTS] = "umts",
 40                 [QMI_DMS_RADIO_INTERFACE_LTE] = "lte",
 41         };
 42         const char *service_cap[] = {
 43                 [QMI_DMS_DATA_SERVICE_CAPABILITY_NONE] = "none",
 44                 [QMI_DMS_DATA_SERVICE_CAPABILITY_CS] = "cs",
 45                 [QMI_DMS_DATA_SERVICE_CAPABILITY_PS] = "ps",
 46                 [QMI_DMS_DATA_SERVICE_CAPABILITY_SIMULTANEOUS_CS_PS] = "simultaneous_cs_ps",
 47                 [QMI_DMS_DATA_SERVICE_CAPABILITY_NON_SIMULTANEOUS_CS_PS] = "non_simultaneous_cs_ps",
 48         };
 49 
 50         qmi_parse_dms_get_capabilities_response(msg, &res);
 51 
 52         t = blobmsg_open_table(&status, NULL);
 53 
 54         blobmsg_add_u32(&status, "max_tx_channel_rate", (int32_t) res.data.info.max_tx_channel_rate);
 55         blobmsg_add_u32(&status, "max_rx_channel_rate", (int32_t) res.data.info.max_rx_channel_rate);
 56         if ((int)res.data.info.data_service_capability >= 0 && res.data.info.data_service_capability < ARRAY_SIZE(service_cap))
 57                 blobmsg_add_string(&status, "data_service", service_cap[res.data.info.data_service_capability]);
 58 
 59         if(res.data.info.sim_capability == QMI_DMS_SIM_CAPABILITY_NOT_SUPPORTED)
 60                 blobmsg_add_string(&status, "sim", "not supported");
 61         else if(res.data.info.sim_capability == QMI_DMS_SIM_CAPABILITY_SUPPORTED)
 62                 blobmsg_add_string(&status, "sim", "supported");
 63 
 64         networks = blobmsg_open_array(&status, "networks");
 65         for (i = 0; i < res.data.info.radio_interface_list_n; i++) {
 66                 if ((int)res.data.info.radio_interface_list[i] >= 0 && res.data.info.radio_interface_list[i] < ARRAY_SIZE(radio_cap))
 67                         blobmsg_add_string(&status, NULL, radio_cap[res.data.info.radio_interface_list[i]]);
 68                 else
 69                         blobmsg_add_string(&status, NULL, "unknown");
 70         }
 71         blobmsg_close_array(&status, networks);
 72 
 73         blobmsg_close_table(&status, t);
 74 }
 75 
 76 static enum qmi_cmd_result
 77 cmd_dms_get_capabilities_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
 78 {
 79         qmi_set_dms_get_capabilities_request(msg);
 80         return QMI_CMD_REQUEST;
 81 }
 82 
 83 static const char *get_pin_status(int status)
 84 {
 85         static const char *pin_status[] = {
 86                 [QMI_DMS_UIM_PIN_STATUS_NOT_INITIALIZED] = "not_initialized",
 87                 [QMI_DMS_UIM_PIN_STATUS_ENABLED_NOT_VERIFIED] = "not_verified",
 88                 [QMI_DMS_UIM_PIN_STATUS_ENABLED_VERIFIED] = "verified",
 89                 [QMI_DMS_UIM_PIN_STATUS_DISABLED] = "disabled",
 90                 [QMI_DMS_UIM_PIN_STATUS_BLOCKED] = "blocked",
 91                 [QMI_DMS_UIM_PIN_STATUS_PERMANENTLY_BLOCKED] = "permanently_blocked",
 92                 [QMI_DMS_UIM_PIN_STATUS_UNBLOCKED] = "unblocked",
 93                 [QMI_DMS_UIM_PIN_STATUS_CHANGED] = "changed",
 94         };
 95         const char *res = "Unknown";
 96 
 97         if (status < ARRAY_SIZE(pin_status) && pin_status[status])
 98                 res = pin_status[status];
 99 
100         return res;
101 }
102 
103 static void cmd_dms_get_pin_status_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
104 {
105         struct qmi_dms_uim_get_pin_status_response res;
106         void *c;
107 
108         qmi_parse_dms_uim_get_pin_status_response(msg, &res);
109         c = blobmsg_open_table(&status, NULL);
110         if (res.set.pin1_status) {
111                 blobmsg_add_string(&status, "pin1_status", get_pin_status(res.data.pin1_status.current_status));
112                 blobmsg_add_u32(&status, "pin1_verify_tries", (int32_t) res.data.pin1_status.verify_retries_left);
113                 blobmsg_add_u32(&status, "pin1_unblock_tries", (int32_t) res.data.pin1_status.unblock_retries_left);
114         }
115         if (res.set.pin2_status) {
116                 blobmsg_add_string(&status, "pin2_status", get_pin_status(res.data.pin2_status.current_status));
117                 blobmsg_add_u32(&status, "pin2_verify_tries", (int32_t) res.data.pin2_status.verify_retries_left);
118                 blobmsg_add_u32(&status, "pin2_unblock_tries", (int32_t) res.data.pin2_status.unblock_retries_left);
119         }
120         blobmsg_close_table(&status, c);
121 }
122 
123 static enum qmi_cmd_result
124 cmd_dms_get_pin_status_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
125 {
126         qmi_set_dms_uim_get_pin_status_request(msg);
127         return QMI_CMD_REQUEST;
128 }
129 
130 #define cmd_dms_verify_pin1_cb no_cb
131 static enum qmi_cmd_result
132 cmd_dms_verify_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
133 {
134         struct qmi_dms_uim_verify_pin_request data = {
135                 QMI_INIT_SEQUENCE(info,
136                         .pin_id = QMI_DMS_UIM_PIN_ID_PIN,
137                         .pin = arg
138                 )
139         };
140         qmi_set_dms_uim_verify_pin_request(msg, &data);
141         return QMI_CMD_REQUEST;
142 }
143 
144 #define cmd_dms_verify_pin2_cb no_cb
145 static enum qmi_cmd_result
146 cmd_dms_verify_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
147 {
148         struct qmi_dms_uim_verify_pin_request data = {
149                 QMI_INIT_SEQUENCE(info,
150                         .pin_id = QMI_DMS_UIM_PIN_ID_PIN2,
151                         .pin = arg
152                 )
153         };
154         qmi_set_dms_uim_verify_pin_request(msg, &data);
155         return QMI_CMD_REQUEST;
156 }
157 
158 #define cmd_dms_set_pin_cb no_cb
159 static enum qmi_cmd_result
160 cmd_dms_set_pin_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
161 {
162         dms_req_data.pin = arg;
163         return QMI_CMD_DONE;
164 }
165 
166 static enum qmi_cmd_result
167 cmd_dms_set_pin_protection_prepare(struct qmi_msg *msg, char *arg)
168 {
169         if (!dms_req_data.pin) {
170                 uqmi_add_error("Missing argument");
171                 return QMI_CMD_EXIT;
172         }
173 
174         int is_enabled;
175         if (strcasecmp(arg, "disabled") == 0)
176                 is_enabled = false;
177         else if (strcasecmp(arg, "enabled") == 0)
178                 is_enabled = true;
179         else {
180                 uqmi_add_error("Invalid value (valid: disabled, enabled)");
181                 return QMI_CMD_EXIT;
182         }
183 
184         struct qmi_dms_uim_set_pin_protection_request dms_pin_protection_req = {
185                 QMI_INIT_SEQUENCE(info,
186                         .pin_id = dms_req_data.pin_id
187                 ),
188                 QMI_INIT_PTR(info.pin, dms_req_data.pin),
189                 QMI_INIT_PTR(info.protection_enabled, is_enabled)
190         };
191 
192         qmi_set_dms_uim_set_pin_protection_request(msg, &dms_pin_protection_req);
193         return QMI_CMD_REQUEST;
194 }
195 
196 #define cmd_dms_set_pin1_protection_cb no_cb
197 static enum qmi_cmd_result
198 cmd_dms_set_pin1_protection_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
199 {
200         dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN;
201         return cmd_dms_set_pin_protection_prepare(msg, arg);
202 }
203 
204 #define cmd_dms_set_pin2_protection_cb no_cb
205 static enum qmi_cmd_result
206 cmd_dms_set_pin2_protection_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
207 {
208         dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN2;
209         return cmd_dms_set_pin_protection_prepare(msg, arg);
210 }
211 
212 static enum qmi_cmd_result
213 cmd_dms_change_pin_prepare(struct qmi_msg *msg, char *arg)
214 {
215         if (!dms_req_data.pin || !dms_req_data.new_pin) {
216                 uqmi_add_error("Missing argument");
217                 return QMI_CMD_EXIT;
218         }
219 
220         struct qmi_dms_uim_change_pin_request dms_change_pin_req = {
221                 QMI_INIT_SEQUENCE(info,
222                         .pin_id = dms_req_data.pin_id
223                 ),
224                 QMI_INIT_PTR(info.old_pin, dms_req_data.pin),
225                 QMI_INIT_PTR(info.new_pin, dms_req_data.new_pin)
226         };
227 
228         qmi_set_dms_uim_change_pin_request(msg, &dms_change_pin_req);
229         return QMI_CMD_REQUEST;
230 }
231 
232 #define cmd_dms_change_pin1_cb no_cb
233 static enum qmi_cmd_result
234 cmd_dms_change_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
235 {
236         dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN;
237         return cmd_dms_change_pin_prepare(msg, arg);
238 }
239 
240 #define cmd_dms_change_pin2_cb no_cb
241 static enum qmi_cmd_result
242 cmd_dms_change_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
243 {
244         dms_req_data.pin_id = QMI_DMS_UIM_PIN_ID_PIN2;
245         return cmd_dms_change_pin_prepare(msg, arg);
246 }
247 
248 #define cmd_dms_set_new_pin_cb no_cb
249 static enum qmi_cmd_result
250 cmd_dms_set_new_pin_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
251 {
252         dms_req_data.new_pin = arg;
253         return QMI_CMD_DONE;
254 }
255 
256 #define cmd_dms_set_puk_cb no_cb
257 static enum qmi_cmd_result
258 cmd_dms_set_puk_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
259 {
260         dms_req_data.puk = arg;
261         return QMI_CMD_DONE;
262 }
263 
264 #define cmd_dms_unblock_pin1_cb no_cb
265 static enum qmi_cmd_result
266 cmd_dms_unblock_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
267 {
268         if (!dms_req_data.puk || !dms_req_data.new_pin) {
269                 uqmi_add_error("Missing argument");
270                 return QMI_CMD_EXIT;
271         }
272 
273         struct qmi_dms_uim_unblock_pin_request dms_unlock_pin_req = {
274                 QMI_INIT_SEQUENCE(info,
275                                 .pin_id = QMI_DMS_UIM_PIN_ID_PIN
276                         ),
277                 QMI_INIT_PTR(info.puk, dms_req_data.puk),
278                 QMI_INIT_PTR(info.new_pin, dms_req_data.new_pin)
279                 };
280 
281         qmi_set_dms_uim_unblock_pin_request(msg, &dms_unlock_pin_req);
282         return QMI_CMD_REQUEST;
283 }
284 
285 #define cmd_dms_unblock_pin2_cb no_cb
286 static enum qmi_cmd_result
287 cmd_dms_unblock_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
288 {
289         if (!dms_req_data.puk || !dms_req_data.new_pin) {
290                 uqmi_add_error("Missing argument");
291                 return QMI_CMD_EXIT;
292         }
293 
294         struct qmi_dms_uim_unblock_pin_request dms_unlock_pin_req = {
295                 QMI_INIT_SEQUENCE(info,
296                         .pin_id = QMI_DMS_UIM_PIN_ID_PIN2
297                 ),
298                 QMI_INIT_PTR(info.puk, dms_req_data.puk),
299                 QMI_INIT_PTR(info.new_pin, dms_req_data.new_pin)
300         };
301 
302         qmi_set_dms_uim_unblock_pin_request(msg, &dms_unlock_pin_req);
303         return QMI_CMD_REQUEST;
304 }
305 
306 static void cmd_dms_get_iccid_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
307 {
308         struct qmi_dms_uim_get_iccid_response res;
309 
310         qmi_parse_dms_uim_get_iccid_response(msg, &res);
311         if (res.data.iccid)
312                 blobmsg_add_string(&status, NULL, res.data.iccid);
313 }
314 
315 static enum qmi_cmd_result
316 cmd_dms_get_iccid_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
317 {
318         qmi_set_dms_uim_get_iccid_request(msg);
319         return QMI_CMD_REQUEST;
320 }
321 
322 static void cmd_dms_get_imsi_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
323 {
324         struct qmi_dms_uim_get_imsi_response res;
325 
326         qmi_parse_dms_uim_get_imsi_response(msg, &res);
327         if (res.data.imsi)
328                 blobmsg_add_string(&status, NULL, res.data.imsi);
329 }
330 
331 static enum qmi_cmd_result
332 cmd_dms_get_imsi_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
333 {
334         qmi_set_dms_uim_get_imsi_request(msg);
335         return QMI_CMD_REQUEST;
336 }
337 
338 static void cmd_dms_get_msisdn_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
339 {
340         struct qmi_dms_get_msisdn_response res;
341 
342         qmi_parse_dms_get_msisdn_response(msg, &res);
343         if (res.data.msisdn)
344                 blobmsg_add_string(&status, NULL, res.data.msisdn);
345 }
346 
347 static enum qmi_cmd_result
348 cmd_dms_get_msisdn_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
349 {
350         qmi_set_dms_get_msisdn_request(msg);
351         return QMI_CMD_REQUEST;
352 }
353 
354 static void cmd_dms_get_imei_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
355 {
356         struct qmi_dms_get_ids_response res;
357 
358         qmi_parse_dms_get_ids_response(msg, &res);
359         if (res.data.imei)
360                 blobmsg_add_string(&status, NULL, res.data.imei);
361 }
362 
363 static enum qmi_cmd_result
364 cmd_dms_get_imei_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
365 {
366         qmi_set_dms_get_ids_request(msg);
367         return QMI_CMD_REQUEST;
368 }
369 
370 #define cmd_dms_reset_cb no_cb
371 static enum qmi_cmd_result
372 cmd_dms_reset_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
373 {
374         qmi_set_dms_reset_request(msg);
375         return QMI_CMD_REQUEST;
376 }
377 
378 #define cmd_dms_set_operating_mode_cb no_cb
379 static enum qmi_cmd_result
380 cmd_dms_set_operating_mode_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
381 {
382         static const char *modes[] = {
383                 [QMI_DMS_OPERATING_MODE_ONLINE] = "online",
384                 [QMI_DMS_OPERATING_MODE_LOW_POWER] = "low_power",
385                 [QMI_DMS_OPERATING_MODE_FACTORY_TEST] = "factory_test",
386                 [QMI_DMS_OPERATING_MODE_OFFLINE] = "offline",
387                 [QMI_DMS_OPERATING_MODE_RESET] = "reset",
388                 [QMI_DMS_OPERATING_MODE_SHUTTING_DOWN] = "shutting_down",
389                 [QMI_DMS_OPERATING_MODE_PERSISTENT_LOW_POWER] = "persistent_low_power",
390                 [QMI_DMS_OPERATING_MODE_MODE_ONLY_LOW_POWER] = "mode_only_low_power",
391         };
392         static struct qmi_dms_set_operating_mode_request sreq = {
393                 QMI_INIT(mode, QMI_DMS_OPERATING_MODE_ONLINE),
394         };
395         int i;
396 
397         for (i = 0; i < ARRAY_SIZE(modes); i++) {
398                 if (!modes[i])
399                         continue;
400 
401                 if (strcmp(arg, modes[i]) != 0)
402                         continue;
403 
404                 sreq.data.mode = i;
405                 qmi_set_dms_set_operating_mode_request(msg, &sreq);
406                 return QMI_CMD_REQUEST;
407         }
408 
409         return uqmi_add_error("Invalid argument");
410 }
411 
412 #define cmd_dms_set_fcc_authentication_cb no_cb
413 static enum qmi_cmd_result
414 cmd_dms_set_fcc_authentication_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
415 {
416         qmi_set_dms_set_fcc_authentication_request(msg);
417         return QMI_CMD_REQUEST;
418 }
419 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt