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

Sources/uqmi/uqmid/sim.c

  1 /*
  2  * uqmi -- tiny QMI support implementation
  3  *
  4  * Copyright (C) 2024 Alexander Couzens <lynxis@fe80.eu>
  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 #include "sim.h"
 23 #include "qmi-enums-uim.h"
 24 #include "osmocom/utils.h"
 25 
 26 #include <errno.h>
 27 #include <stdbool.h>
 28 
 29 enum uqmi_sim_state uim_card_application_state_to_uqmi_state(int app_state)
 30 {
 31         switch (app_state) {
 32         case QMI_UIM_CARD_APPLICATION_STATE_UNKNOWN:
 33                 return UQMI_SIM_UNKNOWN;
 34         case QMI_UIM_CARD_APPLICATION_STATE_PIN1_OR_UPIN_PIN_REQUIRED:
 35                 return UQMI_SIM_PIN_REQUIRED;
 36         case QMI_UIM_CARD_APPLICATION_STATE_PUK1_OR_UPIN_PUK_REQUIRED:
 37                 return UQMI_SIM_PUK_REQUIRED;
 38         case QMI_UIM_CARD_APPLICATION_STATE_READY:
 39                 return UQMI_SIM_READY;
 40         default:
 41                 return UQMI_SIM_UNKNOWN;
 42         }
 43 }
 44 
 45 enum uqmi_sim_state uim_pin_to_uqmi_state(int upin_state)
 46 {
 47         switch (upin_state) {
 48         case QMI_UIM_PIN_STATE_NOT_INITIALIZED:
 49                 return UQMI_SIM_UNKNOWN;
 50         case QMI_UIM_PIN_STATE_DISABLED:
 51                 return UQMI_SIM_READY;
 52         case QMI_UIM_PIN_STATE_ENABLED_VERIFIED:
 53                 return UQMI_SIM_READY;
 54         case QMI_UIM_PIN_STATE_ENABLED_NOT_VERIFIED:
 55                 return UQMI_SIM_PIN_REQUIRED;
 56         case QMI_UIM_PIN_STATE_BLOCKED:
 57                 return UQMI_SIM_PUK_REQUIRED;
 58         case QMI_UIM_PIN_STATE_PERMANENTLY_BLOCKED:
 59                 return UQMI_SIM_BLOCKED;
 60         default:
 61                 return UQMI_SIM_UNKNOWN;
 62         }
 63 }
 64 
 65 int uqmi_sim_decode_imsi(uint8_t *imsi_ef, uint8_t imsi_ef_size, char *imsi_str, uint8_t imsi_str_len)
 66 {
 67         uint8_t imsi_len;
 68         uint8_t imsi_enc_len;
 69         uint8_t oe;
 70         // int offset = 0, i;
 71         if (imsi_ef_size < 9)
 72                 return -EINVAL;
 73 
 74         imsi_enc_len = imsi_ef[0];
 75         if (imsi_enc_len > 8 || imsi_enc_len == 0)
 76                 return -EINVAL;
 77 
 78         imsi_len = imsi_enc_len * 2 - 1;
 79         oe = (imsi_ef[1] >> 3) & 0x1;
 80         if (!oe)
 81                 imsi_len--;
 82 
 83         /* additional 0 byte */
 84         if (imsi_str_len < imsi_len + 1)
 85                 return -ENOMEM;
 86 
 87         return osmo_bcd2str(imsi_str, imsi_str_len, imsi_ef + 1, 1, imsi_len + 1, false);
 88 }
 89 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt