aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2024-06-05 19:43:43 +0200
committerHarald Welte <laforge@osmocom.org>2024-06-06 19:40:13 +0200
commit55ea51049775e623880f62026ad827f580aec7a2 (patch)
tree35af9c89a69b98c0b99bf76d1c70a1bdd8772833
parent6e7f8fa57ac30d76bb0846616bf2605e5f87d436 (diff)
libosmosim: class_tables: Fix GlobalPlatform CLA=8x INS=CA/CB GET DATA
in their infinite wisdom, GlobalPlatform made GET DATA a command that can be either APDU case 2 or case 4. As the specify Le must be 0x00, we can conclude that P3 == 0x00 must be Le, while P3 != 0x00 must be Lc and hence case 4 */ Change-Id: Ic8a17921f5a42d227791f1de39f90b4967c2e1b6 Related: SYS#6865
-rw-r--r--src/sim/class_tables.c15
-rw-r--r--tests/sim/sim_test.c4
-rw-r--r--tests/sim/sim_test.ok2
3 files changed, 19 insertions, 2 deletions
diff --git a/src/sim/class_tables.c b/src/sim/class_tables.c
index 1cda9a84..32174469 100644
--- a/src/sim/class_tables.c
+++ b/src/sim/class_tables.c
@@ -178,6 +178,7 @@ static int gp_cla_ins_helper(const struct osim_cla_ins_case *cic,
{
uint8_t ins = hdr[1];
uint8_t p1 = hdr[2];
+ uint8_t p3 = hdr[4];
switch (ins) {
case 0xE2: /* STORE DATA */
@@ -197,6 +198,16 @@ static int gp_cla_ins_helper(const struct osim_cla_ins_case *cic,
else
return 2; /* ETSI TS 102 221 V16.2.0 11.1.2 */
break;
+ case 0xCA:
+ case 0xCB:
+ /* in their infinite wisdom, GlobalPlatform made GET DATA a command that can be either APDU
+ * case 2 or case 4. As the specify Le must be 0x00, we can conclude that P3 == 0x00 must be
+ * Le, while P3 != 0x00 must be Lc and hence case 4 */
+ if (p3 == 0x00)
+ return 2;
+ else
+ return 4;
+ break;
}
return 0;
}
@@ -225,8 +236,8 @@ static const uint8_t uicc_ins_tbl_80[256] = {
static const uint8_t gp_ins_tbl_8ce[256] = {
[0xE4] = 4, /* DELETE */
[0xE2] = 0x80, /* STORE DATA */
- [0xCA] = 4, /* GET DATA */
- [0xCB] = 4, /* GET DATA */
+ [0xCA] = 0x80, /* GET DATA */
+ [0xCB] = 0x80, /* GET DATA */
[0xF2] = 0x80, /* GET STATUS */
[0xE6] = 4, /* INSTALL */
[0xE8] = 4, /* LOAD */
diff --git a/tests/sim/sim_test.c b/tests/sim/sim_test.c
index 9a52af47..ab5d2be3 100644
--- a/tests/sim/sim_test.c
+++ b/tests/sim/sim_test.c
@@ -29,6 +29,8 @@ const uint8_t uicc_read[] = { 0x00, 0xB0, 0x00, 0x00, 0x10 };
const uint8_t uicc_upd[] = { 0x00, 0xD6, 0x00, 0x00, 0x02, 0x01, 0x02 };
const uint8_t uicc_get_status[] = { 0x80, 0xf2, 0x00, 0x02, 0x10 };
const uint8_t euicc_m2m_get_status[] = { 0x81, 0xf2, 0x40, 0x02, 0x02, 0x4f, 0x00 };
+const uint8_t gp_get_data2[] = { 0x81, 0xCA, 0x00, 0x5A, 0x00 };
+const uint8_t gp_get_data4[] = { 0x81, 0xCA, 0x00, 0x5A, 0x12 };
#define APDU_CASE_ASSERT(x, y) \
do { \
@@ -49,6 +51,8 @@ static void test_cla_ins_tbl(void)
APDU_CASE_ASSERT(uicc_upd, 3);
APDU_CASE_ASSERT(uicc_get_status, 2);
APDU_CASE_ASSERT(euicc_m2m_get_status, 4);
+ APDU_CASE_ASSERT(gp_get_data2, 2);
+ APDU_CASE_ASSERT(gp_get_data4, 4);
}
int main(int argc, char **argv)
diff --git a/tests/sim/sim_test.ok b/tests/sim/sim_test.ok
index cac59ba0..3abfb718 100644
--- a/tests/sim/sim_test.ok
+++ b/tests/sim/sim_test.ok
@@ -6,3 +6,5 @@ Testing uicc_read
Testing uicc_upd
Testing uicc_get_status
Testing euicc_m2m_get_status
+Testing gp_get_data2
+Testing gp_get_data4