7 #include <osmocom/core/msgb.h> 8 #include <osmocom/core/linuxlist.h> 10 #define APDU_HDR_LEN 5 11 #define MAX_AID_LEN 16 18 #define OSIM_MAX_ATR_LEN 33 51 #define msgb_apdu_dr(__x) 64 #define OSIM_MSGB_CB(__msgb) ((struct osim_msgb_cb *)&((__msgb)->cb[0])) 66 #define msgb_apdu_case(__x) OSIM_MSGB_CB(__x)->apduc 67 #define msgb_apdu_lc(__x) OSIM_MSGB_CB(__x)->lc 68 #define msgb_apdu_le(__x) OSIM_MSGB_CB(__x)->le 69 #define msgb_apdu_sw(__x) OSIM_MSGB_CB(__x)->sw 71 #define msgb_apdu_h(__x) ((struct osim_apdu_cmd_hdr *)(__x)->l2h) 73 #define msgb_apdu_dc(__x) ((__x)->l2h + sizeof(struct osim_apdu_cmd_hdr)) 74 #define msgb_apdu_de(__x) ((__x)->l2h + sizeof(struct osim_apdu_cmd_hdr) + msgb_apdu_lc(__x)) 89 int len, uint8_t *data);
157 #define F_OPTIONAL 0x0001 159 #define SFI_NONE 0xFF 200 #define EF(pfid, sfi, pns, pflags, pnl, ptype, smin, srec, pdec, penc) \ 209 .ops = { .encode = penc, .parse = pdec }, \ 210 .size = { .min = smin, .rec = srec}, \ 215 #define EF_TRANSP(fid, sfi, ns, flags, smin, srec, nl, dec, enc) \ 216 EF(fid, sfi, ns, flags, nl, EF_TYPE_TRANSP, \ 217 smin, srec, dec, enc) 219 #define EF_TRANSP_N(fid, sfi, ns, flags, smin, srec, nl) \ 220 EF_TRANSP(fid, sfi, ns, flags, smin, srec, \ 221 nl, &default_decode, NULL) 224 #define EF_CYCLIC(fid, sfi, ns, flags, smin, srec, nl, dec, enc) \ 225 EF(fid, sfi, ns, flags, nl, EF_TYPE_RECORD_CYCLIC, \ 226 smin, srec, dec, enc) 228 #define EF_CYCLIC_N(fid, sfi, ns, flags, smin, srec, nl) \ 229 EF_CYCLIC(fid, sfi, ns, flags, smin, srec, nl, \ 230 &default_decode, NULL) 233 #define EF_LIN_FIX(fid, sfi, ns, flags, smin, srec, nl, dec, enc) \ 234 EF(fid, sfi, ns, flags, nl, EF_TYPE_RECORD_FIXED, \ 235 smin, srec, dec, enc) 237 #define EF_LIN_FIX_N(fid, sfi, ns, flags, smin, srec, nl) \ 238 EF_LIN_FIX(fid, sfi, ns, flags, smin, srec, nl, \ 239 &default_decode, NULL) 242 #define EF_KEY(fid, sfi, ns, flags, smin, srec, nl, dec, enc) \ 243 EF(fid, sfi, ns, flags, nl, EF_TYPE_KEY, \ 244 smin, srec, dec, enc) 246 #define EF_KEY_N(fid, sfi, ns, flags, smin, srec, nl) \ 247 EF_KEY(fid, sfi, ns, flags, smin, srec, nl, \ 248 &default_decode, NULL) 292 #define OSIM_CARD_SW_LAST { \ 293 .code = 0, .mask = 0, .type = SW_TYPE_NONE, \ 294 .class = SW_CLS_NONE, .u.str = NULL \ 358 uint8_t
p2, uint16_t
lc, uint16_t
le);
443 const char *name,
void *ctx);
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.
Definition: core.c:431
const struct tlv_definition ts102221_fcp_tlv_def
Definition: card_fs_uicc.c:209
const struct osim_file * file
file to which we belong
Definition: sim.h:135
ts102221_fcp_tag
Definition: sim.h:341
char * osim_print_sw_c(const void *ctx, const struct osim_chan_hdl *ch, uint16_t sw_in)
Definition: core.c:407
struct osim_file_desc * osim_file_desc_find_fid(struct osim_file_desc *parent, uint16_t fid)
Definition: core.c:203
uint8_t aid_len
Definition: sim.h:305
command header, no command data field, no response data field
Definition: sim.h:25
const struct osim_file_desc * desc
Descriptor for the file.
Definition: sim.h:191
Decoded data for a single file, consisting of all decoded elements.
Definition: sim.h:133
osim_reader_driver
Definition: sim.h:367
Internal Entry File.
Definition: sim.h:146
const struct osim_card_sw * sw
Status words defined by application.
Definition: sim.h:309
unsigned integer
Definition: sim.h:99
struct llist_head list
Definition: sim.h:115
struct osim_file_desc::@1 size
struct osim_card_hdl * osim_card_open(struct osim_reader_hdl *rh, enum osim_proto proto)
Definition: reader.c:261
descriptor for a given application present on a card
Definition: sim.h:393
uint8_t p1
Parameter 1 byte.
Definition: sim.h:46
const struct osim_card_app_profile * prof
application profile (if any known)
Definition: sim.h:402
const struct osim_reader_ops * ops
Definition: sim.h:385
struct llist_head list
member in global list of readers
Definition: sim.h:384
unsigned int flags
Definition: sim.h:176
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.
Definition: core.c:245
void * priv
Definition: sim.h:387
const char * name
Definition: sim.h:374
Key file as used in TETRA.
Definition: sim.h:154
unsigned int length
Definition: sim.h:121
int osim_card_reset(struct osim_card_hdl *card, bool cold_reset)
Definition: reader.c:277
uint8_t aid[MAX_AID_LEN]
AID of the application.
Definition: sim.h:397
uint16_t lc
number of bytes in the command data field Nc, which will encoded in 0, 1 or 3 bytes into Lc...
Definition: sim.h:33
uint16_t fid
File Identifier.
Definition: sim.h:169
command header, no command data field, response data field (extended)
Definition: sim.h:27
BCD encoded digits.
Definition: sim.h:102
uint16_t code
status word code (2 bytes)
Definition: sim.h:281
osim_apdu_case
command-response pairs cases
Definition: sim.h:24
struct llist_head list
member in global list of cards
Definition: sim.h:407
Dedicated File.
Definition: sim.h:143
uint16_t mask
status word mask (2 bytes), to match range/prefix of SW
Definition: sim.h:283
osim_card_sw_class
Definition: sim.h:270
Master File.
Definition: sim.h:147
struct osim_card_hdl * card
card to which this channel belongs
Definition: sim.h:430
int osim_transceive_apdu(struct osim_chan_hdl *st, struct msgb *amsg)
Definition: reader.c:224
enum osim_element_type type
Definition: sim.h:117
uint8_t cla
CLASS byte.
Definition: sim.h:44
a boolean flag
Definition: sim.h:97
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.
Definition: core.c:287
uint16_t sw
status word, composed of SW1 and SW2 bytes
Definition: sim.h:62
unsigned integer
Definition: sim.h:98
uint8_t ins
INSTRUCTION byte.
Definition: sim.h:45
command header, command data field (extended), response data field (extended)
Definition: sim.h:31
enum osim_element_repr representation
Definition: sim.h:118
size_t rec
Recommended size.
Definition: sim.h:184
int osim_init(void *ctx)
Definition: core.c:473
struct osim_file_desc * osim_file_desc_find_sfid(struct osim_file_desc *parent, uint8_t sfid)
Definition: core.c:215
int(* parse)(struct osim_decoded_data *dd, const struct osim_file_desc *desc, int len, uint8_t *data)
Parse binary file data into osim_decoded_data.
Definition: sim.h:87
const char * name
Definition: sim.h:119
uint8_t aid[MAX_AID_LEN]
AID of this application, as used in EF.DIR.
Definition: sim.h:304
enum osim_apdu_case apduc
command-response pair case, defining the encoding of Lc and Le
Definition: sim.h:59
struct osim_file_desc * mf
Descriptor for the MF (root directory.
Definition: sim.h:324
command header, command data field (short), response data field (short)
Definition: sim.h:30
A card application (e.g.
Definition: sim.h:298
A single decoded element inside a file.
Definition: sim.h:114
enum osim_card_sw_class osim_sw_class(const struct osim_chan_hdl *ch, uint16_t sw_in)
Definition: core.c:442
uint8_t * buf
Definition: sim.h:126
uint16_t le
maximum number of bytes expected in the response data field, which will encoded in 0...
Definition: sim.h:61
Cyclic Record EF.
Definition: sim.h:153
enum osim_ef_type ef_type
Type of the EF, if type == TYPE_EF.
Definition: sim.h:167
uint8_t ins
INSTRUCTION byte.
Definition: sim.h:33
char * label
application label from EF_DIR
Definition: sim.h:400
osim_card_sw_type
Definition: sim.h:265
osim_ef_type
Definition: sim.h:150
enum osim_card_sw_type type
Definition: sim.h:284
struct llist_head list
entry in the global list of card application profiles
Definition: sim.h:300
Application Dedicated File.
Definition: sim.h:144
struct osim_reader_hdl * osim_reader_open(enum osim_reader_driver drv, int idx, const char *name, void *ctx)
Definition: reader.c:234
struct llist_head child_list
list of children EF in DF
Definition: sim.h:163
uint16_t le
maximum number of bytes expected in the response data field, which will encoded in 0...
Definition: sim.h:34
uint8_t aid_len
Definition: sim.h:398
Operations for a given File.
Definition: sim.h:85
group container, has siblings
Definition: sim.h:104
struct llist_head channels
list of channels for this card
Definition: sim.h:416
uint8_t sfid
Short File IDentifier.
Definition: sim.h:170
const struct osim_card_sw ** sws
Array of pointers to status words.
Definition: sim.h:326
int(* transceive)(struct osim_reader_hdl *rh, struct msgb *msg)
Definition: sim.h:379
osim_proto
Definition: sim.h:362
unsigned integer
Definition: sim.h:100
const char * str
Human-readable meaning of SW.
Definition: sim.h:288
command header, command data field (extended), no response data field
Definition: sim.h:29
#define OSIM_MAX_ATR_LEN
Maximum Answer-To-Reset (ATR) size in bytes.
Definition: sim.h:18
const char * long_name
Long / description.
Definition: sim.h:175
uint8_t df_name_len
Definition: sim.h:172
const struct osim_file_desc * cwd
current working directory
Definition: sim.h:432
int(* card_close)(struct osim_card_hdl *card)
Definition: sim.h:378
APDU command body.
Definition: sim.h:58
const struct value_string ts102221_fcp_vals[14]
Definition: card_fs_uicc.c:191
osim_element_repr
Definition: sim.h:107
osim_element_type
Definition: sim.h:95
command header, no command data field, response data field (short)
Definition: sim.h:26
struct osim_decoded_data * decoded_data
Parsed/Decoded file contents.
Definition: sim.h:196
struct llist_head decoded_elements
list of 'struct decoded_element'
Definition: sim.h:137
struct osim_file_ops ops
Operations (parse/encode.
Definition: sim.h:178
struct llist_head list
member in card list of applications
Definition: sim.h:395
osim_file_type
Definition: sim.h:141
struct osim_file_desc * osim_file_desc_find_aid(struct osim_file_desc *parent, const uint8_t *aid, uint8_t aid_len)
Definition: core.c:187
int osim_card_close(struct osim_card_hdl *card)
Definition: reader.c:284
Entry File.
Definition: sim.h:145
Fixed-Size Record EF.
Definition: sim.h:152
uint16_t u16
Definition: sim.h:124
size_t min
Minimum size of the file (transparent) or record in cyclic / linear file.
Definition: sim.h:181
uint32_t u32
Definition: sim.h:125
uint8_t u8
Definition: sim.h:123
struct osim_card_app_hdl * cur_app
currently selected application (if any)
Definition: sim.h:434
A card profile (e.g.
Definition: sim.h:321
struct llist_head siblings
A list of sibling decoded_items.
Definition: sim.h:128
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.
Definition: core.c:416
unsigned int atr_len
Definition: sim.h:423
const char * name
human-readable name
Definition: sim.h:302
char * osim_print_sw(const struct osim_chan_hdl *ch, uint16_t sw_in)
Definition: core.c:401
enum osim_file_type type
Type of the file (EF, DF, ...)
Definition: sim.h:166
uint32_t proto_supported
Definition: sim.h:386
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.
Definition: core.c:258
struct llist_head list
linked to card->channels
Definition: sim.h:428
const char * name
Definition: sim.h:322
int(* card_reset)(struct osim_card_hdl *card, bool cold_reset)
Definition: sim.h:377
struct llist_head apps
list of applications found on card
Definition: sim.h:419
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.
Definition: core.c:324
uint8_t cla
CLASS byte.
Definition: sim.h:32
static size_t len(const char *str)
struct osim_file_desc * adf
file system description
Definition: sim.h:307
command header, command data field (short), no response data field
Definition: sim.h:28
#define MAX_AID_LEN
Definition: sim.h:11
uint8_t atr[OSIM_MAX_ATR_LEN]
ATR (Answer To Reset) of the card.
Definition: sim.h:422
uint8_t p1
Parameter 1 byte.
Definition: sim.h:34
const uint8_t * df_name
Definition: sim.h:171
uint8_t p2
Parameter 2 byte.
Definition: sim.h:47
uint16_t lc
number of bytes in the command data field Nc, which will encoded in 0, 1 or 3 bytes into Lc...
Definition: sim.h:60
struct llist_head list
local element in list
Definition: sim.h:162
struct osim_file_ops __attribute__
union osim_decoded_element::@0 u
struct osim_file_desc * osim_file_desc_find_name(struct osim_file_desc *parent, const char *name)
Definition: core.c:175
struct osim_card_hdl * card
current card, if any
Definition: sim.h:389
A card status word (SW)
Definition: sim.h:279
Transparent EF.
Definition: sim.h:151
generic string
Definition: sim.h:101
struct msgb * encoded_data
Encoded file contents.
Definition: sim.h:194
struct osim_card_profile * prof
card profile
Definition: sim.h:411
uint8_t p3
Parameter 3 byte, used for TPDU by T=0.
Definition: sim.h:48
struct osim_file_desc * parent
parent DF
Definition: sim.h:164
uint8_t p2
Parameter 2 byte.
Definition: sim.h:35
A single instance of a file: Descriptor and contents.
Definition: sim.h:189
enum osim_proto proto
card protocol
Definition: sim.h:413
BCD encoded digits.
Definition: sim.h:103
APDU/TPDU command header.
Definition: sim.h:43
const char * short_name
Short Name (like EF.ICCID)
Definition: sim.h:174
char * osim_print_sw_buf(char *buf, size_t buf_len, const struct osim_chan_hdl *ch, uint16_t sw_in)
Definition: core.c:366
struct osim_reader_hdl * reader
reader through which card is accessed
Definition: sim.h:409