simtrace.py: Use mitm.py in phone and mitm mode
diff --git a/usb_application/mitm.py b/usb_application/mitm.py
index 4ae7b0e..0c9efd8 100755
--- a/usb_application/mitm.py
+++ b/usb_application/mitm.py
@@ -2,6 +2,7 @@
 import usb.util
 
 from ccid_raw import SmartcardConnection
+from smartcard_emulator import SmartCardEmulator
 
 from contextlib import closing
 
@@ -43,9 +44,13 @@
     print("WR: ", HEX(resp))
     dev.write(PHONE_WR, resp, 10)
 
-def do_mitm():
+def do_mitm(sim_emul=True):
     dev = find_dev()
-    with closing(SmartcardConnection()) as sm_con:
+    if sim_emul == True:
+        my_class = SmartCardEmulator
+    else:
+        my_class = SmartcardConnection
+    with closing(my_class()) as sm_con:
         atr = sm_con.getATR()
 
         apdus = []
diff --git a/usb_application/simtrace.py b/usb_application/simtrace.py
index 1cb9c7c..4b8f3c7 100755
--- a/usb_application/simtrace.py
+++ b/usb_application/simtrace.py
@@ -4,16 +4,11 @@
 import sniffer
 import ccid
 import ccid_select
-import phone
 import mitm
 
 import usb.core
 import usb.util
-
-import hashlib
-import os
-import random
-import re
+import sys
 import time
 
 cmd1 = {0x00, 0x10, 0x00, 0x00}
@@ -91,9 +86,9 @@
     if args.select_file is True:
         ccid_select.select()
     if args.phone is True:
-        phone.emulate_sim()
+        mitm.do_mitm(sim_emul=True)
     if args.mitm is True:
-        mitm.do_mitm()
+        mitm.do_mitm(sim_emul=False)
 
     return
 
diff --git a/usb_application/smartcard_emulator.py b/usb_application/smartcard_emulator.py
new file mode 100644
index 0000000..aa40125
--- /dev/null
+++ b/usb_application/smartcard_emulator.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+import constants
+import array
+
+INS = 1
+CNT = 4
+
+class SmartCardEmulator:
+    def getATR(self):
+        return array.array('B', constants.ATR_SYSMOCOM2)
+
+    def send_receive_cmd(self, cmd):
+        if len(cmd) == 5:         # Received cmd from phone
+            if cmd[INS] == 0xA4:
+                resp = [cmd[INS]]       # Respond with INS byte
+            elif cmd[INS] == 0xC0:
+                data = [0x00, 0x00, 0x00, 0x00,
+                        0x7F, 0x20, 0x02, 0x00,
+                        0x00, 0x00, 0x00, 0x00,
+                        0x09, 0x91, 0x00, 0x17,
+                        0x04, 0x00, 0x83, 0x8A,
+                        0x83, 0x8A]
+                SW = [0x90, 0x00]
+                resp = [cmd[INS]] + data + SW       # Respond with INS byte
+                #state = WAIT_RST
+            else:
+                print("Unknown cmd")
+                resp = [0x60, 0x00]
+        elif len(cmd) == 2:
+            resp = [0x9F, 0x16]
+        else:
+            resp = [0x60, 0x00]
+
+        print("Cmd, resp: ")
+        print("".join("%02x " % b for b in cmd))
+        print("".join("%02x " % b for b in resp))
+
+        return array.array('B', resp)
+
+    def reset_card():
+        pass
+
+    def close(self):
+        pass