Project

General

Profile

Cardem » History » Version 1

tsaitgaist, 09/10/2019 02:13 PM
created

1 1 tsaitgaist
h1. Cardem
2
3
Card emulation (cardem for short) is a firmware for the SIMtrace v2 board allowing to emulate cards (e.g. SIM).
4
You then can leave the card adapter cable in the reader (e.g. phone), and have the actual card outside.
5
This allows to easily change or reprogram the card without having to touch the phone.
6
7
This functionality is already implemented and working on sysmoQMOD board.
8
It is not also available for SIMtrace v2 boards.
9
*This is a beta firmware and still in development*.
10
See [[Cardem#Limitations|limitations]] for known limitations and issues.
11
12
h2. Flashing
13
14
You can download the beta firmware for the SIMtrace v2 board here: attachment:simtrace-cardem-flash.bin.
15
16
To flash the firmware on the board:
17
<pre>
18
dfu-util --device 1d50:60e3 --cfg 1 --alt 1 --reset --download simtrace-cardem-flash.bin
19
</pre>
20
21
For more details about the flashing procedure, read [[Flashing#SIMtrace2-board|this article]].
22
23
h2. Software
24
25
With the cardem firmware, the SIMtrace v2 board mainly forwards the ISO 7816 card communication over USB.
26
A software on the host must receive the APDU requests and send the corresponding APDU response.
27
There are several software available to do that.
28
Since the USB messages are "specified":https://git.osmocom.org/simtrace2/tree/firmware/libcommon/include/simtrace_prot.h and the software is "open source":https://git.osmocom.org/simtrace2/tree/host, you could implement your own APDU handler.
29
30
h3. simtrace2-remsim
31
32
@simtrace2-remsim@ is the simplest solution.
33
If forwards the APDU request/response to/from a PCSC card reader.
34
35
To get @simtrace2-remsim@:
36
* Install required packages to compile the software:
37
<pre>
38
sudo apt-get install libusb-1.0-0-dev libosmocore-dev libpcsclite-dev
39
</pre>
40
* Get and compile the software:
41
<pre>
42
git clone git://git.osmocom.org/simtrace2.git
43
cd simtrace2/host/
44
make
45
</pre>
46
47
To use @simtrace2-remsim@:
48
# power of phone
49
# insert card adapter cable into phone
50
# insert card adapter cable SIMtrace v2 board
51
# plug SIMtrace v2 board in host computer USB port
52
# connect external card reader to host (any USB CCID reader should do the job)
53
# install PCSC daemon (only need to be done once)
54
<pre>
55
sudo apt install pcscd
56
</pre>
57
# ensure the PCSC daemon is started
58
<pre>
59
sudo systemctl start pcscd
60
</pre>
61
# install tool to check reader status
62
<pre>
63
sudo systemctl start pcsc-tools
64
</pre>
65
# check if the card is detected by the reader (use CTRL-C to exit)
66
<pre>
67
pcsc_scan 
68
69
Using reader plug'n play mechanism
70
Scanning present readers...
71
0: OMNIKEY 6321 CLi USB (OKCM0030506091345044320140749730) 00 00
72
 
73
Tue Sep 10 16:03:49 2019
74
 Reader 0: OMNIKEY 6321 CLi USB (OKCM0030506091345044320140749730) 00 00
75
  Event number: 0
76
  Card state: Card inserted, 
77
  ATR: 3B 9F 94 80 1F C7 80 31 E0 73 FE 21 1B 67 01 00 00 04 4D 02 01 99
78
</pre>
79
# get SIMtrace USB path (this step will soon be not required anymore)
80
<pre>
81
dfu-util -l
82
83
...
84
Found Runtime: [1d50:60e3] ver=0002, devnum=59, cfg=1, intf=1, path="1-2.2", alt=0, name="UNKNOWN", serial="UNKNOWN"
85
</pre>
86
# start @simtrace2-remsim@ with corresponding USB path (here 1-2.2)
87
<pre>
88
./simtrace2-remsim --usb-vendor 1d50 --usb-product 60e3 --usb-path 1-2.2 --usb-config 1
89
90
(C) 2010-2017, Harald Welte <laforge@gnumonks.org>
91
(C) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
92
93
SCardEstablishContext: OK
94
95
SCardListReaders: OK
96
97
SCardConnect: OK
98
99
<- 01 05 00 00 00 00 09 00 01 
100
<- 02 02 00 00 00 00 09 00 01 
101
<= cardem_request_set_atr(3b 00 )
102
<- 01 02 00 00 00 00 0b 00 02 3b 00 
103
<- 02 01 00 00 00 00 0b 00 02 2c 01 
104
Entering main loop
105
</pre>
106
# now you can power on the phone (only after @simtrace2-remsim@ is started since @simtrace2-remsim@ can't tell the phone a card has been inserted). you should also see some APDU traffic
107
<pre>
108
URB: 01 06 00 00 00 00 13 00 01 00 00 00 05 00 a0 a4 00 00 02 
109
-> 01 06 00 00 00 00 13 00 01 00 00 00 05 00 a0 a4 00 00 02 
110
=> DATA: flags=1, a0 a4 00 00 02 : CLA=a0 INS=a4 P1=00 P2=00 P3=02; case=4, lc=2(0), le=0(0)
111
<= cardem_request_pb_and_rx(a4, 2)
112
<- 01 01 00 00 00 00 0f 00 08 00 00 00 01 00 a4 
113
URB: 01 06 00 00 00 00 10 00 02 00 00 00 02 00 7f 20 
114
-> 01 06 00 00 00 00 10 00 02 00 00 00 02 00 7f 20 
115
=> DATA: flags=2, 7f 20 : CLA=a0 INS=a4 P1=00 P2=00 P3=02; case=4, lc=2(2), le=0(0)
116
TX: a0 a4 00 00 02 7f 20 
117
SCardEndTransaction: OK
118
119
RX: 9f 17 
120
SW=0x9f17, len_rx=0
121
<= cardem_request_sw_tx(9f 17)
122
<- 01 01 00 00 00 00 10 00 06 00 00 00 02 00 9f 17 
123
URB: 01 06 00 00 00 00 13 00 01 00 00 00 05 00 a0 f2 00 00 17 
124
-> 01 06 00 00 00 00 13 00 01 00 00 00 05 00 a0 f2 00 00 17 
125
=> DATA: flags=1, a0 f2 00 00 17 : CLA=a0 INS=f2 P1=00 P2=00 P3=17; case=2, lc=0(0), le=23(0)
126
TX: a0 f2 00 00 17 
127
SCardEndTransaction: OK
128
</pre>
129
130
h2. Limitations
131
132
Here are the known limitations:
133
* there is no way for SIMtrace to tell the reader that a new card has been inserted. There is no specified way to do it (e.g. in ISO 7816 standard). This is generally done inside the reader hardware by a mechanical switch. The only way around is to restarted the reader (e.g. phone).
134
* the cardem is currently a separate firmware. it is planned to combine it with the trace firmware (the software will then select the right functionality)
135
* the firmware ignores the sent ATR (sent by the software, from the card to forward). this is to prevent the reader from switching to a yet untested baud rate
136
* the error messages returned by @simtrace2-remsim@ are not very useful
137
* @simtrace2-remsim@ does not automatically reconnect to the SIMtrace board when the hardware is reset
138
* you have to specify the USB path to @simtrace2-remsim@
139
* no long term tests have been performed (this is already planned)
140
* you can't use the card reader built in SIMtrace.
141
142
We are currently working on resolving these issues.
143
If you found yet unknown issues, you can report them to the main developer at kredon AT sysmocom DOT de.
144
If possible, please also attach the corresponding debug serial output. To get the serial output, connect a USB to UART cable either to the 2.5 mm stereo headphone connector (tip = TX, ring = RX, sleeve = GND) or the nearby DEBUG port (pin 1 = GND, pin 4 = TX, pin 5 = RX). Open the serial port with the following configuration: 921600 8N1.
Add picture from clipboard (Maximum size: 48.8 MB)