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

Sources/uqmi/commands-uim.c

  1 /*
  2  * uqmi -- tiny QMI support implementation
  3  *
  4  * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
  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 
 22 #define cmd_uim_verify_pin1_cb no_cb
 23 static enum qmi_cmd_result
 24 cmd_uim_verify_pin1_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
 25 {
 26         struct qmi_uim_verify_pin_request data = {
 27                 QMI_INIT_SEQUENCE(session,
 28                         .session_type = QMI_UIM_SESSION_TYPE_CARD_SLOT_1,
 29                         .application_identifier_n = 0
 30                 ),
 31                 QMI_INIT_SEQUENCE(info,
 32                         .pin_id = QMI_UIM_PIN_ID_PIN1,
 33                         .pin_value = arg
 34                 )
 35         };
 36         qmi_set_uim_verify_pin_request(msg, &data);
 37         return QMI_CMD_REQUEST;
 38 }
 39 
 40 #define cmd_uim_verify_pin2_cb no_cb
 41 static enum qmi_cmd_result
 42 cmd_uim_verify_pin2_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
 43 {
 44         struct qmi_uim_verify_pin_request data = {
 45                 QMI_INIT_SEQUENCE(session,
 46                         .session_type = QMI_UIM_SESSION_TYPE_CARD_SLOT_1,
 47                         .application_identifier_n = 0
 48                 ),
 49                 QMI_INIT_SEQUENCE(info,
 50                         .pin_id = QMI_UIM_PIN_ID_PIN2,
 51                         .pin_value = arg
 52                 )
 53         };
 54         qmi_set_uim_verify_pin_request(msg, &data);
 55         return QMI_CMD_REQUEST;
 56 }
 57 
 58 static void cmd_uim_get_sim_state_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
 59 {
 60         struct qmi_uim_get_card_status_response res;
 61         void * const card_table = blobmsg_open_table(&status, NULL);
 62 
 63         qmi_parse_uim_get_card_status_response(msg, &res);
 64 
 65         for (int i = 0; i < res.data.card_status.cards_n; ++i) {
 66                 if (res.data.card_status.cards[i].card_state != QMI_UIM_CARD_STATE_PRESENT)
 67                         continue;
 68 
 69                 uint8_t pin1_state = res.data.card_status.cards[i].upin_state;
 70                 uint8_t pin1_retries = res.data.card_status.cards[i].upin_retries;
 71                 uint8_t puk1_retries = res.data.card_status.cards[i].upuk_retries;
 72                 uint8_t pin2_state;
 73                 uint8_t pin2_retries;
 74                 uint8_t puk2_retries;
 75                 bool has_pin2 = false;
 76 
 77                 for (int j = 0; j < res.data.card_status.cards[i].applications_n; ++j) {
 78                         if (res.data.card_status.cards[i].applications[j].type == QMI_UIM_CARD_APPLICATION_TYPE_UNKNOWN)
 79                                 continue;
 80 
 81                         if (!res.data.card_status.cards[i].applications[j].upin_replaces_pin1) {
 82                                 pin1_state = res.data.card_status.cards[i].applications[j].pin1_state;
 83                                 pin1_retries = res.data.card_status.cards[i].applications[j].pin1_retries;
 84                                 puk1_retries = res.data.card_status.cards[i].applications[j].puk1_retries;
 85                         }
 86 
 87                         pin2_state = res.data.card_status.cards[i].applications[j].pin2_state;
 88                         pin2_retries = res.data.card_status.cards[i].applications[j].pin2_retries;
 89                         puk2_retries = res.data.card_status.cards[i].applications[j].puk2_retries;
 90                         has_pin2 = true;
 91 
 92                         break; /* handle first application only for now */
 93                 }
 94 
 95                 blobmsg_add_string(&status, "pin1_status", get_pin_status(pin1_state));
 96                 blobmsg_add_u32(&status, "pin1_verify_tries", pin1_retries);
 97                 blobmsg_add_u32(&status, "pin1_unlock_tries", puk1_retries);
 98                 if (has_pin2) {
 99                         blobmsg_add_string(&status, "pin2_status", get_pin_status(pin2_state));
100                         blobmsg_add_u32(&status, "pin2_verify_tries", pin2_retries);
101                         blobmsg_add_u32(&status, "pin2_unlock_tries", puk2_retries);
102                 }
103 
104                 break; /* handle only first preset SIM card for now */
105         }
106 
107         blobmsg_close_table(&status, card_table);
108 }
109 
110 static enum qmi_cmd_result
111 cmd_uim_get_sim_state_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
112 {
113         qmi_set_uim_get_card_status_request(msg);
114         return QMI_CMD_REQUEST;
115 }
116 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt