From 6899b2fd6b2a52ed2666322880b205ca038d360d Mon Sep 17 00:00:00 2001
From: Kevin Redon <kevredon@mail.tsaitgaist.info>
Date: Tue, 11 Sep 2012 11:44:18 +0200
Subject: [PATCH 3/6] renamed case to the one defined in ISO7816-3

APDU_CASE_2 becomes APDU_CASE_2S
APDU_CASE_2_EXT becmoes APDU_CASE_2E
APDU_CASE_3 becomes APDU_CASE_3S
APDU_CASE_3_EXT becmoes APDU_CASE_3E
APDU_CASE_4 becomes APDU_CASE_4S
APDU_CASE_4_EXT becmoes APDU_CASE_4E
---
 include/osmocom/sim/sim.h |   12 ++++++------
 src/sim/core.c            |   12 ++++++------
 src/sim/reader.c          |   24 ++++++++++++------------
 3 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/include/osmocom/sim/sim.h b/include/osmocom/sim/sim.h
index 35ff7b4..3273193 100644
--- a/include/osmocom/sim/sim.h
+++ b/include/osmocom/sim/sim.h
@@ -9,12 +9,12 @@
 /* command-response pairs cases, as specified in ISO/IEC 7816-3:2006(E) §12.1 */
 enum osim_apdu_case {
 	APDU_CASE_1, /* command header, no command data field, no response data field */
-	APDU_CASE_2, /* command header, no command data field, response data field (short) */
-	APDU_CASE_2_EXT, /* command header, no command data field, response data field (extended) */
-	APDU_CASE_3, /* command header, command data field (short), no response data field */
-	APDU_CASE_3_EXT, /* command header, command data field (extended), no response data field */
-	APDU_CASE_4, /* command header, command data field (short), response data field (short) */
-	APDU_CASE_4_EXT /* command header, command data field (extended), response data field (extended) */
+	APDU_CASE_2S, /* command header, no command data field, response data field (short) */
+	APDU_CASE_2E, /* command header, no command data field, response data field (extended) */
+	APDU_CASE_3S, /* command header, command data field (short), no response data field */
+	APDU_CASE_3E, /* command header, command data field (extended), no response data field */
+	APDU_CASE_4S, /* command header, command data field (short), response data field (short) */
+	APDU_CASE_4E /* command header, command data field (extended), response data field (extended) */
 };
 
 struct osim_apdu_cmd_hdr {
diff --git a/src/sim/core.c b/src/sim/core.c
index 8690752..9c1c9ae 100644
--- a/src/sim/core.c
+++ b/src/sim/core.c
@@ -206,19 +206,19 @@ struct msgb *osim_new_apdumsg(uint8_t cla, uint8_t ins, uint8_t p1,
 		msgb_apdu_case(msg) = APDU_CASE_1;
 	else if (lc == 0 && le >= 1) {
 		if (le <= 256)
-			msgb_apdu_case(msg) = APDU_CASE_2;
+			msgb_apdu_case(msg) = APDU_CASE_2S;
 		else
-			msgb_apdu_case(msg) = APDU_CASE_2_EXT;
+			msgb_apdu_case(msg) = APDU_CASE_2E;
 	} else if (le == 0 && lc >= 1) {
 		if (lc <= 255)
-			msgb_apdu_case(msg) = APDU_CASE_3;
+			msgb_apdu_case(msg) = APDU_CASE_3S;
 		else
-			msgb_apdu_case(msg) = APDU_CASE_3_EXT;
+			msgb_apdu_case(msg) = APDU_CASE_3E;
 	} else if (lc >= 1 && le >= 1) {
 		if (lc <= 255 & le <= 256)
-			msgb_apdu_case(msg) = APDU_CASE_4;
+			msgb_apdu_case(msg) = APDU_CASE_4S;
 		else
-			msgb_apdu_case(msg) = APDU_CASE_4_EXT;
+			msgb_apdu_case(msg) = APDU_CASE_4E;
 	}
 
 	return msg;
diff --git a/src/sim/reader.c b/src/sim/reader.c
index 71fb763..6106519 100644
--- a/src/sim/reader.c
+++ b/src/sim/reader.c
@@ -63,10 +63,10 @@ static int transceive_apdu_t0(struct osim_card_hdl *st, struct msgb *amsg)
 	case APDU_CASE_1:
 		tpduh->p3 = 0x00;
 		break;
-	case APDU_CASE_2:
+	case APDU_CASE_2S:
 		tpduh->p3 = msgb_apdu_le(amsg);
 		break;
-	case APDU_CASE_2_EXT:
+	case APDU_CASE_2E:
 		if (msgb_apdu_le(amsg) <= 256) {
 			/* case 2E.1 */
 			tpduh->p3 = msgb_apdu_le(amsg) & 0xff;
@@ -76,14 +76,14 @@ static int transceive_apdu_t0(struct osim_card_hdl *st, struct msgb *amsg)
 			msgb_put_u16(tmsg, msgb_apdu_le(amsg));
 		}
 		break;
-	case APDU_CASE_3:
-	case APDU_CASE_4:
+	case APDU_CASE_3S:
+	case APDU_CASE_4S:
 		tpduh->p3 = msgb_apdu_lc(amsg);
 		cur = msgb_put(tmsg, tpduh->p3);
 		memcpy(cur, msgb_apdu_dc(amsg), tpduh->p3);
 		break;
-	case APDU_CASE_3_EXT:
-	case APDU_CASE_4_EXT:
+	case APDU_CASE_3E:
+	case APDU_CASE_4E:
 		if (msgb_apdu_lc(amsg) < 256) {
 			/* Case 3E.1 */
 			tpduh->p3 = msgb_apdu_lc(amsg);
@@ -118,10 +118,10 @@ transceive_again:
 
 	switch (msgb_apdu_case(amsg)) {
 	case APDU_CASE_1:
-	case APDU_CASE_3:
+	case APDU_CASE_3S:
 		/* just copy SW */
 		break;
-	case APDU_CASE_2:
+	case APDU_CASE_2S:
 case_2s:
 		switch (sw >> 8) {
 		case 0x67: /* Case 2S.2: Le definitely not accepted */
@@ -142,7 +142,7 @@ case_2s:
 			memcpy(cur, tmsg->l3h, msgb_l3len(tmsg));
 		}
 		break;
-	case APDU_CASE_4:
+	case APDU_CASE_4S:
 		/* FIXME: this is 4S.2 only for 2nd... response: */
 		if (num_resp >= 2)
 			goto case_2s;
@@ -174,7 +174,7 @@ case_2s:
 		/* Case 4S.2: Command accepted: just copy SW */
 		/* Case 4S.4: Just copy SW */
 		break;
-	case APDU_CASE_2_EXT:
+	case APDU_CASE_2E:
 		if (msgb_apdu_le(amsg) <= 256) {
 			/* Case 2E.1: Le <= 256 */
 			goto case_2s;
@@ -198,10 +198,10 @@ case_2s:
 			break;
 		}
 		break;
-	case APDU_CASE_3_EXT:
+	case APDU_CASE_3E:
 		/* FIXME: handling for ENVELOPE splitting */
 		break;
-	case APDU_CASE_4_EXT:
+	case APDU_CASE_4E:
 		break;
 	}
 
-- 
1.7.9.5

