Skip to content

Commit 5b98bed

Browse files
committed
Stringify Application Selection Registered Proprietary Data (field 9F0A)
This field contains proprietary data identified by registered identifiers. Even if the identifier is know, the data remains proprietary.
1 parent 26af3d5 commit 5b98bed

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

src/emv_fields.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file emv_fields.h
33
* @brief EMV field definitions and helper functions
44
*
5-
* Copyright (c) 2021, 2022, 2023 Leon Lynch
5+
* Copyright (c) 2021-2024 Leon Lynch
66
*
77
* This library is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU Lesser General Public
@@ -152,6 +152,12 @@ __BEGIN_DECLS
152152
#define EMV_ADDL_TERM_CAPS_OUTPUT_CODE_TABLE_2 (0x02) ///< Terminal Data Output Capability: Code table 2
153153
#define EMV_ADDL_TERM_CAPS_OUTPUT_CODE_TABLE_1 (0x01) ///< Terminal Data Output Capability: Code table 1
154154

155+
// Application Selection Registered Proprietary Data (field 9F0A)
156+
// See EMV 4.4 Book 1, 12.5
157+
// See https://www.emvco.com/registered-ids/
158+
#define EMV_ASRPD_ECSG (0x0001) ///< European Cards Stakeholders Group
159+
#define EMV_ASRPD_TCEA (0x0002) ///< Technical Cooperation ep2 Association
160+
155161
// Application Interchange Profile (field 82) byte 1
156162
// See EMV 4.4 Book 3, Annex C1, Table 41
157163
// See EMV Contactless Book C-2 v2.10, Annex A.1.16

src/emv_strings.c

+80
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,18 @@ int emv_tlv_get_info(
523523
info->format = EMV_FORMAT_B;
524524
return 0;
525525

526+
case EMV_TAG_9F0A_ASRPD:
527+
info->tag_name = "Application Selection Registered Proprietary Data (ASRPD)";
528+
info->tag_desc =
529+
"Proprietary data allowing for proprietary processing during "
530+
"application selection. Proprietary data is identified using "
531+
"Proprietary Data Identifiers that are managed by EMVCo and "
532+
"their usage by the Application Selection processing is "
533+
"according to their intended usage, as agreed by EMVCo during "
534+
"registration.";
535+
info->format = EMV_FORMAT_B;
536+
return emv_asrpd_get_string_list(tlv->value, tlv->length, value_str, value_str_len);
537+
526538
case EMV_TAG_9F0D_ISSUER_ACTION_CODE_DEFAULT:
527539
info->tag_name = "Issuer Action Code (IAC) - Default";
528540
info->tag_desc =
@@ -2124,6 +2136,74 @@ int emv_aid_get_string(
21242136
return 0;
21252137
}
21262138

2139+
int emv_asrpd_get_string_list(
2140+
const uint8_t* asrpd,
2141+
size_t asrpd_len,
2142+
char* str,
2143+
size_t str_len
2144+
)
2145+
{
2146+
struct str_itr_t itr;
2147+
2148+
2149+
if (!asrpd || !asrpd_len) {
2150+
return -1;
2151+
}
2152+
2153+
if (!str || !str_len) {
2154+
// Caller didn't want the value string
2155+
return 0;
2156+
}
2157+
2158+
if (asrpd_len < 3) {
2159+
// Application Selection Registered Proprietary Data (ASRPD) must
2160+
// contain at least one ID and a length
2161+
return 1;
2162+
}
2163+
2164+
emv_str_list_init(&itr, str, str_len);
2165+
2166+
// Application Selection Registered Proprietary Data (ASRPD)
2167+
// See EMV 4.4 Book 1, 12.5
2168+
// See https://www.emvco.com/registered-ids/
2169+
while (asrpd_len) {
2170+
uint16_t asrpd_id;
2171+
size_t asrpd_entry_len;
2172+
2173+
if (asrpd_len < 3) {
2174+
// Incomplete ASRPD entry
2175+
return 2;
2176+
}
2177+
2178+
asrpd_id = (asrpd[0] << 8) + asrpd[1];
2179+
switch (asrpd_id) {
2180+
case EMV_ASRPD_ECSG:
2181+
emv_str_list_add(&itr, "European Cards Stakeholders Group");
2182+
break;
2183+
2184+
case EMV_ASRPD_TCEA:
2185+
emv_str_list_add(&itr, "Technical Cooperation ep2 Association");
2186+
break;
2187+
2188+
default:
2189+
emv_str_list_add(&itr, "Unknown ASRPD identifier");
2190+
}
2191+
2192+
// Validate entry length
2193+
asrpd_entry_len = 2 + 1 + asrpd[2];
2194+
if (asrpd_entry_len > asrpd_len) {
2195+
// Invalid ASRPD length
2196+
return 3;
2197+
}
2198+
2199+
// Advance
2200+
asrpd += asrpd_entry_len;
2201+
asrpd_len -= asrpd_entry_len;
2202+
}
2203+
2204+
return 0;
2205+
}
2206+
21272207
int emv_aip_get_string_list(
21282208
const uint8_t* aip,
21292209
size_t aip_len,

src/emv_strings.h

+16
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,22 @@ int emv_aid_get_string(
329329
size_t str_len
330330
);
331331

332+
/**
333+
* Stringify Application Selection Registered Proprietary Data (field 9F0A)
334+
* @note Strings in output buffer are delimited using "\n", including the last string
335+
* @param asrpd Application Selection Registered Proprietary Data (ASRPD) field.
336+
* @param asrpd_len Length of Application Selection Registered Proprietary Data (ASRPD) field.
337+
* @param str String buffer output
338+
* @param str_len Length of string buffer in bytes
339+
* @return Zero for success. Less than zero for internal error. Greater than zero for parse error.
340+
*/
341+
int emv_asrpd_get_string_list(
342+
const uint8_t* asrpd,
343+
size_t asrpd_len,
344+
char* str,
345+
size_t str_len
346+
);
347+
332348
/**
333349
* Stringify Application Interchange Profile (field 82)
334350
* @note Strings in output buffer are delimited using "\n", including the last string

src/emv_tags.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @remark See EMV 4.4 Book 3, Annex A
66
* @remark See ISO 7816-4:2005, 5.2.4
77
*
8-
* Copyright (c) 2021, 2022, 2023 Leon Lynch
8+
* Copyright (c) 2021-2024 Leon Lynch
99
*
1010
* This library is free software; you can redistribute it and/or
1111
* modify it under the terms of the GNU Lesser General Public
@@ -196,6 +196,9 @@ __BEGIN_DECLS
196196
/// EMV tag 9F09 Application Version Number - terminal
197197
#define EMV_TAG_9F09_APPLICATION_VERSION_NUMBER_TERMINAL (0x9F09)
198198

199+
/// EMV tag 9F0A Application Selection Registered Proprietary Data (ASRPD)
200+
#define EMV_TAG_9F0A_ASRPD (0x9F0A)
201+
199202
/// EMV tag 9F0D Issuer Action Code (IAC) - Default. Template 70 or 77.
200203
#define EMV_TAG_9F0D_ISSUER_ACTION_CODE_DEFAULT (0x9F0D)
201204

0 commit comments

Comments
 (0)