VPCD protocol support (for vsmartcard.git PCD/PICC code)

vsmartcard.git contains an implementation of a virtual card reader
(vpcd) which registers with PC/SC (such as pcsc-lite).  It simply
binds to a TCP port and waits for a TCP client to connect to it,
implementing APDU transfer over TCP.

This code implements the related protocol as a TTCN-3 test port
for Eclipse TITAN, which will enable us to implement a 'virtual smart
card' in TTCN-3 tets cases, primarily for testing remsim-bankd at
this point.

Change-Id: Iac37dd231a0f2e1efd484887bca1a9d672b446bb
diff --git a/library/VPCD_Types.ttcn b/library/VPCD_Types.ttcn
new file mode 100644
index 0000000..5caa0be
--- /dev/null
+++ b/library/VPCD_Types.ttcn
@@ -0,0 +1,75 @@
+module VPCD_Types {
+
+/* VPCD/VPICC Types, implementing the protocol used by vpcd/vpicc of
+ * vsmartcard.git by Frank Morgner.
+ */
+
+import from General_Types all;
+import from Osmocom_Types all;
+
+type enumerated VPCD_CtrlCmd {
+	VPCD_CTRL_OFF	(0),
+	VPCD_CTRL_ON	(1),
+	VPCD_CTRL_RESET (2),
+	VPCD_CTRL_ATR	(4)
+} with { variant "FIELDLENGTH(8)" };
+
+type union VPCD_MsgUnion {
+	VPCD_CtrlCmd	ctrl,
+	octetstring	data
+};
+
+type record VPCD_PDU {
+	uint16_t 	len,
+	VPCD_MsgUnion	u
+} with {
+	variant (len) "LENGTHTO(u)"
+	variant (u) "CROSSTAG(
+			ctrl,	len = 1;
+			data,	OTHERWISE)"
+};
+
+
+template (value) VPCD_PDU ts_VPCD_CTRL(template (value) VPCD_CtrlCmd cmd) := {
+	len := 0, // overwritten
+	u := {
+		ctrl := cmd
+	}
+}
+template (value) VPCD_PDU ts_VPCD_CTRL_OFF := ts_VPCD_CTRL(VPCD_CTRL_OFF);
+template (value) VPCD_PDU ts_VPCD_CTRL_ON := ts_VPCD_CTRL(VPCD_CTRL_ON);
+template (value) VPCD_PDU ts_VPCD_CTRL_RESET := ts_VPCD_CTRL(VPCD_CTRL_RESET);
+template (value) VPCD_PDU ts_VPCD_CTRL_ATR := ts_VPCD_CTRL(VPCD_CTRL_ATR);
+template (value) VPCD_PDU ts_VPCD_DATA(template (value) octetstring data) := {
+	len := 0, //overwritten
+	u := {
+		data := data
+	}
+}
+
+template (present) VPCD_PDU tr_VPCD_CTRL(template (present) VPCD_CtrlCmd cmd) := {
+	len := ?,
+	u := {
+		ctrl := cmd
+	}
+}
+template (present) VPCD_PDU tr_VPCD_CTRL_OFF := tr_VPCD_CTRL(VPCD_CTRL_OFF);
+template (present) VPCD_PDU tr_VPCD_CTRL_ON := tr_VPCD_CTRL(VPCD_CTRL_ON);
+template (present) VPCD_PDU tr_VPCD_CTRL_RESET := tr_VPCD_CTRL(VPCD_CTRL_RESET);
+template (present) VPCD_PDU tr_VPCD_CTRL_ATR := tr_VPCD_CTRL(VPCD_CTRL_ATR);
+template (present) VPCD_PDU tr_VPCD_DATA(template (present) octetstring data) := {
+	len := ?,
+	u := {
+		data := data
+	}
+}
+
+external function enc_VPCD_PDU(in VPCD_PDU msg) return octetstring
+	with { extension "prototype(convert) encode(RAW)" };
+
+external function dec_VPCD_PDU(in octetstring msg) return VPCD_PDU
+	with { extension "prototype(convert) decode(RAW)" };
+
+
+
+} with { encode "RAW" };