Project

General

Profile

SIMtrace » History » Version 18

laforge, 02/19/2016 10:48 PM
add image and update status

1 1 laforge
[[PageOutline]]
2
= Osmocom SIMtrace =
3
4
Osmocom SIMtrace is a software and hardware system for passively tracing SIM-ME communication between the SIM card and the mobile phone.
5
6 18 laforge
It looks a bit like this:
7
{{{
8
#!graphviz
9
digraph G{
10
  //rankdir = LR;
11
  Phone -> SIMtrace [label = "Flexi-PCB cable"];
12
  SIMtrace -> SIM;
13
  SIMtrace -> PC [label = "USB cable"];
14 1 laforge
15 18 laforge
  SIMtrace [ label = "SIMtrace hardware" ];
16
}
17
}}}
18
19
It works by utilizing the T=0 capable USART of the USB-attached AT91SAM7 microcontroller.
20
21 1 laforge
The USART passively receives the bytes as they are exchanged on the ISO 7816-3 / TS 11.11 interface between SIM and phone.
22
The received bytes are sent via USB to the PC, where a program called {{{simtrace}}} on the PC gathers data from the USB device,
23
parses the APDUs and forwards them via [wiki:GSMTAP] to the [wiki:wireshark] protocol analyzer.
24
25
== Features ==
26
 * Completely passive scanner
27 17 laforge
 * RST and ATR detection
28 1 laforge
 * Auto-bauding with PPS / PTS support
29
 * Segmentation of APDUs
30
31
== TODO ==
32
 * Check for parity errors
33
 * Verify TCK / PCK check-bytes
34
35
== Hardware ==
36 17 laforge
37 1 laforge
There is no ready-built hardware for this yet, but we're working on it; see [wiki:SIMtrace/Hardware]
38 15 laforge
39 18 laforge
The first implementations used an Olimex SAM7-P64 development board with some of the I/O lines hooked up to the mechanical SIM card adapters from [wiki:RebelSIM_Scanner]. If the RebelSIM scanner is used, connect the USB even if just the lines are used. It needs to be powered, else the real reader will often fail to initialize the card.
40 1 laforge
41 18 laforge
Right now we are in the prototpying phase for a custom circuit board which looks like this:
42
43
[[Image(SIMtrace/Hardware:simtrace_v09_top_mid.jpg, 33%)]]
44 1 laforge
=== Interconnections ===
45
46
The hardware schematics are very, very simple:
47
48
 * Connect SIM-RST with PA7
49
 * Connect SIM-I/O with PA6(TXD0) and PA1(TIOB0)
50
 * Connect SIM-CLK with PA2(SCK0) and PA4(TCLK0)
51
 * Connect SIM-GND with GND
