aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2019-11-22 00:35:52 +0100
committerHarald Welte <laforge@osmocom.org>2019-11-22 22:53:40 +0100
commit619b2a654737951d2ddac94b156ef0e0dbfcae81 (patch)
treec649889384a5448cdd543063fa6dc2fd46c41d7a /library
parent04c7a3d669840aa3acd5f626adef00e79830a65f (diff)
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
Diffstat (limited to 'library')
-rw-r--r--library/VPCD_Adapter.ttcn73
-rw-r--r--library/VPCD_CodecPort.ttcn64
-rw-r--r--library/VPCD_CodecPort_CtrlFunct.ttcn52
-rw-r--r--library/VPCD_CodecPort_CtrlFunctDef.cc66
-rw-r--r--library/VPCD_Types.ttcn75
5 files changed, 330 insertions, 0 deletions
diff --git a/library/VPCD_Adapter.ttcn b/library/VPCD_Adapter.ttcn
new file mode 100644
index 00000000..289be06e
--- /dev/null
+++ b/library/VPCD_Adapter.ttcn
@@ -0,0 +1,73 @@
+module VPCD_Adapter {
+
+/* VPCD Adapter layer, sitting on top of VPCD_CodecPort.
+ * test suites can 'inherit' in order to have a VPCD connection to the IUT which they're testing
+ *
+ * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
+ * All rights reserved.
+ *
+ * Released under the terms of GNU General Public License, Version 2 or
+ * (at your option) any later version.
+ */
+
+import from VPCD_Types all;
+import from VPCD_CodecPort all;
+import from VPCD_CodecPort_CtrlFunct all;
+import from IPL4asp_Types all;
+import from IPL4asp_PortType all;
+import from Socket_API_Definitions all;
+
+modulepar {
+ integer mp_vpcd_port := 35963;
+ charstring mp_vpcd_host := "127.0.0.1";
+}
+
+type component VPCD_Adapter_CT {
+ port VPCD_CODEC_PT VPCD;
+ var integer g_vpcd_conn_id;
+};
+
+
+private function f_set_tcp_segmentation() runs on VPCD_Adapter_CT {
+ /* Set function for dissecting the binary stream into packets */
+ var f_IPL4_getMsgLen vl_f := refers(f_IPL4_fixedMsgLen);
+ /* Offset: 0, size of length: 2, delta: 0, multiplier: 1, big-endian: 0 */
+ VPCD_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(VPCD, g_vpcd_conn_id, vl_f, {0, 2, 2, 1, 0});
+}
+
+function f_connect(charstring remote_host := mp_vpcd_host, integer remote_port := mp_vpcd_port)
+runs on VPCD_Adapter_CT {
+ var IPL4asp_Types.Result res;
+ map(self:VPCD, system:VPCD);
+ res := VPCD_CodecPort_CtrlFunct.f_IPL4_connect(VPCD, remote_host, remote_port, "", 0, 0,
+ { tcp := {} });
+ if (not ispresent(res.connId)) {
+ setverdict(fail, "Could not connect to VPCD at ", remote_host, ":", remote_port,
+ ", check your configuration");
+ mtc.stop;
+ }
+ g_vpcd_conn_id := res.connId;
+ f_set_tcp_segmentation();
+}
+
+function f_bind(charstring local_host, IPL4asp_Types.PortNumber local_port)
+runs on VPCD_Adapter_CT {
+ var IPL4asp_Types.Result res;
+ map(self:VPCD, system:VPCD);
+ res := VPCD_CodecPort_CtrlFunct.f_IPL4_listen(VPCD, local_host, local_port, { tcp:={} });
+ g_vpcd_conn_id := res.connId;
+ f_set_tcp_segmentation();
+}
+
+function f_vpcd_send(template (value) VPCD_PDU pdu) runs on VPCD_Adapter_CT {
+ VPCD.send(ts_VPCD_Send(g_vpcd_conn_id, pdu));
+}
+
+function f_vpcd_exp(template VPCD_PDU exp) runs on VPCD_Adapter_CT return VPCD_PDU {
+ var VPCD_RecvFrom rf;
+ VPCD.receive(tr_VPCD_Recv(g_vpcd_conn_id, exp)) -> value rf;
+ return rf.msg;
+}
+
+
+}
diff --git a/library/VPCD_CodecPort.ttcn b/library/VPCD_CodecPort.ttcn
new file mode 100644
index 00000000..a9ae97fd
--- /dev/null
+++ b/library/VPCD_CodecPort.ttcn
@@ -0,0 +1,64 @@
+module VPCD_CodecPort {
+
+/* Simple VPCD Codec Port, translating between raw TCP octetstring payload
+ * towards the IPL4asp port provider, and VPCD primitives
+ * which carry the decoded VPCD data types as payload.
+ *
+ * (C) 2018 by Harald Welte <laforge@gnumonks.org>
+ * All rights reserved.
+ *
+ * Released under the terms of GNU General Public License, Version 2 or
+ * (at your option) any later version.
+ */
+
+
+import from IPL4asp_PortType all;
+import from IPL4asp_Types all;
+import from VPCD_Types all;
+
+type record VPCD_RecvFrom {
+ ConnectionId connId,
+ VPCD_PDU msg
+}
+
+type record VPCD_Send {
+ ConnectionId connId,
+ VPCD_PDU msg
+}
+
+template (value) VPCD_Send ts_VPCD_Send(ConnectionId conn_id, template (value) VPCD_PDU msg) := {
+ connId := conn_id,
+ msg := msg
+}
+
+template VPCD_RecvFrom tr_VPCD_Recv(template ConnectionId conn_id, template VPCD_PDU msg) := {
+ connId := conn_id,
+ msg := msg
+}
+
+private function IPL4_to_VPCD_RecvFrom(in ASP_RecvFrom pin, out VPCD_RecvFrom pout) {
+ pout.connId := pin.connId;
+ pout.msg := dec_VPCD_PDU(pin.msg);
+} with { extension "prototype(fast)" }
+
+private function VPCD_to_IPL4_Send(in VPCD_Send pin, out ASP_Send pout) {
+ pout.connId := pin.connId;
+ pout.proto := { tcp := {} };
+ pout.msg := enc_VPCD_PDU(pin.msg);
+} with { extension "prototype(fast)" }
+
+type port VPCD_CODEC_PT message {
+ out VPCD_Send;
+ in VPCD_RecvFrom,
+ ASP_ConnId_ReadyToRelease,
+ ASP_Event;
+} with { extension "user IPL4asp_PT
+ out(VPCD_Send -> ASP_Send: function(VPCD_to_IPL4_Send))
+ in(ASP_RecvFrom -> VPCD_RecvFrom: function(IPL4_to_VPCD_RecvFrom);
+ ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
+ ASP_Event -> ASP_Event: simple)"
+}
+
+
+
+}
diff --git a/library/VPCD_CodecPort_CtrlFunct.ttcn b/library/VPCD_CodecPort_CtrlFunct.ttcn
new file mode 100644
index 00000000..62b79c5c
--- /dev/null
+++ b/library/VPCD_CodecPort_CtrlFunct.ttcn
@@ -0,0 +1,52 @@
+module VPCD_CodecPort_CtrlFunct {
+
+ import from VPCD_CodecPort all;
+ import from IPL4asp_Types all;
+
+ external function f_IPL4_listen(
+ inout VPCD_CODEC_PT portRef,
+ in HostName locName,
+ in PortNumber locPort,
+ in ProtoTuple proto,
+ in OptionList options := {}
+ ) return Result;
+
+ external function f_IPL4_connect(
+ inout VPCD_CODEC_PT portRef,
+ in HostName remName,
+ in PortNumber remPort,
+ in HostName locName,
+ in PortNumber locPort,
+ in ConnectionId connId,
+ in ProtoTuple proto,
+ in OptionList options := {}
+ ) return Result;
+
+ external function f_IPL4_close(
+ inout VPCD_CODEC_PT portRef,
+ in ConnectionId id,
+ in ProtoTuple proto := { unspecified := {} }
+ ) return Result;
+
+ external function f_IPL4_setUserData(
+ inout VPCD_CODEC_PT portRef,
+ in ConnectionId id,
+ in UserData userData
+ ) return Result;
+
+ external function f_IPL4_getUserData(
+ inout VPCD_CODEC_PT portRef,
+ in ConnectionId id,
+ out UserData userData
+ ) return Result;
+
+ external function f_IPL4_setGetMsgLen(
+ inout VPCD_CODEC_PT portRef,
+ in ConnectionId id,
+ inout f_IPL4_getMsgLen f,
+ in ro_integer msgLenArgs
+ );
+
+
+}
+
diff --git a/library/VPCD_CodecPort_CtrlFunctDef.cc b/library/VPCD_CodecPort_CtrlFunctDef.cc
new file mode 100644
index 00000000..74c1176b
--- /dev/null
+++ b/library/VPCD_CodecPort_CtrlFunctDef.cc
@@ -0,0 +1,66 @@
+#include "IPL4asp_PortType.hh"
+#include "VPCD_CodecPort.hh"
+#include "IPL4asp_PT.hh"
+
+namespace VPCD__CodecPort__CtrlFunct {
+
+ IPL4asp__Types::Result f__IPL4__listen(
+ VPCD__CodecPort::VPCD__CODEC__PT& portRef,
+ const IPL4asp__Types::HostName& locName,
+ const IPL4asp__Types::PortNumber& locPort,
+ const IPL4asp__Types::ProtoTuple& proto,
+ const IPL4asp__Types::OptionList& options)
+ {
+ return f__IPL4__PROVIDER__listen(portRef, locName, locPort, proto, options);
+ }
+
+ IPL4asp__Types::Result f__IPL4__connect(
+ VPCD__CodecPort::VPCD__CODEC__PT& portRef,
+ const IPL4asp__Types::HostName& remName,
+ const IPL4asp__Types::PortNumber& remPort,
+ const IPL4asp__Types::HostName& locName,
+ const IPL4asp__Types::PortNumber& locPort,
+ const IPL4asp__Types::ConnectionId& connId,
+ const IPL4asp__Types::ProtoTuple& proto,
+ const IPL4asp__Types::OptionList& options)
+ {
+ return f__IPL4__PROVIDER__connect(portRef, remName, remPort,
+ locName, locPort, connId, proto, options);
+ }
+
+ IPL4asp__Types::Result f__IPL4__close(
+ VPCD__CodecPort::VPCD__CODEC__PT& portRef,
+ const IPL4asp__Types::ConnectionId& connId,
+ const IPL4asp__Types::ProtoTuple& proto)
+ {
+ return f__IPL4__PROVIDER__close(portRef, connId, proto);
+ }
+
+ IPL4asp__Types::Result f__IPL4__setUserData(
+ VPCD__CodecPort::VPCD__CODEC__PT& portRef,
+ const IPL4asp__Types::ConnectionId& connId,
+ const IPL4asp__Types::UserData& userData)
+ {
+ return f__IPL4__PROVIDER__setUserData(portRef, connId, userData);
+ }
+
+ IPL4asp__Types::Result f__IPL4__getUserData(
+ VPCD__CodecPort::VPCD__CODEC__PT& portRef,
+ const IPL4asp__Types::ConnectionId& connId,
+ IPL4asp__Types::UserData& userData)
+ {
+ return f__IPL4__PROVIDER__getUserData(portRef, connId, userData);
+ }
+
+ void f__IPL4__setGetMsgLen(
+ VPCD__CodecPort::VPCD__CODEC__PT& portRef,
+ const IPL4asp__Types::ConnectionId& connId,
+ Socket__API__Definitions::f__getMsgLen& f,
+ const Socket__API__Definitions::ro__integer& msgLenArgs)
+ {
+ return f__IPL4__PROVIDER__setGetMsgLen(portRef, connId, f, msgLenArgs);
+ }
+
+
+}
+
diff --git a/library/VPCD_Types.ttcn b/library/VPCD_Types.ttcn
new file mode 100644
index 00000000..5caa0be6
--- /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" };