libosmosim 1.9.0.209-e0c63
Osmocom SIM library
core.c File Reference

Core routines for SIM/UICC/USIM access. More...

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <osmocom/core/talloc.h>
#include <osmocom/sim/sim.h>
#include "sim_int.h"

Functions

struct osim_decoded_dataosim_file_decode (struct osim_file *file, int len, uint8_t *data)
 
struct msgbosim_file_encode (const struct osim_file_desc *desc, const struct osim_decoded_data *data)
 
static struct osim_decoded_element__element_alloc (void *ctx, const char *name, enum osim_element_type type, enum osim_element_repr repr)
 
struct osim_decoded_elementelement_alloc (struct osim_decoded_data *dd, const char *name, enum osim_element_type type, enum osim_element_repr repr)
 
struct osim_decoded_elementelement_alloc_sub (struct osim_decoded_element *ee, const char *name, enum osim_element_type type, enum osim_element_repr repr)
 
void add_filedesc (struct osim_file_desc *root, const struct osim_file_desc *in, int num)
 
struct osim_file_descalloc_df (void *ctx, uint16_t fid, const char *name)
 
struct osim_file_descadd_df_with_ef (struct osim_file_desc *parent, uint16_t fid, const char *name, const struct osim_file_desc *in, int num)
 
struct osim_file_descalloc_adf_with_ef (void *ctx, const uint8_t *adf_name, uint8_t adf_name_len, const char *name, const struct osim_file_desc *in, int num)
 
struct osim_file_descosim_file_desc_find_name (struct osim_file_desc *parent, const char *name)
 
struct osim_file_descosim_file_desc_find_aid (struct osim_file_desc *parent, const uint8_t *aid, uint8_t aid_len)
 
struct osim_file_descosim_file_desc_find_fid (struct osim_file_desc *parent, uint16_t fid)
 
struct osim_file_descosim_file_desc_find_sfid (struct osim_file_desc *parent, uint8_t sfid)
 
static LLIST_HEAD (g_app_profiles)
 
void osim_app_profile_register (struct osim_card_app_profile *aprof)
 Register an application profile. More...
 
const struct osim_card_app_profileosim_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_profileosim_app_profile_find_by_aid (const uint8_t *aid, uint8_t aid_len)
 Find any registered application profile based on its AID. More...
 
struct osim_card_app_hdlosim_card_hdl_find_app (struct osim_card_hdl *ch, const uint8_t *aid, uint8_t aid_len)
 
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...
 
struct msgbosim_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...
 
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)
 
const struct osim_card_swosim_cprof_find_sw (const struct osim_card_profile *cp, uint16_t sw_in)
 Find status word within given card profile. More...
 
const struct osim_card_swosim_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...
 
enum osim_card_sw_class osim_sw_class (const struct osim_chan_hdl *ch, uint16_t sw_in)
 
int default_decode (struct osim_decoded_data *dd, const struct osim_file_desc *desc, int len, uint8_t *data)
 
int osim_init (void *ctx)
 

Detailed Description

Core routines for SIM/UICC/USIM access.

Function Documentation

◆ __element_alloc()

◆ add_df_with_ef()

struct osim_file_desc * add_df_with_ef ( struct osim_file_desc parent,
uint16_t  fid,
const char *  name,
const struct osim_file_desc in,
int  num 
)

◆ add_filedesc()

void add_filedesc ( struct osim_file_desc root,
const struct osim_file_desc in,
int  num 
)

◆ alloc_adf_with_ef()

struct osim_file_desc * alloc_adf_with_ef ( void *  ctx,
const uint8_t *  adf_name,
uint8_t  adf_name_len,
const char *  name,
const struct osim_file_desc in,
int  num 
)

◆ alloc_df()

◆ default_decode()

int default_decode ( struct osim_decoded_data dd,
const struct osim_file_desc desc,
int  len,
uint8_t *  data 
)

◆ element_alloc()

◆ element_alloc_sub()

◆ LLIST_HEAD()

static LLIST_HEAD ( g_app_profiles  )
static

◆ osim_app_profile_find_by_aid()

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().

◆ osim_app_profile_find_by_name()

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().

◆ osim_app_profile_find_sw()

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().

◆ osim_app_profile_register()

void osim_app_profile_register ( struct osim_card_app_profile aprof)

◆ osim_card_hdl_add_app()

int osim_card_hdl_add_app ( struct osim_card_hdl ch,
const uint8_t *  aid,
uint8_t  aid_len,
const char *  label 
)

◆ osim_card_hdl_find_app()

struct osim_card_app_hdl * osim_card_hdl_find_app ( struct osim_card_hdl ch,
const uint8_t *  aid,
uint8_t  aid_len 
)

◆ osim_cprof_find_sw()

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().

◆ osim_file_decode()

struct osim_decoded_data * osim_file_decode ( struct osim_file file,
int  len,
uint8_t *  data 
)

◆ osim_file_desc_find_aid()

struct osim_file_desc * osim_file_desc_find_aid ( struct osim_file_desc parent,
const uint8_t *  aid,
uint8_t  aid_len 
)

◆ osim_file_desc_find_fid()

struct osim_file_desc * osim_file_desc_find_fid ( struct osim_file_desc parent,
uint16_t  fid 
)

◆ osim_file_desc_find_name()

struct osim_file_desc * osim_file_desc_find_name ( struct osim_file_desc parent,
const char *  name 
)

◆ osim_file_desc_find_sfid()

struct osim_file_desc * osim_file_desc_find_sfid ( struct osim_file_desc parent,
uint8_t  sfid 
)

◆ osim_file_encode()

struct msgb * osim_file_encode ( const struct osim_file_desc desc,
const struct osim_decoded_data data 
)

References data.

◆ osim_init()

int osim_init ( void *  ctx)

◆ osim_new_apdumsg()

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.

Parameters
[in]claCLASS byte
[in]insINSTRUCTION byte
[in]p1Parameter 1 byte
[in]p2Parameter 2 byte
[in]lcnumber of bytes in the command data field Nc, which will encoded in 0, 1 or 3 bytes into Lc
[in]lemaximum number of bytes expected in the response data field, which will encoded in 0, 1, 2 or 3 bytes into Le
Returns
an APDU message generated using provided APDU parameters

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.

◆ osim_print_sw()

char * osim_print_sw ( const struct osim_chan_hdl ch,
uint16_t  sw_in 
)

References osim_print_sw_buf().

◆ 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 
)

◆ 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().

◆ osim_sw_class()