52
53
=== Mode of operation ===
54
55 6 tsaitgaist
The USART of the AT91SAM7S is capable of T=0. The documentation only mentions it in clock-master mode, like you
56
would run it in a smart card reader to actively talk to a smart card. However, by using the USART input clock multiplexer,
57 1 laforge
you can use an externally-generated CLK like the one from the SIM card socket of the phone.
58
59 4 laforge
Unfortunately, the Rx Timeout feature of the USART is not working in T=0 mode, so I had to re-implement Rx timeout (waiting time)
60
handling by means of the TC (timer/counter) block 0.  Due to technical limitations, we will wait up to one byte (12 etu) more
61
than we should.
62
63 1 laforge
== Firmware ==
64
65
The Firmware for the AT91SAM7S device was written by reusing a lot of the code for the [http://www.openpcd.org/ OpenPCD]
66
RFID reader.  
67
68
There is a {{{simtrace}}} branch in the git://git.gnumonks.org/openpcd.git repository containing the latest firmware code.
69
70
Eventually, the OS part of OpenPCD/OpenPICC/SIMtrace will be separated.  At that point, the firmware source can become
71
part of simtrace.git
72
73 6 tsaitgaist
=== Toolchain ===
74
75
The toolchain gnuarm-4.0.2 can be used to crosscompile the firmware.
76
77
{{{
78
wget http://www.gnuarm.com/bu-2.16.1_gcc-4.0.2-c-c++_nl-1.14.0_gi-6.4_x86-64.tar.bz2
79
tar xf bu-*_gcc-*-c-c++_nl-*_gi-*_x86-64.tar.bz2
80
mv gnuarm-* ~/gnuarm
81
}}}
82
83
To be able to use the toolchain, add the crosscompilers to your PATH
84
85
{{{
86
export PATH=~/gnuarm/bin:$PATH
87
}}}
88
89 1 laforge
=== Building the firmware ===
90 5 laforge
91 1 laforge
Precondition: You need to set your PATH in a way that contains an arm-elf toolchain, i.e. the same way that you build [OsmocomBB].
92
93
{{{
94 6 tsaitgaist
git clone git://git.gnumonks.org/openpcd.git
95
cd openpcd/firmware
96
git checkout simtrace
97
make -f Makefile.dfu BOARD=OLIMEX
98
make BOARD=SIMTRACE DEBUG=1 TARGET=main_simtrace
99
cat dfu.bin main_simtrace.bin > main_simtrace.samba
100
cd ../..
101 1 laforge
}}}
102
103 6 tsaitgaist
=== Firmware parts ===
104 1 laforge
105
The firmware build process creates two images:
106 6 tsaitgaist
 * dfu.bin -- the sam7dfu 2nd level bootloader. It implements the USB DFU (Device Firmware Upgrade) profile.
107
 * main_simtrace.bin -- the actual simtrace program. To be loaded via DFU, using [http://dfu-util.gnumonks.org/ dfu-util].
108
 * main_simtrace.samba -- [http://www.openpcd.org/Sam7dfu sam7dfu] + simtrace image. to be loaded via SAM-BA, using sam7utils (see below).
109 1 laforge
110 6 tsaitgaist
=== Flashing the firmware ===
111
112
after the firmware has been flashed, '''lsusb''' should show:
113
{{{
114
Bus 004 Device 005: ID 16c0:0762 VOTI
115
}}}
116
117 1 laforge
==== SAM-BA ====
118
119 6 tsaitgaist
The first time you flash the device, you will have to use the SAM-BA method using the '''main_simtrace.samba''' image.
120
121
To put the board into SAM-BA mode, use the following steps:
122
 * unplug the board
123 10 tsaitgaist
 * short TEST to VCC (3.3V) pin using a jumper. leave PA0,PA1,PA2 unconnected.
124 6 tsaitgaist
 * power up the board
125
 * wait 20s
126
 * unplug board
127
 * remove jumper
128
129
Now when the board is attached to USB, '''lsusb''' should show :
130
{{{
131
Bus 002 Device 015: ID 03eb:6124 Atmel Corp. at91sam SAMBA bootloader
132
}}}
133
134 1 laforge
For more information about SAM-BA, please refer to the Atmel documentation on the AT91SAM7S component.
135
136 6 tsaitgaist
==== sam7utils ====
137 1 laforge
138 6 tsaitgaist
sam7utils will be used to flash the '''main_simtrace.samba''' image over SAM-BA.
139
{{{
140
sudo aptitude install libreadline-dev
141
wget http://www.openpcd.org/dl/sam7utils-0.2.1-bm.tar.bz2
142
tar xf sam7utils-*.tar.bz2
143
cd sam7utils
144
./configure --prefix=/usr/local
145
make
146
}}}
147 1 laforge
148 11 tsaitgaist
to flash the samba image using serial :
149
{{{
150
sudo ./sam7 -l /dev/ttyUSB0 --exec set_clock --exec unlock_regions --exec "flash ../openpcd/firmware/main_simtrace.samba"
151
}}}
152
to flash the samba image using libusb :
153
{{{
154
sudo ./sam7 --exec set_clock --exec unlock_regions --exec "flash ../openpcd/firmware/main_simtrace.samba"
155
}}}
156
157 6 tsaitgaist
===== sam7utils for x86 =====
158
159
On x86, sam7utils will be compile to communicate with the board using POSIX.
160
161
The board should be attached to a node. On ubuntu 10.10, the usb device 03eb:6124 is mapped on /dev/ttyACM0 using the cdc_cam module. If not mapped, use usbserial :
162
{{{
163
sudo rmmod usbserial
164
sudo modprobe usbserial vendor=0x03EB product=0x6124
165 1 laforge
}}}
166 11 tsaitgaist
167 6 tsaitgaist
Now replug board. It should map to /dev/ttyUSBx (use dmesg to know which).
168
169
===== sam7utils for amd64 =====
170 11 tsaitgaist
171 6 tsaitgaist
On amd64, sam7utils will be compiled to communicate with the board using libusb.
172 11 tsaitgaist
173
On ubuntu 10.10 & 11.04, the usb device 03eb:6124 is mapped on /dev/ttyACMx using the cdc_cam module.
174 6 tsaitgaist
Remove it while the board is plugged, so sam7utils is able to communicate with it (using libusb for 10.10 and serial for 11.04).
175
{{{
176
sudo rmmod cdc_acm
177
}}}
178 1 laforge
179 6 tsaitgaist
==== DFU ====
180
181 18 laforge
TODO: Document this.
182 1 laforge
183 5 laforge
== Host PC Software ==
184
185 6 tsaitgaist
The {{{simtrace}}} program is part of the git://git.osmocom.org/simtrace.git repository. It will bind to the USB device
186 5 laforge
and send GSMTAP frames using UDP/IPv4 to localhost:4729.
187 6 tsaitgaist
188 14 tsaitgaist
=== Preconditions ===
189 1 laforge
190 14 tsaitgaist
[wiki:libosmocore] and headers (simtrace_usb.h) from the firmware.
191
192
additional packages :
193 6 tsaitgaist
{{{
194 14 tsaitgaist
sudo apt-get install libusb-dev
195 6 tsaitgaist
}}}
196
197 7 tsaitgaist
=== Compiling it ===
198 1 laforge
199 6 tsaitgaist
Precondition:  [wiki:libosmocore] and headers (simtrace_usb.h) from the firmware.
200
201
{{{
202 14 tsaitgaist
git clone git://git.osmocom.org/simtrace.git
203 6 tsaitgaist
cd simtrace/at91sam7/host/
204
make
205
}}}
206
207
=== Using it ===
208
209
Simply start '''simtrace'''.
210 13 tsaitgaist
It will send the GSMTAP frames to UDP/IPv4 localhost:4729.
211 1 laforge
212
It will also print hexdumps of the frames to the console, looking like this:
213 6 tsaitgaist
{{{
214 1 laforge
sudo ./simtrace
215
APDU: (9):  a0 a4 00 00 02 6f 07 9f 0f
216
APDU: (22):  a0 c0 00 00 0f 00 00 00 09 6f 07 04 00 15 00 15 01 02 00 00 91 78
217
APDU: (9):  a0 a4 00 00 02 6f 38 9f 0f
218
APDU: (22):  a0 c0 00 00 0f 00 00 00 09 6f 38 04 00 15 00 55 01 02 00 00 91 78
219
APDU: (16):  a0 b0 00 00 09 ff 3f ff ff 00 00 3f 03 00 91 78
220
APDU: (9):  a0 a4 00 00 02 6f ad 9f 0f
221
APDU: (8):  a0 b0 00 00 01 00 91 78
222
APDU: (9):  a0 a4 00 00 02 6f 07 9f 0f
223
APDU: (16):  a0 b0 00 00 09 08 49 06 20 11 49 00 11 06 91 78
224
APDU: (9):  a0 a4 00 00 02 6f 7e 9f 0f
225
APDU: (18):  a0 b0 00 00 0b ff ff ff ff 64 f0 00 ff fe 00 03 91 78
226
APDU: (9):  a0 a4 00 00 02 6f 78 9f 0f
227
APDU: (9):  a0 b0 00 00 02 00 01 91 78
228
APDU: (9):  a0 a4 00 00 02 6f 74 9f 0f
229 2 laforge
APDU: (23):  a0 b0 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 91 78
230
APDU: (9):  a0 a4 00 00 02 6f 20 9f 0f
231
APDU: (16):  a0 b0 00 00 09 ff ff ff ff ff ff ff ff 07 91 78
232
APDU: (9):  a0 a4 00 00 02 6f 30 9f 0f
233 1 laforge
APDU: (22):  a0 c0 00 00 0f 00 00 00 f0 6f 30 04 00 11 00 55 01 02 00 00 91 78
234
}}}
235
236
== Wireshark integration ==
237
238 6 tsaitgaist
There is an experimental patch, also part of the simtrace.git package.  You will have to apply this against the latest
239 1 laforge
[wiki:wireshark] developer version.
240
241
[[Image(wireshark-sim.png)]]
242
243
Protocol parsing is far from being complete, patches are always welcome!
Add picture from clipboard (Maximum size: 48.8 MB)