libosmosim 1.11.0.30-c17053
Osmocom SIM library
|
Routines for helping with SIM (ISO/IEC 7816-4 more generally) communication. More...
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. More... | |
#define | msgb_apdu_dr(__x) |
#define | OSIM_MSGB_CB(__msgb) ((struct osim_msgb_cb *)&((__msgb)->cb[0])) |
#define | msgb_apdu_case(__x) OSIM_MSGB_CB(__x)->apduc |
status word from msgb->cb More... | |
#define | msgb_apdu_lc(__x) OSIM_MSGB_CB(__x)->lc |
#define | msgb_apdu_le(__x) OSIM_MSGB_CB(__x)->le |
#define | msgb_apdu_sw(__x) OSIM_MSGB_CB(__x)->sw |
#define | msgb_apdu_h(__x) ((struct osim_apdu_cmd_hdr *)(__x)->l2h) |
pointer to the command header of the APDU More... | |
#define | msgb_apdu_dc(__x) ((__x)->l2h + sizeof(struct osim_apdu_cmd_hdr)) |
#define | msgb_apdu_de(__x) ((__x)->l2h + sizeof(struct osim_apdu_cmd_hdr) + msgb_apdu_lc(__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. More... | |
#define | EF_TRANSP(fid, sfi, ns, flags, smin, srec, nl, dec, enc) |
Convenience macros for defining EF. More... | |
#define | EF_TRANSP_N(fid, sfi, ns, flags, smin, srec, nl) |
Convenience macros for defining EF. More... | |
#define | EF_CYCLIC(fid, sfi, ns, flags, smin, srec, nl, dec, enc) |
Convenience macros for defining EF. More... | |
#define | EF_CYCLIC_N(fid, sfi, ns, flags, smin, srec, nl) |
Convenience macros for defining EF. More... | |
#define | EF_LIN_FIX(fid, sfi, ns, flags, smin, srec, nl, dec, enc) |
Convenience macros for defining EF. More... | |
#define | EF_LIN_FIX_N(fid, sfi, ns, flags, smin, srec, nl) |
Convenience macros for defining EF. More... | |
#define | EF_KEY(fid, sfi, ns, flags, smin, srec, nl, dec, enc) |
Convenience macros for defining EF. More... | |
#define | EF_KEY_N(fid, sfi, ns, flags, smin, srec, nl) |
Convenience macros for defining EF. More... | |
#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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
uint8_t | ins |
INSTRUCTION byte. More... | |
uint8_t | p1 |
Parameter 1 byte. More... | |
uint8_t | p2 |
Parameter 2 byte. More... | |
uint8_t | p3 |
Parameter 3 byte, used for TPDU by T=0. More... | |
enum osim_apdu_case | apduc |
command-response pair case, defining the encoding of Lc and Le More... | |
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 More... | |
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 More... | |
uint16_t | sw |
status word, composed of SW1 and SW2 bytes More... | |
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 | |||
) |
#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 */ |
#define msgb_apdu_case | ( | __x | ) | OSIM_MSGB_CB(__x)->apduc |
status word from msgb->cb
#define msgb_apdu_dc | ( | __x | ) | ((__x)->l2h + sizeof(struct osim_apdu_cmd_hdr)) |
#define msgb_apdu_de | ( | __x | ) | ((__x)->l2h + sizeof(struct osim_apdu_cmd_hdr) + msgb_apdu_lc(__x)) |
#define msgb_apdu_dr | ( | __x | ) |
#define msgb_apdu_h | ( | __x | ) | ((struct osim_apdu_cmd_hdr *)(__x)->l2h) |
pointer to the command header of the APDU
#define msgb_apdu_lc | ( | __x | ) | OSIM_MSGB_CB(__x)->lc |
#define msgb_apdu_le | ( | __x | ) | OSIM_MSGB_CB(__x)->le |
#define msgb_apdu_sw | ( | __x | ) | OSIM_MSGB_CB(__x)->sw |
#define OSIM_CARD_SW_LAST |
#define OSIM_MAX_ATR_LEN 33 |
Maximum Answer-To-Reset (ATR) size in bytes.
#define OSIM_MSGB_CB | ( | __msgb | ) | ((struct osim_msgb_cb *)&((__msgb)->cb[0])) |
#define SFI_NONE 0xFF |
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__) | ) |
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, osim_card_app_profile::list, and llist_for_each_entry.
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, llist_for_each_entry, name, 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 sw, and osim_card_app_profile::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, llist_add_tail(), 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 | ||
) |
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 | ||
) |
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, msgb::l2h, lc, le, msgb_alloc(), msgb_apdu_case, msgb_apdu_lc, msgb_apdu_le, msgb_put(), p1, osim_apdu_cmd_hdr::p1, p2, and osim_apdu_cmd_hdr::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 |