Project

General

Profile

SIMtrace » History » Version 27

Anonymous, 02/19/2016 10:48 PM
Move the Hardware info to the Hardware page (try to remove duplication)

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 27 laforge
[[Image(SIMtrace/Hardware:simtrace_v09_top_mid.jpg, align=right,33%)]]
8 18 laforge
{{{
9
#!graphviz
10
digraph G{
11
  //rankdir = LR;
12
  Phone -> SIMtrace [label = "Flexi-PCB cable"];
13
  SIMtrace -> SIM;
14
  SIMtrace -> PC [label = "USB cable"];
15 1 laforge
16 18 laforge
  SIMtrace [ label = "SIMtrace hardware" ];
17
}
18
}}}
19
20
It works by utilizing the T=0 capable USART of the USB-attached AT91SAM7 microcontroller.
21
22 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.
23
The received bytes are sent via USB to the PC, where a program called {{{simtrace}}} on the PC gathers data from the USB device,
24
parses the APDUs and forwards them via [wiki:GSMTAP] to the [wiki:wireshark] protocol analyzer.
25
26
== Features ==
27
 * Completely passive scanner
28 17 laforge
 * RST and ATR detection
29 1 laforge
 * Auto-bauding with PPS / PTS support
30
 * Segmentation of APDUs
31
32
== TODO ==
33
 * Check for parity errors
34
 * Verify TCK / PCK check-bytes
