2009-07-09 21:40:58 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
2010-01-02 01:00:10 +00:00
|
|
|
* Copyright (C) 2008-2010 Intel Corporation. All rights reserved.
|
2009-07-09 21:40:58 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2009-07-10 23:56:44 +00:00
|
|
|
|
|
|
|
enum sim_fileid {
|
2009-09-17 13:58:29 +00:00
|
|
|
SIM_EFPL_FILEID = 0x2f05,
|
2010-05-20 10:01:48 +00:00
|
|
|
SIM_EF_ICCID_FILEID = 0x2fe2,
|
2009-09-17 13:58:29 +00:00
|
|
|
SIM_EFLI_FILEID = 0x6f05,
|
2010-01-07 11:39:21 +00:00
|
|
|
SIM_EF_CPHS_MWIS_FILEID = 0x6f11,
|
2010-01-07 11:38:47 +00:00
|
|
|
SIM_EF_CPHS_INFORMATION_FILEID = 0x6f16,
|
2010-01-07 11:39:00 +00:00
|
|
|
SIM_EF_CPHS_MBDN_FILEID = 0x6f17,
|
2009-07-10 23:56:44 +00:00
|
|
|
SIM_EFMSISDN_FILEID = 0x6f40,
|
|
|
|
SIM_EFSPN_FILEID = 0x6f46,
|
2009-08-26 02:27:04 +00:00
|
|
|
SIM_EFSDN_FILEID = 0x6f49,
|
2009-08-26 00:36:45 +00:00
|
|
|
SIM_EFAD_FILEID = 0x6fad,
|
2009-12-19 01:49:21 +00:00
|
|
|
SIM_EFPHASE_FILEID = 0x6fae,
|
2009-07-10 23:56:44 +00:00
|
|
|
SIM_EFPNN_FILEID = 0x6fc5,
|
|
|
|
SIM_EFOPL_FILEID = 0x6fc6,
|
2009-08-03 12:50:14 +00:00
|
|
|
SIM_EFMBDN_FILEID = 0x6fc7,
|
|
|
|
SIM_EFMBI_FILEID = 0x6fc9,
|
|
|
|
SIM_EFMWIS_FILEID = 0x6fca,
|
2009-07-10 23:56:44 +00:00
|
|
|
SIM_EFSPDI_FILEID = 0x6fcd,
|
2009-08-14 08:38:10 +00:00
|
|
|
SIM_EFECC_FILEID = 0x6fb7,
|
2009-09-15 19:35:39 +00:00
|
|
|
SIM_EFCBMIR_FILEID = 0x6f50,
|
|
|
|
SIM_EFCBMI_FILEID = 0x6f45,
|
|
|
|
SIM_EFCBMID_FILEID = 0x6f48,
|
2009-07-10 23:56:44 +00:00
|
|
|
};
|
|
|
|
|
2009-07-27 21:53:03 +00:00
|
|
|
/* 51.011 Section 9.3 */
|
|
|
|
enum sim_file_access {
|
|
|
|
SIM_FILE_ACCESS_ALWAYS = 0,
|
|
|
|
SIM_FILE_ACCESS_CHV1 = 1,
|
|
|
|
SIM_FILE_ACCESS_CHV2 = 2,
|
|
|
|
SIM_FILE_ACCESS_RESERVED = 3,
|
|
|
|
SIM_FILE_ACCESS_ADM = 4,
|
|
|
|
SIM_FILE_ACCESS_NEVER = 15,
|
|
|
|
};
|
|
|
|
|
2009-07-10 23:59:37 +00:00
|
|
|
#define SIM_EFSPN_DC_HOME_PLMN_BIT 0x1
|
|
|
|
#define SIM_EFSPN_DC_ROAMING_SPN_BIT 0x2
|
|
|
|
|
2010-02-23 06:37:55 +00:00
|
|
|
enum ber_tlv_data_type {
|
|
|
|
BER_TLV_DATA_TYPE_UNIVERSAL = 0,
|
|
|
|
BER_TLV_DATA_TYPE_APPLICATION = 1,
|
|
|
|
BER_TLV_DATA_TYPE_CONTEXT_SPECIFIC = 2,
|
|
|
|
BER_TLV_DATA_TYPE_PRIVATE = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ber_tlv_data_encoding_type {
|
|
|
|
BER_TLV_DATA_ENCODING_TYPE_PRIMITIVE = 0,
|
|
|
|
BER_TLV_DATA_ENCODING_TYPE_CONSTRUCTED = 1,
|
|
|
|
};
|
|
|
|
|
2009-07-14 15:58:52 +00:00
|
|
|
struct sim_eons_operator_info {
|
|
|
|
char *longname;
|
|
|
|
gboolean long_ci;
|
|
|
|
char *shortname;
|
|
|
|
gboolean short_ci;
|
|
|
|
char *info;
|
|
|
|
};
|
|
|
|
|
2009-10-02 18:08:30 +00:00
|
|
|
struct sim_ef_info {
|
|
|
|
unsigned short id;
|
|
|
|
unsigned short parent;
|
|
|
|
unsigned char file_type;
|
|
|
|
unsigned char size;
|
|
|
|
enum sim_file_access perm_read;
|
|
|
|
enum sim_file_access perm_update;
|
|
|
|
};
|
|
|
|
|
2010-02-23 17:22:06 +00:00
|
|
|
struct simple_tlv_iter {
|
|
|
|
unsigned int max;
|
|
|
|
unsigned int pos;
|
|
|
|
const unsigned char *pdu;
|
|
|
|
unsigned char tag;
|
|
|
|
unsigned short len;
|
|
|
|
const unsigned char *data;
|
|
|
|
};
|
|
|
|
|
2010-02-23 18:01:09 +00:00
|
|
|
struct comprehension_tlv_iter {
|
|
|
|
unsigned int max;
|
|
|
|
unsigned int pos;
|
|
|
|
const unsigned char *pdu;
|
|
|
|
unsigned short tag;
|
|
|
|
gboolean cr;
|
|
|
|
unsigned int len;
|
|
|
|
const unsigned char *data;
|
|
|
|
};
|
|
|
|
|
2010-02-23 06:37:55 +00:00
|
|
|
struct ber_tlv_iter {
|
|
|
|
unsigned int max;
|
|
|
|
unsigned int pos;
|
|
|
|
const unsigned char *pdu;
|
|
|
|
unsigned int tag;
|
|
|
|
enum ber_tlv_data_type class;
|
|
|
|
enum ber_tlv_data_encoding_type encoding;
|
|
|
|
unsigned int len;
|
|
|
|
const unsigned char *data;
|
|
|
|
};
|
|
|
|
|
2010-02-23 17:22:06 +00:00
|
|
|
void simple_tlv_iter_init(struct simple_tlv_iter *iter,
|
|
|
|
const unsigned char *pdu, unsigned int len);
|
|
|
|
gboolean simple_tlv_iter_next(struct simple_tlv_iter *iter);
|
|
|
|
unsigned char simple_tlv_iter_get_tag(struct simple_tlv_iter *iter);
|
|
|
|
unsigned short simple_tlv_iter_get_length(struct simple_tlv_iter *iter);
|
|
|
|
const unsigned char *simple_tlv_iter_get_data(struct simple_tlv_iter *iter);
|
|
|
|
|
2010-02-23 18:01:09 +00:00
|
|
|
void comprehension_tlv_iter_init(struct comprehension_tlv_iter *iter,
|
|
|
|
const unsigned char *pdu,
|
|
|
|
unsigned int len);
|
|
|
|
gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter);
|
|
|
|
unsigned short comprehension_tlv_iter_get_tag(struct comprehension_tlv_iter *i);
|
|
|
|
gboolean comprehension_tlv_get_cr(struct comprehension_tlv_iter *iter);
|
|
|
|
unsigned int comprehension_tlv_iter_get_length(
|
|
|
|
struct comprehension_tlv_iter *iter);
|
|
|
|
const unsigned char *comprehension_tlv_iter_get_data(
|
|
|
|
struct comprehension_tlv_iter *iter);
|
|
|
|
|
2010-05-13 10:48:19 +00:00
|
|
|
void comprehension_tlv_iter_copy(struct comprehension_tlv_iter *from,
|
|
|
|
struct comprehension_tlv_iter *to);
|
|
|
|
|
2010-02-23 06:37:55 +00:00
|
|
|
void ber_tlv_iter_init(struct ber_tlv_iter *iter, const unsigned char *pdu,
|
|
|
|
unsigned int len);
|
|
|
|
/*
|
|
|
|
* Returns the tag value of the TLV. Note that the tag value can be either
|
|
|
|
* short (0-30) or long
|
|
|
|
*/
|
|
|
|
unsigned int ber_tlv_iter_get_tag(struct ber_tlv_iter *iter);
|
|
|
|
|
|
|
|
enum ber_tlv_data_type ber_tlv_iter_get_class(struct ber_tlv_iter *iter);
|
|
|
|
enum ber_tlv_data_encoding_type
|
|
|
|
ber_tlv_iter_get_encoding(struct ber_tlv_iter *iter);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This will return the short tag along with class and encoding information.
|
|
|
|
* This is more convenient to use for TLV contents of SIM Elementary Files
|
|
|
|
* and SIM toolkit since these elements only use short tags. In case of an
|
|
|
|
* error (e.g. not a short tag) a zero is returned. According to ISO 7816,
|
|
|
|
* a tag value of '00' is invalid.
|
|
|
|
*/
|
|
|
|
unsigned char ber_tlv_iter_get_short_tag(struct ber_tlv_iter *iter);
|
|
|
|
unsigned int ber_tlv_iter_get_length(struct ber_tlv_iter *iter);
|
|
|
|
|
|
|
|
const unsigned char *ber_tlv_iter_get_data(struct ber_tlv_iter *iter);
|
|
|
|
|
|
|
|
gboolean ber_tlv_iter_next(struct ber_tlv_iter *iter);
|
|
|
|
void ber_tlv_iter_recurse(struct ber_tlv_iter *iter,
|
|
|
|
struct ber_tlv_iter *recurse);
|
2010-02-23 17:22:06 +00:00
|
|
|
void ber_tlv_iter_recurse_simple(struct ber_tlv_iter *iter,
|
|
|
|
struct simple_tlv_iter *container);
|
2010-02-23 18:01:09 +00:00
|
|
|
void ber_tlv_iter_recurse_comprehension(struct ber_tlv_iter *iter,
|
|
|
|
struct comprehension_tlv_iter *recurse);
|
2010-02-23 06:37:55 +00:00
|
|
|
|
2009-07-13 23:30:17 +00:00
|
|
|
struct sim_eons *sim_eons_new(int pnn_records);
|
|
|
|
void sim_eons_add_pnn_record(struct sim_eons *eons, int record,
|
|
|
|
const guint8 *tlv, int length);
|
|
|
|
gboolean sim_eons_pnn_is_empty(struct sim_eons *eons);
|
|
|
|
void sim_eons_add_opl_record(struct sim_eons *eons,
|
2009-07-17 23:42:54 +00:00
|
|
|
const guint8 *contents, int length);
|
2009-07-13 23:30:17 +00:00
|
|
|
void sim_eons_optimize(struct sim_eons *eons);
|
2009-07-17 23:42:54 +00:00
|
|
|
const struct sim_eons_operator_info *sim_eons_lookup_with_lac(
|
|
|
|
struct sim_eons *eons,
|
|
|
|
const char *mcc,
|
|
|
|
const char *mnc,
|
|
|
|
guint16 lac);
|
|
|
|
const struct sim_eons_operator_info *sim_eons_lookup(struct sim_eons *eons,
|
2009-07-14 15:58:52 +00:00
|
|
|
const char *mcc,
|
2009-07-14 18:47:22 +00:00
|
|
|
const char *mnc);
|
2009-07-13 23:30:17 +00:00
|
|
|
void sim_eons_free(struct sim_eons *eons);
|
2009-07-13 21:12:22 +00:00
|
|
|
|
2010-03-25 16:07:31 +00:00
|
|
|
void sim_parse_mcc_mnc(const guint8 *bcd, char *mcc, char *mnc);
|
2009-07-13 21:12:22 +00:00
|
|
|
struct sim_spdi *sim_spdi_new(const guint8 *tlv, int length);
|
|
|
|
gboolean sim_spdi_lookup(struct sim_spdi *spdi,
|
|
|
|
const char *mcc, const char *mnc);
|
|
|
|
void sim_spdi_free(struct sim_spdi *spdi);
|
2009-07-27 21:53:03 +00:00
|
|
|
|
|
|
|
static inline enum sim_file_access file_access_condition_decode(int bcd)
|
|
|
|
{
|
|
|
|
if (bcd >= 4 && bcd <= 14)
|
|
|
|
return SIM_FILE_ACCESS_ADM;
|
|
|
|
return bcd;
|
|
|
|
}
|
2009-07-30 08:04:59 +00:00
|
|
|
|
|
|
|
gboolean sim_adn_parse(const unsigned char *data, int length,
|
2009-08-26 01:14:06 +00:00
|
|
|
struct ofono_phone_number *ph, char **identifier);
|
2009-08-05 07:08:40 +00:00
|
|
|
void sim_adn_build(unsigned char *data, int length,
|
2009-08-26 01:14:06 +00:00
|
|
|
const struct ofono_phone_number *ph,
|
|
|
|
const char *identifier);
|
2009-10-02 19:51:47 +00:00
|
|
|
|
|
|
|
struct sim_ef_info *sim_ef_db_lookup(unsigned short efid);
|
2009-10-02 19:52:52 +00:00
|
|
|
|
2009-10-03 00:25:44 +00:00
|
|
|
gboolean sim_parse_3g_get_response(const unsigned char *data, int len,
|
2009-10-02 22:47:44 +00:00
|
|
|
int *file_len, int *record_len,
|
|
|
|
int *structure, unsigned char *access,
|
|
|
|
unsigned short *efid);
|
|
|
|
|
2009-10-03 00:25:44 +00:00
|
|
|
gboolean sim_parse_2g_get_response(const unsigned char *response, int len,
|
2009-10-02 19:52:52 +00:00
|
|
|
int *file_len, int *record_len,
|
|
|
|
int *structure, unsigned char *access);
|