|
libosmosim 1.11.0
Osmocom SIM library
|
Routines for helping with SIM (ISO/IEC 7816-4 more generally) communication. More...
#include <osmocom/core/msgb.h>#include <osmocom/core/linuxlist.h>Go to the source code of this file.
Data Structures | |
| struct | osim_apdu_cmd_hdr |
| APDU/TPDU command header. More... | |
| struct | osim_msgb_cb |
| APDU command body. More... | |
| struct | osim_file_ops |
| Operations for a given File. More... | |
| struct | osim_decoded_element |
| A single decoded element inside a file. More... | |
| struct | osim_decoded_data |
| Decoded data for a single file, consisting of all decoded elements. More... | |
| struct | osim_file_desc |
| struct | osim_file |
| A single instance of a file: Descriptor and contents. More... | |
| struct | osim_card_sw |
| A card status word (SW). More... | |
| struct | osim_card_app_profile |
| A card application (e.g. More... | |
| struct | osim_card_profile |
| A card profile (e.g. More... | |
| struct | osim_reader_ops |
| struct | osim_reader_hdl |
| struct | osim_card_app_hdl |
| descriptor for a given application present on a card More... | |
| struct | osim_card_hdl |
| struct | osim_chan_hdl |
Macros | |
| #define | APDU_HDR_LEN 5 |
| #define | MAX_AID_LEN 16 /* Table 13.2 of TS 102 221 */ |
| #define | OSIM_MAX_ATR_LEN 33 |
| Maximum Answer-To-Reset (ATR) size in bytes. | |
| #define | msgb_apdu_dr(__x) |
| #define | OSIM_MSGB_CB(__msgb) |
| #define | msgb_apdu_case(__x) |
| status word from msgb->cb | |
| #define | msgb_apdu_lc(__x) |
| #define | msgb_apdu_le(__x) |
| #define | msgb_apdu_sw(__x) |
| #define | msgb_apdu_h(__x) |
| pointer to the command header of the APDU | |
| #define | msgb_apdu_dc(__x) |
| #define | msgb_apdu_de(__x) |
| #define | F_OPTIONAL 0x0001 |
| #define | SFI_NONE 0xFF |
| #define | EF(pfid, sfi, pns, pflags, pnl, ptype, smin, srec, pdec, penc) |
| Convenience macros for defining EF. | |
| #define | EF_TRANSP(fid, sfi, ns, flags, smin, srec, nl, dec, enc) |
| Convenience macros for defining EF. | |
| #define | EF_TRANSP_N(fid, sfi, ns, flags, smin, srec, nl) |
| Convenience macros for defining EF. | |
| #define | EF_CYCLIC(fid, sfi, ns, flags, smin, srec, nl, dec, enc) |
| Convenience macros for defining EF. | |
| #define | EF_CYCLIC_N(fid, sfi, ns, flags, smin, srec, nl) |
| Convenience macros for defining EF. | |
| #define | EF_LIN_FIX(fid, sfi, ns, flags, smin, srec, nl, dec, enc) |
| Convenience macros for defining EF. | |
| #define | EF_LIN_FIX_N(fid, sfi, ns, flags, smin, srec, nl) |
| Convenience macros for defining EF. | |
| #define | EF_KEY(fid, sfi, ns, flags, smin, srec, nl, dec, enc) |
| Convenience macros for defining EF. | |
| #define | EF_KEY_N(fid, sfi, ns, flags, smin, srec, nl) |
| Convenience macros for defining EF. | |
| #define | OSIM_CARD_SW_LAST |
Functions | |
| struct osim_apdu_cmd_hdr | __attribute__ ((packed)) |
| struct osim_msgb_cb | __attribute__ ((__may_alias__)) |
| int | osim_init (void *ctx) |
| struct osim_file_desc * | osim_file_desc_find_name (struct osim_file_desc *parent, const char *name) |
| struct osim_file_desc * | osim_file_desc_find_aid (struct osim_file_desc *parent, const uint8_t *aid, uint8_t aid_len) |
| struct osim_file_desc * | osim_file_desc_find_fid (struct osim_file_desc *parent, uint16_t fid) |
| struct osim_file_desc * | osim_file_desc_find_sfid (struct osim_file_desc *parent, uint8_t sfid) |
| const struct osim_card_app_profile * | osim_app_profile_find_by_name (const char *name) |
| Find any registered application profile based on its name (e.g. | |
| const struct osim_card_app_profile * | osim_app_profile_find_by_aid (const uint8_t *aid, uint8_t aid_len) |
| Find any registered application profile based on its AID. | |
| const struct osim_card_sw * | osim_app_profile_find_sw (const struct osim_card_app_profile *ap, uint16_t sw_in) |
| Find application-specific status word within given card application profile. | |
| const struct osim_card_sw * | osim_cprof_find_sw (const struct osim_card_profile *cp, uint16_t sw_in) |
| Find status word within given card profile. | |
| enum osim_card_sw_class | osim_sw_class (const struct osim_chan_hdl *ch, uint16_t sw_in) |
| char * | osim_print_sw_buf (char *buf, size_t buf_len, const struct osim_chan_hdl *ch, uint16_t sw_in) |
| char * | osim_print_sw (const struct osim_chan_hdl *ch, uint16_t sw_in) |
| char * | osim_print_sw_c (const void *ctx, const struct osim_chan_hdl *ch, uint16_t sw_in) |
| struct msgb * | osim_new_apdumsg (uint8_t cla, uint8_t ins, uint8_t p1, uint8_t p2, uint16_t lc, uint16_t le) |
| Generate an APDU message and initialize APDU command header. | |
| int | osim_card_hdl_add_app (struct osim_card_hdl *ch, const uint8_t *aid, uint8_t aid_len, const char *label) |
| Add an application to a given card. | |
| int | osim_transceive_apdu (struct osim_chan_hdl *st, struct msgb *amsg) |
| struct osim_reader_hdl * | osim_reader_open (enum osim_reader_driver drv, int idx, const char *name, void *ctx) |
| struct osim_card_hdl * | osim_card_open (struct osim_reader_hdl *rh, enum osim_proto proto) |
| int | osim_card_reset (struct osim_card_hdl *card, bool cold_reset) |
| int | osim_card_close (struct osim_card_hdl *card) |
Variables | |
| uint8_t | cla |
| CLASS byte. | |
| uint8_t | ins |
| INSTRUCTION byte. | |
| uint8_t | p1 |
| Parameter 1 byte. | |
| uint8_t | p2 |
| Parameter 2 byte. | |
| uint8_t | p3 |
| Parameter 3 byte, used for TPDU by T=0. | |
| enum osim_apdu_case | apduc |
| command-response pair case, defining the encoding of Lc and Le | |
| uint16_t | lc |
| number of bytes in the command data field Nc, which will encoded in 0, 1 or 3 bytes into Lc, depending on the case | |
| uint16_t | le |
| maximum number of bytes expected in the response data field, which will encoded in 0, 1, 2 or 3 bytes into Le, depending on the case | |
| uint16_t | sw |
| status word, composed of SW1 and SW2 bytes | |
| struct osim_file_ops | __attribute__ |
| const struct tlv_definition | ts102221_fcp_tlv_def |
| const struct value_string | ts102221_fcp_vals [14] |
Routines for helping with SIM (ISO/IEC 7816-4 more generally) communication.
| #define APDU_HDR_LEN 5 |
| #define EF | ( | pfid, | |
| sfi, | |||
| pns, | |||
| pflags, | |||
| pnl, | |||
| ptype, | |||
| smin, | |||
| srec, | |||
| pdec, | |||
| penc ) |
Convenience macros for defining EF.
| #define EF_CYCLIC | ( | fid, | |
| sfi, | |||
| ns, | |||
| flags, | |||
| smin, | |||
| srec, | |||
| nl, | |||
| dec, | |||
| enc ) |
Convenience macros for defining EF.
| #define EF_CYCLIC_N | ( | fid, | |
| sfi, | |||
| ns, | |||
| flags, | |||
| smin, | |||
| srec, | |||
| nl ) |
Convenience macros for defining EF.
| #define EF_KEY | ( | fid, | |
| sfi, | |||
| ns, | |||
| flags, | |||
| smin, | |||
| srec, | |||
| nl, | |||
| dec, | |||
| enc ) |
Convenience macros for defining EF.
| #define EF_KEY_N | ( | fid, | |
| sfi, | |||
| ns, | |||
| flags, | |||
| smin, | |||
| srec, | |||
| nl ) |
Convenience macros for defining EF.
| #define EF_LIN_FIX | ( | fid, | |
| sfi, | |||
| ns, | |||
| flags, | |||
| smin, | |||
| srec, | |||
| nl, | |||
| dec, | |||
| enc ) |
Convenience macros for defining EF.
| #define EF_LIN_FIX_N | ( | fid, | |
| sfi, | |||
| ns, | |||
| flags, | |||
| smin, | |||
| srec, | |||
| nl ) |
Convenience macros for defining EF.
| #define EF_TRANSP | ( | fid, | |
| sfi, | |||
| ns, | |||
| flags, | |||
| smin, | |||
| srec, | |||
| nl, | |||
| dec, | |||
| enc ) |
Convenience macros for defining EF.
| #define EF_TRANSP_N | ( | fid, | |
| sfi, | |||
| ns, | |||
| flags, | |||
| smin, | |||
| srec, | |||
| nl ) |
Convenience macros for defining EF.
| #define F_OPTIONAL 0x0001 |
| #define MAX_AID_LEN 16 /* Table 13.2 of TS 102 221 */ |
Referenced by osim_card_hdl_add_app(), and osim_card_hdl_find_app().
| #define msgb_apdu_case | ( | __x | ) |
status word from msgb->cb
Referenced by osim_new_apdumsg(), and transceive_apdu_t0().
| #define msgb_apdu_dc | ( | __x | ) |
Referenced by transceive_apdu_t0().
| #define msgb_apdu_de | ( | __x | ) |
Referenced by transceive_apdu_t0().
| #define msgb_apdu_dr | ( | __x | ) |
| #define msgb_apdu_h | ( | __x | ) |
pointer to the command header of the APDU
Referenced by transceive_apdu_t0().
| #define msgb_apdu_lc | ( | __x | ) |
Referenced by osim_new_apdumsg(), and transceive_apdu_t0().
| #define msgb_apdu_le | ( | __x | ) |
Referenced by get_sw(), osim_new_apdumsg(), pcsc_transceive(), and transceive_apdu_t0().
| #define msgb_apdu_sw | ( | __x | ) |
Referenced by transceive_apdu_t0().
| #define OSIM_CARD_SW_LAST |
| #define OSIM_MAX_ATR_LEN 33 |
Maximum Answer-To-Reset (ATR) size in bytes.
| #define OSIM_MSGB_CB | ( | __msgb | ) |
| #define SFI_NONE 0xFF |
Referenced by osim_file_desc_find_sfid().
| enum osim_apdu_case |
command-response pairs cases
Enumeration used to identify the APDU structure based on command-response pair case , as specified in ISO/IEC 7816-3:2006(E) §12.1.
| enum osim_card_sw_class |
| enum osim_card_sw_type |
| enum osim_ef_type |
| enum osim_element_repr |
| enum osim_element_type |
| enum osim_file_type |
| enum osim_proto |
| enum osim_reader_driver |
| enum ts102221_fcp_tag |
| struct osim_msgb_cb __attribute__ | ( | (__may_alias__) | ) |
| struct osim_apdu_cmd_hdr __attribute__ | ( | (packed) | ) |
| const struct osim_card_app_profile * osim_app_profile_find_by_aid | ( | const uint8_t * | aid, |
| uint8_t | aid_len ) |
Find any registered application profile based on its AID.
References osim_card_app_profile::aid, osim_card_app_profile::aid_len, and osim_card_app_profile::list.
Referenced by osim_app_profile_register(), and osim_card_hdl_add_app().
| const struct osim_card_app_profile * osim_app_profile_find_by_name | ( | const char * | name | ) |
Find any registered application profile based on its name (e.g.
"ADF.USIM")
References osim_card_app_profile::list, and osim_card_app_profile::name.
Referenced by osim_app_profile_register().
| const struct osim_card_sw * osim_app_profile_find_sw | ( | const struct osim_card_app_profile * | ap, |
| uint16_t | sw_in ) |
Find application-specific status word within given card application profile.
References osim_card_app_profile::sw, and sw.
Referenced by osim_print_sw_buf(), and osim_sw_class().
| int osim_card_close | ( | struct osim_card_hdl * | card | ) |
| int osim_card_hdl_add_app | ( | struct osim_card_hdl * | ch, |
| const uint8_t * | aid, | ||
| uint8_t | aid_len, | ||
| const char * | label ) |
Add an application to a given card.
References osim_card_app_hdl::aid, osim_card_app_hdl::aid_len, osim_card_hdl::apps, osim_card_app_hdl::label, osim_card_app_hdl::list, MAX_AID_LEN, osim_app_profile_find_by_aid(), osim_card_hdl_find_app(), and osim_card_app_hdl::prof.
| struct osim_card_hdl * osim_card_open | ( | struct osim_reader_hdl * | rh, |
| enum osim_proto | proto ) |
| int osim_card_reset | ( | struct osim_card_hdl * | card, |
| bool | cold_reset ) |
| const struct osim_card_sw * osim_cprof_find_sw | ( | const struct osim_card_profile * | cp, |
| uint16_t | sw_in ) |
Find status word within given card profile.
References sw, and osim_card_profile::sws.
Referenced by osim_print_sw_buf(), and osim_sw_class().
| struct osim_file_desc * osim_file_desc_find_aid | ( | struct osim_file_desc * | parent, |
| const uint8_t * | aid, | ||
| uint8_t | aid_len ) |
| struct osim_file_desc * osim_file_desc_find_fid | ( | struct osim_file_desc * | parent, |
| uint16_t | fid ) |
References osim_file_desc::child_list, osim_file_desc::fid, osim_file_desc::list, and osim_file_desc::parent.
| struct osim_file_desc * osim_file_desc_find_name | ( | struct osim_file_desc * | parent, |
| const char * | name ) |
| struct osim_file_desc * osim_file_desc_find_sfid | ( | struct osim_file_desc * | parent, |
| uint8_t | sfid ) |
References osim_file_desc::child_list, osim_file_desc::list, osim_file_desc::parent, SFI_NONE, and osim_file_desc::sfid.
| int osim_init | ( | void * | ctx | ) |
References osim_app_profile_register(), osim_aprof_hpsim(), osim_aprof_isim(), and osim_aprof_usim().
| struct msgb * osim_new_apdumsg | ( | uint8_t | cla, |
| uint8_t | ins, | ||
| uint8_t | p1, | ||
| uint8_t | p2, | ||
| uint16_t | lc, | ||
| uint16_t | le ) |
Generate an APDU message and initialize APDU command header.
| [in] | cla | CLASS byte |
| [in] | ins | INSTRUCTION byte |
| [in] | p1 | Parameter 1 byte |
| [in] | p2 | Parameter 2 byte |
| [in] | lc | number of bytes in the command data field Nc, which will encoded in 0, 1 or 3 bytes into Lc |
| [in] | le | maximum number of bytes expected in the response data field, which will encoded in 0, 1, 2 or 3 bytes into Le |
This function generates an APDU message, as defined in ISO/IEC 7816-4:2005(E) §5.1. The APDU command header, command and response fields lengths are initialized using the parameters. The APDU case is determined by the command and response fields lengths.
References APDU_CASE_1, APDU_CASE_2E, APDU_CASE_2S, APDU_CASE_3E, APDU_CASE_3S, APDU_CASE_4E, APDU_CASE_4S, cla, osim_apdu_cmd_hdr::cla, ins, osim_apdu_cmd_hdr::ins, lc, le, msgb_apdu_case, msgb_apdu_lc, msgb_apdu_le, osim_apdu_cmd_hdr::p1, p1, osim_apdu_cmd_hdr::p2, and p2.
| char * osim_print_sw | ( | const struct osim_chan_hdl * | ch, |
| uint16_t | sw_in ) |
References osim_print_sw_buf().
| char * osim_print_sw_buf | ( | char * | buf, |
| size_t | buf_len, | ||
| const struct osim_chan_hdl * | ch, | ||
| uint16_t | sw_in ) |
References osim_chan_hdl::card, osim_chan_hdl::cur_app, osim_app_profile_find_sw(), osim_cprof_find_sw(), osim_card_app_hdl::prof, osim_card_hdl::prof, osim_card_sw::str, SW_TYPE_STR, osim_card_sw::type, and osim_card_sw::u.
Referenced by osim_print_sw(), and osim_print_sw_c().
| char * osim_print_sw_c | ( | const void * | ctx, |
| const struct osim_chan_hdl * | ch, | ||
| uint16_t | sw_in ) |
References osim_print_sw_buf().
| struct osim_reader_hdl * osim_reader_open | ( | enum osim_reader_driver | drv, |
| int | idx, | ||
| const char * | name, | ||
| void * | ctx ) |
| enum osim_card_sw_class osim_sw_class | ( | const struct osim_chan_hdl * | ch, |
| uint16_t | sw_in ) |
| int osim_transceive_apdu | ( | struct osim_chan_hdl * | st, |
| struct msgb * | amsg ) |
References osim_chan_hdl::card, OSIM_PROTO_T0, osim_card_hdl::proto, and transceive_apdu_t0().
| struct osim_file_ops __attribute__ |
| enum osim_apdu_case apduc |
command-response pair case, defining the encoding of Lc and Le
| uint8_t cla |
CLASS byte.
Referenced by osim_determine_apdu_case(), and osim_new_apdumsg().
| uint8_t ins |
INSTRUCTION byte.
Referenced by gp_cla_ins_helper(), osim_determine_apdu_case(), osim_new_apdumsg(), and uicc046_cla_ins_helper().
| uint16_t lc |
number of bytes in the command data field Nc, which will encoded in 0, 1 or 3 bytes into Lc, depending on the case
Referenced by osim_new_apdumsg().
| uint16_t le |
maximum number of bytes expected in the response data field, which will encoded in 0, 1, 2 or 3 bytes into Le, depending on the case
Referenced by osim_new_apdumsg().
| uint8_t p1 |
Parameter 1 byte.
Referenced by gp_cla_ins_helper(), osim_new_apdumsg(), and uicc046_cla_ins_helper().
| uint8_t p2 |
Parameter 2 byte.
Referenced by osim_new_apdumsg(), and uicc046_cla_ins_helper().
| uint8_t p3 |
Parameter 3 byte, used for TPDU by T=0.
Referenced by gp_cla_ins_helper().
| uint16_t sw |
status word, composed of SW1 and SW2 bytes
Referenced by osim_app_profile_find_sw(), osim_cprof_find_sw(), and transceive_apdu_t0().
|
extern |
|
extern |