35
36
== Hardware ==
37 17 laforge
38 1 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.
39 4 laforge
40 27 laforge
More details are available at [wiki:SIMtrace/Hardware]
41 4 laforge
42 1 laforge
== Firmware ==
43
44
The Firmware for the AT91SAM7S device was written by reusing a lot of the code for the [http://www.openpcd.org/ OpenPCD]
45
RFID reader.  
46
47 22 tsaitgaist
There is a {{{simtrace}}} Makefile target in the git://git.gnumonks.org/openpcd.git repository containing the latest firmware code.
48 1 laforge
49
Eventually, the OS part of OpenPCD/OpenPICC/SIMtrace will be separated.  At that point, the firmware source can become
50
part of simtrace.git
51 6 tsaitgaist
52
=== Building the firmware ===
53 5 laforge
54 22 tsaitgaist
Precondition: You need to set your PATH in a way that contains an arm-elf [wiki:toolchain], i.e. the same way that you build [wiki:GettingStarted OsmocomBB].
55 1 laforge
56
{{{
57 6 tsaitgaist
git clone git://git.gnumonks.org/openpcd.git
58
cd openpcd/firmware
59 21 tsaitgaist
make -f Makefile.dfu BOARD=SIMTRACE
60 6 tsaitgaist
make BOARD=SIMTRACE DEBUG=1 TARGET=main_simtrace
61
cat dfu.bin main_simtrace.bin > main_simtrace.samba
62
cd ../..
63 1 laforge
}}}
64
65 6 tsaitgaist
=== Firmware parts ===
66 1 laforge
67
The firmware build process creates two images:
68 6 tsaitgaist
 * dfu.bin -- the sam7dfu 2nd level bootloader. It implements the USB DFU (Device Firmware Upgrade) profile.
69
 * main_simtrace.bin -- the actual simtrace program. To be loaded via DFU, using [http://dfu-util.gnumonks.org/ dfu-util].
70
 * main_simtrace.samba -- [http://www.openpcd.org/Sam7dfu sam7dfu] + simtrace image. to be loaded via SAM-BA, using sam7utils (see below).
71 1 laforge
72 6 tsaitgaist
=== Flashing the firmware ===
73
74
after the firmware has been flashed, '''lsusb''' should show:
75
{{{
76
Bus 004 Device 005: ID 16c0:0762 VOTI
77
}}}
78
79 1 laforge
==== SAM-BA ====
80
81 6 tsaitgaist
The first time you flash the device, you will have to use the SAM-BA method using the '''main_simtrace.samba''' image.
82
83
To put the board into SAM-BA mode, use the following steps:
84
 * unplug the board
85 10 tsaitgaist
 * short TEST to VCC (3.3V) pin using a jumper. leave PA0,PA1,PA2 unconnected.
86 6 tsaitgaist
 * power up the board
87
 * wait 20s
88
 * unplug board
89
 * remove jumper
90
91
Now when the board is attached to USB, '''lsusb''' should show :
92
{{{
93
Bus 002 Device 015: ID 03eb:6124 Atmel Corp. at91sam SAMBA bootloader
94
}}}
95
96 23 tsaitgaist
note for v1.0p boards: sometimes the SAM-BA mode it not working.
97
This is the case if the 2 LEDs are on when powering up the board while VCC and TEST are shorted.
98
The reason in unknown yet, but there are several methods to correct this:
99
 * press the RESET button while powering up
100
 * touch PA0 (pin 48, on the right upper corner) with a piece of metal
101
 * short PA0 and PA1 (pin 48 and 47, next to ech other on the right upper corner)
102
As soon as the LEDs go off, the SAM-BA mode is working.
103
104 1 laforge
For more information about SAM-BA, please refer to the Atmel documentation on the AT91SAM7S component.
105
106 6 tsaitgaist
==== sam7utils ====
107 1 laforge
108 6 tsaitgaist
sam7utils will be used to flash the '''main_simtrace.samba''' image over SAM-BA.
109
{{{
110
sudo aptitude install libreadline-dev
111
wget http://www.openpcd.org/dl/sam7utils-0.2.1-bm.tar.bz2
112
tar xf sam7utils-*.tar.bz2
113
cd sam7utils
114
./configure --prefix=/usr/local
115
make
116
}}}
117 1 laforge
118 11 tsaitgaist
to flash the samba image using serial :
119
{{{
120
sudo ./sam7 -l /dev/ttyUSB0 --exec set_clock --exec unlock_regions --exec "flash ../openpcd/firmware/main_simtrace.samba"
121
}}}
122
to flash the samba image using libusb :
123
{{{
124
sudo ./sam7 --exec set_clock --exec unlock_regions --exec "flash ../openpcd/firmware/main_simtrace.samba"
125
}}}
126
127 25 tsaitgaist
if you want to use sam7 multiple times, remove the loaded module after each run:
128
{{{
129
sudo rmmod sam_ba
130
}}}
131
132 6 tsaitgaist
===== sam7utils for x86 =====
133
134 19 laforge
On x86, sam7utils will be compiled to communicate with the board using POSIX.
135 6 tsaitgaist
136
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 :
137
{{{
138
sudo rmmod usbserial
139
sudo modprobe usbserial vendor=0x03EB product=0x6124
140 1 laforge
}}}
141 11 tsaitgaist
142 6 tsaitgaist
Now replug board. It should map to /dev/ttyUSBx (use dmesg to know which).
143
144
===== sam7utils for amd64 =====
145 11 tsaitgaist
146 6 tsaitgaist
On amd64, sam7utils will be compiled to communicate with the board using libusb.
147 11 tsaitgaist
148
On ubuntu 10.10 & 11.04, the usb device 03eb:6124 is mapped on /dev/ttyACMx using the cdc_cam module.
149 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).
150
{{{
151
sudo rmmod cdc_acm
152
}}}
153 1 laforge
154 6 tsaitgaist
==== DFU ====
155
156 24 tsaitgaist
The SAM-BA mode is useful to recover from broken firmwares, but the DFU bootloader included into it is easier to use for updates.
157
You can upload the firmware over USB using dfu-util.
158
159
To get dfu-util:
160
{{{
161
sudo apt-get install dfu-util
162
}}}
163
164
To flash the firmware:
165
{{{
166
dfu-util -d 16c0:0762 -a0 -D ./main_simtrace.bin -R
167
}}}
168
dfu-util should reset the board and use the DFU bootloader. Try the command a second time if it did not work at first.
169
If this still does not work, power up the board while pressing the '''BOOTLOADER''' button.
170
171 1 laforge
172 5 laforge
== Host PC Software ==
173
174 6 tsaitgaist
The {{{simtrace}}} program is part of the git://git.osmocom.org/simtrace.git repository. It will bind to the USB device
175 5 laforge
and send GSMTAP frames using UDP/IPv4 to localhost:4729.
176 6 tsaitgaist
177 14 tsaitgaist
=== Preconditions ===
178 1 laforge
179 14 tsaitgaist
[wiki:libosmocore] and headers (simtrace_usb.h) from the firmware.
180
181
additional packages :
182 6 tsaitgaist
{{{
183 26 tsaitgaist
sudo apt-get install libusb-1.0-0-dev
184 6 tsaitgaist
}}}
185
186 7 tsaitgaist
=== Compiling it ===
187 1 laforge
188 6 tsaitgaist
Precondition:  [wiki:libosmocore] and headers (simtrace_usb.h) from the firmware.
189
190 1 laforge
{{{
191 14 tsaitgaist
git clone git://git.osmocom.org/simtrace.git
192 21 tsaitgaist
cd simtrace/host/
193 6 tsaitgaist
make
194
}}}
195
196
=== Using it ===
197
198
Simply start '''simtrace'''.
199 13 tsaitgaist
It will send the GSMTAP frames to UDP/IPv4 localhost:4729.
200 1 laforge
201
It will also print hexdumps of the frames to the console, looking like this:
202 6 tsaitgaist
{{{
203 1 laforge
sudo ./simtrace
204
APDU: (9):  a0 a4 00 00 02 6f 07 9f 0f
205
APDU: (22):  a0 c0 00 00 0f 00 00 00 09 6f 07 04 00 15 00 15 01 02 00 00 91 78
206
APDU: (9):  a0 a4 00 00 02 6f 38 9f 0f
207
APDU: (22):  a0 c0 00 00 0f 00 00 00 09 6f 38 04 00 15 00 55 01 02 00 00 91 78
208
APDU: (16):  a0 b0 00 00 09 ff 3f ff ff 00 00 3f 03 00 91 78
209
APDU: (9):  a0 a4 00 00 02 6f ad 9f 0f
210
APDU: (8):  a0 b0 00 00 01 00 91 78
211
APDU: (9):  a0 a4 00 00 02 6f 07 9f 0f
212
APDU: (16):  a0 b0 00 00 09 08 49 06 20 11 49 00 11 06 91 78
213
APDU: (9):  a0 a4 00 00 02 6f 7e 9f 0f
214
APDU: (18):  a0 b0 00 00 0b ff ff ff ff 64 f0 00 ff fe 00 03 91 78
215
APDU: (9):  a0 a4 00 00 02 6f 78 9f 0f
216
APDU: (9):  a0 b0 00 00 02 00 01 91 78
217
APDU: (9):  a0 a4 00 00 02 6f 74 9f 0f
218 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
219
APDU: (9):  a0 a4 00 00 02 6f 20 9f 0f
220
APDU: (16):  a0 b0 00 00 09 ff ff ff ff ff ff ff ff 07 91 78
221
APDU: (9):  a0 a4 00 00 02 6f 30 9f 0f
222 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
223
}}}
224
225
== Wireshark integration ==
226
227 6 tsaitgaist
There is an experimental patch, also part of the simtrace.git package.  You will have to apply this against the latest
228 1 laforge
[wiki:wireshark] developer version.
229
230
[[Image(wireshark-sim.png)]]
231
232
Protocol parsing is far from being complete, patches are always welcome!
Add picture from clipboard (Maximum size: 48.8 MB)